@wordpress/editor 14.50.0 → 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.
- package/CHANGELOG.md +10 -0
- package/build/components/collab-sidebar/format.cjs +83 -0
- package/build/components/collab-sidebar/format.cjs.map +7 -0
- package/build/components/collab-sidebar/hooks.cjs +117 -16
- package/build/components/collab-sidebar/hooks.cjs.map +2 -2
- package/build/components/collab-sidebar/index.cjs +18 -2
- package/build/components/collab-sidebar/index.cjs.map +2 -2
- package/build/components/collab-sidebar/note-highlight-styles.cjs +67 -0
- package/build/components/collab-sidebar/note-highlight-styles.cjs.map +7 -0
- package/build/components/collab-sidebar/utils.cjs +139 -0
- package/build/components/collab-sidebar/utils.cjs.map +2 -2
- package/build/components/collaborators-presence/use-collaborator-notifications.cjs +55 -30
- package/build/components/collaborators-presence/use-collaborator-notifications.cjs.map +2 -2
- package/build/components/commands/index.cjs +99 -3
- package/build/components/commands/index.cjs.map +2 -2
- package/build/components/document-bar/index.cjs +28 -34
- package/build/components/document-bar/index.cjs.map +2 -2
- package/build/components/entities-saved-states/index.cjs +1 -4
- package/build/components/entities-saved-states/index.cjs.map +2 -2
- package/build/components/media-categories/index.cjs +92 -6
- package/build/components/media-categories/index.cjs.map +2 -2
- package/build/components/page-attributes/parent.cjs +0 -1
- package/build/components/page-attributes/parent.cjs.map +2 -2
- package/build/components/post-author/combobox.cjs +0 -1
- package/build/components/post-author/combobox.cjs.map +2 -2
- package/build/components/post-author/select.cjs +0 -1
- package/build/components/post-author/select.cjs.map +2 -2
- package/build/components/post-preview-button/index.cjs +29 -2
- package/build/components/post-preview-button/index.cjs.map +2 -2
- package/build/components/post-publish-panel/maybe-upload-media.cjs +15 -26
- package/build/components/post-publish-panel/maybe-upload-media.cjs.map +3 -3
- package/build/components/post-revisions-preview/revisions-slider.cjs +3 -1
- package/build/components/post-revisions-preview/revisions-slider.cjs.map +2 -2
- package/build/components/post-taxonomies/flat-term-selector.cjs +0 -1
- package/build/components/post-taxonomies/flat-term-selector.cjs.map +2 -2
- package/build/components/post-taxonomies/hierarchical-term-selector.cjs +0 -2
- package/build/components/post-taxonomies/hierarchical-term-selector.cjs.map +2 -2
- package/build/components/post-template/classic-theme.cjs +0 -1
- package/build/components/post-template/classic-theme.cjs.map +2 -2
- package/build/components/preferences-modal/index.cjs +54 -28
- package/build/components/preferences-modal/index.cjs.map +2 -2
- package/build/components/preview-dropdown/index.cjs +3 -3
- package/build/components/preview-dropdown/index.cjs.map +2 -2
- package/build/components/provider/use-block-editor-settings.cjs +23 -3
- package/build/components/provider/use-block-editor-settings.cjs.map +3 -3
- package/build/components/sidebar/dataform-post-summary.cjs +5 -1
- package/build/components/sidebar/dataform-post-summary.cjs.map +3 -3
- package/build/components/sidebar/index.cjs +29 -38
- package/build/components/sidebar/index.cjs.map +3 -3
- package/build/components/sidebar/post-summary.cjs +0 -13
- package/build/components/sidebar/post-summary.cjs.map +3 -3
- package/build/dataviews/store/private-actions.cjs +24 -19
- package/build/dataviews/store/private-actions.cjs.map +2 -2
- package/build/store/private-actions.cjs +5 -2
- package/build/store/private-actions.cjs.map +2 -2
- package/build/utils/media-sideload-from-url/index.cjs +63 -0
- package/build/utils/media-sideload-from-url/index.cjs.map +7 -0
- package/build-module/components/collab-sidebar/format.mjs +57 -0
- package/build-module/components/collab-sidebar/format.mjs.map +7 -0
- package/build-module/components/collab-sidebar/hooks.mjs +121 -16
- package/build-module/components/collab-sidebar/hooks.mjs.map +2 -2
- package/build-module/components/collab-sidebar/index.mjs +21 -5
- package/build-module/components/collab-sidebar/index.mjs.map +2 -2
- package/build-module/components/collab-sidebar/note-highlight-styles.mjs +41 -0
- package/build-module/components/collab-sidebar/note-highlight-styles.mjs.map +7 -0
- package/build-module/components/collab-sidebar/utils.mjs +133 -0
- package/build-module/components/collab-sidebar/utils.mjs.map +2 -2
- package/build-module/components/collaborators-presence/use-collaborator-notifications.mjs +55 -30
- package/build-module/components/collaborators-presence/use-collaborator-notifications.mjs.map +2 -2
- package/build-module/components/commands/index.mjs +99 -3
- package/build-module/components/commands/index.mjs.map +2 -2
- package/build-module/components/document-bar/index.mjs +28 -34
- package/build-module/components/document-bar/index.mjs.map +2 -2
- package/build-module/components/entities-saved-states/index.mjs +1 -4
- package/build-module/components/entities-saved-states/index.mjs.map +2 -2
- package/build-module/components/media-categories/index.mjs +93 -7
- package/build-module/components/media-categories/index.mjs.map +2 -2
- package/build-module/components/page-attributes/parent.mjs +0 -1
- package/build-module/components/page-attributes/parent.mjs.map +2 -2
- package/build-module/components/post-author/combobox.mjs +0 -1
- package/build-module/components/post-author/combobox.mjs.map +2 -2
- package/build-module/components/post-author/select.mjs +0 -1
- package/build-module/components/post-author/select.mjs.map +2 -2
- package/build-module/components/post-preview-button/index.mjs +29 -2
- package/build-module/components/post-preview-button/index.mjs.map +2 -2
- package/build-module/components/post-publish-panel/maybe-upload-media.mjs +19 -27
- package/build-module/components/post-publish-panel/maybe-upload-media.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/revisions-slider.mjs +3 -1
- package/build-module/components/post-revisions-preview/revisions-slider.mjs.map +2 -2
- package/build-module/components/post-taxonomies/flat-term-selector.mjs +0 -1
- package/build-module/components/post-taxonomies/flat-term-selector.mjs.map +2 -2
- package/build-module/components/post-taxonomies/hierarchical-term-selector.mjs +0 -2
- package/build-module/components/post-taxonomies/hierarchical-term-selector.mjs.map +2 -2
- package/build-module/components/post-template/classic-theme.mjs +0 -1
- package/build-module/components/post-template/classic-theme.mjs.map +2 -2
- package/build-module/components/preferences-modal/index.mjs +54 -28
- package/build-module/components/preferences-modal/index.mjs.map +2 -2
- package/build-module/components/preview-dropdown/index.mjs +3 -3
- package/build-module/components/preview-dropdown/index.mjs.map +2 -2
- package/build-module/components/provider/use-block-editor-settings.mjs +23 -3
- package/build-module/components/provider/use-block-editor-settings.mjs.map +2 -2
- package/build-module/components/sidebar/dataform-post-summary.mjs +6 -2
- package/build-module/components/sidebar/dataform-post-summary.mjs.map +2 -2
- package/build-module/components/sidebar/index.mjs +29 -42
- package/build-module/components/sidebar/index.mjs.map +2 -2
- package/build-module/components/sidebar/post-summary.mjs +0 -13
- package/build-module/components/sidebar/post-summary.mjs.map +2 -2
- package/build-module/dataviews/store/private-actions.mjs +26 -19
- package/build-module/dataviews/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +5 -2
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/utils/media-sideload-from-url/index.mjs +32 -0
- package/build-module/utils/media-sideload-from-url/index.mjs.map +7 -0
- package/build-style/style-rtl.css +65 -33
- package/build-style/style.css +65 -33
- package/build-types/components/collab-sidebar/format.d.ts +17 -0
- package/build-types/components/collab-sidebar/format.d.ts.map +1 -0
- package/build-types/components/collab-sidebar/hooks.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/note-highlight-styles.d.ts +31 -0
- package/build-types/components/collab-sidebar/note-highlight-styles.d.ts.map +1 -0
- package/build-types/components/collab-sidebar/utils.d.ts +82 -2
- package/build-types/components/collab-sidebar/utils.d.ts.map +1 -1
- package/build-types/components/collaborators-presence/use-collaborator-notifications.d.ts.map +1 -1
- package/build-types/components/commands/index.d.ts.map +1 -1
- package/build-types/components/document-bar/index.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/index.d.ts.map +1 -1
- package/build-types/components/media-categories/index.d.ts +12 -3
- package/build-types/components/media-categories/index.d.ts.map +1 -1
- package/build-types/components/page-attributes/parent.d.ts.map +1 -1
- package/build-types/components/post-author/combobox.d.ts.map +1 -1
- package/build-types/components/post-author/select.d.ts.map +1 -1
- package/build-types/components/post-preview-button/index.d.ts.map +1 -1
- package/build-types/components/post-publish-panel/maybe-upload-media.d.ts.map +1 -1
- package/build-types/components/post-revisions-preview/revisions-slider.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/flat-term-selector.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/hierarchical-term-selector.d.ts.map +1 -1
- package/build-types/components/post-template/classic-theme.d.ts.map +1 -1
- package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
- package/build-types/components/sidebar/dataform-post-summary.d.ts.map +1 -1
- package/build-types/components/sidebar/index.d.ts.map +1 -1
- package/build-types/components/sidebar/post-summary.d.ts.map +1 -1
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts.map +1 -1
- package/build-types/utils/get-template-part-icon.d.ts.map +1 -1
- package/build-types/utils/media-sideload-from-url/index.d.ts +18 -0
- package/build-types/utils/media-sideload-from-url/index.d.ts.map +1 -0
- package/package.json +48 -46
- package/src/components/collab-sidebar/format.js +72 -0
- package/src/components/collab-sidebar/hooks.js +203 -22
- package/src/components/collab-sidebar/index.js +19 -5
- package/src/components/collab-sidebar/note-highlight-styles.js +83 -0
- package/src/components/collab-sidebar/style.scss +9 -0
- package/src/components/collab-sidebar/test/note-highlight-styles.js +106 -0
- package/src/components/collab-sidebar/test/utils.js +471 -0
- package/src/components/collab-sidebar/utils.js +225 -2
- package/src/components/collaborators-presence/test/use-collaborator-notifications.ts +265 -262
- package/src/components/collaborators-presence/use-collaborator-notifications.ts +70 -34
- package/src/components/commands/index.js +142 -0
- package/src/components/document-bar/index.js +0 -9
- package/src/components/document-bar/style.scss +0 -17
- package/src/components/entities-saved-states/index.js +1 -5
- package/src/components/header/style.scss +7 -3
- package/src/components/media-categories/index.js +160 -6
- package/src/components/media-categories/test/index.js +202 -0
- package/src/components/page-attributes/parent.js +0 -1
- package/src/components/post-author/combobox.js +0 -1
- package/src/components/post-author/select.js +0 -1
- package/src/components/post-preview-button/index.js +68 -2
- package/src/components/post-publish-panel/maybe-upload-media.js +25 -30
- package/src/components/post-publish-panel/style.scss +1 -1
- package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +11 -127
- package/src/components/post-revisions-preview/revisions-slider.js +4 -1
- package/src/components/post-revisions-preview/test/block-diff.js +2 -2
- package/src/components/post-taxonomies/flat-term-selector.js +0 -1
- package/src/components/post-taxonomies/hierarchical-term-selector.js +0 -2
- package/src/components/post-template/classic-theme.js +0 -1
- package/src/components/preferences-modal/index.js +40 -22
- package/src/components/preferences-modal/test/index.js +83 -0
- package/src/components/preview-dropdown/index.js +3 -3
- package/src/components/provider/use-block-editor-settings.js +42 -1
- package/src/components/sidebar/dataform-post-summary.js +13 -1
- package/src/components/sidebar/index.js +32 -47
- package/src/components/sidebar/post-summary.js +0 -17
- package/src/dataviews/store/private-actions.ts +30 -26
- package/src/store/private-actions.js +6 -2
- package/src/utils/media-sideload-from-url/index.js +54 -0
- package/src/utils/media-sideload-from-url/test/index.js +162 -0
- package/build/components/post-publish-panel/media-util.cjs +0 -72
- package/build/components/post-publish-panel/media-util.cjs.map +0 -7
- package/build-module/components/post-publish-panel/media-util.mjs +0 -46
- package/build-module/components/post-publish-panel/media-util.mjs.map +0 -7
- package/build-types/components/post-publish-panel/media-util.d.ts +0 -20
- package/build-types/components/post-publish-panel/media-util.d.ts.map +0 -1
- package/src/components/post-publish-panel/media-util.js +0 -87
- package/src/components/post-publish-panel/test/media-util.js +0 -118
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 14.51.0-next.0 (2026-07-07)
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- Add an "Attachments" source to the block inserter's Media tab, listing images attached to the current post with the ability to attach and detach them ([#79336](https://github.com/WordPress/gutenberg/pull/79336)).
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- External images are now sideloaded on the server when uploaded to the media library, via a new `mediaSideloadFromUrl` block editor setting, so the upload works when the editor is cross-origin isolated (e.g. with client-side media processing enabled) ([#79409](https://github.com/WordPress/gutenberg/pull/79409)).
|
|
14
|
+
|
|
5
15
|
## 14.50.0 (2026-07-01)
|
|
6
16
|
|
|
7
17
|
## 14.49.0 (2026-06-24)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/editor/src/components/collab-sidebar/format.js
|
|
21
|
+
var format_exports = {};
|
|
22
|
+
__export(format_exports, {
|
|
23
|
+
NOTE_FORMAT_NAME: () => NOTE_FORMAT_NAME,
|
|
24
|
+
noteFormat: () => noteFormat
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(format_exports);
|
|
27
|
+
var import_i18n = require("@wordpress/i18n");
|
|
28
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
29
|
+
var import_data = require("@wordpress/data");
|
|
30
|
+
var import_icons = require("@wordpress/icons");
|
|
31
|
+
var import_rich_text = require("@wordpress/rich-text");
|
|
32
|
+
var import_interface = require("@wordpress/interface");
|
|
33
|
+
var import_constants = require("./constants.cjs");
|
|
34
|
+
var import_store = require("../../store/index.cjs");
|
|
35
|
+
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
var NOTE_FORMAT_NAME = "core/note";
|
|
38
|
+
var noteFormat = {
|
|
39
|
+
title: (0, import_i18n.__)("Add note"),
|
|
40
|
+
tagName: "mark",
|
|
41
|
+
className: "wp-note",
|
|
42
|
+
attributes: {
|
|
43
|
+
"data-id": "data-id"
|
|
44
|
+
},
|
|
45
|
+
edit: NoteFormatEdit
|
|
46
|
+
};
|
|
47
|
+
function NoteFormatEdit({ value, isActive, activeAttributes }) {
|
|
48
|
+
const dispatch = (0, import_data.useDispatch)();
|
|
49
|
+
const { getActiveComplementaryArea } = (0, import_data.useSelect)(import_interface.store);
|
|
50
|
+
if (!isActive && (0, import_rich_text.isCollapsed)(value)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const onClick = () => {
|
|
54
|
+
const currentArea = getActiveComplementaryArea("core");
|
|
55
|
+
const targetSidebar = currentArea === import_constants.ALL_NOTES_SIDEBAR ? import_constants.ALL_NOTES_SIDEBAR : import_constants.FLOATING_NOTES_SIDEBAR;
|
|
56
|
+
if (currentArea !== targetSidebar) {
|
|
57
|
+
dispatch(import_interface.store).enableComplementaryArea(
|
|
58
|
+
"core",
|
|
59
|
+
targetSidebar
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const id = activeAttributes["data-id"];
|
|
63
|
+
(0, import_lock_unlock.unlock)(dispatch(import_store.store)).selectNote(
|
|
64
|
+
id ? Number(id) : "new",
|
|
65
|
+
{ focus: true }
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
+
import_block_editor.RichTextToolbarButton,
|
|
70
|
+
{
|
|
71
|
+
icon: import_icons.comment,
|
|
72
|
+
title: (0, import_i18n.__)("Add note"),
|
|
73
|
+
onClick,
|
|
74
|
+
isActive
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
NOTE_FORMAT_NAME,
|
|
81
|
+
noteFormat
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=format.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/collab-sidebar/format.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { comment as commentIcon } from '@wordpress/icons';\nimport { isCollapsed } from '@wordpress/rich-text';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport { ALL_NOTES_SIDEBAR, FLOATING_NOTES_SIDEBAR } from './constants';\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nexport const NOTE_FORMAT_NAME = 'core/note';\n\nexport const noteFormat = {\n\ttitle: __( 'Add note' ),\n\ttagName: 'mark',\n\tclassName: 'wp-note',\n\tattributes: {\n\t\t'data-id': 'data-id',\n\t},\n\tedit: NoteFormatEdit,\n};\n\nfunction NoteFormatEdit( { value, isActive, activeAttributes } ) {\n\tconst dispatch = useDispatch();\n\t// Static selector getter: the active area is only read when the button is\n\t// clicked, so there's no need to subscribe and re-render on its changes.\n\tconst { getActiveComplementaryArea } = useSelect( interfaceStore );\n\n\t// Toolbar button only relevant on an active selection or when standing on\n\t// an existing inline note marker.\n\tif ( ! isActive && isCollapsed( value ) ) {\n\t\treturn null;\n\t}\n\n\tconst onClick = () => {\n\t\t// Bias the floating sidebar when no fixed sidebar is mounted; the\n\t\t// floating panel is the default placement and avoids a layout shift.\n\t\tconst currentArea = getActiveComplementaryArea( 'core' );\n\t\tconst targetSidebar =\n\t\t\tcurrentArea === ALL_NOTES_SIDEBAR\n\t\t\t\t? ALL_NOTES_SIDEBAR\n\t\t\t\t: FLOATING_NOTES_SIDEBAR;\n\t\tif ( currentArea !== targetSidebar ) {\n\t\t\tdispatch( interfaceStore ).enableComplementaryArea(\n\t\t\t\t'core',\n\t\t\t\ttargetSidebar\n\t\t\t);\n\t\t}\n\n\t\tconst id = activeAttributes[ 'data-id' ];\n\t\tunlock( dispatch( editorStore ) ).selectNote(\n\t\t\tid ? Number( id ) : 'new',\n\t\t\t{ focus: true }\n\t\t);\n\t};\n\n\treturn (\n\t\t<RichTextToolbarButton\n\t\t\ticon={ commentIcon }\n\t\t\ttitle={ __( 'Add note' ) }\n\t\t\tonClick={ onClick }\n\t\t\tisActive={ isActive }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,0BAAsC;AACtC,kBAAuC;AACvC,mBAAuC;AACvC,uBAA4B;AAC5B,uBAAwC;AAKxC,uBAA0D;AAC1D,mBAAqC;AACrC,yBAAuB;AAiDrB;AA/CK,IAAM,mBAAmB;AAEzB,IAAM,aAAa;AAAA,EACzB,WAAO,gBAAI,UAAW;AAAA,EACtB,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,IACX,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AACP;AAEA,SAAS,eAAgB,EAAE,OAAO,UAAU,iBAAiB,GAAI;AAChE,QAAM,eAAW,yBAAY;AAG7B,QAAM,EAAE,2BAA2B,QAAI,uBAAW,iBAAAA,KAAe;AAIjE,MAAK,CAAE,gBAAY,8BAAa,KAAM,GAAI;AACzC,WAAO;AAAA,EACR;AAEA,QAAM,UAAU,MAAM;AAGrB,UAAM,cAAc,2BAA4B,MAAO;AACvD,UAAM,gBACL,gBAAgB,qCACb,qCACA;AACJ,QAAK,gBAAgB,eAAgB;AACpC,eAAU,iBAAAA,KAAe,EAAE;AAAA,QAC1B;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAEA,UAAM,KAAK,iBAAkB,SAAU;AACvC,mCAAQ,SAAU,aAAAC,KAAY,CAAE,EAAE;AAAA,MACjC,KAAK,OAAQ,EAAG,IAAI;AAAA,MACpB,EAAE,OAAO,KAAK;AAAA,IACf;AAAA,EACD;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAO,aAAAC;AAAA,MACP,WAAQ,gBAAI,UAAW;AAAA,MACvB;AAAA,MACA;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": ["interfaceStore", "editorStore", "commentIcon"]
|
|
7
|
+
}
|
|
@@ -35,10 +35,12 @@ var import_notices = require("@wordpress/notices");
|
|
|
35
35
|
var import_dom = require("@wordpress/dom");
|
|
36
36
|
var import_html_entities = require("@wordpress/html-entities");
|
|
37
37
|
var import_interface = require("@wordpress/interface");
|
|
38
|
+
var import_rich_text = require("@wordpress/rich-text");
|
|
38
39
|
var import_store = require("../../store/index.cjs");
|
|
39
40
|
var import_constants = require("./constants.cjs");
|
|
40
41
|
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
41
42
|
var import_board_store = require("./board-store.cjs");
|
|
43
|
+
var import_format = require("./format.cjs");
|
|
42
44
|
var import_utils = require("./utils.cjs");
|
|
43
45
|
var { cleanEmptyObject } = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
|
|
44
46
|
function useNoteThreads(postId) {
|
|
@@ -100,12 +102,26 @@ function useNoteThreads(postId) {
|
|
|
100
102
|
}
|
|
101
103
|
const unresolved = [];
|
|
102
104
|
const resolved = [];
|
|
103
|
-
for (const noteIds of Object.
|
|
104
|
-
|
|
105
|
+
for (const [clientId, noteIds] of Object.entries(
|
|
106
|
+
blocksWithNotes
|
|
107
|
+
)) {
|
|
108
|
+
const attributes = getBlockAttributes(clientId);
|
|
109
|
+
const orderedThreads = noteIds.map((noteId) => {
|
|
105
110
|
const thread = threadsById.get(noteId);
|
|
106
111
|
if (!thread) {
|
|
107
|
-
|
|
112
|
+
return null;
|
|
108
113
|
}
|
|
114
|
+
return {
|
|
115
|
+
thread,
|
|
116
|
+
start: (0, import_utils.getInlineMarkerStart)(thread, attributes)
|
|
117
|
+
};
|
|
118
|
+
}).filter(Boolean).sort((a, b) => {
|
|
119
|
+
if (a.start !== b.start) {
|
|
120
|
+
return a.start - b.start;
|
|
121
|
+
}
|
|
122
|
+
return a.thread.id - b.thread.id;
|
|
123
|
+
});
|
|
124
|
+
for (const { thread } of orderedThreads) {
|
|
109
125
|
if (thread.status === "hold") {
|
|
110
126
|
unresolved.push(thread);
|
|
111
127
|
} else if (thread.status === "approved") {
|
|
@@ -126,11 +142,62 @@ function useNoteThreads(postId) {
|
|
|
126
142
|
unresolvedNotes
|
|
127
143
|
};
|
|
128
144
|
}
|
|
145
|
+
function readInlineSelection(getSelectionStart, getSelectionEnd) {
|
|
146
|
+
const start = getSelectionStart();
|
|
147
|
+
const end = getSelectionEnd();
|
|
148
|
+
if (!start?.clientId || start.clientId !== end.clientId || !start.attributeKey || start.offset === void 0 || end.offset === void 0 || start.offset === end.offset) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const [startOffset, endOffset] = start.offset < end.offset ? [start.offset, end.offset] : [end.offset, start.offset];
|
|
152
|
+
return {
|
|
153
|
+
clientId: start.clientId,
|
|
154
|
+
attributeKey: start.attributeKey,
|
|
155
|
+
start: startOffset,
|
|
156
|
+
end: endOffset
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function wrapInlineNote(value, id, start, end) {
|
|
160
|
+
if (!(value instanceof import_rich_text.RichTextData)) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const record = (0, import_utils.applyNoteFormat)(
|
|
164
|
+
(0, import_rich_text.create)({ html: value.toHTMLString() }),
|
|
165
|
+
{ type: import_format.NOTE_FORMAT_NAME, attributes: { "data-id": String(id) } },
|
|
166
|
+
start,
|
|
167
|
+
end
|
|
168
|
+
);
|
|
169
|
+
return import_rich_text.RichTextData.fromHTMLString(
|
|
170
|
+
new import_rich_text.RichTextData(record).toHTMLString()
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
function clearInlineNoteMarker(noteId, getClientIdsWithDescendants, getBlockAttributes, updateBlockAttributes) {
|
|
174
|
+
for (const clientId of getClientIdsWithDescendants()) {
|
|
175
|
+
const attributes = getBlockAttributes(clientId);
|
|
176
|
+
const found = (0, import_utils.findNoteInBlock)(attributes, noteId);
|
|
177
|
+
if (!found) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const next = (0, import_utils.removeNoteFormat)(
|
|
181
|
+
attributes[found.attributeKey],
|
|
182
|
+
noteId
|
|
183
|
+
);
|
|
184
|
+
if (next) {
|
|
185
|
+
updateBlockAttributes(clientId, { [found.attributeKey]: next });
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
129
190
|
function useNoteActions() {
|
|
130
191
|
const { createNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
131
192
|
const { saveEntityRecord, deleteEntityRecord } = (0, import_data.useDispatch)(import_core_data.store);
|
|
132
193
|
const { getCurrentPostId } = (0, import_data.useSelect)(import_store.store);
|
|
133
|
-
const {
|
|
194
|
+
const {
|
|
195
|
+
getBlockAttributes,
|
|
196
|
+
getClientIdsWithDescendants,
|
|
197
|
+
getSelectedBlockClientId,
|
|
198
|
+
getSelectionStart,
|
|
199
|
+
getSelectionEnd
|
|
200
|
+
} = (0, import_data.useSelect)(import_block_editor.store);
|
|
134
201
|
const { updateBlockAttributes } = (0, import_data.useDispatch)(import_block_editor.store);
|
|
135
202
|
const onError = (error) => {
|
|
136
203
|
const errorMessage = error.message && error.code !== "unknown_error" ? (0, import_html_entities.decodeEntities)(error.message) : (0, import_i18n.__)("An error occurred while performing an update.");
|
|
@@ -141,6 +208,7 @@ function useNoteActions() {
|
|
|
141
208
|
};
|
|
142
209
|
const onCreate = async ({ content, parent }) => {
|
|
143
210
|
try {
|
|
211
|
+
const inlineSelection = !parent ? readInlineSelection(getSelectionStart, getSelectionEnd) : null;
|
|
144
212
|
const savedRecord = await saveEntityRecord(
|
|
145
213
|
"root",
|
|
146
214
|
"comment",
|
|
@@ -154,18 +222,31 @@ function useNoteActions() {
|
|
|
154
222
|
{ throwOnError: true }
|
|
155
223
|
);
|
|
156
224
|
if (!parent && savedRecord?.id) {
|
|
157
|
-
const clientId = getSelectedBlockClientId();
|
|
225
|
+
const clientId = inlineSelection?.clientId || getSelectedBlockClientId();
|
|
158
226
|
if (!clientId) {
|
|
159
227
|
return savedRecord;
|
|
160
228
|
}
|
|
161
|
-
const
|
|
229
|
+
const attributes = getBlockAttributes(clientId);
|
|
230
|
+
const metadata = attributes?.metadata;
|
|
162
231
|
const updatedMetadata = (0, import_utils.addNoteIdToMetadata)(
|
|
163
232
|
metadata,
|
|
164
233
|
savedRecord.id
|
|
165
234
|
);
|
|
166
|
-
|
|
235
|
+
const newAttributes = {
|
|
167
236
|
metadata: cleanEmptyObject(updatedMetadata)
|
|
168
|
-
}
|
|
237
|
+
};
|
|
238
|
+
if (inlineSelection) {
|
|
239
|
+
const wrapped = wrapInlineNote(
|
|
240
|
+
attributes?.[inlineSelection.attributeKey],
|
|
241
|
+
savedRecord.id,
|
|
242
|
+
inlineSelection.start,
|
|
243
|
+
inlineSelection.end
|
|
244
|
+
);
|
|
245
|
+
if (wrapped) {
|
|
246
|
+
newAttributes[inlineSelection.attributeKey] = wrapped;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
updateBlockAttributes(clientId, newAttributes);
|
|
169
250
|
}
|
|
170
251
|
createNotice(
|
|
171
252
|
"snackbar",
|
|
@@ -214,6 +295,14 @@ function useNoteActions() {
|
|
|
214
295
|
await saveEntityRecord("root", "comment", newNoteData, {
|
|
215
296
|
throwOnError: true
|
|
216
297
|
});
|
|
298
|
+
if (status === "approved") {
|
|
299
|
+
clearInlineNoteMarker(
|
|
300
|
+
id,
|
|
301
|
+
getClientIdsWithDescendants,
|
|
302
|
+
getBlockAttributes,
|
|
303
|
+
updateBlockAttributes
|
|
304
|
+
);
|
|
305
|
+
}
|
|
217
306
|
} else {
|
|
218
307
|
const updateData = {
|
|
219
308
|
id,
|
|
@@ -246,14 +335,26 @@ function useNoteActions() {
|
|
|
246
335
|
if (!clientId) {
|
|
247
336
|
return;
|
|
248
337
|
}
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
metadata
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
338
|
+
const attributes = getBlockAttributes(clientId);
|
|
339
|
+
const newAttributes = {
|
|
340
|
+
metadata: cleanEmptyObject(
|
|
341
|
+
(0, import_utils.removeNoteIdFromMetadata)(
|
|
342
|
+
attributes?.metadata,
|
|
343
|
+
note.id
|
|
344
|
+
)
|
|
345
|
+
)
|
|
346
|
+
};
|
|
347
|
+
const found = (0, import_utils.findNoteInBlock)(attributes, note.id);
|
|
348
|
+
if (found) {
|
|
349
|
+
const next = (0, import_utils.removeNoteFormat)(
|
|
350
|
+
attributes[found.attributeKey],
|
|
351
|
+
note.id
|
|
352
|
+
);
|
|
353
|
+
if (next) {
|
|
354
|
+
newAttributes[found.attributeKey] = next;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
updateBlockAttributes(clientId, newAttributes);
|
|
257
358
|
}
|
|
258
359
|
createNotice("snackbar", (0, import_i18n.__)("Note deleted."), {
|
|
259
360
|
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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,qBAKO;AACP,uBAAqD;AACrD,kBAAoD;AACpD,0BAGO;AACP,qBAAsC;AACtC,iBAAmC;AACnC,2BAA+B;AAC/B,uBAAwC;
|
|
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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,k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AAM,UAAU,MAAM,qBAAqB;AAG3C,UAAM,SAAS,SAAS,QAAS,oBAAqB,KAAK;AAC3D,UAAM,SAAS,aAAS,+BAAoB,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,aAAS,qCAAwB;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": ["blockEditorPrivateApis", "blockEditorStore", "noticesStore", "coreStore", "editorStore", "interfaceStore"]
|
|
7
7
|
}
|
|
@@ -42,19 +42,28 @@ var import_icons = require("@wordpress/icons");
|
|
|
42
42
|
var import_block_editor = require("@wordpress/block-editor");
|
|
43
43
|
var import_interface = require("@wordpress/interface");
|
|
44
44
|
var import_preferences = require("@wordpress/preferences");
|
|
45
|
+
var import_rich_text = require("@wordpress/rich-text");
|
|
45
46
|
var import_plugin_sidebar = __toESM(require("../plugin-sidebar/index.cjs"));
|
|
46
47
|
var import_constants = require("./constants.cjs");
|
|
47
48
|
var import_notes = require("./notes.cjs");
|
|
48
49
|
var import_store = require("../../store/index.cjs");
|
|
49
50
|
var import_add_note_menu_item = require("./add-note-menu-item.cjs");
|
|
50
51
|
var import_note_indicator_toolbar = require("./note-indicator-toolbar.cjs");
|
|
52
|
+
var import_note_highlight_styles = require("./note-highlight-styles.cjs");
|
|
51
53
|
var import_global_styles = require("../global-styles/index.cjs");
|
|
52
54
|
var import_hooks = require("./hooks.cjs");
|
|
53
55
|
var import_utils = require("./utils.cjs");
|
|
56
|
+
var import_format = require("./format.cjs");
|
|
54
57
|
var import_post_type_support_check = __toESM(require("../post-type-support-check/index.cjs"));
|
|
55
58
|
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
56
59
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
57
60
|
function NotesSidebar({ postId }) {
|
|
61
|
+
(0, import_element.useEffect)(() => {
|
|
62
|
+
(0, import_rich_text.registerFormatType)(import_format.NOTE_FORMAT_NAME, import_format.noteFormat);
|
|
63
|
+
return () => {
|
|
64
|
+
(0, import_rich_text.unregisterFormatType)(import_format.NOTE_FORMAT_NAME);
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
58
67
|
const { getActiveComplementaryArea } = (0, import_data.useSelect)(import_interface.store);
|
|
59
68
|
const { enableComplementaryArea } = (0, import_data.useDispatch)(import_interface.store);
|
|
60
69
|
const { toggleBlockSpotlight, selectBlock } = (0, import_lock_unlock.unlock)(
|
|
@@ -79,7 +88,7 @@ function NotesSidebar({ postId }) {
|
|
|
79
88
|
isDistractionFree: get("core", "distractionFree")
|
|
80
89
|
};
|
|
81
90
|
}, []);
|
|
82
|
-
const
|
|
91
|
+
const selectedNoteId = (0, import_data.useSelect)(
|
|
83
92
|
(select) => (0, import_lock_unlock.unlock)(select(import_store.store)).getSelectedNote(),
|
|
84
93
|
[]
|
|
85
94
|
);
|
|
@@ -87,7 +96,7 @@ function NotesSidebar({ postId }) {
|
|
|
87
96
|
const showFloatingSidebar = isLargeViewport;
|
|
88
97
|
const showAllNotesSidebar = notes.length > 0 || !showFloatingSidebar;
|
|
89
98
|
(0, import_hooks.useEnableFloatingSidebar)(
|
|
90
|
-
showFloatingSidebar && (unresolvedNotes.length > 0 ||
|
|
99
|
+
showFloatingSidebar && (unresolvedNotes.length > 0 || selectedNoteId !== void 0)
|
|
91
100
|
);
|
|
92
101
|
async function focusNote({
|
|
93
102
|
targetClientId,
|
|
@@ -150,6 +159,13 @@ function NotesSidebar({ postId }) {
|
|
|
150
159
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_add_note_menu_item.AddNoteMenuItem, { isDistractionFree: true });
|
|
151
160
|
}
|
|
152
161
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
163
|
+
import_note_highlight_styles.NoteHighlightStyles,
|
|
164
|
+
{
|
|
165
|
+
threads: unresolvedNotes,
|
|
166
|
+
selectedId: selectedNoteId
|
|
167
|
+
}
|
|
168
|
+
),
|
|
153
169
|
!!currentThread && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
154
170
|
import_note_indicator_toolbar.NoteAvatarIndicator,
|
|
155
171
|
{
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,kBAAuC;AACvC,
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,kBAAuC;AACvC,qBAAkC;AAClC,qBAAiC;AACjC,gCAA4B;AAC5B,mBAAuC;AACvC,0BAA0C;AAC1C,uBAAwC;AACxC,yBAA0C;AAC1C,uBAAyD;AAKzD,4BAA0B;AAC1B,uBAIO;AACP,mBAAsB;AACtB,mBAAqC;AACrC,gCAAgC;AAChC,oCAAoC;AACpC,mCAAoC;AACpC,2BAAgC;AAChC,mBAAyD;AACzD,mBAAwD;AACxD,oBAA6C;AAC7C,qCAAiC;AACjC,yBAAuB;AAqId;AAnIT,SAAS,aAAc,EAAE,OAAO,GAAI;AACnC,gCAAW,MAAM;AAChB,6CAAoB,gCAAkB,wBAAW;AACjD,WAAO,MAAM;AACZ,iDAAsB,8BAAiB;AAAA,IACxC;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,EAAE,2BAA2B,QAAI,uBAAW,iBAAAA,KAAe;AACjE,QAAM,EAAE,wBAAwB,QAAI,yBAAa,iBAAAA,KAAe;AAChE,QAAM,EAAE,sBAAsB,YAAY,QAAI;AAAA,QAC7C,yBAAa,oBAAAC,KAAiB;AAAA,EAC/B;AACA,QAAM,EAAE,WAAW,QAAI,+BA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AAgB;AAC7C,WAAO;AAAA,EACR;AAEA,SACC,4CAAC,+BAAAI,SAAA,EAAqB,aAAY,gBACjC,sDAAC,gBAAa,QAAkB,GACjC;AAEF;",
|
|
6
6
|
"names": ["interfaceStore", "blockEditorStore", "editorStore", "preferencesStore", "PluginSidebar", "commentIcon", "PostTypeSupportCheck"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/editor/src/components/collab-sidebar/note-highlight-styles.js
|
|
21
|
+
var note_highlight_styles_exports = {};
|
|
22
|
+
__export(note_highlight_styles_exports, {
|
|
23
|
+
NoteHighlightStyles: () => NoteHighlightStyles,
|
|
24
|
+
buildHighlightCss: () => buildHighlightCss
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(note_highlight_styles_exports);
|
|
27
|
+
var import_element = require("@wordpress/element");
|
|
28
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
29
|
+
var import_utils = require("./utils.cjs");
|
|
30
|
+
var REST_ALPHA = "40";
|
|
31
|
+
var ACTIVE_ALPHA = "80";
|
|
32
|
+
var BASE_RESET = "mark.wp-note{background-color:transparent;color:inherit;}";
|
|
33
|
+
function buildHighlightCss(threads, selectedId = null) {
|
|
34
|
+
const rules = [BASE_RESET];
|
|
35
|
+
for (const thread of threads ?? []) {
|
|
36
|
+
if (!thread?.id) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const color = (0, import_utils.getAvatarBorderColor)(thread.author ?? 0);
|
|
40
|
+
const escapedId = String(thread.id).replace(/["\\]/g, "\\$&");
|
|
41
|
+
const sel = `mark.wp-note[data-id="${escapedId}"]`;
|
|
42
|
+
rules.push(`${sel}{background-color:${color}${REST_ALPHA};}`);
|
|
43
|
+
rules.push(
|
|
44
|
+
`${sel}:hover,${sel}:focus-within{background-color:${color}${ACTIVE_ALPHA};}`
|
|
45
|
+
);
|
|
46
|
+
if (selectedId && String(selectedId) === String(thread.id)) {
|
|
47
|
+
rules.push(
|
|
48
|
+
`${sel}{background-color:${color}${ACTIVE_ALPHA};}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return rules.join("");
|
|
53
|
+
}
|
|
54
|
+
function NoteHighlightStyles({ threads, selectedId }) {
|
|
55
|
+
const css = (0, import_element.useMemo)(
|
|
56
|
+
() => buildHighlightCss(threads, selectedId),
|
|
57
|
+
[threads, selectedId]
|
|
58
|
+
);
|
|
59
|
+
(0, import_block_editor.useStyleOverride)({ id: "core-note-highlights", css });
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
NoteHighlightStyles,
|
|
65
|
+
buildHighlightCss
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=note-highlight-styles.cjs.map
|