@wordpress/editor 14.49.1 → 14.51.1-next.v.202607070741.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 (262) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/components/collab-sidebar/format.cjs +83 -0
  3. package/build/components/collab-sidebar/format.cjs.map +7 -0
  4. package/build/components/collab-sidebar/hooks.cjs +117 -16
  5. package/build/components/collab-sidebar/hooks.cjs.map +2 -2
  6. package/build/components/collab-sidebar/index.cjs +18 -2
  7. package/build/components/collab-sidebar/index.cjs.map +2 -2
  8. package/build/components/collab-sidebar/note-highlight-styles.cjs +67 -0
  9. package/build/components/collab-sidebar/note-highlight-styles.cjs.map +7 -0
  10. package/build/components/collab-sidebar/utils.cjs +139 -0
  11. package/build/components/collab-sidebar/utils.cjs.map +2 -2
  12. package/build/components/collaborators-presence/use-collaborator-notifications.cjs +55 -30
  13. package/build/components/collaborators-presence/use-collaborator-notifications.cjs.map +2 -2
  14. package/build/components/commands/index.cjs +99 -3
  15. package/build/components/commands/index.cjs.map +2 -2
  16. package/build/components/document-bar/index.cjs +28 -34
  17. package/build/components/document-bar/index.cjs.map +2 -2
  18. package/build/components/entities-saved-states/index.cjs +1 -4
  19. package/build/components/entities-saved-states/index.cjs.map +2 -2
  20. package/build/components/header/index.cjs +1 -8
  21. package/build/components/header/index.cjs.map +2 -2
  22. package/build/components/media-categories/index.cjs +92 -6
  23. package/build/components/media-categories/index.cjs.map +2 -2
  24. package/build/components/page-attributes/parent.cjs +0 -1
  25. package/build/components/page-attributes/parent.cjs.map +2 -2
  26. package/build/components/post-author/combobox.cjs +0 -1
  27. package/build/components/post-author/combobox.cjs.map +2 -2
  28. package/build/components/post-author/select.cjs +0 -1
  29. package/build/components/post-author/select.cjs.map +2 -2
  30. package/build/components/post-preview-button/index.cjs +29 -2
  31. package/build/components/post-preview-button/index.cjs.map +2 -2
  32. package/build/components/post-publish-panel/maybe-upload-media.cjs +15 -26
  33. package/build/components/post-publish-panel/maybe-upload-media.cjs.map +3 -3
  34. package/build/components/post-revisions-preview/revisions-slider.cjs +3 -1
  35. package/build/components/post-revisions-preview/revisions-slider.cjs.map +2 -2
  36. package/build/components/post-taxonomies/flat-term-selector.cjs +0 -1
  37. package/build/components/post-taxonomies/flat-term-selector.cjs.map +2 -2
  38. package/build/components/post-taxonomies/hierarchical-term-selector.cjs +0 -2
  39. package/build/components/post-taxonomies/hierarchical-term-selector.cjs.map +2 -2
  40. package/build/components/post-template/classic-theme.cjs +0 -1
  41. package/build/components/post-template/classic-theme.cjs.map +2 -2
  42. package/build/components/preferences-modal/index.cjs +54 -28
  43. package/build/components/preferences-modal/index.cjs.map +2 -2
  44. package/build/components/preview-dropdown/index.cjs +38 -9
  45. package/build/components/preview-dropdown/index.cjs.map +3 -3
  46. package/build/components/provider/use-block-editor-settings.cjs +23 -9
  47. package/build/components/provider/use-block-editor-settings.cjs.map +3 -3
  48. package/build/components/resizable-editor/index.cjs +54 -9
  49. package/build/components/resizable-editor/index.cjs.map +3 -3
  50. package/build/components/sidebar/dataform-post-summary.cjs +5 -1
  51. package/build/components/sidebar/dataform-post-summary.cjs.map +3 -3
  52. package/build/components/sidebar/index.cjs +29 -38
  53. package/build/components/sidebar/index.cjs.map +3 -3
  54. package/build/components/sidebar/post-summary.cjs +0 -13
  55. package/build/components/sidebar/post-summary.cjs.map +3 -3
  56. package/build/components/visual-editor/index.cjs +15 -11
  57. package/build/components/visual-editor/index.cjs.map +3 -3
  58. package/build/dataviews/store/private-actions.cjs +24 -19
  59. package/build/dataviews/store/private-actions.cjs.map +2 -2
  60. package/build/store/actions.cjs +5 -3
  61. package/build/store/actions.cjs.map +2 -2
  62. package/build/store/constants.cjs +26 -0
  63. package/build/store/constants.cjs.map +2 -2
  64. package/build/store/private-actions.cjs +25 -18
  65. package/build/store/private-actions.cjs.map +3 -3
  66. package/build/store/private-selectors.cjs +5 -0
  67. package/build/store/private-selectors.cjs.map +2 -2
  68. package/build/store/reducer.cjs +6 -6
  69. package/build/store/reducer.cjs.map +2 -2
  70. package/build/store/selectors.cjs +3 -1
  71. package/build/store/selectors.cjs.map +2 -2
  72. package/build/utils/device-type.cjs +52 -0
  73. package/build/utils/device-type.cjs.map +7 -0
  74. package/build/utils/media-sideload-from-url/index.cjs +63 -0
  75. package/build/utils/media-sideload-from-url/index.cjs.map +7 -0
  76. package/build-module/components/collab-sidebar/format.mjs +57 -0
  77. package/build-module/components/collab-sidebar/format.mjs.map +7 -0
  78. package/build-module/components/collab-sidebar/hooks.mjs +121 -16
  79. package/build-module/components/collab-sidebar/hooks.mjs.map +2 -2
  80. package/build-module/components/collab-sidebar/index.mjs +21 -5
  81. package/build-module/components/collab-sidebar/index.mjs.map +2 -2
  82. package/build-module/components/collab-sidebar/note-highlight-styles.mjs +41 -0
  83. package/build-module/components/collab-sidebar/note-highlight-styles.mjs.map +7 -0
  84. package/build-module/components/collab-sidebar/utils.mjs +133 -0
  85. package/build-module/components/collab-sidebar/utils.mjs.map +2 -2
  86. package/build-module/components/collaborators-presence/use-collaborator-notifications.mjs +55 -30
  87. package/build-module/components/collaborators-presence/use-collaborator-notifications.mjs.map +2 -2
  88. package/build-module/components/commands/index.mjs +99 -3
  89. package/build-module/components/commands/index.mjs.map +2 -2
  90. package/build-module/components/document-bar/index.mjs +28 -34
  91. package/build-module/components/document-bar/index.mjs.map +2 -2
  92. package/build-module/components/entities-saved-states/index.mjs +1 -4
  93. package/build-module/components/entities-saved-states/index.mjs.map +2 -2
  94. package/build-module/components/header/index.mjs +1 -13
  95. package/build-module/components/header/index.mjs.map +2 -2
  96. package/build-module/components/media-categories/index.mjs +93 -7
  97. package/build-module/components/media-categories/index.mjs.map +2 -2
  98. package/build-module/components/page-attributes/parent.mjs +0 -1
  99. package/build-module/components/page-attributes/parent.mjs.map +2 -2
  100. package/build-module/components/post-author/combobox.mjs +0 -1
  101. package/build-module/components/post-author/combobox.mjs.map +2 -2
  102. package/build-module/components/post-author/select.mjs +0 -1
  103. package/build-module/components/post-author/select.mjs.map +2 -2
  104. package/build-module/components/post-preview-button/index.mjs +29 -2
  105. package/build-module/components/post-preview-button/index.mjs.map +2 -2
  106. package/build-module/components/post-publish-panel/maybe-upload-media.mjs +19 -27
  107. package/build-module/components/post-publish-panel/maybe-upload-media.mjs.map +2 -2
  108. package/build-module/components/post-revisions-preview/revisions-slider.mjs +3 -1
  109. package/build-module/components/post-revisions-preview/revisions-slider.mjs.map +2 -2
  110. package/build-module/components/post-taxonomies/flat-term-selector.mjs +0 -1
  111. package/build-module/components/post-taxonomies/flat-term-selector.mjs.map +2 -2
  112. package/build-module/components/post-taxonomies/hierarchical-term-selector.mjs +0 -2
  113. package/build-module/components/post-taxonomies/hierarchical-term-selector.mjs.map +2 -2
  114. package/build-module/components/post-template/classic-theme.mjs +0 -1
  115. package/build-module/components/post-template/classic-theme.mjs.map +2 -2
  116. package/build-module/components/preferences-modal/index.mjs +54 -28
  117. package/build-module/components/preferences-modal/index.mjs.map +2 -2
  118. package/build-module/components/preview-dropdown/index.mjs +38 -9
  119. package/build-module/components/preview-dropdown/index.mjs.map +2 -2
  120. package/build-module/components/provider/use-block-editor-settings.mjs +23 -9
  121. package/build-module/components/provider/use-block-editor-settings.mjs.map +2 -2
  122. package/build-module/components/resizable-editor/index.mjs +55 -10
  123. package/build-module/components/resizable-editor/index.mjs.map +2 -2
  124. package/build-module/components/sidebar/dataform-post-summary.mjs +6 -2
  125. package/build-module/components/sidebar/dataform-post-summary.mjs.map +2 -2
  126. package/build-module/components/sidebar/index.mjs +29 -42
  127. package/build-module/components/sidebar/index.mjs.map +2 -2
  128. package/build-module/components/sidebar/post-summary.mjs +0 -13
  129. package/build-module/components/sidebar/post-summary.mjs.map +2 -2
  130. package/build-module/components/visual-editor/index.mjs +16 -13
  131. package/build-module/components/visual-editor/index.mjs.map +2 -2
  132. package/build-module/dataviews/store/private-actions.mjs +26 -19
  133. package/build-module/dataviews/store/private-actions.mjs.map +2 -2
  134. package/build-module/store/actions.mjs +5 -3
  135. package/build-module/store/actions.mjs.map +2 -2
  136. package/build-module/store/constants.mjs +25 -0
  137. package/build-module/store/constants.mjs.map +2 -2
  138. package/build-module/store/private-actions.mjs +27 -17
  139. package/build-module/store/private-actions.mjs.map +2 -2
  140. package/build-module/store/private-selectors.mjs +4 -0
  141. package/build-module/store/private-selectors.mjs.map +2 -2
  142. package/build-module/store/reducer.mjs +5 -5
  143. package/build-module/store/reducer.mjs.map +2 -2
  144. package/build-module/store/selectors.mjs +3 -1
  145. package/build-module/store/selectors.mjs.map +2 -2
  146. package/build-module/utils/device-type.mjs +25 -0
  147. package/build-module/utils/device-type.mjs.map +7 -0
  148. package/build-module/utils/media-sideload-from-url/index.mjs +32 -0
  149. package/build-module/utils/media-sideload-from-url/index.mjs.map +7 -0
  150. package/build-style/style-rtl.css +84 -39
  151. package/build-style/style.css +84 -39
  152. package/build-types/components/collab-sidebar/format.d.ts +17 -0
  153. package/build-types/components/collab-sidebar/format.d.ts.map +1 -0
  154. package/build-types/components/collab-sidebar/hooks.d.ts.map +1 -1
  155. package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
  156. package/build-types/components/collab-sidebar/note-highlight-styles.d.ts +31 -0
  157. package/build-types/components/collab-sidebar/note-highlight-styles.d.ts.map +1 -0
  158. package/build-types/components/collab-sidebar/utils.d.ts +82 -2
  159. package/build-types/components/collab-sidebar/utils.d.ts.map +1 -1
  160. package/build-types/components/collaborators-presence/use-collaborator-notifications.d.ts.map +1 -1
  161. package/build-types/components/commands/index.d.ts.map +1 -1
  162. package/build-types/components/document-bar/index.d.ts.map +1 -1
  163. package/build-types/components/entities-saved-states/index.d.ts.map +1 -1
  164. package/build-types/components/header/index.d.ts.map +1 -1
  165. package/build-types/components/media-categories/index.d.ts +12 -3
  166. package/build-types/components/media-categories/index.d.ts.map +1 -1
  167. package/build-types/components/page-attributes/parent.d.ts.map +1 -1
  168. package/build-types/components/post-author/combobox.d.ts.map +1 -1
  169. package/build-types/components/post-author/select.d.ts.map +1 -1
  170. package/build-types/components/post-preview-button/index.d.ts.map +1 -1
  171. package/build-types/components/post-publish-panel/maybe-upload-media.d.ts.map +1 -1
  172. package/build-types/components/post-revisions-preview/revisions-slider.d.ts.map +1 -1
  173. package/build-types/components/post-taxonomies/flat-term-selector.d.ts.map +1 -1
  174. package/build-types/components/post-taxonomies/hierarchical-term-selector.d.ts.map +1 -1
  175. package/build-types/components/post-template/classic-theme.d.ts.map +1 -1
  176. package/build-types/components/preview-dropdown/index.d.ts.map +1 -1
  177. package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
  178. package/build-types/components/resizable-editor/index.d.ts.map +1 -1
  179. package/build-types/components/sidebar/dataform-post-summary.d.ts.map +1 -1
  180. package/build-types/components/sidebar/index.d.ts.map +1 -1
  181. package/build-types/components/sidebar/post-summary.d.ts.map +1 -1
  182. package/build-types/components/visual-editor/index.d.ts.map +1 -1
  183. package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
  184. package/build-types/store/actions.d.ts.map +1 -1
  185. package/build-types/store/constants.d.ts +6 -0
  186. package/build-types/store/constants.d.ts.map +1 -1
  187. package/build-types/store/index.d.ts +2 -2
  188. package/build-types/store/private-actions.d.ts +9 -15
  189. package/build-types/store/private-actions.d.ts.map +1 -1
  190. package/build-types/store/private-selectors.d.ts +7 -0
  191. package/build-types/store/private-selectors.d.ts.map +1 -1
  192. package/build-types/store/reducer.d.ts +6 -7
  193. package/build-types/store/reducer.d.ts.map +1 -1
  194. package/build-types/store/selectors.d.ts +1 -1
  195. package/build-types/store/selectors.d.ts.map +1 -1
  196. package/build-types/utils/device-type.d.ts +23 -0
  197. package/build-types/utils/device-type.d.ts.map +1 -0
  198. package/build-types/utils/get-template-part-icon.d.ts.map +1 -1
  199. package/build-types/utils/media-sideload-from-url/index.d.ts +18 -0
  200. package/build-types/utils/media-sideload-from-url/index.d.ts.map +1 -0
  201. package/package.json +48 -46
  202. package/src/components/collab-sidebar/format.js +72 -0
  203. package/src/components/collab-sidebar/hooks.js +203 -22
  204. package/src/components/collab-sidebar/index.js +19 -5
  205. package/src/components/collab-sidebar/note-highlight-styles.js +83 -0
  206. package/src/components/collab-sidebar/style.scss +9 -0
  207. package/src/components/collab-sidebar/test/note-highlight-styles.js +106 -0
  208. package/src/components/collab-sidebar/test/utils.js +471 -0
  209. package/src/components/collab-sidebar/utils.js +225 -2
  210. package/src/components/collaborators-presence/test/use-collaborator-notifications.ts +265 -262
  211. package/src/components/collaborators-presence/use-collaborator-notifications.ts +70 -34
  212. package/src/components/commands/index.js +142 -0
  213. package/src/components/document-bar/index.js +0 -9
  214. package/src/components/document-bar/style.scss +0 -17
  215. package/src/components/entities-saved-states/index.js +1 -5
  216. package/src/components/header/index.js +1 -15
  217. package/src/components/header/style.scss +7 -3
  218. package/src/components/media-categories/index.js +160 -6
  219. package/src/components/media-categories/test/index.js +202 -0
  220. package/src/components/page-attributes/parent.js +0 -1
  221. package/src/components/post-author/combobox.js +0 -1
  222. package/src/components/post-author/select.js +0 -1
  223. package/src/components/post-preview-button/index.js +68 -2
  224. package/src/components/post-publish-panel/maybe-upload-media.js +25 -30
  225. package/src/components/post-publish-panel/style.scss +1 -1
  226. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +11 -127
  227. package/src/components/post-revisions-preview/revisions-slider.js +4 -1
  228. package/src/components/post-revisions-preview/test/block-diff.js +2 -2
  229. package/src/components/post-taxonomies/flat-term-selector.js +0 -1
  230. package/src/components/post-taxonomies/hierarchical-term-selector.js +0 -2
  231. package/src/components/post-template/classic-theme.js +0 -1
  232. package/src/components/preferences-modal/index.js +40 -22
  233. package/src/components/preferences-modal/test/index.js +83 -0
  234. package/src/components/preview-dropdown/index.js +42 -3
  235. package/src/components/provider/use-block-editor-settings.js +42 -7
  236. package/src/components/resizable-editor/index.js +71 -9
  237. package/src/components/resizable-editor/style.scss +7 -0
  238. package/src/components/sidebar/dataform-post-summary.js +13 -1
  239. package/src/components/sidebar/index.js +32 -47
  240. package/src/components/sidebar/post-summary.js +0 -17
  241. package/src/components/styles-canvas/style.scss +1 -2
  242. package/src/components/visual-editor/index.js +19 -15
  243. package/src/components/visual-editor/style.scss +11 -4
  244. package/src/dataviews/store/private-actions.ts +30 -26
  245. package/src/store/actions.js +6 -3
  246. package/src/store/constants.ts +45 -0
  247. package/src/store/private-actions.js +38 -28
  248. package/src/store/private-selectors.js +10 -0
  249. package/src/store/reducer.js +7 -9
  250. package/src/store/selectors.js +3 -1
  251. package/src/store/test/actions.js +31 -22
  252. package/src/utils/device-type.js +46 -0
  253. package/src/utils/media-sideload-from-url/index.js +54 -0
  254. package/src/utils/media-sideload-from-url/test/index.js +162 -0
  255. package/build/components/post-publish-panel/media-util.cjs +0 -72
  256. package/build/components/post-publish-panel/media-util.cjs.map +0 -7
  257. package/build-module/components/post-publish-panel/media-util.mjs +0 -46
  258. package/build-module/components/post-publish-panel/media-util.mjs.map +0 -7
  259. package/build-types/components/post-publish-panel/media-util.d.ts +0 -20
  260. package/build-types/components/post-publish-panel/media-util.d.ts.map +0 -1
  261. package/src/components/post-publish-panel/media-util.js +0 -87
  262. package/src/components/post-publish-panel/test/media-util.js +0 -118
