@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.
- package/CHANGELOG.md +12 -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/header/index.cjs +1 -8
- package/build/components/header/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 +38 -9
- package/build/components/preview-dropdown/index.cjs.map +3 -3
- package/build/components/provider/use-block-editor-settings.cjs +23 -9
- package/build/components/provider/use-block-editor-settings.cjs.map +3 -3
- package/build/components/resizable-editor/index.cjs +54 -9
- package/build/components/resizable-editor/index.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/components/visual-editor/index.cjs +15 -11
- package/build/components/visual-editor/index.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/actions.cjs +5 -3
- package/build/store/actions.cjs.map +2 -2
- package/build/store/constants.cjs +26 -0
- package/build/store/constants.cjs.map +2 -2
- package/build/store/private-actions.cjs +25 -18
- package/build/store/private-actions.cjs.map +3 -3
- package/build/store/private-selectors.cjs +5 -0
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/store/reducer.cjs +6 -6
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +3 -1
- package/build/store/selectors.cjs.map +2 -2
- package/build/utils/device-type.cjs +52 -0
- package/build/utils/device-type.cjs.map +7 -0
- 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/header/index.mjs +1 -13
- package/build-module/components/header/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 +38 -9
- package/build-module/components/preview-dropdown/index.mjs.map +2 -2
- package/build-module/components/provider/use-block-editor-settings.mjs +23 -9
- package/build-module/components/provider/use-block-editor-settings.mjs.map +2 -2
- package/build-module/components/resizable-editor/index.mjs +55 -10
- package/build-module/components/resizable-editor/index.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/components/visual-editor/index.mjs +16 -13
- package/build-module/components/visual-editor/index.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/actions.mjs +5 -3
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/constants.mjs +25 -0
- package/build-module/store/constants.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +27 -17
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +4 -0
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -5
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +3 -1
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-module/utils/device-type.mjs +25 -0
- package/build-module/utils/device-type.mjs.map +7 -0
- 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 +84 -39
- package/build-style/style.css +84 -39
- 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/header/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/preview-dropdown/index.d.ts.map +1 -1
- package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
- package/build-types/components/resizable-editor/index.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/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/constants.d.ts +6 -0
- package/build-types/store/constants.d.ts.map +1 -1
- package/build-types/store/index.d.ts +2 -2
- package/build-types/store/private-actions.d.ts +9 -15
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts +7 -0
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +6 -7
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -1
- package/build-types/store/selectors.d.ts.map +1 -1
- package/build-types/utils/device-type.d.ts +23 -0
- package/build-types/utils/device-type.d.ts.map +1 -0
- 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/index.js +1 -15
- 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 +42 -3
- package/src/components/provider/use-block-editor-settings.js +42 -7
- package/src/components/resizable-editor/index.js +71 -9
- package/src/components/resizable-editor/style.scss +7 -0
- 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/components/styles-canvas/style.scss +1 -2
- package/src/components/visual-editor/index.js +19 -15
- package/src/components/visual-editor/style.scss +11 -4
- package/src/dataviews/store/private-actions.ts +30 -26
- package/src/store/actions.js +6 -3
- package/src/store/constants.ts +45 -0
- package/src/store/private-actions.js +38 -28
- package/src/store/private-selectors.js +10 -0
- package/src/store/reducer.js +7 -9
- package/src/store/selectors.js +3 -1
- package/src/store/test/actions.js +31 -22
- package/src/utils/device-type.js +46 -0
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// packages/editor/src/components/collab-sidebar/utils.js
|
|
2
2
|
import { _x } from "@wordpress/i18n";
|
|
3
|
+
import { create, RichTextData } from "@wordpress/rich-text";
|
|
3
4
|
function sanitizeNoteContent(str) {
|
|
4
5
|
return str.trim();
|
|
5
6
|
}
|
|
@@ -65,6 +66,132 @@ function addNoteIdToMetadata(metadata, noteId) {
|
|
|
65
66
|
ids.add(id);
|
|
66
67
|
return { ...metadata, noteId: [...ids] };
|
|
67
68
|
}
|
|
69
|
+
var NOTE_FORMAT_TYPE = "core/note";
|
|
70
|
+
function findNoteRange(value, noteId) {
|
|
71
|
+
if (noteId === void 0 || noteId === null) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
let html = null;
|
|
75
|
+
if (value instanceof RichTextData) {
|
|
76
|
+
html = value.toHTMLString();
|
|
77
|
+
} else if (typeof value === "string") {
|
|
78
|
+
html = value;
|
|
79
|
+
}
|
|
80
|
+
if (!html || html.indexOf("wp-note") === -1) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const target = String(noteId);
|
|
84
|
+
const record = create({ html });
|
|
85
|
+
const formats = record.formats;
|
|
86
|
+
let start = -1;
|
|
87
|
+
for (let i = 0; i < formats.length; i++) {
|
|
88
|
+
const stack = formats[i];
|
|
89
|
+
const hit = stack?.find(
|
|
90
|
+
(f) => f.type === NOTE_FORMAT_TYPE && f.attributes && f.attributes["data-id"] === target
|
|
91
|
+
);
|
|
92
|
+
if (hit) {
|
|
93
|
+
if (start === -1) {
|
|
94
|
+
start = i;
|
|
95
|
+
}
|
|
96
|
+
} else if (start !== -1) {
|
|
97
|
+
return { start, end: i };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (start !== -1) {
|
|
101
|
+
return { start, end: formats.length };
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function findNoteInBlock(attributes, noteId) {
|
|
106
|
+
if (!attributes) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
for (const attributeKey of Object.keys(attributes)) {
|
|
110
|
+
const range = findNoteRange(attributes[attributeKey], noteId);
|
|
111
|
+
if (range) {
|
|
112
|
+
return { attributeKey, start: range.start, end: range.end };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
var BLOCK_LEVEL_NOTE_START = -1;
|
|
118
|
+
function getInlineMarkerStart(thread, attributes) {
|
|
119
|
+
const found = findNoteInBlock(attributes, thread?.id);
|
|
120
|
+
return found ? found.start : BLOCK_LEVEL_NOTE_START;
|
|
121
|
+
}
|
|
122
|
+
function applyNoteFormat(record, format, start, end) {
|
|
123
|
+
const formats = record.formats.slice();
|
|
124
|
+
for (let i = start; i < end; i++) {
|
|
125
|
+
const stack = formats[i] ? formats[i].slice() : [];
|
|
126
|
+
stack.push(format);
|
|
127
|
+
formats[i] = stack;
|
|
128
|
+
}
|
|
129
|
+
const spans = /* @__PURE__ */ new Map();
|
|
130
|
+
for (let i = 0; i < formats.length; i++) {
|
|
131
|
+
const stack = formats[i];
|
|
132
|
+
if (!stack) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
for (const fmt of stack) {
|
|
136
|
+
if (fmt.type !== NOTE_FORMAT_TYPE) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const id = fmt.attributes?.["data-id"];
|
|
140
|
+
const span = spans.get(id);
|
|
141
|
+
if (span) {
|
|
142
|
+
span.end = i;
|
|
143
|
+
} else {
|
|
144
|
+
spans.set(id, { start: i, end: i });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const sizeOf = (id) => {
|
|
149
|
+
const span = spans.get(id);
|
|
150
|
+
return span ? span.end - span.start : 0;
|
|
151
|
+
};
|
|
152
|
+
for (let i = 0; i < formats.length; i++) {
|
|
153
|
+
const stack = formats[i];
|
|
154
|
+
if (!stack || stack.length < 2) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const notes = stack.filter((fmt) => fmt.type === NOTE_FORMAT_TYPE);
|
|
158
|
+
if (notes.length === 0) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (notes.length > 1) {
|
|
162
|
+
notes.sort(
|
|
163
|
+
(a, b) => sizeOf(b.attributes?.["data-id"]) - sizeOf(a.attributes?.["data-id"])
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
const others = stack.filter((fmt) => fmt.type !== NOTE_FORMAT_TYPE);
|
|
167
|
+
formats[i] = [...notes, ...others];
|
|
168
|
+
}
|
|
169
|
+
return { ...record, formats };
|
|
170
|
+
}
|
|
171
|
+
function removeNoteFormat(value, noteId) {
|
|
172
|
+
if (!(value instanceof RichTextData)) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const target = String(noteId);
|
|
176
|
+
const record = create({ html: value.toHTMLString() });
|
|
177
|
+
let changed = false;
|
|
178
|
+
const formats = record.formats.map((stack) => {
|
|
179
|
+
if (!stack) {
|
|
180
|
+
return stack;
|
|
181
|
+
}
|
|
182
|
+
const filtered = stack.filter(
|
|
183
|
+
(format) => !(format.type === NOTE_FORMAT_TYPE && format.attributes?.["data-id"] === target)
|
|
184
|
+
);
|
|
185
|
+
if (filtered.length === stack.length) {
|
|
186
|
+
return stack;
|
|
187
|
+
}
|
|
188
|
+
changed = true;
|
|
189
|
+
return filtered.length ? filtered : void 0;
|
|
190
|
+
});
|
|
191
|
+
return changed ? RichTextData.fromHTMLString(
|
|
192
|
+
new RichTextData({ ...record, formats }).toHTMLString()
|
|
193
|
+
) : null;
|
|
194
|
+
}
|
|
68
195
|
function pickPrimaryNote(threads) {
|
|
69
196
|
return threads.find((thread) => thread.status === "hold") ?? threads[0] ?? null;
|
|
70
197
|
}
|
|
@@ -183,13 +310,19 @@ function scrollNoteThreadIntoView(noteId, container) {
|
|
|
183
310
|
});
|
|
184
311
|
}
|
|
185
312
|
export {
|
|
313
|
+
BLOCK_LEVEL_NOTE_START,
|
|
186
314
|
addNoteIdToMetadata,
|
|
315
|
+
applyNoteFormat,
|
|
187
316
|
calculateNotePositions,
|
|
317
|
+
findNoteInBlock,
|
|
318
|
+
findNoteRange,
|
|
188
319
|
focusNoteThread,
|
|
189
320
|
getAvatarBorderColor,
|
|
321
|
+
getInlineMarkerStart,
|
|
190
322
|
getNoteExcerpt,
|
|
191
323
|
getNoteIdsFromMetadata,
|
|
192
324
|
pickPrimaryNote,
|
|
325
|
+
removeNoteFormat,
|
|
193
326
|
removeNoteIdFromMetadata,
|
|
194
327
|
sanitizeNoteContent,
|
|
195
328
|
scrollNoteThreadIntoView
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/collab-sidebar/utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\n\n/**\n * Sanitizes a note string by removing non-printable ASCII characters.\n *\n * @param {string} str - The note string to sanitize.\n * @return {string} - The sanitized note string.\n */\nexport function sanitizeNoteContent( str ) {\n\treturn str.trim();\n}\n\nconst THREAD_ALIGN_OFFSET = -16;\nconst THREAD_GAP = 16;\nconst OVERLAP_MARGIN = 20;\n\n/**\n * Avatar border colors chosen to be visually distinct from each other and from\n * the editor's semantic UI colors (Delta E > 10 between all pairs).\n */\nconst AVATAR_BORDER_COLORS = [\n\t'#C36EFF', // Purple\n\t'#D94145', // Red\n\t'#E4780A', // Orange\n\t'#FF35EE', // Magenta\n\t'#879F11', // Olive\n\t'#46A494', // Teal\n\t'#00A2C3', // Cyan\n];\n\n/**\n * Gets the border color for an avatar based on the user ID.\n *\n * @param {number} userId - The user ID.\n * @return {string} - The border color.\n */\nexport function getAvatarBorderColor( userId ) {\n\treturn AVATAR_BORDER_COLORS[ userId % AVATAR_BORDER_COLORS.length ];\n}\n\n/**\n * Generates a note excerpt from text based on word count type and length.\n *\n * @param {string} text - The note text to generate excerpt from.\n * @param {number} excerptLength - The maximum length for the note excerpt.\n * @return {string} - The generated note excerpt.\n */\nexport function getNoteExcerpt( text, excerptLength = 10 ) {\n\tif ( ! text ) {\n\t\treturn '';\n\t}\n\n\t/*\n\t * translators: If your word count is based on single characters (e.g. East Asian characters),\n\t * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.\n\t * Do not translate into your own language.\n\t */\n\tconst wordCountType = _x( 'words', 'Word count type. Do not translate!' );\n\n\tconst rawText = text.trim();\n\tlet trimmedExcerpt = '';\n\n\tif ( wordCountType === 'words' ) {\n\t\ttrimmedExcerpt = rawText.split( ' ', excerptLength ).join( ' ' );\n\t} else if ( wordCountType === 'characters_excluding_spaces' ) {\n\t\t/*\n\t\t * 1. Split the text at the character limit,\n\t\t * then join the substrings back into one string.\n\t\t * 2. Count the number of spaces in the text\n\t\t * by comparing the lengths of the string with and without spaces.\n\t\t * 3. Add the number to the length of the visible excerpt,\n\t\t * so that the spaces are excluded from the word count.\n\t\t */\n\t\tconst textWithSpaces = rawText.split( '', excerptLength ).join( '' );\n\n\t\tconst numberOfSpaces =\n\t\t\ttextWithSpaces.length - textWithSpaces.replaceAll( ' ', '' ).length;\n\n\t\ttrimmedExcerpt = rawText\n\t\t\t.split( '', excerptLength + numberOfSpaces )\n\t\t\t.join( '' );\n\t} else if ( wordCountType === 'characters_including_spaces' ) {\n\t\ttrimmedExcerpt = rawText.split( '', excerptLength ).join( '' );\n\t}\n\n\tconst isTrimmed = trimmedExcerpt !== rawText;\n\treturn isTrimmed ? trimmedExcerpt + '…' : trimmedExcerpt;\n}\n\n/**\n * Normalizes noteId metadata to always return an array of unique numeric ids,\n * preserving insertion order. Handles both scalar (legacy, possibly\n * string-typed) and array (new) values.\n *\n * @param {Object} metadata Block metadata object\n * @return {number[]} Array of note IDs (may be empty)\n */\nexport function getNoteIdsFromMetadata( metadata ) {\n\tconst noteId = metadata?.noteId;\n\tconst raw = Array.isArray( noteId ) ? noteId : [ noteId ];\n\tconst ids = new Set();\n\tfor ( const value of raw ) {\n\t\tconst id = Number( value );\n\t\tif ( Number.isFinite( id ) && id > 0 ) {\n\t\t\tids.add( id );\n\t\t}\n\t}\n\treturn [ ...ids ];\n}\n\n/**\n * Adds a note ID to the metadata.\n * Converts scalar to array if needed, otherwise appends.\n *\n * @param {Object} metadata Existing block metadata\n * @param {number} noteId Note ID to add\n * @return {Object} Updated metadata object\n */\nexport function addNoteIdToMetadata( metadata, noteId ) {\n\tconst ids = new Set( getNoteIdsFromMetadata( metadata ) );\n\tconst id = Number( noteId );\n\tif ( ids.has( id ) ) {\n\t\treturn metadata;\n\t}\n\tids.add( id );\n\treturn { ...metadata, noteId: [ ...ids ] };\n}\n\n/**\n * Picks the most relevant thread from a list: first unresolved, else first.\n *\n * @param {Array} threads Ordered list of thread objects.\n * @return {Object|null} Selected thread or null when the list is empty.\n */\nexport function pickPrimaryNote( threads ) {\n\treturn (\n\t\tthreads.find( ( thread ) => thread.status === 'hold' ) ??\n\t\tthreads[ 0 ] ??\n\t\tnull\n\t);\n}\n\n/**\n * Removes a note ID from the metadata.\n *\n * @param {Object} metadata Existing block metadata\n * @param {number} noteId Note ID to remove\n * @return {Object} Updated metadata object\n */\nexport function removeNoteIdFromMetadata( metadata, noteId ) {\n\tconst ids = new Set( getNoteIdsFromMetadata( metadata ) );\n\tids.delete( Number( noteId ) );\n\treturn {\n\t\t...metadata,\n\t\tnoteId: ids.size > 0 ? [ ...ids ] : undefined,\n\t};\n}\n\n/**\n * Calculate final top positions for all floating note threads in the\n * editor's content coordinate space. Adjusts positions to prevent overlapping\n * by pushing threads above the selected one upward and threads below it downward.\n *\n * @param {Object} params\n * @param {Array} params.threads Ordered list of thread objects.\n * @param {string|number|undefined} params.selectedNoteId ID of the currently selected thread.\n * @param {Object<string,DOMRect>} params.blockRects Pre-read bounding rects keyed by thread ID.\n * @param {Object<string,number>} params.heights Rendered heights keyed by thread ID.\n * @param {number} params.scrollTop Current scroll offset of the editor content.\n * @return {{ positions: Object<string,number> }} Computed top positions.\n */\nexport function calculateNotePositions( {\n\tthreads,\n\tselectedNoteId,\n\tblockRects,\n\theights,\n\tscrollTop = 0,\n} ) {\n\tconst offsets = {};\n\n\tconst anchorIndex = Math.max(\n\t\t0,\n\t\tthreads.findIndex( ( thread ) => thread.id === selectedNoteId )\n\t);\n\n\tconst anchorThread = threads[ anchorIndex ];\n\n\tif ( ! anchorThread || ! blockRects[ anchorThread.id ] ) {\n\t\treturn { positions: {} };\n\t}\n\n\tconst anchorRect = blockRects[ anchorThread.id ];\n\tconst anchorTop = anchorRect.top || 0;\n\tconst anchorHeight = heights[ anchorThread.id ] || 0;\n\n\toffsets[ anchorThread.id ] = THREAD_ALIGN_OFFSET;\n\n\t// Process threads after the anchor, offsetting overlapping threads downward.\n\tlet prevAdjustedTop = anchorTop + THREAD_ALIGN_OFFSET;\n\tlet prevHeight = anchorHeight;\n\n\tfor ( let i = anchorIndex + 1; i < threads.length; i++ ) {\n\t\tconst thread = threads[ i ];\n\t\tconst threadRect = blockRects[ thread.id ];\n\t\tif ( ! threadRect ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst threadTop = threadRect.top || 0;\n\t\tconst threadHeight = heights[ thread.id ] || 0;\n\n\t\tlet offset = THREAD_ALIGN_OFFSET;\n\n\t\tconst prevBottom = prevAdjustedTop + prevHeight;\n\t\tif ( threadTop < prevBottom + THREAD_GAP ) {\n\t\t\toffset = prevBottom - threadTop + OVERLAP_MARGIN;\n\t\t}\n\n\t\toffsets[ thread.id ] = offset;\n\n\t\tprevAdjustedTop = threadTop + offset;\n\t\tprevHeight = threadHeight;\n\t}\n\n\t// Process threads before the anchor, offsetting overlapping threads upward.\n\tlet belowAdjustedTop = anchorTop + THREAD_ALIGN_OFFSET;\n\n\tfor ( let i = anchorIndex - 1; i >= 0; i-- ) {\n\t\tconst thread = threads[ i ];\n\t\tconst threadRect = blockRects[ thread.id ];\n\t\tif ( ! threadRect ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst threadTop = threadRect.top || 0;\n\t\tconst threadHeight = heights[ thread.id ] || 0;\n\n\t\tlet offset = THREAD_ALIGN_OFFSET;\n\n\t\tconst threadBottom = threadTop + threadHeight;\n\n\t\tif ( threadBottom > belowAdjustedTop ) {\n\t\t\toffset =\n\t\t\t\tbelowAdjustedTop - threadTop - threadHeight - OVERLAP_MARGIN;\n\t\t}\n\n\t\toffsets[ thread.id ] = offset;\n\n\t\tbelowAdjustedTop = threadTop + offset;\n\t}\n\n\t// blockRect.top + scrollTop is the block's absolute y within the editor's\n\t// scroll content; CSS translates each thread by -scrollTop at render time.\n\tconst positions = {};\n\tfor ( const thread of threads ) {\n\t\tconst blockRect = blockRects[ thread.id ];\n\t\tif ( blockRect && offsets[ thread.id ] !== undefined ) {\n\t\t\tpositions[ thread.id ] =\n\t\t\t\tblockRect.top + scrollTop + offsets[ thread.id ];\n\t\t}\n\t}\n\n\treturn { positions };\n}\n\n/**\n * Resolve the DOM element for a note thread once it's mounted,\n * or `null` if not found within 3 seconds.\n *\n * @param {string} noteId Note thread ID.\n * @param {?HTMLElement} container Container to search within.\n * @param {string} additionalSelector Optional descendant selector.\n * @return {Promise<HTMLElement|null>} Resolved element, or `null` on timeout.\n */\nfunction findNoteThread( noteId, container, additionalSelector ) {\n\tif ( ! container ) {\n\t\treturn Promise.resolve( null );\n\t}\n\n\t// A thread without a noteId is a new note thread.\n\tconst threadSelector =\n\t\tnoteId && noteId !== 'new'\n\t\t\t? `[role=treeitem][id=\"note-thread-${ noteId }\"]`\n\t\t\t: '[role=treeitem]:not([id])';\n\tconst selector = additionalSelector\n\t\t? `${ threadSelector } ${ additionalSelector }`\n\t\t: threadSelector;\n\n\treturn new Promise( ( resolve ) => {\n\t\tif ( container.querySelector( selector ) ) {\n\t\t\treturn resolve( container.querySelector( selector ) );\n\t\t}\n\n\t\tlet timer = null;\n\t\t// Wait for the element to be added to the DOM.\n\t\tconst observer = new window.MutationObserver( () => {\n\t\t\tif ( container.querySelector( selector ) ) {\n\t\t\t\tclearTimeout( timer );\n\t\t\t\tobserver.disconnect();\n\t\t\t\tresolve( container.querySelector( selector ) );\n\t\t\t}\n\t\t} );\n\n\t\tobserver.observe( container, { childList: true, subtree: true } );\n\n\t\t// Stop trying after 3 seconds.\n\t\ttimer = setTimeout( () => {\n\t\t\tobserver.disconnect();\n\t\t\tresolve( null );\n\t\t}, 3000 );\n\t} );\n}\n\n/**\n * Focus a note thread (or a descendant) and scroll it into view.\n *\n * @param {string} noteId Note thread ID.\n * @param {?HTMLElement} container Container to search within.\n * @param {string} additionalSelector Optional descendant selector.\n */\nexport function focusNoteThread( noteId, container, additionalSelector ) {\n\treturn findNoteThread( noteId, container, additionalSelector ).then(\n\t\t( element ) => {\n\t\t\tif ( ! element ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telement.focus();\n\t\t\telement.scrollIntoView( { block: 'nearest' } );\n\t\t}\n\t);\n}\n\n/**\n * Scroll a note thread into view without changing focus.\n *\n * @param {string} noteId Note thread ID.\n * @param {?HTMLElement} container Container to search within.\n */\nexport function scrollNoteThreadIntoView( noteId, container ) {\n\treturn findNoteThread( noteId, container ).then( ( element ) => {\n\t\telement?.scrollIntoView( { block: 'nearest' } );\n\t} );\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\nimport { create, RichTextData } from '@wordpress/rich-text';\n\n/**\n * Sanitizes a note string by trimming leading and trailing whitespace.\n *\n * @param {string} str - The note string to sanitize.\n * @return {string} - The sanitized note string.\n */\nexport function sanitizeNoteContent( str ) {\n\treturn str.trim();\n}\n\nconst THREAD_ALIGN_OFFSET = -16;\nconst THREAD_GAP = 16;\nconst OVERLAP_MARGIN = 20;\n\n/**\n * Avatar border colors chosen to be visually distinct from each other and from\n * the editor's semantic UI colors (Delta E > 10 between all pairs).\n */\nconst AVATAR_BORDER_COLORS = [\n\t'#C36EFF', // Purple\n\t'#D94145', // Red\n\t'#E4780A', // Orange\n\t'#FF35EE', // Magenta\n\t'#879F11', // Olive\n\t'#46A494', // Teal\n\t'#00A2C3', // Cyan\n];\n\n/**\n * Gets the border color for an avatar based on the user ID.\n *\n * Always returns a 6-digit `#RRGGBB` hex string; callers (e.g. the highlight\n * styles) rely on this format to append alpha suffixes.\n *\n * @param {number} userId - The user ID.\n * @return {string} - The border color as a `#RRGGBB` hex string.\n */\nexport function getAvatarBorderColor( userId ) {\n\treturn AVATAR_BORDER_COLORS[ userId % AVATAR_BORDER_COLORS.length ];\n}\n\n/**\n * Generates a note excerpt from text based on word count type and length.\n *\n * @param {string} text - The note text to generate excerpt from.\n * @param {number} excerptLength - The maximum length for the note excerpt.\n * @return {string} - The generated note excerpt.\n */\nexport function getNoteExcerpt( text, excerptLength = 10 ) {\n\tif ( ! text ) {\n\t\treturn '';\n\t}\n\n\t/*\n\t * translators: If your word count is based on single characters (e.g. East Asian characters),\n\t * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.\n\t * Do not translate into your own language.\n\t */\n\tconst wordCountType = _x( 'words', 'Word count type. Do not translate!' );\n\n\tconst rawText = text.trim();\n\tlet trimmedExcerpt = '';\n\n\tif ( wordCountType === 'words' ) {\n\t\ttrimmedExcerpt = rawText.split( ' ', excerptLength ).join( ' ' );\n\t} else if ( wordCountType === 'characters_excluding_spaces' ) {\n\t\t/*\n\t\t * 1. Split the text at the character limit,\n\t\t * then join the substrings back into one string.\n\t\t * 2. Count the number of spaces in the text\n\t\t * by comparing the lengths of the string with and without spaces.\n\t\t * 3. Add the number to the length of the visible excerpt,\n\t\t * so that the spaces are excluded from the word count.\n\t\t */\n\t\tconst textWithSpaces = rawText.split( '', excerptLength ).join( '' );\n\n\t\tconst numberOfSpaces =\n\t\t\ttextWithSpaces.length - textWithSpaces.replaceAll( ' ', '' ).length;\n\n\t\ttrimmedExcerpt = rawText\n\t\t\t.split( '', excerptLength + numberOfSpaces )\n\t\t\t.join( '' );\n\t} else if ( wordCountType === 'characters_including_spaces' ) {\n\t\ttrimmedExcerpt = rawText.split( '', excerptLength ).join( '' );\n\t}\n\n\tconst isTrimmed = trimmedExcerpt !== rawText;\n\treturn isTrimmed ? trimmedExcerpt + '…' : trimmedExcerpt;\n}\n\n/**\n * Normalizes noteId metadata to always return an array of unique numeric ids,\n * preserving insertion order. Handles both scalar (legacy, possibly\n * string-typed) and array (new) values.\n *\n * @param {Object} metadata Block metadata object\n * @return {number[]} Array of note IDs (may be empty)\n */\nexport function getNoteIdsFromMetadata( metadata ) {\n\tconst noteId = metadata?.noteId;\n\tconst raw = Array.isArray( noteId ) ? noteId : [ noteId ];\n\tconst ids = new Set();\n\tfor ( const value of raw ) {\n\t\tconst id = Number( value );\n\t\tif ( Number.isFinite( id ) && id > 0 ) {\n\t\t\tids.add( id );\n\t\t}\n\t}\n\treturn [ ...ids ];\n}\n\n/**\n * Adds a note ID to the metadata.\n * Converts scalar to array if needed, otherwise appends.\n *\n * @param {Object} metadata Existing block metadata\n * @param {number} noteId Note ID to add\n * @return {Object} Updated metadata object\n */\nexport function addNoteIdToMetadata( metadata, noteId ) {\n\tconst ids = new Set( getNoteIdsFromMetadata( metadata ) );\n\tconst id = Number( noteId );\n\tif ( ids.has( id ) ) {\n\t\treturn metadata;\n\t}\n\tids.add( id );\n\treturn { ...metadata, noteId: [ ...ids ] };\n}\n\nconst NOTE_FORMAT_TYPE = 'core/note';\n\n/**\n * Search a rich-text value for a `core/note` marker matching `noteId` and\n * return its character range. Used to derive an inline note's anchor from\n * the in-content marker (resilient to edits) rather than stale offset meta.\n *\n * @param {*} value Block attribute value (RichTextData, string, or other).\n * @param {number|string} noteId Note id to search for.\n * @return {?{start: number, end: number}} Range or null when no marker is found.\n */\nexport function findNoteRange( value, noteId ) {\n\tif ( noteId === undefined || noteId === null ) {\n\t\treturn null;\n\t}\n\tlet html = null;\n\tif ( value instanceof RichTextData ) {\n\t\thtml = value.toHTMLString();\n\t} else if ( typeof value === 'string' ) {\n\t\thtml = value;\n\t}\n\tif ( ! html || html.indexOf( 'wp-note' ) === -1 ) {\n\t\treturn null;\n\t}\n\tconst target = String( noteId );\n\tconst record = create( { html } );\n\tconst formats = record.formats;\n\tlet start = -1;\n\tfor ( let i = 0; i < formats.length; i++ ) {\n\t\tconst stack = formats[ i ];\n\t\tconst hit = stack?.find(\n\t\t\t( f ) =>\n\t\t\t\tf.type === NOTE_FORMAT_TYPE &&\n\t\t\t\tf.attributes &&\n\t\t\t\tf.attributes[ 'data-id' ] === target\n\t\t);\n\t\tif ( hit ) {\n\t\t\tif ( start === -1 ) {\n\t\t\t\tstart = i;\n\t\t\t}\n\t\t} else if ( start !== -1 ) {\n\t\t\treturn { start, end: i };\n\t\t}\n\t}\n\tif ( start !== -1 ) {\n\t\treturn { start, end: formats.length };\n\t}\n\treturn null;\n}\n\n/**\n * Locate a note's in-content `core/note` marker across all of a block's\n * attributes. The marker (carrying `data-id`) is the single source of truth for\n * an inline note's anchor: a note is inline iff a marker with its id exists in\n * the block, and the attribute that holds it is discovered here rather than\n * stored separately. Returns the matching attribute key and the marker range.\n *\n * @param {?Object} attributes Block attributes, or null/undefined when unloaded.\n * @param {number|string} noteId Note id to search for.\n * @return {?{attributeKey: string, start: number, end: number}} Anchor or null when no marker is found.\n */\nexport function findNoteInBlock( attributes, noteId ) {\n\tif ( ! attributes ) {\n\t\treturn null;\n\t}\n\tfor ( const attributeKey of Object.keys( attributes ) ) {\n\t\tconst range = findNoteRange( attributes[ attributeKey ], noteId );\n\t\tif ( range ) {\n\t\t\treturn { attributeKey, start: range.start, end: range.end };\n\t\t}\n\t}\n\treturn null;\n}\n\n// Sentinel that sorts a block-level (whole-block) note before any inline note\n// within the same block. Negative so any real character offset (>= 0) ranks\n// after it. Number.NEGATIVE_INFINITY would work too; -1 is enough and keeps\n// the diff arithmetic in safe integers.\nexport const BLOCK_LEVEL_NOTE_START = -1;\n\n/**\n * Resolve an inline note's character offset in its block so threads can be\n * sorted by reading order. A note is inline iff an in-content `core/note`\n * marker carries its id; block-level notes (no marker) sort first within their\n * block via a sentinel.\n *\n * @param {Object} thread Materialized thread record (with `.id`).\n * @param {?Object} attributes Block attributes for the thread's block.\n * @return {number} Marker start offset, or `BLOCK_LEVEL_NOTE_START` when there is no inline anchor.\n */\nexport function getInlineMarkerStart( thread, attributes ) {\n\tconst found = findNoteInBlock( attributes, thread?.id );\n\treturn found ? found.start : BLOCK_LEVEL_NOTE_START;\n}\n\n/**\n * Apply a `core/note` marker across `[start, end)` without removing notes\n * already present in that range.\n *\n * Rich-text's `applyFormat` strips any existing format of the same type before\n * applying, so two `core/note` markers can't coexist - a note drawn over an\n * existing one would wipe it in the overlap. This keeps every overlapping note\n * and orders the markers outermost-first by span, so a note fully contained in\n * another nests inside it (`<mark><mark>…</mark></mark>`). Crossing (partial)\n * overlaps can't nest in HTML and serialize as split runs, but each note keeps\n * its full range. The returned record is not normalised; callers should\n * round-trip it (e.g. through `RichTextData`) before storing.\n *\n * @param {Object} record A rich-text record (`{ text, formats, … }`).\n * @param {Object} format The `core/note` format to add (`{ type, attributes }`).\n * @param {number} start Range start (inclusive).\n * @param {number} end Range end (exclusive).\n * @return {Object} A new record with the note applied.\n */\nexport function applyNoteFormat( record, format, start, end ) {\n\tconst formats = record.formats.slice();\n\tfor ( let i = start; i < end; i++ ) {\n\t\tconst stack = formats[ i ] ? formats[ i ].slice() : [];\n\t\tstack.push( format );\n\t\tformats[ i ] = stack;\n\t}\n\n\t// Measure each note's full span so containment can order the markers.\n\tconst spans = new Map();\n\tfor ( let i = 0; i < formats.length; i++ ) {\n\t\tconst stack = formats[ i ];\n\t\tif ( ! stack ) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor ( const fmt of stack ) {\n\t\t\tif ( fmt.type !== NOTE_FORMAT_TYPE ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst id = fmt.attributes?.[ 'data-id' ];\n\t\t\tconst span = spans.get( id );\n\t\t\tif ( span ) {\n\t\t\t\tspan.end = i;\n\t\t\t} else {\n\t\t\t\tspans.set( id, { start: i, end: i } );\n\t\t\t}\n\t\t}\n\t}\n\tconst sizeOf = ( id ) => {\n\t\tconst span = spans.get( id );\n\t\treturn span ? span.end - span.start : 0;\n\t};\n\n\t// Order markers outermost-first (widest span) so `toTree` nests them rather\n\t// than splitting an outer note around an inner one. Notes sort ahead of\n\t// other formats so a note wraps the formatted text it spans.\n\tfor ( let i = 0; i < formats.length; i++ ) {\n\t\tconst stack = formats[ i ];\n\t\tif ( ! stack || stack.length < 2 ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst notes = stack.filter( ( fmt ) => fmt.type === NOTE_FORMAT_TYPE );\n\t\tif ( notes.length === 0 ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( notes.length > 1 ) {\n\t\t\tnotes.sort(\n\t\t\t\t( a, b ) =>\n\t\t\t\t\tsizeOf( b.attributes?.[ 'data-id' ] ) -\n\t\t\t\t\tsizeOf( a.attributes?.[ 'data-id' ] )\n\t\t\t);\n\t\t}\n\t\tconst others = stack.filter( ( fmt ) => fmt.type !== NOTE_FORMAT_TYPE );\n\t\tformats[ i ] = [ ...notes, ...others ];\n\t}\n\n\treturn { ...record, formats };\n}\n\n/**\n * Remove a single note's `core/note` marker from a rich-text value, leaving any\n * other notes nested or overlapping with it intact. Used when a note is deleted\n * or resolved so its highlight does not linger in the content.\n *\n * Rich-text's `removeFormat` strips every `core/note` marker in a range, so it\n * would wipe co-located notes; this filters by `data-id` to drop only the target\n * marker.\n *\n * @param {*} value Block attribute value (RichTextData or other).\n * @param {number|string} noteId Note id whose marker should be removed.\n * @return {?RichTextData} A new value with the marker removed, or null when the\n * attribute isn't rich text or carries no such marker.\n */\nexport function removeNoteFormat( value, noteId ) {\n\tif ( ! ( value instanceof RichTextData ) ) {\n\t\treturn null;\n\t}\n\tconst target = String( noteId );\n\tconst record = create( { html: value.toHTMLString() } );\n\tlet changed = false;\n\tconst formats = record.formats.map( ( stack ) => {\n\t\tif ( ! stack ) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst filtered = stack.filter(\n\t\t\t( format ) =>\n\t\t\t\t! (\n\t\t\t\t\tformat.type === NOTE_FORMAT_TYPE &&\n\t\t\t\t\tformat.attributes?.[ 'data-id' ] === target\n\t\t\t\t)\n\t\t);\n\t\tif ( filtered.length === stack.length ) {\n\t\t\treturn stack;\n\t\t}\n\t\tchanged = true;\n\t\treturn filtered.length ? filtered : undefined;\n\t} );\n\t// Round-trip through HTML so the stored value matches a fresh reload.\n\treturn changed\n\t\t? RichTextData.fromHTMLString(\n\t\t\t\tnew RichTextData( { ...record, formats } ).toHTMLString()\n\t\t )\n\t\t: null;\n}\n\n/**\n * Picks the most relevant thread from a list: first unresolved, else first.\n *\n * @param {Array} threads Ordered list of thread objects.\n * @return {Object|null} Selected thread or null when the list is empty.\n */\nexport function pickPrimaryNote( threads ) {\n\treturn (\n\t\tthreads.find( ( thread ) => thread.status === 'hold' ) ??\n\t\tthreads[ 0 ] ??\n\t\tnull\n\t);\n}\n\n/**\n * Removes a note ID from the metadata.\n *\n * @param {Object} metadata Existing block metadata\n * @param {number} noteId Note ID to remove\n * @return {Object} Updated metadata object\n */\nexport function removeNoteIdFromMetadata( metadata, noteId ) {\n\tconst ids = new Set( getNoteIdsFromMetadata( metadata ) );\n\tids.delete( Number( noteId ) );\n\treturn {\n\t\t...metadata,\n\t\tnoteId: ids.size > 0 ? [ ...ids ] : undefined,\n\t};\n}\n\n/**\n * Calculate final top positions for all floating note threads in the\n * editor's content coordinate space. Adjusts positions to prevent overlapping\n * by pushing threads above the selected one upward and threads below it downward.\n *\n * @param {Object} params\n * @param {Array} params.threads Ordered list of thread objects.\n * @param {string|number|undefined} params.selectedNoteId ID of the currently selected thread.\n * @param {Object<string,DOMRect>} params.blockRects Pre-read bounding rects keyed by thread ID.\n * @param {Object<string,number>} params.heights Rendered heights keyed by thread ID.\n * @param {number} params.scrollTop Current scroll offset of the editor content.\n * @return {{ positions: Object<string,number> }} Computed top positions.\n */\nexport function calculateNotePositions( {\n\tthreads,\n\tselectedNoteId,\n\tblockRects,\n\theights,\n\tscrollTop = 0,\n} ) {\n\tconst offsets = {};\n\n\tconst anchorIndex = Math.max(\n\t\t0,\n\t\tthreads.findIndex( ( thread ) => thread.id === selectedNoteId )\n\t);\n\n\tconst anchorThread = threads[ anchorIndex ];\n\n\tif ( ! anchorThread || ! blockRects[ anchorThread.id ] ) {\n\t\treturn { positions: {} };\n\t}\n\n\tconst anchorRect = blockRects[ anchorThread.id ];\n\tconst anchorTop = anchorRect.top || 0;\n\tconst anchorHeight = heights[ anchorThread.id ] || 0;\n\n\toffsets[ anchorThread.id ] = THREAD_ALIGN_OFFSET;\n\n\t// Process threads after the anchor, offsetting overlapping threads downward.\n\tlet prevAdjustedTop = anchorTop + THREAD_ALIGN_OFFSET;\n\tlet prevHeight = anchorHeight;\n\n\tfor ( let i = anchorIndex + 1; i < threads.length; i++ ) {\n\t\tconst thread = threads[ i ];\n\t\tconst threadRect = blockRects[ thread.id ];\n\t\tif ( ! threadRect ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst threadTop = threadRect.top || 0;\n\t\tconst threadHeight = heights[ thread.id ] || 0;\n\n\t\tlet offset = THREAD_ALIGN_OFFSET;\n\n\t\tconst prevBottom = prevAdjustedTop + prevHeight;\n\t\tif ( threadTop < prevBottom + THREAD_GAP ) {\n\t\t\toffset = prevBottom - threadTop + OVERLAP_MARGIN;\n\t\t}\n\n\t\toffsets[ thread.id ] = offset;\n\n\t\tprevAdjustedTop = threadTop + offset;\n\t\tprevHeight = threadHeight;\n\t}\n\n\t// Process threads before the anchor, offsetting overlapping threads upward.\n\tlet belowAdjustedTop = anchorTop + THREAD_ALIGN_OFFSET;\n\n\tfor ( let i = anchorIndex - 1; i >= 0; i-- ) {\n\t\tconst thread = threads[ i ];\n\t\tconst threadRect = blockRects[ thread.id ];\n\t\tif ( ! threadRect ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst threadTop = threadRect.top || 0;\n\t\tconst threadHeight = heights[ thread.id ] || 0;\n\n\t\tlet offset = THREAD_ALIGN_OFFSET;\n\n\t\tconst threadBottom = threadTop + threadHeight;\n\n\t\tif ( threadBottom > belowAdjustedTop ) {\n\t\t\toffset =\n\t\t\t\tbelowAdjustedTop - threadTop - threadHeight - OVERLAP_MARGIN;\n\t\t}\n\n\t\toffsets[ thread.id ] = offset;\n\n\t\tbelowAdjustedTop = threadTop + offset;\n\t}\n\n\t// blockRect.top + scrollTop is the block's absolute y within the editor's\n\t// scroll content; CSS translates each thread by -scrollTop at render time.\n\tconst positions = {};\n\tfor ( const thread of threads ) {\n\t\tconst blockRect = blockRects[ thread.id ];\n\t\tif ( blockRect && offsets[ thread.id ] !== undefined ) {\n\t\t\tpositions[ thread.id ] =\n\t\t\t\tblockRect.top + scrollTop + offsets[ thread.id ];\n\t\t}\n\t}\n\n\treturn { positions };\n}\n\n/**\n * Resolve the DOM element for a note thread once it's mounted,\n * or `null` if not found within 3 seconds.\n *\n * @param {string} noteId Note thread ID.\n * @param {?HTMLElement} container Container to search within.\n * @param {string} additionalSelector Optional descendant selector.\n * @return {Promise<HTMLElement|null>} Resolved element, or `null` on timeout.\n */\nfunction findNoteThread( noteId, container, additionalSelector ) {\n\tif ( ! container ) {\n\t\treturn Promise.resolve( null );\n\t}\n\n\t// A thread without a noteId is a new note thread.\n\tconst threadSelector =\n\t\tnoteId && noteId !== 'new'\n\t\t\t? `[role=treeitem][id=\"note-thread-${ noteId }\"]`\n\t\t\t: '[role=treeitem]:not([id])';\n\tconst selector = additionalSelector\n\t\t? `${ threadSelector } ${ additionalSelector }`\n\t\t: threadSelector;\n\n\treturn new Promise( ( resolve ) => {\n\t\tif ( container.querySelector( selector ) ) {\n\t\t\treturn resolve( container.querySelector( selector ) );\n\t\t}\n\n\t\tlet timer = null;\n\t\t// Wait for the element to be added to the DOM.\n\t\tconst observer = new window.MutationObserver( () => {\n\t\t\tif ( container.querySelector( selector ) ) {\n\t\t\t\tclearTimeout( timer );\n\t\t\t\tobserver.disconnect();\n\t\t\t\tresolve( container.querySelector( selector ) );\n\t\t\t}\n\t\t} );\n\n\t\tobserver.observe( container, { childList: true, subtree: true } );\n\n\t\t// Stop trying after 3 seconds.\n\t\ttimer = setTimeout( () => {\n\t\t\tobserver.disconnect();\n\t\t\tresolve( null );\n\t\t}, 3000 );\n\t} );\n}\n\n/**\n * Focus a note thread (or a descendant) and scroll it into view.\n *\n * @param {string} noteId Note thread ID.\n * @param {?HTMLElement} container Container to search within.\n * @param {string} additionalSelector Optional descendant selector.\n */\nexport function focusNoteThread( noteId, container, additionalSelector ) {\n\treturn findNoteThread( noteId, container, additionalSelector ).then(\n\t\t( element ) => {\n\t\t\tif ( ! element ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telement.focus();\n\t\t\telement.scrollIntoView( { block: 'nearest' } );\n\t\t}\n\t);\n}\n\n/**\n * Scroll a note thread into view without changing focus.\n *\n * @param {string} noteId Note thread ID.\n * @param {?HTMLElement} container Container to search within.\n */\nexport function scrollNoteThreadIntoView( noteId, container ) {\n\treturn findNoteThread( noteId, container ).then( ( element ) => {\n\t\telement?.scrollIntoView( { block: 'nearest' } );\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,QAAQ,oBAAoB;AAQ9B,SAAS,oBAAqB,KAAM;AAC1C,SAAO,IAAI,KAAK;AACjB;AAEA,IAAM,sBAAsB;AAC5B,IAAM,aAAa;AACnB,IAAM,iBAAiB;AAMvB,IAAM,uBAAuB;AAAA,EAC5B;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AA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,IAAK;AAAA,IACf,GAAG,GAAK;AAAA,EACT,CAAE;AACH;AASO,SAAS,gBAAiB,QAAQ,WAAW,oBAAqB;AACxE,SAAO,eAAgB,QAAQ,WAAW,kBAAmB,EAAE;AAAA,IAC9D,CAAE,YAAa;AACd,UAAK,CAAE,SAAU;AAChB;AAAA,MACD;AACA,cAAQ,MAAM;AACd,cAAQ,eAAgB,EAAE,OAAO,UAAU,CAAE;AAAA,IAC9C;AAAA,EACD;AACD;AAQO,SAAS,yBAA0B,QAAQ,WAAY;AAC7D,SAAO,eAAgB,QAAQ,SAAU,EAAE,KAAM,CAAE,YAAa;AAC/D,aAAS,eAAgB,EAAE,OAAO,UAAU,CAAE;AAAA,EAC/C,CAAE;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,32 +26,54 @@ function getPostUpdatedMessage(name, status, isFirstPublish) {
|
|
|
26
26
|
return sprintf(__("Draft saved by %s."), name);
|
|
27
27
|
}
|
|
28
28
|
function useCollaboratorNotifications(postId, postType) {
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
const {
|
|
30
|
+
postStatus,
|
|
31
|
+
isCollaborationEnabled,
|
|
32
|
+
showJoinNotifications,
|
|
33
|
+
showLeaveNotifications,
|
|
34
|
+
showPostSaveNotifications
|
|
35
|
+
} = useSelect((select) => {
|
|
36
|
+
const {
|
|
37
|
+
getCurrentPostAttribute,
|
|
38
|
+
isCollaborationEnabledForCurrentPost
|
|
39
|
+
} = unlock(select(editorStore));
|
|
40
|
+
const getNotificationPreference = (name) => select(preferencesStore).get("core", name) ?? true;
|
|
41
|
+
return {
|
|
42
|
+
postStatus: getCurrentPostAttribute("status"),
|
|
43
|
+
isCollaborationEnabled: isCollaborationEnabledForCurrentPost(),
|
|
44
|
+
showJoinNotifications: getNotificationPreference(
|
|
45
|
+
"showCollaborationJoinNotifications"
|
|
46
|
+
),
|
|
47
|
+
showLeaveNotifications: getNotificationPreference(
|
|
48
|
+
"showCollaborationLeaveNotifications"
|
|
49
|
+
),
|
|
50
|
+
showPostSaveNotifications: getNotificationPreference(
|
|
51
|
+
"showCollaborationPostSaveNotifications"
|
|
52
|
+
)
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
46
55
|
const { createNotice } = useDispatch(noticesStore);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
56
|
+
const shouldShowJoinNotifications = isCollaborationEnabled && showJoinNotifications;
|
|
57
|
+
const shouldShowLeaveNotifications = isCollaborationEnabled && showLeaveNotifications;
|
|
58
|
+
const shouldShowPostSaveNotifications = isCollaborationEnabled && showPostSaveNotifications;
|
|
59
|
+
const effectiveTarget = (shouldShow) => shouldShow ? [postId, postType] : [null, null];
|
|
60
|
+
const [joinPostId, joinPostType] = effectiveTarget(
|
|
61
|
+
shouldShowJoinNotifications
|
|
62
|
+
);
|
|
63
|
+
const [leavePostId, leavePostType] = effectiveTarget(
|
|
64
|
+
shouldShowLeaveNotifications
|
|
65
|
+
);
|
|
66
|
+
const [postSavePostId, postSavePostType] = effectiveTarget(
|
|
67
|
+
shouldShowPostSaveNotifications
|
|
68
|
+
);
|
|
50
69
|
useOnCollaboratorJoin(
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
joinPostId,
|
|
71
|
+
joinPostType,
|
|
53
72
|
useCallback(
|
|
54
73
|
(collaborator, me) => {
|
|
74
|
+
if (!shouldShowJoinNotifications) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
55
77
|
if (me && collaborator.collaboratorInfo.enteredAt < me.collaboratorInfo.enteredAt) {
|
|
56
78
|
return;
|
|
57
79
|
}
|
|
@@ -69,14 +91,17 @@ function useCollaboratorNotifications(postId, postType) {
|
|
|
69
91
|
}
|
|
70
92
|
);
|
|
71
93
|
},
|
|
72
|
-
[createNotice]
|
|
94
|
+
[createNotice, shouldShowJoinNotifications]
|
|
73
95
|
)
|
|
74
96
|
);
|
|
75
97
|
useOnCollaboratorLeave(
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
leavePostId,
|
|
99
|
+
leavePostType,
|
|
78
100
|
useCallback(
|
|
79
101
|
(collaborator) => {
|
|
102
|
+
if (!shouldShowLeaveNotifications) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
80
105
|
void createNotice(
|
|
81
106
|
"info",
|
|
82
107
|
sprintf(
|
|
@@ -91,15 +116,15 @@ function useCollaboratorNotifications(postId, postType) {
|
|
|
91
116
|
}
|
|
92
117
|
);
|
|
93
118
|
},
|
|
94
|
-
[createNotice]
|
|
119
|
+
[createNotice, shouldShowLeaveNotifications]
|
|
95
120
|
)
|
|
96
121
|
);
|
|
97
122
|
useOnPostSave(
|
|
98
|
-
|
|
99
|
-
|
|
123
|
+
postSavePostId,
|
|
124
|
+
postSavePostType,
|
|
100
125
|
useCallback(
|
|
101
126
|
(saveEvent, saver, prevEvent) => {
|
|
102
|
-
if (!postStatus) {
|
|
127
|
+
if (!shouldShowPostSaveNotifications || !postStatus) {
|
|
103
128
|
return;
|
|
104
129
|
}
|
|
105
130
|
const effectiveStatus = saveEvent.postStatus ?? postStatus ?? "draft";
|
|
@@ -116,7 +141,7 @@ function useCollaboratorNotifications(postId, postType) {
|
|
|
116
141
|
isDismissible: false
|
|
117
142
|
});
|
|
118
143
|
},
|
|
119
|
-
[createNotice, postStatus]
|
|
144
|
+
[createNotice, postStatus, shouldShowPostSaveNotifications]
|
|
120
145
|
)
|
|
121
146
|
);
|
|
122
147
|
}
|
package/build-module/components/collaborators-presence/use-collaborator-notifications.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/collaborators-presence/use-collaborator-notifications.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport {\n\tprivateApis,\n\ttype PostEditorAwarenessState,\n\ttype PostSaveEvent,\n} from '@wordpress/core-data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editorStore } from '../../store';\n\nconst { useOnCollaboratorJoin, useOnCollaboratorLeave, useOnPostSave } =\n\tunlock( privateApis );\n\n/**\n * Notice IDs for each notification type. Using stable IDs prevents duplicate\n * notices if the same event is processed more than once.\n */\nconst NOTIFICATION_TYPE = {\n\tCOLLAB_POST_UPDATED: 'collab-post-updated',\n\tCOLLAB_USER_ENTERED: 'collab-user-entered',\n\tCOLLAB_USER_EXITED: 'collab-user-exited',\n} as const;\n\nconst PUBLISHED_STATUSES = [ 'publish', 'private', 'future' ];\n\n/**\n * Returns the snackbar message for a post updated notification.\n *\n * @param name Display name of the collaborator who saved.\n * @param status WordPress post status at the time of save.\n * @param isFirstPublish Whether this save transitioned the post to published.\n */\nfunction getPostUpdatedMessage(\n\tname: string,\n\tstatus: string,\n\tisFirstPublish: boolean\n): string {\n\tif ( isFirstPublish ) {\n\t\t/* translators: %s: collaborator display name */\n\t\treturn sprintf( __( 'Post published by %s.' ), name );\n\t}\n\tif ( PUBLISHED_STATUSES.includes( status ) ) {\n\t\t/* translators: %s: collaborator display name */\n\t\treturn sprintf( __( 'Post updated by %s.' ), name );\n\t}\n\t/* translators: %s: collaborator display name */\n\treturn sprintf( __( 'Draft saved by %s.' ), name );\n}\n\n/**\n * Hook that watches for collaborator join/leave events and remote save events,\n * dispatching snackbar notices accordingly.\n *\n * @param postId The ID of the post being edited.\n * @param postType The post type of the post being edited.\n */\nexport function useCollaboratorNotifications(\n\tpostId: number | null,\n\tpostType: string | null\n): void {\n\tconst {
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,iBAAiB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,oBAAoB;AACtC;AAAA,EACC;AAAA,OAGM;AACP,SAAS,SAAS,wBAAwB;AAK1C,SAAS,cAAc;AACvB,SAAS,SAAS,mBAAmB;AAErC,IAAM,EAAE,uBAAuB,wBAAwB,cAAc,IACpE,OAAQ,WAAY;AAMrB,IAAM,oBAAoB;AAAA,EACzB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EACrB,oBAAoB;AACrB;AAEA,IAAM,qBAAqB,CAAE,WAAW,WAAW,QAAS;AAS5D,SAAS,sBACR,MACA,QACA,gBACS;AACT,MAAK,gBAAiB;AAErB,WAAO,QAAS,GAAI,uBAAwB,GAAG,IAAK;AAAA,EACrD;AACA,MAAK,mBAAmB,SAAU,MAAO,GAAI;AAE5C,WAAO,QAAS,GAAI,qBAAsB,GAAG,IAAK;AAAA,EACnD;AAEA,SAAO,QAAS,GAAI,oBAAqB,GAAG,IAAK;AAClD;AASO,SAAS,6BACf,QACA,UACO;AACP,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport {\n\tprivateApis,\n\ttype PostEditorAwarenessState,\n\ttype PostSaveEvent,\n} from '@wordpress/core-data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editorStore } from '../../store';\n\nconst { useOnCollaboratorJoin, useOnCollaboratorLeave, useOnPostSave } =\n\tunlock( privateApis );\n\n/**\n * Notice IDs for each notification type. Using stable IDs prevents duplicate\n * notices if the same event is processed more than once.\n */\nconst NOTIFICATION_TYPE = {\n\tCOLLAB_POST_UPDATED: 'collab-post-updated',\n\tCOLLAB_USER_ENTERED: 'collab-user-entered',\n\tCOLLAB_USER_EXITED: 'collab-user-exited',\n} as const;\n\nconst PUBLISHED_STATUSES = [ 'publish', 'private', 'future' ];\n\n/**\n * Returns the snackbar message for a post updated notification.\n *\n * @param name Display name of the collaborator who saved.\n * @param status WordPress post status at the time of save.\n * @param isFirstPublish Whether this save transitioned the post to published.\n */\nfunction getPostUpdatedMessage(\n\tname: string,\n\tstatus: string,\n\tisFirstPublish: boolean\n): string {\n\tif ( isFirstPublish ) {\n\t\t/* translators: %s: collaborator display name */\n\t\treturn sprintf( __( 'Post published by %s.' ), name );\n\t}\n\tif ( PUBLISHED_STATUSES.includes( status ) ) {\n\t\t/* translators: %s: collaborator display name */\n\t\treturn sprintf( __( 'Post updated by %s.' ), name );\n\t}\n\t/* translators: %s: collaborator display name */\n\treturn sprintf( __( 'Draft saved by %s.' ), name );\n}\n\n/**\n * Hook that watches for collaborator join/leave events and remote save events,\n * dispatching snackbar notices accordingly.\n *\n * @param postId The ID of the post being edited.\n * @param postType The post type of the post being edited.\n */\nexport function useCollaboratorNotifications(\n\tpostId: number | null,\n\tpostType: string | null\n): void {\n\tconst {\n\t\tpostStatus,\n\t\tisCollaborationEnabled,\n\t\tshowJoinNotifications,\n\t\tshowLeaveNotifications,\n\t\tshowPostSaveNotifications,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetCurrentPostAttribute,\n\t\t\tisCollaborationEnabledForCurrentPost,\n\t\t} = unlock( select( editorStore ) );\n\t\t// Notification preferences default to enabled when unset.\n\t\tconst getNotificationPreference = ( name: string ) =>\n\t\t\tselect( preferencesStore ).get( 'core', name ) ?? true;\n\t\treturn {\n\t\t\tpostStatus: getCurrentPostAttribute( 'status' ) as\n\t\t\t\t| string\n\t\t\t\t| undefined,\n\t\t\tisCollaborationEnabled: isCollaborationEnabledForCurrentPost(),\n\t\t\tshowJoinNotifications: getNotificationPreference(\n\t\t\t\t'showCollaborationJoinNotifications'\n\t\t\t),\n\t\t\tshowLeaveNotifications: getNotificationPreference(\n\t\t\t\t'showCollaborationLeaveNotifications'\n\t\t\t),\n\t\t\tshowPostSaveNotifications: getNotificationPreference(\n\t\t\t\t'showCollaborationPostSaveNotifications'\n\t\t\t),\n\t\t};\n\t}, [] );\n\n\tconst { createNotice } = useDispatch( noticesStore );\n\n\t// Pass null when collaboration is disabled or a notification type is\n\t// turned off to prevent the hooks from subscribing to awareness state.\n\tconst shouldShowJoinNotifications =\n\t\tisCollaborationEnabled && showJoinNotifications;\n\tconst shouldShowLeaveNotifications =\n\t\tisCollaborationEnabled && showLeaveNotifications;\n\tconst shouldShowPostSaveNotifications =\n\t\tisCollaborationEnabled && showPostSaveNotifications;\n\t// A disabled notification type passes null, which unsubscribes its hook;\n\t// callback guards handle any events already queued before then.\n\tconst effectiveTarget = (\n\t\tshouldShow: boolean\n\t): [ number | null, string | null ] =>\n\t\tshouldShow ? [ postId, postType ] : [ null, null ];\n\tconst [ joinPostId, joinPostType ] = effectiveTarget(\n\t\tshouldShowJoinNotifications\n\t);\n\tconst [ leavePostId, leavePostType ] = effectiveTarget(\n\t\tshouldShowLeaveNotifications\n\t);\n\tconst [ postSavePostId, postSavePostType ] = effectiveTarget(\n\t\tshouldShowPostSaveNotifications\n\t);\n\n\tuseOnCollaboratorJoin(\n\t\tjoinPostId,\n\t\tjoinPostType,\n\t\tuseCallback(\n\t\t\t(\n\t\t\t\tcollaborator: PostEditorAwarenessState,\n\t\t\t\tme?: PostEditorAwarenessState\n\t\t\t) => {\n\t\t\t\tif ( ! shouldShowJoinNotifications ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t/*\n\t\t\t\t * Skip collaborators who were present before the current user\n\t\t\t\t * joined. Their enteredAt is earlier than ours, meaning we're\n\t\t\t\t * the newcomer.\n\t\t\t\t */\n\t\t\t\tif (\n\t\t\t\t\tme &&\n\t\t\t\t\tcollaborator.collaboratorInfo.enteredAt <\n\t\t\t\t\t\tme.collaboratorInfo.enteredAt\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tvoid createNotice(\n\t\t\t\t\t'info',\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: collaborator display name */\n\t\t\t\t\t\t__( '%s has joined the post.' ),\n\t\t\t\t\t\tcollaborator.collaboratorInfo.name\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${ NOTIFICATION_TYPE.COLLAB_USER_ENTERED }-${ collaborator.collaboratorInfo.id }`,\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tisDismissible: false,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t},\n\t\t\t[ createNotice, shouldShowJoinNotifications ]\n\t\t)\n\t);\n\n\tuseOnCollaboratorLeave(\n\t\tleavePostId,\n\t\tleavePostType,\n\t\tuseCallback(\n\t\t\t( collaborator: PostEditorAwarenessState ) => {\n\t\t\t\tif ( ! shouldShowLeaveNotifications ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tvoid createNotice(\n\t\t\t\t\t'info',\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: collaborator display name */\n\t\t\t\t\t\t__( '%s has left the post.' ),\n\t\t\t\t\t\tcollaborator.collaboratorInfo.name\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${ NOTIFICATION_TYPE.COLLAB_USER_EXITED }-${ collaborator.collaboratorInfo.id }`,\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tisDismissible: false,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t},\n\t\t\t[ createNotice, shouldShowLeaveNotifications ]\n\t\t)\n\t);\n\n\tuseOnPostSave(\n\t\tpostSavePostId,\n\t\tpostSavePostType,\n\t\tuseCallback(\n\t\t\t(\n\t\t\t\tsaveEvent: PostSaveEvent,\n\t\t\t\tsaver: PostEditorAwarenessState,\n\t\t\t\tprevEvent: PostSaveEvent | null\n\t\t\t) => {\n\t\t\t\tif ( ! shouldShowPostSaveNotifications || ! postStatus ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prefer the remote status from Y.Doc (accurate at save time)\n\t\t\t\t// over the local Redux value, which may not have synced yet.\n\t\t\t\tconst effectiveStatus =\n\t\t\t\t\tsaveEvent.postStatus ?? postStatus ?? 'draft';\n\n\t\t\t\t// Use the previous save event's status when available for\n\t\t\t\t// accurate first-publish detection across rapid saves.\n\t\t\t\tconst prevStatus = prevEvent?.postStatus ?? postStatus;\n\t\t\t\tconst isFirstPublish =\n\t\t\t\t\t! (\n\t\t\t\t\t\tprevStatus && PUBLISHED_STATUSES.includes( prevStatus )\n\t\t\t\t\t) && PUBLISHED_STATUSES.includes( effectiveStatus );\n\n\t\t\t\tconst message = getPostUpdatedMessage(\n\t\t\t\t\tsaver.collaboratorInfo.name,\n\t\t\t\t\teffectiveStatus,\n\t\t\t\t\tisFirstPublish\n\t\t\t\t);\n\n\t\t\t\tvoid createNotice( 'info', message, {\n\t\t\t\t\tid: `${ NOTIFICATION_TYPE.COLLAB_POST_UPDATED }-${ saver.collaboratorInfo.id }`,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tisDismissible: false,\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[ createNotice, postStatus, shouldShowPostSaveNotifications ]\n\t\t)\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,iBAAiB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,oBAAoB;AACtC;AAAA,EACC;AAAA,OAGM;AACP,SAAS,SAAS,wBAAwB;AAK1C,SAAS,cAAc;AACvB,SAAS,SAAS,mBAAmB;AAErC,IAAM,EAAE,uBAAuB,wBAAwB,cAAc,IACpE,OAAQ,WAAY;AAMrB,IAAM,oBAAoB;AAAA,EACzB,qBAAqB;AAA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,MAAM,iBAAiB;AAAA,UACvB;AAAA,UACA;AAAA,QACD;AAEA,aAAK,aAAc,QAAQ,SAAS;AAAA,UACnC,IAAI,GAAI,kBAAkB,mBAAoB,IAAK,MAAM,iBAAiB,EAAG;AAAA,UAC7E,MAAM;AAAA,UACN,eAAe;AAAA,QAChB,CAAE;AAAA,MACH;AAAA,MACA,CAAE,cAAc,YAAY,+BAAgC;AAAA,IAC7D;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -34,6 +34,30 @@ import {
|
|
|
34
34
|
import { modalName as patternRenameModalName } from "../pattern-rename-modal/index.mjs";
|
|
35
35
|
import { modalName as patternDuplicateModalName } from "../pattern-duplicate-modal/index.mjs";
|
|
36
36
|
import isTemplateRevertable from "../../store/utils/is-template-revertable.mjs";
|
|
37
|
+
function getTogglePatternEditingCommand({
|
|
38
|
+
disableContentOnlyForPatternsAndTemplateParts,
|
|
39
|
+
stopEditingContentOnlySection,
|
|
40
|
+
updateEditorSettings
|
|
41
|
+
}) {
|
|
42
|
+
return {
|
|
43
|
+
name: "core/toggle-pattern-editing",
|
|
44
|
+
label: disableContentOnlyForPatternsAndTemplateParts ? __("Disable editing all patterns") : __("Enable editing all patterns"),
|
|
45
|
+
icon: symbol,
|
|
46
|
+
category: "command",
|
|
47
|
+
callback: ({ close }) => {
|
|
48
|
+
const disableContentOnly = !disableContentOnlyForPatternsAndTemplateParts;
|
|
49
|
+
stopEditingContentOnlySection();
|
|
50
|
+
updateEditorSettings({
|
|
51
|
+
disableContentOnlyForUnsyncedPatterns: disableContentOnly,
|
|
52
|
+
disableContentOnlyForTemplateParts: disableContentOnly
|
|
53
|
+
});
|
|
54
|
+
close();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function isPatternOrTemplatePartBlock(blockName, attributes) {
|
|
59
|
+
return !!attributes?.metadata?.patternName || blockName === "core/template-part";
|
|
60
|
+
}
|
|
37
61
|
var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
38
62
|
const {
|
|
39
63
|
editorMode,
|
|
@@ -45,7 +69,9 @@ var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
|
45
69
|
isViewable,
|
|
46
70
|
isCodeEditingEnabled,
|
|
47
71
|
isRichEditingEnabled,
|
|
48
|
-
isPublishSidebarEnabled
|
|
72
|
+
isPublishSidebarEnabled,
|
|
73
|
+
disableContentOnlyForUnsyncedPatterns,
|
|
74
|
+
disableContentOnlyForTemplateParts
|
|
49
75
|
} = useSelect((select) => {
|
|
50
76
|
const { get } = select(preferencesStore);
|
|
51
77
|
const { isListViewOpened, getCurrentPostType, getEditorSettings } = select(editorStore);
|
|
@@ -61,7 +87,9 @@ var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
|
61
87
|
isViewable: getPostType(getCurrentPostType())?.viewable ?? false,
|
|
62
88
|
isCodeEditingEnabled: getEditorSettings().codeEditingEnabled,
|
|
63
89
|
isRichEditingEnabled: getEditorSettings().richEditingEnabled,
|
|
64
|
-
isPublishSidebarEnabled: select(editorStore).isPublishSidebarEnabled()
|
|
90
|
+
isPublishSidebarEnabled: select(editorStore).isPublishSidebarEnabled(),
|
|
91
|
+
disableContentOnlyForUnsyncedPatterns: !!getEditorSettings().disableContentOnlyForUnsyncedPatterns,
|
|
92
|
+
disableContentOnlyForTemplateParts: !!getEditorSettings().disableContentOnlyForTemplateParts
|
|
65
93
|
};
|
|
66
94
|
}, []);
|
|
67
95
|
const { getActiveComplementaryArea } = useSelect(interfaceStore);
|
|
@@ -73,8 +101,12 @@ var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
|
73
101
|
switchEditorMode,
|
|
74
102
|
toggleDistractionFree,
|
|
75
103
|
toggleSpotlightMode,
|
|
76
|
-
toggleTopToolbar
|
|
104
|
+
toggleTopToolbar,
|
|
105
|
+
updateEditorSettings
|
|
77
106
|
} = useDispatch(editorStore);
|
|
107
|
+
const { stopEditingContentOnlySection } = unlock(
|
|
108
|
+
useDispatch(blockEditorStore)
|
|
109
|
+
);
|
|
78
110
|
const { openModal, enableComplementaryArea, disableComplementaryArea } = useDispatch(interfaceStore);
|
|
79
111
|
const { getCurrentPostId } = useSelect(editorStore);
|
|
80
112
|
const allowSwitchEditorMode = isCodeEditingEnabled && isRichEditingEnabled;
|
|
@@ -82,6 +114,7 @@ var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
|
82
114
|
return { commands: [], isLoading: false };
|
|
83
115
|
}
|
|
84
116
|
const commands = [];
|
|
117
|
+
const disableContentOnlyForPatternsAndTemplateParts = disableContentOnlyForUnsyncedPatterns && disableContentOnlyForTemplateParts;
|
|
85
118
|
commands.push({
|
|
86
119
|
name: "core/open-shortcut-help",
|
|
87
120
|
label: __("Keyboard shortcuts"),
|
|
@@ -145,6 +178,13 @@ var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
|
145
178
|
close();
|
|
146
179
|
}
|
|
147
180
|
});
|
|
181
|
+
commands.push(
|
|
182
|
+
getTogglePatternEditingCommand({
|
|
183
|
+
disableContentOnlyForPatternsAndTemplateParts,
|
|
184
|
+
stopEditingContentOnlySection,
|
|
185
|
+
updateEditorSettings
|
|
186
|
+
})
|
|
187
|
+
);
|
|
148
188
|
if (allowSwitchEditorMode) {
|
|
149
189
|
commands.push({
|
|
150
190
|
name: "core/toggle-code-editor",
|
|
@@ -241,6 +281,57 @@ var getEditorCommandLoader = () => function useEditorCommandLoader() {
|
|
|
241
281
|
isLoading: false
|
|
242
282
|
};
|
|
243
283
|
};
|
|
284
|
+
var getPatternEditingContextualCommands = () => function usePatternEditingContextualCommands({ search }) {
|
|
285
|
+
const {
|
|
286
|
+
disableContentOnlyForPatternsAndTemplateParts,
|
|
287
|
+
hasPatternOrTemplatePartSelection,
|
|
288
|
+
isPreviewMode
|
|
289
|
+
} = useSelect((select) => {
|
|
290
|
+
const {
|
|
291
|
+
getBlockAttributes,
|
|
292
|
+
getBlockName,
|
|
293
|
+
getBlockParents,
|
|
294
|
+
getSelectedBlockClientId,
|
|
295
|
+
getSelectedBlockClientIds,
|
|
296
|
+
getSettings
|
|
297
|
+
} = select(blockEditorStore);
|
|
298
|
+
const { getEditorSettings } = select(editorStore);
|
|
299
|
+
const editorSettings = getEditorSettings();
|
|
300
|
+
const selectedBlockClientId = getSelectedBlockClientId();
|
|
301
|
+
const selectedBlockClientIds = getSelectedBlockClientIds();
|
|
302
|
+
const clientIdsToCheck = selectedBlockClientId && selectedBlockClientIds.length === 1 ? [
|
|
303
|
+
selectedBlockClientId,
|
|
304
|
+
...getBlockParents(selectedBlockClientId, true)
|
|
305
|
+
] : [];
|
|
306
|
+
return {
|
|
307
|
+
disableContentOnlyForPatternsAndTemplateParts: !!editorSettings.disableContentOnlyForUnsyncedPatterns && !!editorSettings.disableContentOnlyForTemplateParts,
|
|
308
|
+
hasPatternOrTemplatePartSelection: clientIdsToCheck.some(
|
|
309
|
+
(clientId) => isPatternOrTemplatePartBlock(
|
|
310
|
+
getBlockName(clientId),
|
|
311
|
+
getBlockAttributes(clientId)
|
|
312
|
+
)
|
|
313
|
+
),
|
|
314
|
+
isPreviewMode: getSettings().isPreviewMode
|
|
315
|
+
};
|
|
316
|
+
}, []);
|
|
317
|
+
const { updateEditorSettings } = useDispatch(editorStore);
|
|
318
|
+
const { stopEditingContentOnlySection } = unlock(
|
|
319
|
+
useDispatch(blockEditorStore)
|
|
320
|
+
);
|
|
321
|
+
if (search || !hasPatternOrTemplatePartSelection && !disableContentOnlyForPatternsAndTemplateParts || isPreviewMode) {
|
|
322
|
+
return { isLoading: false, commands: [] };
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
isLoading: false,
|
|
326
|
+
commands: [
|
|
327
|
+
getTogglePatternEditingCommand({
|
|
328
|
+
disableContentOnlyForPatternsAndTemplateParts,
|
|
329
|
+
stopEditingContentOnlySection,
|
|
330
|
+
updateEditorSettings
|
|
331
|
+
})
|
|
332
|
+
]
|
|
333
|
+
};
|
|
334
|
+
};
|
|
244
335
|
var getEditedEntityContextualCommands = () => function useEditedEntityContextualCommands() {
|
|
245
336
|
const { postType } = useSelect((select) => {
|
|
246
337
|
const { getCurrentPostType } = select(editorStore);
|
|
@@ -401,6 +492,11 @@ function useCommands() {
|
|
|
401
492
|
hook: getEditedEntityContextualCommands(),
|
|
402
493
|
context: "entity-edit"
|
|
403
494
|
});
|
|
495
|
+
useCommandLoader({
|
|
496
|
+
name: "core/editor/pattern-editing-contextual-commands",
|
|
497
|
+
hook: getPatternEditingContextualCommands(),
|
|
498
|
+
context: "block-selection-edit"
|
|
499
|
+
});
|
|
404
500
|
useCommandLoader({
|
|
405
501
|
name: "core/editor/page-content-focus",
|
|
406
502
|
hook: getPageContentFocusCommands(),
|