@@ -16,14 +16,20 @@ import { store as noticesStore } from "@wordpress/notices";
16
16
  import { getScrollContainer } from "@wordpress/dom";
17
17
  import { decodeEntities } from "@wordpress/html-entities";
18
18
  import { store as interfaceStore } from "@wordpress/interface";
19
+ import { RichTextData, create } from "@wordpress/rich-text";
19
20
  import { store as editorStore } from "../../store/index.mjs";
20
21
  import { FLOATING_NOTES_SIDEBAR } from "./constants.mjs";
21
22
  import { unlock } from "../../lock-unlock.mjs";
22
23
  import { createBoardStore } from "./board-store.mjs";
24
+ import { NOTE_FORMAT_NAME } from "./format.mjs";
23
25
  import {
26
+ applyNoteFormat,
24
27
  calculateNotePositions,
28
+ findNoteInBlock,
29
+ getInlineMarkerStart,
25
30
  getNoteIdsFromMetadata,
26
31
  addNoteIdToMetadata,
32
+ removeNoteFormat,
27
33
  removeNoteIdFromMetadata
28
34
  } from "./utils.mjs";
29
35
  var { cleanEmptyObject } = unlock(blockEditorPrivateApis);
@@ -86,12 +92,26 @@ function useNoteThreads(postId) {
86
92
  }
87
93
  const unresolved = [];
88
94
  const resolved = [];
89
- for (const noteIds of Object.values(blocksWithNotes)) {
90
- for (const noteId of noteIds) {
95
+ for (const [clientId, noteIds] of Object.entries(
96
+ blocksWithNotes
97
+ )) {
98
+ const attributes = getBlockAttributes(clientId);
99
+ const orderedThreads = noteIds.map((noteId) => {
91
100
  const thread = threadsById.get(noteId);
92
101
  if (!thread) {
93
- continue;
102
+ return null;
94
103
  }
104
+ return {
105
+ thread,
106
+ start: getInlineMarkerStart(thread, attributes)
107
+ };
108
+ }).filter(Boolean).sort((a, b) => {
109
+ if (a.start !== b.start) {
110
+ return a.start - b.start;
111
+ }
112
+ return a.thread.id - b.thread.id;
113
+ });
114
+ for (const { thread } of orderedThreads) {
95
115
  if (thread.status === "hold") {
96
116
  unresolved.push(thread);
97
117
  } else if (thread.status === "approved") {
@@ -112,11 +132,62 @@ function useNoteThreads(postId) {
112
132
  unresolvedNotes
113
133
  };
114
134
  }
135
+ function readInlineSelection(getSelectionStart, getSelectionEnd) {
136
+ const start = getSelectionStart();
137
+ const end = getSelectionEnd();
138
+ if (!start?.clientId || start.clientId !== end.clientId || !start.attributeKey || start.offset === void 0 || end.offset === void 0 || start.offset === end.offset) {
139
+ return null;
140
+ }
141
+ const [startOffset, endOffset] = start.offset < end.offset ? [start.offset, end.offset] : [end.offset, start.offset];
142
+ return {
143
+ clientId: start.clientId,
144
+ attributeKey: start.attributeKey,
145
+ start: startOffset,
146
+ end: endOffset
147
+ };
148
+ }
149
+ function wrapInlineNote(value, id, start, end) {
150
+ if (!(value instanceof RichTextData)) {
151
+ return null;
152
+ }
153
+ const record = applyNoteFormat(
154
+ create({ html: value.toHTMLString() }),
155
+ { type: NOTE_FORMAT_NAME, attributes: { "data-id": String(id) } },
156
+ start,
157
+ end
158
+ );
159
+ return RichTextData.fromHTMLString(
160
+ new RichTextData(record).toHTMLString()
161
+ );
162
+ }
163
+ function clearInlineNoteMarker(noteId, getClientIdsWithDescendants, getBlockAttributes, updateBlockAttributes) {
164
+ for (const clientId of getClientIdsWithDescendants()) {
165
+ const attributes = getBlockAttributes(clientId);
166
+ const found = findNoteInBlock(attributes, noteId);
167
+ if (!found) {
168
+ continue;
169
+ }
170
+ const next = removeNoteFormat(
171
+ attributes[found.attributeKey],
172
+ noteId
173
+ );
174
+ if (next) {
175
+ updateBlockAttributes(clientId, { [found.attributeKey]: next });
176
+ }
177
+ return;
178
+ }
179
+ }
115
180
  function useNoteActions() {
116
181
  const { createNotice } = useDispatch(noticesStore);
117
182
  const { saveEntityRecord, deleteEntityRecord } = useDispatch(coreStore);
118
183
  const { getCurrentPostId } = useSelect(editorStore);
119
- const { getBlockAttributes, getSelectedBlockClientId } = useSelect(blockEditorStore);
184
+ const {
185
+ getBlockAttributes,
186
+ getClientIdsWithDescendants,
187
+ getSelectedBlockClientId,
188
+ getSelectionStart,
189
+ getSelectionEnd
190
+ } = useSelect(blockEditorStore);
120
191
  const { updateBlockAttributes } = useDispatch(blockEditorStore);
121
192
  const onError = (error) => {
122
193
  const errorMessage = error.message && error.code !== "unknown_error" ? decodeEntities(error.message) : __("An error occurred while performing an update.");
@@ -127,6 +198,7 @@ function useNoteActions() {
127
198
  };
128
199
  const onCreate = async ({ content, parent }) => {
129
200
  try {
201
+ const inlineSelection = !parent ? readInlineSelection(getSelectionStart, getSelectionEnd) : null;
130
202
  const savedRecord = await saveEntityRecord(
131
203
  "root",
132
204
  "comment",
@@ -140,18 +212,31 @@ function useNoteActions() {
140
212
  { throwOnError: true }
141
213
  );
142
214
  if (!parent && savedRecord?.id) {
143
- const clientId = getSelectedBlockClientId();
215
+ const clientId = inlineSelection?.clientId || getSelectedBlockClientId();
144
216
  if (!clientId) {
145
217
  return savedRecord;
146
218
  }
147
- const metadata = getBlockAttributes(clientId)?.metadata;
219
+ const attributes = getBlockAttributes(clientId);
220
+ const metadata = attributes?.metadata;
148
221
  const updatedMetadata = addNoteIdToMetadata(
149
222
  metadata,
150
223
  savedRecord.id
151
224
  );
152
- updateBlockAttributes(clientId, {
225
+ const newAttributes = {
153
226
  metadata: cleanEmptyObject(updatedMetadata)
154
- });
227
+ };
228
+ if (inlineSelection) {
229
+ const wrapped = wrapInlineNote(
230
+ attributes?.[inlineSelection.attributeKey],
231
+ savedRecord.id,
232
+ inlineSelection.start,
233
+ inlineSelection.end
234
+ );
235
+ if (wrapped) {
236
+ newAttributes[inlineSelection.attributeKey] = wrapped;
237
+ }
238
+ }
239
+ updateBlockAttributes(clientId, newAttributes);
155
240
  }
156
241
  createNotice(
157
242
  "snackbar",
@@ -200,6 +285,14 @@ function useNoteActions() {
200
285
  await saveEntityRecord("root", "comment", newNoteData, {
201
286
  throwOnError: true
202
287
  });
288
+ if (status === "approved") {
289
+ clearInlineNoteMarker(
290
+ id,
291
+ getClientIdsWithDescendants,
292
+ getBlockAttributes,
293
+ updateBlockAttributes
294
+ );
295
+ }
203
296
  } else {
204
297
  const updateData = {
205
298
  id,
@@ -232,14 +325,26 @@ function useNoteActions() {
232
325
  if (!clientId) {
233
326
  return;
234
327
  }
235
- const metadata = getBlockAttributes(clientId)?.metadata;
236
- const updatedMetadata = removeNoteIdFromMetadata(
237
- metadata,
238
- note.id
239
- );
240
- updateBlockAttributes(clientId, {
241
- metadata: cleanEmptyObject(updatedMetadata)
242
- });
328
+ const attributes = getBlockAttributes(clientId);
329
+ const newAttributes = {
330
+ metadata: cleanEmptyObject(
331
+ removeNoteIdFromMetadata(
332
+ attributes?.metadata,
333
+ note.id
334
+ )
335
+ )
336
+ };
337
+ const found = findNoteInBlock(attributes, note.id);
338
+ if (found) {
339
+ const next = removeNoteFormat(
340
+ attributes[found.attributeKey],
341
+ note.id
342
+ );
343
+ if (next) {
344
+ newAttributes[found.attributeKey] = next;
345
+ }
346
+ }
347
+ updateBlockAttributes(clientId, newAttributes);
243
348
  }
244
349
  createNotice("snackbar", __("Note deleted."), {
245
350
  type: "snackbar",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/collab-sidebar/hooks.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseMemo,\n\tuseSyncExternalStore,\n} from '@wordpress/element';\nimport { useEntityRecords, store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { FLOATING_NOTES_SIDEBAR } from './constants';\nimport { unlock } from '../../lock-unlock';\nimport { createBoardStore } from './board-store';\nimport {\n\tcalculateNotePositions,\n\tgetNoteIdsFromMetadata,\n\taddNoteIdToMetadata,\n\tremoveNoteIdFromMetadata,\n} from './utils';\n\nconst { cleanEmptyObject } = unlock( blockEditorPrivateApis );\n\nexport function useNoteThreads( postId ) {\n\tconst queryArgs = {\n\t\tpost: postId,\n\t\ttype: 'note',\n\t\tstatus: 'all',\n\t\tper_page: -1,\n\t};\n\n\tconst { records: threads } = useEntityRecords(\n\t\t'root',\n\t\t'comment',\n\t\tqueryArgs,\n\t\t{ enabled: !! postId && typeof postId === 'number' }\n\t);\n\n\tconst { getBlockAttributes } = useSelect( blockEditorStore );\n\tconst { clientIds } = useSelect( ( select ) => {\n\t\tconst { getClientIdsWithDescendants } = select( blockEditorStore );\n\t\treturn {\n\t\t\tclientIds: getClientIdsWithDescendants(),\n\t\t};\n\t}, [] );\n\n\t// Process notes to build the tree structure.\n\tconst { notes, unresolvedNotes } = useMemo( () => {\n\t\tif ( ! threads || threads.length === 0 ) {\n\t\t\treturn { notes: [], unresolvedNotes: [] };\n\t\t}\n\n\t\t// Single pass over clientIds builds the forward map and reverse lookup\n\t\t// together. getNoteIdsFromMetadata returns numeric ids, matching the\n\t\t// types returned by the comments REST endpoint.\n\t\tconst blocksWithNotes = {};\n\t\tconst clientIdByNoteId = new Map();\n\t\tfor ( const clientId of clientIds ) {\n\t\t\tconst metadata = getBlockAttributes( clientId )?.metadata;\n\t\t\tconst noteIds = getNoteIdsFromMetadata( metadata );\n\t\t\tif ( noteIds.length > 0 ) {\n\t\t\t\tblocksWithNotes[ clientId ] = noteIds;\n\t\t\t\tfor ( const noteId of noteIds ) {\n\t\t\t\t\tclientIdByNoteId.set( noteId, clientId );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Materialize threads; collect roots; replies linked in a second pass\n\t\t// via unshift to invert order (matches prior reverse semantics).\n\t\tconst threadsById = new Map();\n\t\tconst rootThreads = [];\n\t\tfor ( const item of threads ) {\n\t\t\tconst thread = {\n\t\t\t\t...item,\n\t\t\t\treply: [],\n\t\t\t\tblockClientId:\n\t\t\t\t\titem.parent === 0\n\t\t\t\t\t\t? clientIdByNoteId.get( item.id ) ?? null\n\t\t\t\t\t\t: null,\n\t\t\t};\n\t\t\tthreadsById.set( item.id, thread );\n\t\t\tif ( item.parent === 0 ) {\n\t\t\t\trootThreads.push( thread );\n\t\t\t}\n\t\t}\n\t\tfor ( const item of threads ) {\n\t\t\tif ( item.parent !== 0 ) {\n\t\t\t\tthreadsById\n\t\t\t\t\t.get( item.parent )\n\t\t\t\t\t?.reply.unshift( threadsById.get( item.id ) );\n\t\t\t}\n\t\t}\n\n\t\tif ( rootThreads.length === 0 ) {\n\t\t\treturn { notes: [], unresolvedNotes: [] };\n\t\t}\n\n\t\t// Single partition over notes-in-block-order. Each block can have\n\t\t// multiple note IDs, so iterate the flattened list.\n\t\tconst unresolved = [];\n\t\tconst resolved = [];\n\t\tfor ( const noteIds of Object.values( blocksWithNotes ) ) {\n\t\t\tfor ( const noteId of noteIds ) {\n\t\t\t\tconst thread = threadsById.get( noteId );\n\t\t\t\tif ( ! thread ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif ( thread.status === 'hold' ) {\n\t\t\t\t\tunresolved.push( thread );\n\t\t\t\t} else if ( thread.status === 'approved' ) {\n\t\t\t\t\tresolved.push( thread );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Orphans: root threads without a linked block. They only need to come last.\n\t\tconst orphans = rootThreads.filter(\n\t\t\t( thread ) => ! thread.blockClientId\n\t\t);\n\n\t\treturn {\n\t\t\tnotes: [ ...unresolved, ...resolved, ...orphans ],\n\t\t\tunresolvedNotes: unresolved,\n\t\t};\n\t}, [ clientIds, threads, getBlockAttributes ] );\n\n\treturn {\n\t\tnotes,\n\t\tunresolvedNotes,\n\t};\n}\n\nexport function useNoteActions() {\n\tconst { createNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord, deleteEntityRecord } = useDispatch( coreStore );\n\tconst { getCurrentPostId } = useSelect( editorStore );\n\tconst { getBlockAttributes, getSelectedBlockClientId } =\n\t\tuseSelect( blockEditorStore );\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\tconst onError = ( error ) => {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? decodeEntities( error.message )\n\t\t\t\t: __( 'An error occurred while performing an update.' );\n\t\tcreateNotice( 'error', errorMessage, {\n\t\t\ttype: 'snackbar',\n\t\t\tisDismissible: true,\n\t\t} );\n\t};\n\n\tconst onCreate = async ( { content, parent } ) => {\n\t\ttry {\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'comment',\n\t\t\t\t{\n\t\t\t\t\tpost: getCurrentPostId(),\n\t\t\t\t\tcontent,\n\t\t\t\t\tstatus: 'hold',\n\t\t\t\t\ttype: 'note',\n\t\t\t\t\tparent: parent || 0,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// If it's a top-level note, update the block attributes with the note id.\n\t\t\t// Read-modify-write on metadata is racy under concurrent edits:\n\t\t\t// two near-simultaneous adds against the same base will each write\n\t\t\t// a 2-element array and the later write wins, dropping the other\n\t\t\t// id. Tracking issue: https://github.com/WordPress/gutenberg/issues/74751.\n\t\t\tif ( ! parent && savedRecord?.id ) {\n\t\t\t\tconst clientId = getSelectedBlockClientId();\n\t\t\t\tif ( ! clientId ) {\n\t\t\t\t\treturn savedRecord;\n\t\t\t\t}\n\t\t\t\tconst metadata = getBlockAttributes( clientId )?.metadata;\n\t\t\t\tconst updatedMetadata = addNoteIdToMetadata(\n\t\t\t\t\tmetadata,\n\t\t\t\t\tsavedRecord.id\n\t\t\t\t);\n\t\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\t\tmetadata: cleanEmptyObject( updatedMetadata ),\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcreateNotice(\n\t\t\t\t'snackbar',\n\t\t\t\tparent ? __( 'Reply added.' ) : __( 'Note added.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tisDismissible: true,\n\t\t\t\t}\n\t\t\t);\n\t\t\treturn savedRecord;\n\t\t} catch ( error ) {\n\t\t\tonError( error );\n\t\t}\n\t};\n\n\tconst onEdit = async ( { id, content, status } ) => {\n\t\tconst messageType = status ? status : 'updated';\n\t\tconst messages = {\n\t\t\tapproved: __( 'Note marked as resolved.' ),\n\t\t\thold: __( 'Note reopened.' ),\n\t\t\tupdated: __( 'Note updated.' ),\n\t\t};\n\n\t\ttry {\n\t\t\t// For resolution or reopen actions, create a new note with metadata.\n\t\t\tif ( status === 'approved' || status === 'hold' ) {\n\t\t\t\t// First, update the thread status.\n\t\t\t\tawait saveEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'comment',\n\t\t\t\t\t{\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\t// Then create a new note with the metadata.\n\t\t\t\tconst newNoteData = {\n\t\t\t\t\tpost: getCurrentPostId(),\n\t\t\t\t\tcontent: content || '', // Empty content for resolve, content for reopen.\n\t\t\t\t\ttype: 'note',\n\t\t\t\t\tstatus,\n\t\t\t\t\tparent: id,\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\t_wp_note_status:\n\t\t\t\t\t\t\tstatus === 'approved' ? 'resolved' : 'reopen',\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tawait saveEntityRecord( 'root', 'comment', newNoteData, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst updateData = {\n\t\t\t\t\tid,\n\t\t\t\t\tcontent,\n\t\t\t\t\tstatus,\n\t\t\t\t};\n\n\t\t\t\tawait saveEntityRecord( 'root', 'comment', updateData, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcreateNotice(\n\t\t\t\t'snackbar',\n\t\t\t\tmessages[ messageType ] ?? __( 'Note updated.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tisDismissible: true,\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tonError( error );\n\t\t}\n\t};\n\n\tconst onDelete = async ( note ) => {\n\t\ttry {\n\t\t\tawait deleteEntityRecord( 'root', 'comment', note.id, undefined, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\n\t\t\tif ( ! note.parent ) {\n\t\t\t\t// Use blockClientId if available, otherwise fall back to selected block.\n\t\t\t\tconst clientId =\n\t\t\t\t\tnote.blockClientId || getSelectedBlockClientId();\n\t\t\t\tif ( ! clientId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst metadata = getBlockAttributes( clientId )?.metadata;\n\t\t\t\tconst updatedMetadata = removeNoteIdFromMetadata(\n\t\t\t\t\tmetadata,\n\t\t\t\t\tnote.id\n\t\t\t\t);\n\t\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\t\tmetadata: cleanEmptyObject( updatedMetadata ),\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcreateNotice( 'snackbar', __( 'Note deleted.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError( error );\n\t\t}\n\t};\n\n\treturn { onCreate, onEdit, onDelete };\n}\n\nexport function useEnableFloatingSidebar( enabled = false ) {\n\tconst registry = useRegistry();\n\tuseEffect( () => {\n\t\tif ( ! enabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { getActiveComplementaryArea } =\n\t\t\tregistry.select( interfaceStore );\n\t\tconst { disableComplementaryArea, enableComplementaryArea } =\n\t\t\tregistry.dispatch( interfaceStore );\n\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Return `null` to indicate the user hid the complementary area.\n\t\t\tif ( getActiveComplementaryArea( 'core' ) === null ) {\n\t\t\t\tenableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tif (\n\t\t\t\tgetActiveComplementaryArea( 'core' ) === FLOATING_NOTES_SIDEBAR\n\t\t\t) {\n\t\t\t\tdisableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );\n\t\t\t}\n\t\t};\n\t}, [ enabled, registry ] );\n}\n\nexport function useFloatingBoard( {\n\tthreads,\n\tselectedNoteId,\n\tisFloating,\n\tsidebarRef,\n} ) {\n\tconst [ notePositions, setNotePositions ] = useState( {} );\n\tconst [ store ] = useState( createBoardStore );\n\n\tconst heights = useSyncExternalStore( store.subscribe, store.getSnapshot );\n\n\t// Notes are positioned in canvas content-space; CSS inherits\n\t// `--canvas-scroll` to translate each thread in sync with the canvas.\n\tuseEffect( () => {\n\t\tif ( ! isFloating || ! sidebarRef?.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst panel = sidebarRef.current;\n\t\tconst blockEl = store.getFirstBlockElement();\n\t\t// Climb to the block-list root so nested scroll containers\n\t\t// (e.g. a Group with overflow:auto) don't shadow the canvas.\n\t\tconst rootEl = blockEl?.closest( '.is-root-container' ) ?? blockEl;\n\t\tconst canvas = rootEl ? getScrollContainer( rootEl ) : null;\n\n\t\tconst applyScroll = () => {\n\t\t\tpanel.style.setProperty(\n\t\t\t\t'--canvas-scroll',\n\t\t\t\t`${ -( canvas?.scrollTop ?? 0 ) }px`\n\t\t\t);\n\t\t};\n\n\t\t// Recalc is deferred to a rAF; back-to-back updates collapse into one paint.\n\t\tconst rafId = window.requestAnimationFrame( () => {\n\t\t\tconst result = calculateNotePositions( {\n\t\t\t\tthreads,\n\t\t\t\tselectedNoteId,\n\t\t\t\tblockRects: store.getBlockRects(),\n\t\t\t\theights,\n\t\t\t\tscrollTop: canvas?.scrollTop ?? 0,\n\t\t\t} );\n\n\t\t\tsetNotePositions( result.positions );\n\t\t\tapplyScroll();\n\t\t} );\n\n\t\t// Root scrolling elements (documentElement/body) don't fire scroll\n\t\t// on themselves; capture on the window catches them in either canvas.\n\t\tconst view = canvas?.ownerDocument?.defaultView;\n\t\tconst listenerOptions = { passive: true, capture: true };\n\t\tview?.addEventListener( 'scroll', applyScroll, listenerOptions );\n\n\t\treturn () => {\n\t\t\twindow.cancelAnimationFrame( rafId );\n\t\t\tview?.removeEventListener( 'scroll', applyScroll, listenerOptions );\n\t\t};\n\t}, [ sidebarRef, heights, isFloating, selectedNoteId, store, threads ] );\n\n\treturn {\n\t\tnotePositions,\n\t\tregisterThread: store.registerThread,\n\t\tunregisterThread: store.unregisterThread,\n\t};\n}\n"],
5
- "mappings": ";AAGA,SAAS,UAAU;AACnB;AAAA,EACC;AAAA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AU,CAAC,CAAE;AACzD,QAAM,CAAE,KAAM,IAAI,SAAU,gBAAiB;AAE7C,QAAM,UAAU,qBAAsB,MAAM,WAAW,MAAM,WAAY;AAIzE,YAAW,MAAM;AAChB,QAAK,CAAE,cAAc,CAAE,YAAY,SAAU;AAC5C;AAAA,IACD;AAEA,UAAM,QAAQ,WAAW;AACzB,UAAM,UAAU,MAAM,qBAAqB;AAG3C,UAAM,SAAS,SAAS,QAAS,oBAAqB,KAAK;AAC3D,UAAM,SAAS,SAAS,mBAAoB,MAAO,IAAI;AAEvD,UAAM,cAAc,MAAM;AACzB,YAAM,MAAM;AAAA,QACX;AAAA,QACA,GAAI,EAAG,QAAQ,aAAa,EAAI;AAAA,MACjC;AAAA,IACD;AAGA,UAAM,QAAQ,OAAO,sBAAuB,MAAM;AACjD,YAAM,SAAS,uBAAwB;AAAA,QACtC;AAAA,QACA;AAAA,QACA,YAAY,MAAM,cAAc;AAAA,QAChC;AAAA,QACA,WAAW,QAAQ,aAAa;AAAA,MACjC,CAAE;AAEF,uBAAkB,OAAO,SAAU;AACnC,kBAAY;AAAA,IACb,CAAE;AAIF,UAAM,OAAO,QAAQ,eAAe;AACpC,UAAM,kBAAkB,EAAE,SAAS,MAAM,SAAS,KAAK;AACvD,UAAM,iBAAkB,UAAU,aAAa,eAAgB;AAE/D,WAAO,MAAM;AACZ,aAAO,qBAAsB,KAAM;AACnC,YAAM,oBAAqB,UAAU,aAAa,eAAgB;AAAA,IACnE;AAAA,EACD,GAAG,CAAE,YAAY,SAAS,YAAY,gBAAgB,OAAO,OAAQ,CAAE;AAEvE,SAAO;AAAA,IACN;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,kBAAkB,MAAM;AAAA,EACzB;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseMemo,\n\tuseSyncExternalStore,\n} from '@wordpress/element';\nimport { useEntityRecords, store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { RichTextData, create } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { FLOATING_NOTES_SIDEBAR } from './constants';\nimport { unlock } from '../../lock-unlock';\nimport { createBoardStore } from './board-store';\nimport { NOTE_FORMAT_NAME } from './format';\nimport {\n\tapplyNoteFormat,\n\tcalculateNotePositions,\n\tfindNoteInBlock,\n\tgetInlineMarkerStart,\n\tgetNoteIdsFromMetadata,\n\taddNoteIdToMetadata,\n\tremoveNoteFormat,\n\tremoveNoteIdFromMetadata,\n} from './utils';\n\nconst { cleanEmptyObject } = unlock( blockEditorPrivateApis );\n\nexport function useNoteThreads( postId ) {\n\tconst queryArgs = {\n\t\tpost: postId,\n\t\ttype: 'note',\n\t\tstatus: 'all',\n\t\tper_page: -1,\n\t};\n\n\tconst { records: threads } = useEntityRecords(\n\t\t'root',\n\t\t'comment',\n\t\tqueryArgs,\n\t\t{ enabled: !! postId && typeof postId === 'number' }\n\t);\n\n\tconst { getBlockAttributes } = useSelect( blockEditorStore );\n\tconst { clientIds } = useSelect( ( select ) => {\n\t\tconst { getClientIdsWithDescendants } = select( blockEditorStore );\n\t\treturn {\n\t\t\tclientIds: getClientIdsWithDescendants(),\n\t\t};\n\t}, [] );\n\n\t// Process notes to build the tree structure.\n\tconst { notes, unresolvedNotes } = useMemo( () => {\n\t\tif ( ! threads || threads.length === 0 ) {\n\t\t\treturn { notes: [], unresolvedNotes: [] };\n\t\t}\n\n\t\t// Single pass over clientIds builds the forward map and reverse lookup\n\t\t// together. getNoteIdsFromMetadata returns numeric ids, matching the\n\t\t// types returned by the comments REST endpoint.\n\t\tconst blocksWithNotes = {};\n\t\tconst clientIdByNoteId = new Map();\n\t\tfor ( const clientId of clientIds ) {\n\t\t\tconst metadata = getBlockAttributes( clientId )?.metadata;\n\t\t\tconst noteIds = getNoteIdsFromMetadata( metadata );\n\t\t\tif ( noteIds.length > 0 ) {\n\t\t\t\tblocksWithNotes[ clientId ] = noteIds;\n\t\t\t\tfor ( const noteId of noteIds ) {\n\t\t\t\t\tclientIdByNoteId.set( noteId, clientId );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Materialize threads; collect roots; replies linked in a second pass\n\t\t// via unshift to invert order (matches prior reverse semantics).\n\t\tconst threadsById = new Map();\n\t\tconst rootThreads = [];\n\t\tfor ( const item of threads ) {\n\t\t\tconst thread = {\n\t\t\t\t...item,\n\t\t\t\treply: [],\n\t\t\t\tblockClientId:\n\t\t\t\t\titem.parent === 0\n\t\t\t\t\t\t? clientIdByNoteId.get( item.id ) ?? null\n\t\t\t\t\t\t: null,\n\t\t\t};\n\t\t\tthreadsById.set( item.id, thread );\n\t\t\tif ( item.parent === 0 ) {\n\t\t\t\trootThreads.push( thread );\n\t\t\t}\n\t\t}\n\t\tfor ( const item of threads ) {\n\t\t\tif ( item.parent !== 0 ) {\n\t\t\t\tthreadsById\n\t\t\t\t\t.get( item.parent )\n\t\t\t\t\t?.reply.unshift( threadsById.get( item.id ) );\n\t\t\t}\n\t\t}\n\n\t\tif ( rootThreads.length === 0 ) {\n\t\t\treturn { notes: [], unresolvedNotes: [] };\n\t\t}\n\n\t\t// Order within a block: block-level notes (no inline anchor) come\n\t\t// first as the \"overall comment\", then inline notes ascending by\n\t\t// marker start offset. Ties (rare; two markers at the same offset)\n\t\t// fall back to creation order via thread id. Blocks themselves are\n\t\t// already iterated in document order above.\n\t\tconst unresolved = [];\n\t\tconst resolved = [];\n\t\tfor ( const [ clientId, noteIds ] of Object.entries(\n\t\t\tblocksWithNotes\n\t\t) ) {\n\t\t\tconst attributes = getBlockAttributes( clientId );\n\t\t\tconst orderedThreads = noteIds\n\t\t\t\t.map( ( noteId ) => {\n\t\t\t\t\tconst thread = threadsById.get( noteId );\n\t\t\t\t\tif ( ! thread ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tthread,\n\t\t\t\t\t\tstart: getInlineMarkerStart( thread, attributes ),\n\t\t\t\t\t};\n\t\t\t\t} )\n\t\t\t\t.filter( Boolean )\n\t\t\t\t.sort( ( a, b ) => {\n\t\t\t\t\tif ( a.start !== b.start ) {\n\t\t\t\t\t\treturn a.start - b.start;\n\t\t\t\t\t}\n\t\t\t\t\treturn a.thread.id - b.thread.id;\n\t\t\t\t} );\n\t\t\tfor ( const { thread } of orderedThreads ) {\n\t\t\t\tif ( thread.status === 'hold' ) {\n\t\t\t\t\tunresolved.push( thread );\n\t\t\t\t} else if ( thread.status === 'approved' ) {\n\t\t\t\t\tresolved.push( thread );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Orphans: root threads without a linked block. They only need to come last.\n\t\tconst orphans = rootThreads.filter(\n\t\t\t( thread ) => ! thread.blockClientId\n\t\t);\n\n\t\treturn {\n\t\t\tnotes: [ ...unresolved, ...resolved, ...orphans ],\n\t\t\tunresolvedNotes: unresolved,\n\t\t};\n\t}, [ clientIds, threads, getBlockAttributes ] );\n\n\treturn {\n\t\tnotes,\n\t\tunresolvedNotes,\n\t};\n}\n\n/**\n * Read an inline selection from block-editor selection state, returning\n * normalized anchor data when a non-collapsed selection sits inside a single\n * rich-text attribute. Returns null for block-level or collapsed selections.\n *\n * @param {Function} getSelectionStart Block-editor selector.\n * @param {Function} getSelectionEnd Block-editor selector.\n * @return {?Object} { clientId, attributeKey, start, end } or null.\n */\nfunction readInlineSelection( getSelectionStart, getSelectionEnd ) {\n\tconst start = getSelectionStart();\n\tconst end = getSelectionEnd();\n\tif (\n\t\t! start?.clientId ||\n\t\tstart.clientId !== end.clientId ||\n\t\t! start.attributeKey ||\n\t\tstart.offset === undefined ||\n\t\tend.offset === undefined ||\n\t\tstart.offset === end.offset\n\t) {\n\t\treturn null;\n\t}\n\t// Normalize direction so callers don't have to think about reversed ranges.\n\tconst [ startOffset, endOffset ] =\n\t\tstart.offset < end.offset\n\t\t\t? [ start.offset, end.offset ]\n\t\t\t: [ end.offset, start.offset ];\n\treturn {\n\t\tclientId: start.clientId,\n\t\tattributeKey: start.attributeKey,\n\t\tstart: startOffset,\n\t\tend: endOffset,\n\t};\n}\n\n/**\n * Wrap a rich-text range with a core/note marker. Returns a new\n * RichTextData ready to write back into block attributes, or null when the\n * incoming value isn't a rich-text instance (legacy/string attributes).\n *\n * @param {*} value Existing block attribute value.\n * @param {number} id New note id to embed as `data-id`.\n * @param {number} start Range start offset.\n * @param {number} end Range end offset.\n * @return {?RichTextData} Wrapped value or null when the attribute isn't rich text.\n */\nfunction wrapInlineNote( value, id, start, end ) {\n\tif ( ! ( value instanceof RichTextData ) ) {\n\t\treturn null;\n\t}\n\tconst record = applyNoteFormat(\n\t\tcreate( { html: value.toHTMLString() } ),\n\t\t{ type: NOTE_FORMAT_NAME, attributes: { 'data-id': String( id ) } },\n\t\tstart,\n\t\tend\n\t);\n\t// Round-trip through HTML to normalise format references (applyNoteFormat\n\t// leaves them un-normalised) so the stored value matches a fresh reload.\n\treturn RichTextData.fromHTMLString(\n\t\tnew RichTextData( record ).toHTMLString()\n\t);\n}\n\n/**\n * Strip a note's inline `core/note` marker from whichever block holds it, if\n * any, so a deleted or resolved note's highlight does not linger in the content.\n * No-op for block-level notes (those carry no marker). Used by the resolve path,\n * which only knows the note id; the delete path strips the marker inline since\n * it already has the block.\n *\n * @param {number} noteId Note id whose marker to remove.\n * @param {Function} getClientIdsWithDescendants Block-editor selector.\n * @param {Function} getBlockAttributes Block-editor selector.\n * @param {Function} updateBlockAttributes Block-editor action.\n */\nfunction clearInlineNoteMarker(\n\tnoteId,\n\tgetClientIdsWithDescendants,\n\tgetBlockAttributes,\n\tupdateBlockAttributes\n) {\n\tfor ( const clientId of getClientIdsWithDescendants() ) {\n\t\tconst attributes = getBlockAttributes( clientId );\n\t\tconst found = findNoteInBlock( attributes, noteId );\n\t\tif ( ! found ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst next = removeNoteFormat(\n\t\t\tattributes[ found.attributeKey ],\n\t\t\tnoteId\n\t\t);\n\t\tif ( next ) {\n\t\t\tupdateBlockAttributes( clientId, { [ found.attributeKey ]: next } );\n\t\t}\n\t\treturn;\n\t}\n}\n\nexport function useNoteActions() {\n\tconst { createNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord, deleteEntityRecord } = useDispatch( coreStore );\n\tconst { getCurrentPostId } = useSelect( editorStore );\n\tconst {\n\t\tgetBlockAttributes,\n\t\tgetClientIdsWithDescendants,\n\t\tgetSelectedBlockClientId,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t} = useSelect( blockEditorStore );\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\tconst onError = ( error ) => {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? decodeEntities( error.message )\n\t\t\t\t: __( 'An error occurred while performing an update.' );\n\t\tcreateNotice( 'error', errorMessage, {\n\t\t\ttype: 'snackbar',\n\t\t\tisDismissible: true,\n\t\t} );\n\t};\n\n\tconst onCreate = async ( { content, parent } ) => {\n\t\ttry {\n\t\t\t// Capture inline selection *before* the async save: focus may shift\n\t\t\t// during the round-trip and the editor's stored selection can\n\t\t\t// collapse if the user clicks elsewhere. The selection drives the\n\t\t\t// in-content marker written below, which is the note's only anchor.\n\t\t\tconst inlineSelection = ! parent\n\t\t\t\t? readInlineSelection( getSelectionStart, getSelectionEnd )\n\t\t\t\t: null;\n\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'comment',\n\t\t\t\t{\n\t\t\t\t\tpost: getCurrentPostId(),\n\t\t\t\t\tcontent,\n\t\t\t\t\tstatus: 'hold',\n\t\t\t\t\ttype: 'note',\n\t\t\t\t\tparent: parent || 0,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// If it's a top-level note, update the block attributes with the note id.\n\t\t\t// Read-modify-write on metadata is racy under concurrent edits:\n\t\t\t// two near-simultaneous adds against the same base will each write\n\t\t\t// a 2-element array and the later write wins, dropping the other\n\t\t\t// id. Tracking issue: https://github.com/WordPress/gutenberg/issues/74751.\n\t\t\tif ( ! parent && savedRecord?.id ) {\n\t\t\t\tconst clientId =\n\t\t\t\t\tinlineSelection?.clientId || getSelectedBlockClientId();\n\t\t\t\tif ( ! clientId ) {\n\t\t\t\t\treturn savedRecord;\n\t\t\t\t}\n\t\t\t\tconst attributes = getBlockAttributes( clientId );\n\t\t\t\tconst metadata = attributes?.metadata;\n\t\t\t\tconst updatedMetadata = addNoteIdToMetadata(\n\t\t\t\t\tmetadata,\n\t\t\t\t\tsavedRecord.id\n\t\t\t\t);\n\t\t\t\tconst newAttributes = {\n\t\t\t\t\tmetadata: cleanEmptyObject( updatedMetadata ),\n\t\t\t\t};\n\n\t\t\t\t// Inline path: also wrap the selected text with a core/note\n\t\t\t\t// marker so the anchor survives later edits.\n\t\t\t\tif ( inlineSelection ) {\n\t\t\t\t\tconst wrapped = wrapInlineNote(\n\t\t\t\t\t\tattributes?.[ inlineSelection.attributeKey ],\n\t\t\t\t\t\tsavedRecord.id,\n\t\t\t\t\t\tinlineSelection.start,\n\t\t\t\t\t\tinlineSelection.end\n\t\t\t\t\t);\n\t\t\t\t\tif ( wrapped ) {\n\t\t\t\t\t\tnewAttributes[ inlineSelection.attributeKey ] = wrapped;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tupdateBlockAttributes( clientId, newAttributes );\n\t\t\t}\n\n\t\t\tcreateNotice(\n\t\t\t\t'snackbar',\n\t\t\t\tparent ? __( 'Reply added.' ) : __( 'Note added.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tisDismissible: true,\n\t\t\t\t}\n\t\t\t);\n\t\t\treturn savedRecord;\n\t\t} catch ( error ) {\n\t\t\tonError( error );\n\t\t}\n\t};\n\n\tconst onEdit = async ( { id, content, status } ) => {\n\t\tconst messageType = status ? status : 'updated';\n\t\tconst messages = {\n\t\t\tapproved: __( 'Note marked as resolved.' ),\n\t\t\thold: __( 'Note reopened.' ),\n\t\t\tupdated: __( 'Note updated.' ),\n\t\t};\n\n\t\ttry {\n\t\t\t// For resolution or reopen actions, create a new note with metadata.\n\t\t\tif ( status === 'approved' || status === 'hold' ) {\n\t\t\t\t// First, update the thread status.\n\t\t\t\tawait saveEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'comment',\n\t\t\t\t\t{\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\t// Then create a new note with the metadata.\n\t\t\t\tconst newNoteData = {\n\t\t\t\t\tpost: getCurrentPostId(),\n\t\t\t\t\tcontent: content || '', // Empty content for resolve, content for reopen.\n\t\t\t\t\ttype: 'note',\n\t\t\t\t\tstatus,\n\t\t\t\t\tparent: id,\n\t\t\t\t\tmeta: {\n\t\t\t\t\t\t_wp_note_status:\n\t\t\t\t\t\t\tstatus === 'approved' ? 'resolved' : 'reopen',\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tawait saveEntityRecord( 'root', 'comment', newNoteData, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\n\t\t\t\t// Resolving a note drops its inline highlight: strip the marker\n\t\t\t\t// so the note falls back to a block-level note in the content.\n\t\t\t\tif ( status === 'approved' ) {\n\t\t\t\t\tclearInlineNoteMarker(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tgetClientIdsWithDescendants,\n\t\t\t\t\t\tgetBlockAttributes,\n\t\t\t\t\t\tupdateBlockAttributes\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst updateData = {\n\t\t\t\t\tid,\n\t\t\t\t\tcontent,\n\t\t\t\t\tstatus,\n\t\t\t\t};\n\n\t\t\t\tawait saveEntityRecord( 'root', 'comment', updateData, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcreateNotice(\n\t\t\t\t'snackbar',\n\t\t\t\tmessages[ messageType ] ?? __( 'Note updated.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tisDismissible: true,\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tonError( error );\n\t\t}\n\t};\n\n\tconst onDelete = async ( note ) => {\n\t\ttry {\n\t\t\tawait deleteEntityRecord( 'root', 'comment', note.id, undefined, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\n\t\t\tif ( ! note.parent ) {\n\t\t\t\t// Use blockClientId if available, otherwise fall back to selected block.\n\t\t\t\tconst clientId =\n\t\t\t\t\tnote.blockClientId || getSelectedBlockClientId();\n\t\t\t\tif ( ! clientId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst attributes = getBlockAttributes( clientId );\n\t\t\t\tconst newAttributes = {\n\t\t\t\t\tmetadata: cleanEmptyObject(\n\t\t\t\t\t\tremoveNoteIdFromMetadata(\n\t\t\t\t\t\t\tattributes?.metadata,\n\t\t\t\t\t\t\tnote.id\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t\t// Strip the inline marker too (if any) so the deleted note's\n\t\t\t\t// highlight doesn't linger in the content. Folded into the same\n\t\t\t\t// attribute update so it's a single undo step.\n\t\t\t\tconst found = findNoteInBlock( attributes, note.id );\n\t\t\t\tif ( found ) {\n\t\t\t\t\tconst next = removeNoteFormat(\n\t\t\t\t\t\tattributes[ found.attributeKey ],\n\t\t\t\t\t\tnote.id\n\t\t\t\t\t);\n\t\t\t\t\tif ( next ) {\n\t\t\t\t\t\tnewAttributes[ found.attributeKey ] = next;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tupdateBlockAttributes( clientId, newAttributes );\n\t\t\t}\n\n\t\t\tcreateNotice( 'snackbar', __( 'Note deleted.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError( error );\n\t\t}\n\t};\n\n\treturn { onCreate, onEdit, onDelete };\n}\n\nexport function useEnableFloatingSidebar( enabled = false ) {\n\tconst registry = useRegistry();\n\tuseEffect( () => {\n\t\tif ( ! enabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { getActiveComplementaryArea } =\n\t\t\tregistry.select( interfaceStore );\n\t\tconst { disableComplementaryArea, enableComplementaryArea } =\n\t\t\tregistry.dispatch( interfaceStore );\n\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Return `null` to indicate the user hid the complementary area.\n\t\t\tif ( getActiveComplementaryArea( 'core' ) === null ) {\n\t\t\t\tenableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tif (\n\t\t\t\tgetActiveComplementaryArea( 'core' ) === FLOATING_NOTES_SIDEBAR\n\t\t\t) {\n\t\t\t\tdisableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );\n\t\t\t}\n\t\t};\n\t}, [ enabled, registry ] );\n}\n\nexport function useFloatingBoard( {\n\tthreads,\n\tselectedNoteId,\n\tisFloating,\n\tsidebarRef,\n} ) {\n\tconst [ notePositions, setNotePositions ] = useState( {} );\n\tconst [ store ] = useState( createBoardStore );\n\n\tconst heights = useSyncExternalStore( store.subscribe, store.getSnapshot );\n\n\t// Notes are positioned in canvas content-space; CSS inherits\n\t// `--canvas-scroll` to translate each thread in sync with the canvas.\n\tuseEffect( () => {\n\t\tif ( ! isFloating || ! sidebarRef?.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst panel = sidebarRef.current;\n\t\tconst blockEl = store.getFirstBlockElement();\n\t\t// Climb to the block-list root so nested scroll containers\n\t\t// (e.g. a Group with overflow:auto) don't shadow the canvas.\n\t\tconst rootEl = blockEl?.closest( '.is-root-container' ) ?? blockEl;\n\t\tconst canvas = rootEl ? getScrollContainer( rootEl ) : null;\n\n\t\tconst applyScroll = () => {\n\t\t\tpanel.style.setProperty(\n\t\t\t\t'--canvas-scroll',\n\t\t\t\t`${ -( canvas?.scrollTop ?? 0 ) }px`\n\t\t\t);\n\t\t};\n\n\t\t// Recalc is deferred to a rAF; back-to-back updates collapse into one paint.\n\t\tconst rafId = window.requestAnimationFrame( () => {\n\t\t\tconst result = calculateNotePositions( {\n\t\t\t\tthreads,\n\t\t\t\tselectedNoteId,\n\t\t\t\tblockRects: store.getBlockRects(),\n\t\t\t\theights,\n\t\t\t\tscrollTop: canvas?.scrollTop ?? 0,\n\t\t\t} );\n\n\t\t\tsetNotePositions( result.positions );\n\t\t\tapplyScroll();\n\t\t} );\n\n\t\t// Root scrolling elements (documentElement/body) don't fire scroll\n\t\t// on themselves; capture on the window catches them in either canvas.\n\t\tconst view = canvas?.ownerDocument?.defaultView;\n\t\tconst listenerOptions = { passive: true, capture: true };\n\t\tview?.addEventListener( 'scroll', applyScroll, listenerOptions );\n\n\t\treturn () => {\n\t\t\twindow.cancelAnimationFrame( rafId );\n\t\t\tview?.removeEventListener( 'scroll', applyScroll, listenerOptions );\n\t\t};\n\t}, [ sidebarRef, heights, isFloating, selectedNoteId, store, threads ] );\n\n\treturn {\n\t\tnotePositions,\n\t\tregisterThread: store.registerThread,\n\t\tunregisterThread: store.unregisterThread,\n\t};\n}\n"],
5
+ "mappings": ";AAGA,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB,SAA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AAChB,QAAK,CAAE,cAAc,CAAE,YAAY,SAAU;AAC5C;AAAA,IACD;AAEA,UAAM,QAAQ,WAAW;AACzB,UAAM,UAAU,MAAM,qBAAqB;AAG3C,UAAM,SAAS,SAAS,QAAS,oBAAqB,KAAK;AAC3D,UAAM,SAAS,SAAS,mBAAoB,MAAO,IAAI;AAEvD,UAAM,cAAc,MAAM;AACzB,YAAM,MAAM;AAAA,QACX;AAAA,QACA,GAAI,EAAG,QAAQ,aAAa,EAAI;AAAA,MACjC;AAAA,IACD;AAGA,UAAM,QAAQ,OAAO,sBAAuB,MAAM;AACjD,YAAM,SAAS,uBAAwB;AAAA,QACtC;AAAA,QACA;AAAA,QACA,YAAY,MAAM,cAAc;AAAA,QAChC;AAAA,QACA,WAAW,QAAQ,aAAa;AAAA,MACjC,CAAE;AAEF,uBAAkB,OAAO,SAAU;AACnC,kBAAY;AAAA,IACb,CAAE;AAIF,UAAM,OAAO,QAAQ,eAAe;AACpC,UAAM,kBAAkB,EAAE,SAAS,MAAM,SAAS,KAAK;AACvD,UAAM,iBAAkB,UAAU,aAAa,eAAgB;AAE/D,WAAO,MAAM;AACZ,aAAO,qBAAsB,KAAM;AACnC,YAAM,oBAAqB,UAAU,aAAa,eAAgB;AAAA,IACnE;AAAA,EACD,GAAG,CAAE,YAAY,SAAS,YAAY,gBAAgB,OAAO,OAAQ,CAAE;AAEvE,SAAO;AAAA,IACN;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,kBAAkB,MAAM;AAAA,EACzB;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,13 +1,14 @@
1
1
  // packages/editor/src/components/collab-sidebar/index.js
2
2
  import { __ } from "@wordpress/i18n";
3
- import { useSelect, useDispatch } from "@wordpress/data";
4
- import { useRef } from "@wordpress/element";
3
+ import { useDispatch, useSelect } from "@wordpress/data";
4
+ import { useEffect, useRef } from "@wordpress/element";
5
5
  import { useViewportMatch } from "@wordpress/compose";
6
6
  import { useShortcut } from "@wordpress/keyboard-shortcuts";
7
7
  import { comment as commentIcon } from "@wordpress/icons";
8
8
  import { store as blockEditorStore } from "@wordpress/block-editor";
9
9
  import { store as interfaceStore } from "@wordpress/interface";
10
10
  import { store as preferencesStore } from "@wordpress/preferences";
11
+ import { registerFormatType, unregisterFormatType } from "@wordpress/rich-text";
11
12
  import PluginSidebar from "../plugin-sidebar/index.mjs";
12
13
  import {
13
14
  ALL_NOTES_SIDEBAR,
@@ -18,13 +19,21 @@ import { Notes } from "./notes.mjs";
18
19
  import { store as editorStore } from "../../store/index.mjs";
19
20
  import { AddNoteMenuItem } from "./add-note-menu-item.mjs";
20
21
  import { NoteAvatarIndicator } from "./note-indicator-toolbar.mjs";
22
+ import { NoteHighlightStyles } from "./note-highlight-styles.mjs";
21
23
  import { useGlobalStyles } from "../global-styles/index.mjs";
22
- import { useNoteThreads, useEnableFloatingSidebar } from "./hooks.mjs";
24
+ import { useEnableFloatingSidebar, useNoteThreads } from "./hooks.mjs";
23
25
  import { getNoteIdsFromMetadata, pickPrimaryNote } from "./utils.mjs";
26
+ import { NOTE_FORMAT_NAME, noteFormat } from "./format.mjs";
24
27
  import PostTypeSupportCheck from "../post-type-support-check/index.mjs";
25
28
  import { unlock } from "../../lock-unlock.mjs";
26
29
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
27
30
  function NotesSidebar({ postId }) {
31
+ useEffect(() => {
32
+ registerFormatType(NOTE_FORMAT_NAME, noteFormat);
33
+ return () => {
34
+ unregisterFormatType(NOTE_FORMAT_NAME);
35
+ };
36
+ }, []);
28
37
  const { getActiveComplementaryArea } = useSelect(interfaceStore);
29
38
  const { enableComplementaryArea } = useDispatch(interfaceStore);
30
39
  const { toggleBlockSpotlight, selectBlock } = unlock(
@@ -49,7 +58,7 @@ function NotesSidebar({ postId }) {
49
58
  isDistractionFree: get("core", "distractionFree")
50
59
  };
51
60
  }, []);
52
- const selectedNote = useSelect(
61
+ const selectedNoteId = useSelect(
53
62
  (select) => unlock(select(editorStore)).getSelectedNote(),
54
63
  []
55
64
  );
@@ -57,7 +66,7 @@ function NotesSidebar({ postId }) {
57
66
  const showFloatingSidebar = isLargeViewport;
58
67
  const showAllNotesSidebar = notes.length > 0 || !showFloatingSidebar;
59
68
  useEnableFloatingSidebar(
60
- showFloatingSidebar && (unresolvedNotes.length > 0 || selectedNote !== void 0)
69
+ showFloatingSidebar && (unresolvedNotes.length > 0 || selectedNoteId !== void 0)
61
70
  );
62
71
  async function focusNote({
63
72
  targetClientId,
@@ -120,6 +129,13 @@ function NotesSidebar({ postId }) {
120
129
  return /* @__PURE__ */ jsx(AddNoteMenuItem, { isDistractionFree: true });
121
130
  }
122
131
  return /* @__PURE__ */ jsxs(Fragment, { children: [
132
+ /* @__PURE__ */ jsx(
133
+ NoteHighlightStyles,
134
+ {
135
+ threads: unresolvedNotes,
136
+ selectedId: selectedNoteId
137
+ }
138
+ ),
123
139
  !!currentThread && /* @__PURE__ */ jsx(
124
140
  NoteAvatarIndicator,
125
141
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/collab-sidebar/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { comment as commentIcon } from '@wordpress/icons';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport PluginSidebar from '../plugin-sidebar';\nimport {\n\tALL_NOTES_SIDEBAR,\n\tFLOATING_NOTES_SIDEBAR,\n\tSIDEBARS,\n} from './constants';\nimport { Notes } from './notes';\nimport { store as editorStore } from '../../store';\nimport { AddNoteMenuItem } from './add-note-menu-item';\nimport { NoteAvatarIndicator } from './note-indicator-toolbar';\nimport { useGlobalStyles } from '../global-styles';\nimport { useNoteThreads, useEnableFloatingSidebar } from './hooks';\nimport { getNoteIdsFromMetadata, pickPrimaryNote } from './utils';\nimport PostTypeSupportCheck from '../post-type-support-check';\nimport { unlock } from '../../lock-unlock';\n\nfunction NotesSidebar( { postId } ) {\n\tconst { getActiveComplementaryArea } = useSelect( interfaceStore );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst { toggleBlockSpotlight, selectBlock } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tconst { selectNote } = unlock( useDispatch( editorStore ) );\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst sidebarRef = useRef( null );\n\n\tconst { clientId, noteId, isClassicBlock } = useSelect( ( select ) => {\n\t\tconst { getBlockAttributes, getSelectedBlockClientId, getBlockName } =\n\t\t\tselect( blockEditorStore );\n\t\tconst _clientId = getSelectedBlockClientId();\n\t\treturn {\n\t\t\tclientId: _clientId,\n\t\t\tnoteId: _clientId\n\t\t\t\t? getBlockAttributes( _clientId )?.metadata?.noteId\n\t\t\t\t: null,\n\t\t\tisClassicBlock: _clientId\n\t\t\t\t? getBlockName( _clientId ) === 'core/freeform'\n\t\t\t\t: false,\n\t\t};\n\t}, [] );\n\n\tconst blockNoteIds = getNoteIdsFromMetadata( { noteId } );\n\tconst { isDistractionFree } = useSelect( ( select ) => {\n\t\tconst { get } = select( preferencesStore );\n\t\treturn {\n\t\t\tisDistractionFree: get( 'core', 'distractionFree' ),\n\t\t};\n\t}, [] );\n\tconst selectedNote = useSelect(\n\t\t( select ) => unlock( select( editorStore ) ).getSelectedNote(),\n\t\t[]\n\t);\n\n\tconst { notes, unresolvedNotes } = useNoteThreads( postId );\n\n\t// Only enable the floating sidebar for large viewports.\n\tconst showFloatingSidebar = isLargeViewport;\n\t// Fallback to \"All notes\" sidebar on smaller viewports.\n\tconst showAllNotesSidebar = notes.length > 0 || ! showFloatingSidebar;\n\tuseEnableFloatingSidebar(\n\t\tshowFloatingSidebar &&\n\t\t\t( unresolvedNotes.length > 0 || selectedNote !== undefined )\n\t);\n\n\tasync function focusNote( {\n\t\ttargetClientId,\n\t\tnoteId: targetNoteId,\n\t\tisApproved,\n\t} ) {\n\t\tif ( ! targetClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevArea = await getActiveComplementaryArea( 'core' );\n\t\tif ( isApproved ) {\n\t\t\tenableComplementaryArea( 'core', ALL_NOTES_SIDEBAR );\n\t\t} else if ( ! SIDEBARS.includes( prevArea ) || ! showAllNotesSidebar ) {\n\t\t\tenableComplementaryArea(\n\t\t\t\t'core',\n\t\t\t\tshowFloatingSidebar ? FLOATING_NOTES_SIDEBAR : ALL_NOTES_SIDEBAR\n\t\t\t);\n\t\t}\n\n\t\tconst currentArea = await getActiveComplementaryArea( 'core' );\n\t\t// Bail out if the current active area is not one of note sidebars.\n\t\tif ( ! SIDEBARS.includes( currentArea ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// A special case for the List View, where block selection isn't required to trigger an action.\n\t\t// The action won't do anything if the block is already selected.\n\t\tselectBlock( targetClientId, null );\n\t\ttoggleBlockSpotlight( targetClientId, true );\n\t\tselectNote( targetNoteId, { focus: true } );\n\t}\n\n\tfunction openNoteForBlock( targetClientId ) {\n\t\t// A block can carry multiple threads; surface the most relevant.\n\t\tconst blockThreads = notes.filter(\n\t\t\t( thread ) => thread.blockClientId === targetClientId\n\t\t);\n\t\tconst target = pickPrimaryNote( blockThreads );\n\t\treturn focusNote( {\n\t\t\ttargetClientId,\n\t\t\tnoteId: target?.id ?? 'new',\n\t\t\tisApproved: target?.status === 'approved',\n\t\t} );\n\t}\n\n\tfunction addNewNoteForBlock( targetClientId ) {\n\t\treturn focusNote( {\n\t\t\ttargetClientId,\n\t\t\tnoteId: 'new',\n\t\t\tisApproved: false,\n\t\t} );\n\t}\n\n\tuseShortcut(\n\t\t'core/editor/new-note',\n\t\t( event ) => {\n\t\t\tevent.preventDefault();\n\t\t\taddNewNoteForBlock( clientId );\n\t\t},\n\t\t{\n\t\t\tisDisabled: isDistractionFree || isClassicBlock || ! clientId,\n\t\t}\n\t);\n\n\t// Get the global styles to set the background color of the sidebar.\n\tconst { merged: GlobalStyles } = useGlobalStyles();\n\tconst backgroundColor = GlobalStyles?.styles?.color?.background;\n\n\t// Surface one thread for the avatar indicator.\n\tconst currentThreads =\n\t\tblockNoteIds.length > 0\n\t\t\t? notes.filter( ( thread ) => blockNoteIds.includes( thread.id ) )\n\t\t\t: [];\n\tconst currentThread = pickPrimaryNote( currentThreads );\n\n\tif ( isDistractionFree ) {\n\t\treturn <AddNoteMenuItem isDistractionFree />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ !! currentThread && (\n\t\t\t\t<NoteAvatarIndicator\n\t\t\t\t\tnote={ currentThread }\n\t\t\t\t\tonClick={ () => openNoteForBlock( clientId ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<AddNoteMenuItem\n\t\t\t\tonClick={ ( menuClientId ) =>\n\t\t\t\t\taddNewNoteForBlock( menuClientId )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ showAllNotesSidebar && (\n\t\t\t\t<PluginSidebar\n\t\t\t\t\tidentifier={ ALL_NOTES_SIDEBAR }\n\t\t\t\t\tname={ ALL_NOTES_SIDEBAR }\n\t\t\t\t\ttitle={ __( 'All notes' ) }\n\t\t\t\t\theader={\n\t\t\t\t\t\t<h2 className=\"interface-complementary-area-header__title\">\n\t\t\t\t\t\t\t{ __( 'All notes' ) }\n\t\t\t\t\t\t</h2>\n\t\t\t\t\t}\n\t\t\t\t\ticon={ commentIcon }\n\t\t\t\t\tcloseLabel={ __( 'Close Notes' ) }\n\t\t\t\t>\n\t\t\t\t\t<Notes notes={ notes } sidebarRef={ sidebarRef } />\n\t\t\t\t</PluginSidebar>\n\t\t\t) }\n\t\t\t{ isLargeViewport && (\n\t\t\t\t<PluginSidebar\n\t\t\t\t\tisPinnable={ false }\n\t\t\t\t\theader={ false }\n\t\t\t\t\tidentifier={ FLOATING_NOTES_SIDEBAR }\n\t\t\t\t\tclassName=\"editor-collab-sidebar\"\n\t\t\t\t\theaderClassName=\"editor-collab-sidebar__header\"\n\t\t\t\t\tbackgroundColor={ backgroundColor }\n\t\t\t\t>\n\t\t\t\t\t<Notes\n\t\t\t\t\t\tnotes={ unresolvedNotes }\n\t\t\t\t\t\tsidebarRef={ sidebarRef }\n\t\t\t\t\t\tstyles={ { backgroundColor } }\n\t\t\t\t\t\tisFloating\n\t\t\t\t\t/>\n\t\t\t\t</PluginSidebar>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default function NotesSidebarContainer() {\n\tconst { postId, editorMode, revisionsMode } = useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getEditorMode, isRevisionsMode } = unlock(\n\t\t\tselect( editorStore )\n\t\t);\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\teditorMode: getEditorMode(),\n\t\t\trevisionsMode: isRevisionsMode(),\n\t\t};\n\t}, [] );\n\n\tif ( ! postId || typeof postId !== 'number' ) {\n\t\treturn null;\n\t}\n\n\t// Hide Notes sidebar for Code Editor and in-editor revision mode.\n\tif ( editorMode === 'text' || revisionsMode ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PostTypeSupportCheck supportKeys=\"editor.notes\">\n\t\t\t<NotesSidebar postId={ postId } />\n\t\t</PostTypeSupportCheck>\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,WAAW,mBAAmB;AACvC,SAAS,cAAc;AACvB,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,SAAS,sBAAsB;AACxC,SAAS,SAAS,wBAAwB;AAK1C,OAAO,mBAAmB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa;AACtB,SAAS,SAAS,mBAAmB;AACr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5D,OAAQ,WAAY;AAAA,IACrB;AACA,WAAO;AAAA,MACN,QAAQ,iBAAiB;AAAA,MACzB,YAAY,cAAc;AAAA,MAC1B,eAAe,gBAAgB;AAAA,IAChC;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,MAAK,CAAE,UAAU,OAAO,WAAW,UAAW;AAC7C,WAAO;AAAA,EACR;AAGA,MAAK,eAAe,UAAU,eAAgB;AAC7C,WAAO;AAAA,EACR;AAEA,SACC,oBAAC,wBAAqB,aAAY,gBACjC,8BAAC,gBAAa,QAAkB,GACjC;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\nimport { comment as commentIcon } from '@wordpress/icons';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { registerFormatType, unregisterFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport PluginSidebar from '../plugin-sidebar';\nimport {\n\tALL_NOTES_SIDEBAR,\n\tFLOATING_NOTES_SIDEBAR,\n\tSIDEBARS,\n} from './constants';\nimport { Notes } from './notes';\nimport { store as editorStore } from '../../store';\nimport { AddNoteMenuItem } from './add-note-menu-item';\nimport { NoteAvatarIndicator } from './note-indicator-toolbar';\nimport { NoteHighlightStyles } from './note-highlight-styles';\nimport { useGlobalStyles } from '../global-styles';\nimport { useEnableFloatingSidebar, useNoteThreads } from './hooks';\nimport { getNoteIdsFromMetadata, pickPrimaryNote } from './utils';\nimport { NOTE_FORMAT_NAME, noteFormat } from './format';\nimport PostTypeSupportCheck from '../post-type-support-check';\nimport { unlock } from '../../lock-unlock';\n\nfunction NotesSidebar( { postId } ) {\n\tuseEffect( () => {\n\t\tregisterFormatType( NOTE_FORMAT_NAME, noteFormat );\n\t\treturn () => {\n\t\t\tunregisterFormatType( NOTE_FORMAT_NAME );\n\t\t};\n\t}, [] );\n\n\tconst { getActiveComplementaryArea } = useSelect( interfaceStore );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst { toggleBlockSpotlight, selectBlock } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tconst { selectNote } = unlock( useDispatch( editorStore ) );\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst sidebarRef = useRef( null );\n\n\tconst { clientId, noteId, isClassicBlock } = useSelect( ( select ) => {\n\t\tconst { getBlockAttributes, getSelectedBlockClientId, getBlockName } =\n\t\t\tselect( blockEditorStore );\n\t\tconst _clientId = getSelectedBlockClientId();\n\t\treturn {\n\t\t\tclientId: _clientId,\n\t\t\tnoteId: _clientId\n\t\t\t\t? getBlockAttributes( _clientId )?.metadata?.noteId\n\t\t\t\t: null,\n\t\t\tisClassicBlock: _clientId\n\t\t\t\t? getBlockName( _clientId ) === 'core/freeform'\n\t\t\t\t: false,\n\t\t};\n\t}, [] );\n\n\tconst blockNoteIds = getNoteIdsFromMetadata( { noteId } );\n\tconst { isDistractionFree } = useSelect( ( select ) => {\n\t\tconst { get } = select( preferencesStore );\n\t\treturn {\n\t\t\tisDistractionFree: get( 'core', 'distractionFree' ),\n\t\t};\n\t}, [] );\n\tconst selectedNoteId = useSelect(\n\t\t( select ) => unlock( select( editorStore ) ).getSelectedNote(),\n\t\t[]\n\t);\n\n\tconst { notes, unresolvedNotes } = useNoteThreads( postId );\n\n\t// Only enable the floating sidebar for large viewports.\n\tconst showFloatingSidebar = isLargeViewport;\n\t// Fallback to \"All notes\" sidebar on smaller viewports.\n\tconst showAllNotesSidebar = notes.length > 0 || ! showFloatingSidebar;\n\tuseEnableFloatingSidebar(\n\t\tshowFloatingSidebar &&\n\t\t\t( unresolvedNotes.length > 0 || selectedNoteId !== undefined )\n\t);\n\n\tasync function focusNote( {\n\t\ttargetClientId,\n\t\tnoteId: targetNoteId,\n\t\tisApproved,\n\t} ) {\n\t\tif ( ! targetClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevArea = await getActiveComplementaryArea( 'core' );\n\t\tif ( isApproved ) {\n\t\t\tenableComplementaryArea( 'core', ALL_NOTES_SIDEBAR );\n\t\t} else if ( ! SIDEBARS.includes( prevArea ) || ! showAllNotesSidebar ) {\n\t\t\tenableComplementaryArea(\n\t\t\t\t'core',\n\t\t\t\tshowFloatingSidebar ? FLOATING_NOTES_SIDEBAR : ALL_NOTES_SIDEBAR\n\t\t\t);\n\t\t}\n\n\t\tconst currentArea = await getActiveComplementaryArea( 'core' );\n\t\t// Bail out if the current active area is not one of note sidebars.\n\t\tif ( ! SIDEBARS.includes( currentArea ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// A special case for the List View, where block selection isn't required to trigger an action.\n\t\t// The action won't do anything if the block is already selected.\n\t\tselectBlock( targetClientId, null );\n\t\ttoggleBlockSpotlight( targetClientId, true );\n\t\tselectNote( targetNoteId, { focus: true } );\n\t}\n\n\tfunction openNoteForBlock( targetClientId ) {\n\t\t// A block can carry multiple threads; surface the most relevant.\n\t\tconst blockThreads = notes.filter(\n\t\t\t( thread ) => thread.blockClientId === targetClientId\n\t\t);\n\t\tconst target = pickPrimaryNote( blockThreads );\n\t\treturn focusNote( {\n\t\t\ttargetClientId,\n\t\t\tnoteId: target?.id ?? 'new',\n\t\t\tisApproved: target?.status === 'approved',\n\t\t} );\n\t}\n\n\tfunction addNewNoteForBlock( targetClientId ) {\n\t\treturn focusNote( {\n\t\t\ttargetClientId,\n\t\t\tnoteId: 'new',\n\t\t\tisApproved: false,\n\t\t} );\n\t}\n\n\tuseShortcut(\n\t\t'core/editor/new-note',\n\t\t( event ) => {\n\t\t\tevent.preventDefault();\n\t\t\taddNewNoteForBlock( clientId );\n\t\t},\n\t\t{\n\t\t\tisDisabled: isDistractionFree || isClassicBlock || ! clientId,\n\t\t}\n\t);\n\n\t// Get the global styles to set the background color of the sidebar.\n\tconst { merged: GlobalStyles } = useGlobalStyles();\n\tconst backgroundColor = GlobalStyles?.styles?.color?.background;\n\n\t// Surface one thread for the avatar indicator.\n\tconst currentThreads =\n\t\tblockNoteIds.length > 0\n\t\t\t? notes.filter( ( thread ) => blockNoteIds.includes( thread.id ) )\n\t\t\t: [];\n\tconst currentThread = pickPrimaryNote( currentThreads );\n\n\tif ( isDistractionFree ) {\n\t\treturn <AddNoteMenuItem isDistractionFree />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<NoteHighlightStyles\n\t\t\t\tthreads={ unresolvedNotes }\n\t\t\t\tselectedId={ selectedNoteId }\n\t\t\t/>\n\t\t\t{ !! currentThread && (\n\t\t\t\t<NoteAvatarIndicator\n\t\t\t\t\tnote={ currentThread }\n\t\t\t\t\tonClick={ () => openNoteForBlock( clientId ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<AddNoteMenuItem\n\t\t\t\tonClick={ ( menuClientId ) =>\n\t\t\t\t\taddNewNoteForBlock( menuClientId )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ showAllNotesSidebar && (\n\t\t\t\t<PluginSidebar\n\t\t\t\t\tidentifier={ ALL_NOTES_SIDEBAR }\n\t\t\t\t\tname={ ALL_NOTES_SIDEBAR }\n\t\t\t\t\ttitle={ __( 'All notes' ) }\n\t\t\t\t\theader={\n\t\t\t\t\t\t<h2 className=\"interface-complementary-area-header__title\">\n\t\t\t\t\t\t\t{ __( 'All notes' ) }\n\t\t\t\t\t\t</h2>\n\t\t\t\t\t}\n\t\t\t\t\ticon={ commentIcon }\n\t\t\t\t\tcloseLabel={ __( 'Close Notes' ) }\n\t\t\t\t>\n\t\t\t\t\t<Notes notes={ notes } sidebarRef={ sidebarRef } />\n\t\t\t\t</PluginSidebar>\n\t\t\t) }\n\t\t\t{ isLargeViewport && (\n\t\t\t\t<PluginSidebar\n\t\t\t\t\tisPinnable={ false }\n\t\t\t\t\theader={ false }\n\t\t\t\t\tidentifier={ FLOATING_NOTES_SIDEBAR }\n\t\t\t\t\tclassName=\"editor-collab-sidebar\"\n\t\t\t\t\theaderClassName=\"editor-collab-sidebar__header\"\n\t\t\t\t\tbackgroundColor={ backgroundColor }\n\t\t\t\t>\n\t\t\t\t\t<Notes\n\t\t\t\t\t\tnotes={ unresolvedNotes }\n\t\t\t\t\t\tsidebarRef={ sidebarRef }\n\t\t\t\t\t\tstyles={ { backgroundColor } }\n\t\t\t\t\t\tisFloating\n\t\t\t\t\t/>\n\t\t\t\t</PluginSidebar>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default function NotesSidebarContainer() {\n\tconst { postId, editorMode, revisionsMode } = useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getEditorMode, isRevisionsMode } = unlock(\n\t\t\tselect( editorStore )\n\t\t);\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\teditorMode: getEditorMode(),\n\t\t\trevisionsMode: isRevisionsMode(),\n\t\t};\n\t}, [] );\n\n\tif ( ! postId || typeof postId !== 'number' ) {\n\t\treturn null;\n\t}\n\n\t// Hide Notes sidebar for Code Editor and in-editor revision mode.\n\tif ( editorMode === 'text' || revisionsMode ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PostTypeSupportCheck supportKeys=\"editor.notes\">\n\t\t\t<NotesSidebar postId={ postId } />\n\t\t</PostTypeSupportCheck>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,aAAa,iBAAiB;AACvC,SAAS,WAAW,cAAc;AAClC,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,SAAS,sBAAsB;AACxC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,oBAAoB,4BAA4B;AAKzD,OAAO,mBAAmB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAC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,QAChB;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,OAAQ;AAAA,YACR;AAAA,YACA,QAAS,EAAE,gBAAgB;AAAA,YAC3B,YAAU;AAAA;AAAA,QACX;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEe,SAAR,wBAAyC;AAC/C,QAAM,EAAE,QAAQ,YAAY,cAAc,IAAI,UAAW,CAAE,WAAY;AACtE,UAAM,EAAE,kBAAkB,eAAe,gBAAgB,IAAI;AAAA,MAC5D,OAAQ,WAAY;AAAA,IACrB;AACA,WAAO;AAAA,MACN,QAAQ,iBAAiB;AAAA,MACzB,YAAY,cAAc;AAAA,MAC1B,eAAe,gBAAgB;AAAA,IAChC;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,MAAK,CAAE,UAAU,OAAO,WAAW,UAAW;AAC7C,WAAO;AAAA,EACR;AAGA,MAAK,eAAe,UAAU,eAAgB;AAC7C,WAAO;AAAA,EACR;AAEA,SACC,oBAAC,wBAAqB,aAAY,gBACjC,8BAAC,gBAAa,QAAkB,GACjC;AAEF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,41 @@
1
+ // packages/editor/src/components/collab-sidebar/note-highlight-styles.js
2
+ import { useMemo } from "@wordpress/element";
3
+ import { useStyleOverride } from "@wordpress/block-editor";
4
+ import { getAvatarBorderColor } from "./utils.mjs";
5
+ var REST_ALPHA = "40";
6
+ var ACTIVE_ALPHA = "80";
7
+ var BASE_RESET = "mark.wp-note{background-color:transparent;color:inherit;}";
8
+ function buildHighlightCss(threads, selectedId = null) {
9
+ const rules = [BASE_RESET];
10
+ for (const thread of threads ?? []) {
11
+ if (!thread?.id) {
12
+ continue;
13
+ }
14
+ const color = getAvatarBorderColor(thread.author ?? 0);
15
+ const escapedId = String(thread.id).replace(/["\\]/g, "\\$&");
16
+ const sel = `mark.wp-note[data-id="${escapedId}"]`;
17
+ rules.push(`${sel}{background-color:${color}${REST_ALPHA};}`);
18
+ rules.push(
19
+ `${sel}:hover,${sel}:focus-within{background-color:${color}${ACTIVE_ALPHA};}`
20
+ );
21
+ if (selectedId && String(selectedId) === String(thread.id)) {
22
+ rules.push(
23
+ `${sel}{background-color:${color}${ACTIVE_ALPHA};}`
24
+ );
25
+ }
26
+ }
27
+ return rules.join("");
28
+ }
29
+ function NoteHighlightStyles({ threads, selectedId }) {
30
+ const css = useMemo(
31
+ () => buildHighlightCss(threads, selectedId),
32
+ [threads, selectedId]
33
+ );
34
+ useStyleOverride({ id: "core-note-highlights", css });
35
+ return null;
36
+ }
37
+ export {
38
+ NoteHighlightStyles,
39
+ buildHighlightCss
40
+ };
41
+ //# sourceMappingURL=note-highlight-styles.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/collab-sidebar/note-highlight-styles.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useStyleOverride } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { getAvatarBorderColor } from './utils';\n\n// Hex alpha suffixes for the rest / active states. Kept low so the marker\n// reads as a soft tint at rest and gets noticeably stronger when focused or\n// hovered. (0x40 ≈ 25%, 0x80 ≈ 50%.)\nconst REST_ALPHA = '40';\nconst ACTIVE_ALPHA = '80';\n\n// Reset the browser's default `<mark>` styling so the per-author rules below\n// are what readers actually see (without it, `mark` ships with a bright yellow\n// background in every browser). The `core/note` anchor marker serializes as a\n// `<mark>` and would otherwise inherit the yellow default in the editor canvas.\nconst BASE_RESET = 'mark.wp-note{background-color:transparent;color:inherit;}';\n\n/**\n * Build the CSS rule set that tints each inline-note marker with its author's\n * avatar color. Pure helper extracted so it can be unit-tested without React.\n *\n * @param {Array} threads Unresolved note threads (each with `id` and `author`).\n * @param {string|null} selectedId ID of the currently selected note, if any.\n * @return {string} A serialized CSS string targeting the in-content note markers.\n */\nexport function buildHighlightCss( threads, selectedId = null ) {\n\tconst rules = [ BASE_RESET ];\n\tfor ( const thread of threads ?? [] ) {\n\t\tif ( ! thread?.id ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst color = getAvatarBorderColor( thread.author ?? 0 );\n\t\t// The `core/note` format serializes the id into `data-id`, so the marker\n\t\t// can be targeted directly without a separate annotation layer.\n\t\t// `thread.id` is a server comment ID (always a positive integer), but\n\t\t// escape `\"`/`\\` defensively since it composes a quoted attribute value\n\t\t// from stored data.\n\t\tconst escapedId = String( thread.id ).replace( /[\"\\\\]/g, '\\\\$&' );\n\t\tconst sel = `mark.wp-note[data-id=\"${ escapedId }\"]`;\n\t\trules.push( `${ sel }{background-color:${ color }${ REST_ALPHA };}` );\n\t\trules.push(\n\t\t\t`${ sel }:hover,${ sel }:focus-within{background-color:${ color }${ ACTIVE_ALPHA };}`\n\t\t);\n\t\tif ( selectedId && String( selectedId ) === String( thread.id ) ) {\n\t\t\trules.push(\n\t\t\t\t`${ sel }{background-color:${ color }${ ACTIVE_ALPHA };}`\n\t\t\t);\n\t\t}\n\t}\n\treturn rules.join( '' );\n}\n\n/**\n * Injects per-note background rules into the editor canvas so inline-note\n * markers carry their author's avatar color. The `core/note` format serializes\n * each marker as `<mark class=\"wp-note\" data-id=\"{noteId}\">`, which we target\n * directly.\n *\n * Uses `useStyleOverride` so the styles reach the iframed canvas; a plain\n * `<style>` element rendered in the sidebar would only affect the parent doc.\n *\n * Opacity boosts on `:hover`, `:focus-within`, and when the matching thread is\n * the editor's selected note.\n *\n * @param {Object} props\n * @param {Array} props.threads Unresolved note threads.\n * @param {string|null} [props.selectedId] ID of the currently selected note.\n * @return {null} Renders nothing; styles are applied via `useStyleOverride`.\n */\nexport function NoteHighlightStyles( { threads, selectedId } ) {\n\tconst css = useMemo(\n\t\t() => buildHighlightCss( threads, selectedId ),\n\t\t[ threads, selectedId ]\n\t);\n\tuseStyleOverride( { id: 'core-note-highlights', css } );\n\treturn null;\n}\n"],
5
+ "mappings": ";AAGA,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAKjC,SAAS,4BAA4B;AAKrC,IAAM,aAAa;AACnB,IAAM,eAAe;AAMrB,IAAM,aAAa;AAUZ,SAAS,kBAAmB,SAAS,aAAa,MAAO;AAC/D,QAAM,QAAQ,CAAE,UAAW;AAC3B,aAAY,UAAU,WAAW,CAAC,GAAI;AACrC,QAAK,CAAE,QAAQ,IAAK;AACnB;AAAA,IACD;AACA,UAAM,QAAQ,qBAAsB,OAAO,UAAU,CAAE;AAMvD,UAAM,YAAY,OAAQ,OAAO,EAAG,EAAE,QAAS,UAAU,MAAO;AAChE,UAAM,MAAM,yBAA0B,SAAU;AAChD,UAAM,KAAM,GAAI,GAAI,qBAAsB,KAAM,GAAI,UAAW,IAAK;AACpE,UAAM;AAAA,MACL,GAAI,GAAI,UAAW,GAAI,kCAAmC,KAAM,GAAI,YAAa;AAAA,IAClF;AACA,QAAK,cAAc,OAAQ,UAAW,MAAM,OAAQ,OAAO,EAAG,GAAI;AACjE,YAAM;AAAA,QACL,GAAI,GAAI,qBAAsB,KAAM,GAAI,YAAa;AAAA,MACtD;AAAA,IACD;AAAA,EACD;AACA,SAAO,MAAM,KAAM,EAAG;AACvB;AAmBO,SAAS,oBAAqB,EAAE,SAAS,WAAW,GAAI;AAC9D,QAAM,MAAM;AAAA,IACX,MAAM,kBAAmB,SAAS,UAAW;AAAA,IAC7C,CAAE,SAAS,UAAW;AAAA,EACvB;AACA,mBAAkB,EAAE,IAAI,wBAAwB,IAAI,CAAE;AACtD,SAAO;AACR;",
6
+ "names": []
7
+ }