@wordpress/editor 14.41.2-next.v.202603161435.0 → 14.43.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 +3 -1
- package/build/components/collaborators-overlay/compute-selection.cjs +10 -10
- package/build/components/collaborators-overlay/compute-selection.cjs.map +2 -2
- package/build/components/collaborators-overlay/cursor-registry.cjs +86 -0
- package/build/components/collaborators-overlay/cursor-registry.cjs.map +7 -0
- package/build/components/collaborators-overlay/index.cjs +7 -2
- package/build/components/collaborators-overlay/index.cjs.map +2 -2
- package/build/components/collaborators-overlay/overlay-iframe-styles.cjs +1 -1
- package/build/components/collaborators-overlay/overlay-iframe-styles.cjs.map +2 -2
- package/build/components/collaborators-overlay/overlay.cjs +42 -1
- package/build/components/collaborators-overlay/overlay.cjs.map +2 -2
- package/build/components/collaborators-overlay/timing-utils.cjs +46 -0
- package/build/components/collaborators-overlay/timing-utils.cjs.map +7 -0
- package/build/components/collaborators-overlay/use-render-cursors.cjs +1 -1
- package/build/components/collaborators-overlay/use-render-cursors.cjs.map +2 -2
- package/build/components/collaborators-presence/index.cjs +14 -4
- package/build/components/collaborators-presence/index.cjs.map +2 -2
- package/build/components/collaborators-presence/list.cjs +20 -4
- package/build/components/collaborators-presence/list.cjs.map +2 -2
- package/build/components/post-card-panel/index.cjs +4 -15
- package/build/components/post-card-panel/index.cjs.map +2 -2
- package/build/components/post-content-information/index.cjs +10 -13
- package/build/components/post-content-information/index.cjs.map +2 -2
- package/build/components/post-locked-modal/index.cjs +16 -3
- package/build/components/post-locked-modal/index.cjs.map +2 -2
- package/build/components/post-revisions-panel/index.cjs +164 -0
- package/build/components/post-revisions-panel/index.cjs.map +7 -0
- package/build/components/post-revisions-preview/block-diff.cjs +39 -11
- package/build/components/post-revisions-preview/block-diff.cjs.map +2 -2
- package/build/components/post-revisions-preview/diff-markers.cjs +2 -2
- package/build/components/post-revisions-preview/diff-markers.cjs.map +2 -2
- package/build/components/post-revisions-preview/revisions-canvas.cjs +1 -1
- package/build/components/post-revisions-preview/revisions-canvas.cjs.map +2 -2
- package/build/components/post-revisions-preview/revisions-slider.cjs +24 -5
- package/build/components/post-revisions-preview/revisions-slider.cjs.map +2 -2
- package/build/components/post-template/block-theme.cjs +7 -4
- package/build/components/post-template/block-theme.cjs.map +2 -2
- package/build/components/post-template/create-new-template-modal.cjs +39 -46
- package/build/components/post-template/create-new-template-modal.cjs.map +2 -2
- package/build/components/post-template/hooks.cjs +91 -8
- package/build/components/post-template/hooks.cjs.map +2 -2
- package/build/components/post-template/panel.cjs +5 -42
- package/build/components/post-template/panel.cjs.map +3 -3
- package/build/components/post-template/swap-template-button.cjs +31 -20
- package/build/components/post-template/swap-template-button.cjs.map +2 -2
- package/build/components/preferences-modal/index.cjs +35 -27
- package/build/components/preferences-modal/index.cjs.map +2 -2
- package/build/components/provider/use-block-editor-settings.cjs +2 -0
- package/build/components/provider/use-block-editor-settings.cjs.map +3 -3
- package/build/components/revision-block-diff/index.cjs +61 -0
- package/build/components/revision-block-diff/index.cjs.map +7 -0
- package/build/components/revision-diff-panel/index.cjs +68 -0
- package/build/components/revision-diff-panel/index.cjs.map +7 -0
- package/build/components/revision-fields-diff/index.cjs +96 -0
- package/build/components/revision-fields-diff/index.cjs.map +7 -0
- package/build/components/sidebar/dataform-post-summary.cjs +25 -55
- package/build/components/sidebar/dataform-post-summary.cjs.map +2 -2
- package/build/components/sidebar/index.cjs +30 -23
- package/build/components/sidebar/index.cjs.map +3 -3
- package/build/components/sidebar/post-revision-summary.cjs +74 -0
- package/build/components/sidebar/post-revision-summary.cjs.map +7 -0
- package/build/components/sidebar/post-summary.cjs +35 -42
- package/build/components/sidebar/post-summary.cjs.map +3 -3
- package/build/components/style-book/index.cjs +4 -3
- package/build/components/style-book/index.cjs.map +2 -2
- package/build/components/{sync-connection-modal → sync-connection-error-modal}/index.cjs +89 -80
- package/build/components/sync-connection-error-modal/index.cjs.map +7 -0
- package/build/components/{sync-connection-modal → sync-connection-error-modal}/use-retry-countdown.cjs +14 -27
- package/build/components/sync-connection-error-modal/use-retry-countdown.cjs.map +7 -0
- package/build/components/template-actions-panel/block-theme-content.cjs +188 -0
- package/build/components/template-actions-panel/block-theme-content.cjs.map +7 -0
- package/build/components/template-actions-panel/classic-theme-content.cjs +159 -0
- package/build/components/template-actions-panel/classic-theme-content.cjs.map +7 -0
- package/build/components/template-actions-panel/index.cjs +59 -0
- package/build/components/template-actions-panel/index.cjs.map +7 -0
- package/build/components/visual-editor/index.cjs +2 -2
- package/build/components/visual-editor/index.cjs.map +2 -2
- package/build/dataviews/store/private-actions.cjs +2 -0
- package/build/dataviews/store/private-actions.cjs.map +2 -2
- package/build/store/actions.cjs +1 -3
- package/build/store/actions.cjs.map +2 -2
- package/build/store/private-actions.cjs +21 -2
- package/build/store/private-actions.cjs.map +2 -2
- package/build/store/private-selectors.cjs +40 -15
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/utils/media-finalize/index.cjs +43 -0
- package/build/utils/media-finalize/index.cjs.map +7 -0
- package/build/utils/sync-error-messages.cjs +29 -16
- package/build/utils/sync-error-messages.cjs.map +3 -3
- package/build-module/components/collaborators-overlay/compute-selection.mjs +10 -10
- package/build-module/components/collaborators-overlay/compute-selection.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/cursor-registry.mjs +61 -0
- package/build-module/components/collaborators-overlay/cursor-registry.mjs.map +7 -0
- package/build-module/components/collaborators-overlay/index.mjs +7 -2
- package/build-module/components/collaborators-overlay/index.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/overlay-iframe-styles.mjs +1 -1
- package/build-module/components/collaborators-overlay/overlay-iframe-styles.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/overlay.mjs +43 -2
- package/build-module/components/collaborators-overlay/overlay.mjs.map +2 -2
- package/build-module/components/collaborators-overlay/timing-utils.mjs +21 -0
- package/build-module/components/collaborators-overlay/timing-utils.mjs.map +7 -0
- package/build-module/components/collaborators-overlay/use-render-cursors.mjs +1 -1
- package/build-module/components/collaborators-overlay/use-render-cursors.mjs.map +2 -2
- package/build-module/components/collaborators-presence/index.mjs +14 -4
- package/build-module/components/collaborators-presence/index.mjs.map +2 -2
- package/build-module/components/collaborators-presence/list.mjs +20 -4
- package/build-module/components/collaborators-presence/list.mjs.map +2 -2
- package/build-module/components/post-card-panel/index.mjs +6 -17
- package/build-module/components/post-card-panel/index.mjs.map +2 -2
- package/build-module/components/post-content-information/index.mjs +6 -13
- package/build-module/components/post-content-information/index.mjs.map +2 -2
- package/build-module/components/post-locked-modal/index.mjs +16 -3
- package/build-module/components/post-locked-modal/index.mjs.map +2 -2
- package/build-module/components/post-revisions-panel/index.mjs +139 -0
- package/build-module/components/post-revisions-panel/index.mjs.map +7 -0
- package/build-module/components/post-revisions-preview/block-diff.mjs +39 -11
- package/build-module/components/post-revisions-preview/block-diff.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/diff-markers.mjs +2 -2
- package/build-module/components/post-revisions-preview/diff-markers.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/revisions-canvas.mjs +1 -1
- package/build-module/components/post-revisions-preview/revisions-canvas.mjs.map +2 -2
- package/build-module/components/post-revisions-preview/revisions-slider.mjs +24 -5
- package/build-module/components/post-revisions-preview/revisions-slider.mjs.map +2 -2
- package/build-module/components/post-template/block-theme.mjs +7 -4
- package/build-module/components/post-template/block-theme.mjs.map +2 -2
- package/build-module/components/post-template/create-new-template-modal.mjs +39 -46
- package/build-module/components/post-template/create-new-template-modal.mjs.map +2 -2
- package/build-module/components/post-template/hooks.mjs +90 -8
- package/build-module/components/post-template/hooks.mjs.map +2 -2
- package/build-module/components/post-template/panel.mjs +5 -42
- package/build-module/components/post-template/panel.mjs.map +2 -2
- package/build-module/components/post-template/swap-template-button.mjs +27 -20
- package/build-module/components/post-template/swap-template-button.mjs.map +2 -2
- package/build-module/components/preferences-modal/index.mjs +35 -27
- package/build-module/components/preferences-modal/index.mjs.map +2 -2
- package/build-module/components/provider/use-block-editor-settings.mjs +2 -0
- package/build-module/components/provider/use-block-editor-settings.mjs.map +2 -2
- package/build-module/components/revision-block-diff/index.mjs +30 -0
- package/build-module/components/revision-block-diff/index.mjs.map +7 -0
- package/build-module/components/revision-diff-panel/index.mjs +37 -0
- package/build-module/components/revision-diff-panel/index.mjs.map +7 -0
- package/build-module/components/revision-fields-diff/index.mjs +65 -0
- package/build-module/components/revision-fields-diff/index.mjs.map +7 -0
- package/build-module/components/sidebar/dataform-post-summary.mjs +25 -55
- package/build-module/components/sidebar/dataform-post-summary.mjs.map +2 -2
- package/build-module/components/sidebar/index.mjs +30 -23
- package/build-module/components/sidebar/index.mjs.map +2 -2
- package/build-module/components/sidebar/post-revision-summary.mjs +43 -0
- package/build-module/components/sidebar/post-revision-summary.mjs.map +7 -0
- package/build-module/components/sidebar/post-summary.mjs +31 -42
- package/build-module/components/sidebar/post-summary.mjs.map +2 -2
- package/build-module/components/style-book/index.mjs +4 -3
- package/build-module/components/style-book/index.mjs.map +2 -2
- package/build-module/components/sync-connection-error-modal/index.mjs +177 -0
- package/build-module/components/sync-connection-error-modal/index.mjs.map +7 -0
- package/build-module/components/sync-connection-error-modal/use-retry-countdown.mjs +36 -0
- package/build-module/components/sync-connection-error-modal/use-retry-countdown.mjs.map +7 -0
- package/build-module/components/template-actions-panel/block-theme-content.mjs +167 -0
- package/build-module/components/template-actions-panel/block-theme-content.mjs.map +7 -0
- package/build-module/components/template-actions-panel/classic-theme-content.mjs +138 -0
- package/build-module/components/template-actions-panel/classic-theme-content.mjs.map +7 -0
- package/build-module/components/template-actions-panel/index.mjs +28 -0
- package/build-module/components/template-actions-panel/index.mjs.map +7 -0
- package/build-module/components/visual-editor/index.mjs +2 -2
- package/build-module/components/visual-editor/index.mjs.map +2 -2
- package/build-module/dataviews/store/private-actions.mjs +5 -1
- package/build-module/dataviews/store/private-actions.mjs.map +2 -2
- package/build-module/store/actions.mjs +1 -3
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +21 -2
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +40 -15
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/utils/media-finalize/index.mjs +12 -0
- package/build-module/utils/media-finalize/index.mjs.map +7 -0
- package/build-module/utils/sync-error-messages.mjs +24 -16
- package/build-module/utils/sync-error-messages.mjs.map +3 -3
- package/build-style/style-rtl.css +135 -50
- package/build-style/style.css +135 -50
- package/build-types/components/collaborators-overlay/cursor-registry.d.ts +36 -0
- package/build-types/components/collaborators-overlay/cursor-registry.d.ts.map +1 -0
- package/build-types/components/collaborators-overlay/index.d.ts +7 -4
- package/build-types/components/collaborators-overlay/index.d.ts.map +1 -1
- package/build-types/components/collaborators-overlay/overlay-iframe-styles.d.ts +1 -1
- package/build-types/components/collaborators-overlay/overlay-iframe-styles.d.ts.map +1 -1
- package/build-types/components/collaborators-overlay/overlay.d.ts +4 -1
- package/build-types/components/collaborators-overlay/overlay.d.ts.map +1 -1
- package/build-types/components/collaborators-overlay/timing-utils.d.ts +11 -0
- package/build-types/components/collaborators-overlay/timing-utils.d.ts.map +1 -0
- package/build-types/components/collaborators-presence/index.d.ts.map +1 -1
- package/build-types/components/collaborators-presence/list.d.ts +4 -1
- package/build-types/components/collaborators-presence/list.d.ts.map +1 -1
- package/build-types/components/post-card-panel/index.d.ts.map +1 -1
- package/build-types/components/post-content-information/index.d.ts +4 -1
- package/build-types/components/post-content-information/index.d.ts.map +1 -1
- package/build-types/components/post-locked-modal/index.d.ts +2 -2
- package/build-types/components/post-locked-modal/index.d.ts.map +1 -1
- package/build-types/components/post-revisions-panel/index.d.ts +2 -0
- package/build-types/components/post-revisions-panel/index.d.ts.map +1 -0
- package/build-types/components/post-revisions-preview/block-diff.d.ts.map +1 -1
- package/build-types/components/post-revisions-preview/revisions-slider.d.ts.map +1 -1
- package/build-types/components/post-template/block-theme.d.ts +1 -3
- package/build-types/components/post-template/block-theme.d.ts.map +1 -1
- package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
- package/build-types/components/post-template/hooks.d.ts +2 -1
- package/build-types/components/post-template/hooks.d.ts.map +1 -1
- package/build-types/components/post-template/panel.d.ts.map +1 -1
- package/build-types/components/post-template/swap-template-button.d.ts +4 -0
- package/build-types/components/post-template/swap-template-button.d.ts.map +1 -1
- package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
- package/build-types/components/revision-block-diff/index.d.ts +6 -0
- package/build-types/components/revision-block-diff/index.d.ts.map +1 -0
- package/build-types/components/revision-diff-panel/index.d.ts +14 -0
- package/build-types/components/revision-diff-panel/index.d.ts.map +1 -0
- package/build-types/components/revision-fields-diff/index.d.ts +6 -0
- package/build-types/components/revision-fields-diff/index.d.ts.map +1 -0
- 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-revision-summary.d.ts +2 -0
- package/build-types/components/sidebar/post-revision-summary.d.ts.map +1 -0
- package/build-types/components/sidebar/post-summary.d.ts +3 -0
- package/build-types/components/sidebar/post-summary.d.ts.map +1 -1
- package/build-types/components/style-book/index.d.ts +2 -1
- package/build-types/components/style-book/index.d.ts.map +1 -1
- package/build-types/components/sync-connection-error-modal/index.d.ts +22 -0
- package/build-types/components/sync-connection-error-modal/index.d.ts.map +1 -0
- package/build-types/components/sync-connection-error-modal/use-retry-countdown.d.ts +11 -0
- package/build-types/components/sync-connection-error-modal/use-retry-countdown.d.ts.map +1 -0
- package/build-types/components/template-actions-panel/block-theme-content.d.ts +2 -0
- package/build-types/components/template-actions-panel/block-theme-content.d.ts.map +1 -0
- package/build-types/components/template-actions-panel/classic-theme-content.d.ts +2 -0
- package/build-types/components/template-actions-panel/classic-theme-content.d.ts.map +1 -0
- package/build-types/components/template-actions-panel/index.d.ts +2 -0
- package/build-types/components/template-actions-panel/index.d.ts.map +1 -0
- 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/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/build-types/utils/media-finalize/index.d.ts +2 -0
- package/build-types/utils/media-finalize/index.d.ts.map +1 -0
- package/build-types/utils/sync-error-messages.d.ts +17 -3
- package/build-types/utils/sync-error-messages.d.ts.map +1 -1
- package/package.json +45 -44
- package/src/components/collaborators-overlay/compute-selection.ts +13 -13
- package/src/components/collaborators-overlay/cursor-registry.ts +96 -0
- package/src/components/collaborators-overlay/index.tsx +12 -4
- package/src/components/collaborators-overlay/overlay-iframe-styles.ts +1 -1
- package/src/components/collaborators-overlay/overlay.tsx +64 -1
- package/src/components/collaborators-overlay/timing-utils.ts +30 -0
- package/src/components/collaborators-overlay/use-render-cursors.ts +1 -1
- package/src/components/collaborators-presence/index.tsx +9 -1
- package/src/components/collaborators-presence/list.tsx +25 -1
- package/src/components/post-card-panel/index.js +7 -21
- package/src/components/post-content-information/index.js +5 -16
- package/src/components/post-locked-modal/index.js +21 -3
- package/src/components/post-revisions-panel/index.js +151 -0
- package/src/components/post-revisions-panel/style.scss +16 -0
- package/src/components/post-revisions-preview/block-diff.js +59 -20
- package/src/components/post-revisions-preview/diff-markers.js +2 -2
- package/src/components/post-revisions-preview/revisions-canvas.js +1 -1
- package/src/components/post-revisions-preview/revisions-slider.js +29 -7
- package/src/components/post-revisions-preview/test/block-diff.js +69 -31
- package/src/components/post-template/block-theme.js +4 -1
- package/src/components/post-template/create-new-template-modal.js +1 -4
- package/src/components/post-template/hooks.js +107 -9
- package/src/components/post-template/panel.js +5 -59
- package/src/components/post-template/style.scss +0 -6
- package/src/components/post-template/swap-template-button.js +30 -21
- package/src/components/preferences-modal/index.js +37 -25
- package/src/components/provider/use-block-editor-settings.js +2 -0
- package/src/components/revision-block-diff/index.js +39 -0
- package/src/components/revision-diff-panel/index.js +59 -0
- package/src/components/revision-diff-panel/style.scss +13 -0
- package/src/components/revision-fields-diff/index.js +91 -0
- package/src/components/sidebar/dataform-post-summary.js +45 -68
- package/src/components/sidebar/index.js +35 -22
- package/src/components/sidebar/post-revision-summary.js +50 -0
- package/src/components/sidebar/post-summary.js +22 -40
- package/src/components/sidebar/style.scss +7 -0
- package/src/components/style-book/index.js +4 -2
- package/src/components/sync-connection-error-modal/index.tsx +265 -0
- package/src/components/sync-connection-error-modal/style.scss +14 -0
- package/src/components/sync-connection-error-modal/use-retry-countdown.ts +57 -0
- package/src/components/template-actions-panel/block-theme-content.js +196 -0
- package/src/components/template-actions-panel/classic-theme-content.js +170 -0
- package/src/components/template-actions-panel/index.js +32 -0
- package/src/components/template-actions-panel/style.scss +39 -0
- package/src/components/visual-editor/index.js +2 -2
- package/src/dataviews/store/private-actions.ts +6 -0
- package/src/store/actions.js +1 -4
- package/src/store/private-actions.js +24 -3
- package/src/store/private-selectors.js +46 -16
- package/src/style.scss +4 -1
- package/src/utils/media-finalize/index.js +11 -0
- package/src/utils/media-finalize/test/index.js +34 -0
- package/src/utils/sync-error-messages.ts +72 -0
- package/src/utils/test/sync-error-messages.js +9 -32
- package/build/components/sync-connection-modal/index.cjs.map +0 -7
- package/build/components/sync-connection-modal/use-retry-countdown.cjs.map +0 -7
- package/build-module/components/sync-connection-modal/index.mjs +0 -170
- package/build-module/components/sync-connection-modal/index.mjs.map +0 -7
- package/build-module/components/sync-connection-modal/use-retry-countdown.mjs +0 -49
- package/build-module/components/sync-connection-modal/use-retry-countdown.mjs.map +0 -7
- package/build-types/components/sync-connection-modal/index.d.ts +0 -8
- package/build-types/components/sync-connection-modal/index.d.ts.map +0 -1
- package/build-types/components/sync-connection-modal/use-retry-countdown.d.ts +0 -9
- package/build-types/components/sync-connection-modal/use-retry-countdown.d.ts.map +0 -1
- package/src/components/sync-connection-modal/index.js +0 -206
- package/src/components/sync-connection-modal/style.scss +0 -14
- package/src/components/sync-connection-modal/use-retry-countdown.js +0 -70
- package/src/utils/sync-error-messages.js +0 -58
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
5
|
import { useMemo } from '@wordpress/element';
|
|
6
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
@@ -64,23 +65,120 @@ function useTemplates( postType ) {
|
|
|
64
65
|
);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
export function useAvailableTemplates(
|
|
68
|
+
export function useAvailableTemplates() {
|
|
69
|
+
const { postType, postId } = useEditedPostContext();
|
|
70
|
+
const [ postSlug ] = useEntityProp( 'postType', postType, 'slug', postId );
|
|
68
71
|
const currentTemplateSlug = useCurrentTemplateSlug();
|
|
69
72
|
const allowSwitchingTemplate = useAllowSwitchingTemplates();
|
|
70
73
|
const templates = useTemplates( postType );
|
|
74
|
+
// Add the default template to the available ones. We don't care about
|
|
75
|
+
// possible assignment to postspage/homepage because it's guarded by
|
|
76
|
+
// `allowSwitchingTemplate` above.
|
|
77
|
+
const defaultTemplate = useSelect(
|
|
78
|
+
( select ) => {
|
|
79
|
+
// Only append the default template if the experiment is enabled.
|
|
80
|
+
if ( ! window?.__experimentalDataFormInspector ) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
// If the default template is already assigned, no need
|
|
84
|
+
// to add it to the available templates.
|
|
85
|
+
if ( ! currentTemplateSlug ) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const { getDefaultTemplateId, getEntityRecord } =
|
|
89
|
+
select( coreStore );
|
|
90
|
+
let slug;
|
|
91
|
+
if ( postSlug ) {
|
|
92
|
+
slug =
|
|
93
|
+
postType === 'page'
|
|
94
|
+
? `${ postType }-${ postSlug }`
|
|
95
|
+
: `single-${ postType }-${ postSlug }`;
|
|
96
|
+
} else {
|
|
97
|
+
slug = postType === 'page' ? 'page' : `single-${ postType }`;
|
|
98
|
+
}
|
|
99
|
+
const templateId = getDefaultTemplateId( { slug } );
|
|
100
|
+
if ( ! templateId ) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return getEntityRecord( 'postType', 'wp_template', templateId );
|
|
104
|
+
},
|
|
105
|
+
[ currentTemplateSlug, postSlug, postType ]
|
|
106
|
+
);
|
|
71
107
|
return useMemo(
|
|
72
108
|
() =>
|
|
73
109
|
allowSwitchingTemplate &&
|
|
74
|
-
|
|
75
|
-
(
|
|
76
|
-
template
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
110
|
+
[
|
|
111
|
+
...( templates || [] ).filter(
|
|
112
|
+
( template ) =>
|
|
113
|
+
template.is_custom &&
|
|
114
|
+
template.slug !== currentTemplateSlug &&
|
|
115
|
+
!! template.content.raw // Skip empty templates.
|
|
116
|
+
),
|
|
117
|
+
defaultTemplate && {
|
|
118
|
+
...defaultTemplate,
|
|
119
|
+
title: {
|
|
120
|
+
rendered: sprintf(
|
|
121
|
+
// translators: %s: Template name
|
|
122
|
+
__( '%s (default)' ),
|
|
123
|
+
defaultTemplate.title.rendered
|
|
124
|
+
),
|
|
125
|
+
},
|
|
126
|
+
// That's extra custom prop in order to update to an empty template
|
|
127
|
+
// when we select the default template.
|
|
128
|
+
isDefault: true,
|
|
129
|
+
},
|
|
130
|
+
].filter( Boolean ),
|
|
131
|
+
[
|
|
132
|
+
templates,
|
|
133
|
+
defaultTemplate,
|
|
134
|
+
currentTemplateSlug,
|
|
135
|
+
allowSwitchingTemplate,
|
|
136
|
+
]
|
|
81
137
|
);
|
|
82
138
|
}
|
|
83
139
|
|
|
140
|
+
export function usePostTemplatePanelMode() {
|
|
141
|
+
return useSelect( ( select ) => {
|
|
142
|
+
const { getEditorSettings, getCurrentTemplateId, getCurrentPostType } =
|
|
143
|
+
select( editorStore );
|
|
144
|
+
const { getPostType, canUser } = select( coreStore );
|
|
145
|
+
const postTypeSlug = getCurrentPostType();
|
|
146
|
+
const postType = getPostType( postTypeSlug );
|
|
147
|
+
const settings = getEditorSettings();
|
|
148
|
+
const isBlockTheme = settings.__unstableIsBlockBasedTheme;
|
|
149
|
+
const hasTemplates =
|
|
150
|
+
!! settings.availableTemplates &&
|
|
151
|
+
Object.keys( settings.availableTemplates ).length > 0;
|
|
152
|
+
let isVisible;
|
|
153
|
+
if ( ! postType?.viewable ) {
|
|
154
|
+
isVisible = false;
|
|
155
|
+
} else if ( hasTemplates ) {
|
|
156
|
+
isVisible = true;
|
|
157
|
+
} else if ( ! settings.supportsTemplateMode ) {
|
|
158
|
+
isVisible = false;
|
|
159
|
+
} else {
|
|
160
|
+
isVisible =
|
|
161
|
+
canUser( 'create', {
|
|
162
|
+
kind: 'postType',
|
|
163
|
+
name: 'wp_template',
|
|
164
|
+
} ) ?? false;
|
|
165
|
+
}
|
|
166
|
+
const canViewTemplates = isVisible
|
|
167
|
+
? !! canUser( 'read', {
|
|
168
|
+
kind: 'postType',
|
|
169
|
+
name: 'wp_template',
|
|
170
|
+
} )
|
|
171
|
+
: false;
|
|
172
|
+
if ( ( ! isBlockTheme || ! canViewTemplates ) && isVisible ) {
|
|
173
|
+
return 'classic';
|
|
174
|
+
}
|
|
175
|
+
if ( isBlockTheme && !! getCurrentTemplateId() ) {
|
|
176
|
+
return 'block-theme';
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}, [] );
|
|
180
|
+
}
|
|
181
|
+
|
|
84
182
|
export function useCurrentTemplateSlug() {
|
|
85
183
|
const { postType, postId } = useEditedPostContext();
|
|
86
184
|
const templates = useTemplates( postType );
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* Internal dependencies
|
|
9
3
|
*/
|
|
10
|
-
import {
|
|
4
|
+
import { usePostTemplatePanelMode } from './hooks';
|
|
11
5
|
import ClassicThemeControl from './classic-theme';
|
|
12
6
|
import BlockThemeControl from './block-theme';
|
|
13
7
|
|
|
@@ -17,60 +11,12 @@ import BlockThemeControl from './block-theme';
|
|
|
17
11
|
* @return {React.ReactNode} The rendered PostTemplatePanel component.
|
|
18
12
|
*/
|
|
19
13
|
export default function PostTemplatePanel() {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
select( editorStore );
|
|
23
|
-
return {
|
|
24
|
-
templateId: getCurrentTemplateId(),
|
|
25
|
-
isBlockTheme: getEditorSettings().__unstableIsBlockBasedTheme,
|
|
26
|
-
};
|
|
27
|
-
}, [] );
|
|
28
|
-
|
|
29
|
-
const isVisible = useSelect( ( select ) => {
|
|
30
|
-
const postTypeSlug = select( editorStore ).getCurrentPostType();
|
|
31
|
-
const postType = select( coreStore ).getPostType( postTypeSlug );
|
|
32
|
-
if ( ! postType?.viewable ) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const settings = select( editorStore ).getEditorSettings();
|
|
37
|
-
const hasTemplates =
|
|
38
|
-
!! settings.availableTemplates &&
|
|
39
|
-
Object.keys( settings.availableTemplates ).length > 0;
|
|
40
|
-
if ( hasTemplates ) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if ( ! settings.supportsTemplateMode ) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const canCreateTemplates =
|
|
49
|
-
select( coreStore ).canUser( 'create', {
|
|
50
|
-
kind: 'postType',
|
|
51
|
-
name: 'wp_template',
|
|
52
|
-
} ) ?? false;
|
|
53
|
-
return canCreateTemplates;
|
|
54
|
-
}, [] );
|
|
55
|
-
|
|
56
|
-
const canViewTemplates = useSelect(
|
|
57
|
-
( select ) => {
|
|
58
|
-
return isVisible
|
|
59
|
-
? select( coreStore ).canUser( 'read', {
|
|
60
|
-
kind: 'postType',
|
|
61
|
-
name: 'wp_template',
|
|
62
|
-
} )
|
|
63
|
-
: false;
|
|
64
|
-
},
|
|
65
|
-
[ isVisible ]
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
if ( ( ! isBlockTheme || ! canViewTemplates ) && isVisible ) {
|
|
14
|
+
const mode = usePostTemplatePanelMode();
|
|
15
|
+
if ( mode === 'classic' ) {
|
|
69
16
|
return <ClassicThemeControl />;
|
|
70
17
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return <BlockThemeControl id={ templateId } />;
|
|
18
|
+
if ( mode === 'block-theme' ) {
|
|
19
|
+
return <BlockThemeControl />;
|
|
74
20
|
}
|
|
75
21
|
return null;
|
|
76
22
|
}
|
|
@@ -16,23 +16,40 @@ import { parse } from '@wordpress/blocks';
|
|
|
16
16
|
import { useAvailableTemplates, useEditedPostContext } from './hooks';
|
|
17
17
|
import { searchTemplates } from '../../utils/search-templates';
|
|
18
18
|
|
|
19
|
-
export
|
|
20
|
-
const [ showModal, setShowModal ] = useState( false );
|
|
19
|
+
export function SwapTemplateModal( { onRequestClose, onSelect } ) {
|
|
21
20
|
const { postType, postId } = useEditedPostContext();
|
|
22
|
-
const availableTemplates = useAvailableTemplates( postType );
|
|
23
21
|
const { editEntityRecord } = useDispatch( coreStore );
|
|
24
|
-
|
|
25
22
|
const onTemplateSelect = async ( template ) => {
|
|
26
23
|
editEntityRecord(
|
|
27
24
|
'postType',
|
|
28
25
|
postType,
|
|
29
26
|
postId,
|
|
30
|
-
|
|
27
|
+
// Since we append the default template we need to properly
|
|
28
|
+
// update to an empty string.
|
|
29
|
+
{ template: template.isDefault ? '' : template.name },
|
|
31
30
|
{ undoIgnore: true }
|
|
32
31
|
);
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
onRequestClose();
|
|
33
|
+
onSelect?.();
|
|
35
34
|
};
|
|
35
|
+
return (
|
|
36
|
+
<Modal
|
|
37
|
+
title={ __( 'Choose a template' ) }
|
|
38
|
+
onRequestClose={ onRequestClose }
|
|
39
|
+
overlayClassName="editor-post-template__swap-template-modal"
|
|
40
|
+
isFullScreen
|
|
41
|
+
>
|
|
42
|
+
<div className="editor-post-template__swap-template-modal-content">
|
|
43
|
+
<TemplatesList onSelect={ onTemplateSelect } />
|
|
44
|
+
</div>
|
|
45
|
+
</Modal>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default function SwapTemplateButton( { onClick } ) {
|
|
50
|
+
const [ showModal, setShowModal ] = useState( false );
|
|
51
|
+
const availableTemplates = useAvailableTemplates();
|
|
52
|
+
|
|
36
53
|
return (
|
|
37
54
|
<>
|
|
38
55
|
<MenuItem
|
|
@@ -43,27 +60,18 @@ export default function SwapTemplateButton( { onClick } ) {
|
|
|
43
60
|
{ __( 'Change template' ) }
|
|
44
61
|
</MenuItem>
|
|
45
62
|
{ showModal && (
|
|
46
|
-
<
|
|
47
|
-
title={ __( 'Choose a template' ) }
|
|
63
|
+
<SwapTemplateModal
|
|
48
64
|
onRequestClose={ () => setShowModal( false ) }
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
<div className="editor-post-template__swap-template-modal-content">
|
|
53
|
-
<TemplatesList
|
|
54
|
-
postType={ postType }
|
|
55
|
-
onSelect={ onTemplateSelect }
|
|
56
|
-
/>
|
|
57
|
-
</div>
|
|
58
|
-
</Modal>
|
|
65
|
+
onSelect={ onClick }
|
|
66
|
+
/>
|
|
59
67
|
) }
|
|
60
68
|
</>
|
|
61
69
|
);
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
function TemplatesList( {
|
|
72
|
+
function TemplatesList( { onSelect } ) {
|
|
65
73
|
const [ searchValue, setSearchValue ] = useState( '' );
|
|
66
|
-
const availableTemplates = useAvailableTemplates(
|
|
74
|
+
const availableTemplates = useAvailableTemplates();
|
|
67
75
|
const templatesAsPatterns = useMemo(
|
|
68
76
|
() =>
|
|
69
77
|
availableTemplates.map( ( template ) => ( {
|
|
@@ -71,6 +79,7 @@ function TemplatesList( { postType, onSelect } ) {
|
|
|
71
79
|
blocks: parse( template.content.raw ),
|
|
72
80
|
title: decodeEntities( template.title.rendered ),
|
|
73
81
|
id: template.id,
|
|
82
|
+
isDefault: template.isDefault,
|
|
74
83
|
} ) ),
|
|
75
84
|
[ availableTemplates ]
|
|
76
85
|
);
|
|
@@ -55,20 +55,25 @@ export default function EditorPreferencesModal( { extraSections = {} } ) {
|
|
|
55
55
|
|
|
56
56
|
function PreferencesModalContents( { extraSections = {} } ) {
|
|
57
57
|
const isLargeViewport = useViewportMatch( 'medium' );
|
|
58
|
-
const showBlockBreadcrumbsOption = useSelect(
|
|
58
|
+
const { showBlockBreadcrumbsOption, showCollaborationOptions } = useSelect(
|
|
59
59
|
( select ) => {
|
|
60
|
-
const { getEditorSettings } =
|
|
60
|
+
const { getEditorSettings, isCollaborationEnabledForCurrentPost } =
|
|
61
|
+
select( editorStore );
|
|
61
62
|
const { get } = select( preferencesStore );
|
|
62
63
|
const isRichEditingEnabled = getEditorSettings().richEditingEnabled;
|
|
63
64
|
const isDistractionFreeEnabled = get( 'core', 'distractionFree' );
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
return {
|
|
66
|
+
showBlockBreadcrumbsOption:
|
|
67
|
+
! isDistractionFreeEnabled &&
|
|
68
|
+
isLargeViewport &&
|
|
69
|
+
isRichEditingEnabled,
|
|
70
|
+
showCollaborationOptions:
|
|
71
|
+
isCollaborationEnabledForCurrentPost(),
|
|
72
|
+
};
|
|
69
73
|
},
|
|
70
74
|
[ isLargeViewport ]
|
|
71
75
|
);
|
|
76
|
+
|
|
72
77
|
const { setIsListViewOpened, setIsInserterOpened } =
|
|
73
78
|
useDispatch( editorStore );
|
|
74
79
|
const { set: setPreference } = useDispatch( preferencesStore );
|
|
@@ -120,24 +125,30 @@ function PreferencesModalContents( { extraSections = {} } ) {
|
|
|
120
125
|
) }
|
|
121
126
|
label={ __( 'Show starter patterns' ) }
|
|
122
127
|
/>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
128
|
+
{ showCollaborationOptions && (
|
|
129
|
+
<>
|
|
130
|
+
<PreferenceToggleControl
|
|
131
|
+
scope="core"
|
|
132
|
+
featureName="showCollaborationCursor"
|
|
133
|
+
help={ __(
|
|
134
|
+
'Show your own avatar inside blocks during collaborative editing sessions.'
|
|
135
|
+
) }
|
|
136
|
+
label={ __(
|
|
137
|
+
'Show avatar in blocks'
|
|
138
|
+
) }
|
|
139
|
+
/>
|
|
140
|
+
<PreferenceToggleControl
|
|
141
|
+
scope="core"
|
|
142
|
+
featureName="showCollaborationNotifications"
|
|
143
|
+
help={ __(
|
|
144
|
+
'Show notifications when collaborators join, leave, or save the post.'
|
|
145
|
+
) }
|
|
146
|
+
label={ __(
|
|
147
|
+
'Show collaboration notifications'
|
|
148
|
+
) }
|
|
149
|
+
/>
|
|
150
|
+
</>
|
|
151
|
+
) }
|
|
141
152
|
</PreferencesModalSection>
|
|
142
153
|
<PreferencesModalSection
|
|
143
154
|
title={ __( 'Document settings' ) }
|
|
@@ -350,6 +361,7 @@ function PreferencesModalContents( { extraSections = {} } ) {
|
|
|
350
361
|
].filter( Boolean ),
|
|
351
362
|
[
|
|
352
363
|
showBlockBreadcrumbsOption,
|
|
364
|
+
showCollaborationOptions,
|
|
353
365
|
extraSections,
|
|
354
366
|
setIsInserterOpened,
|
|
355
367
|
setIsListViewOpened,
|
|
@@ -25,6 +25,7 @@ import inserterMediaCategories from '../media-categories';
|
|
|
25
25
|
import { mediaUpload } from '../../utils';
|
|
26
26
|
import mediaUploadOnSuccess from '../../utils/media-upload/on-success';
|
|
27
27
|
import { default as mediaSideload } from '../../utils/media-sideload';
|
|
28
|
+
import { default as mediaFinalize } from '../../utils/media-finalize';
|
|
28
29
|
import { store as editorStore } from '../../store';
|
|
29
30
|
import { unlock } from '../../lock-unlock';
|
|
30
31
|
import { useGlobalStylesContext } from '../global-styles-provider';
|
|
@@ -343,6 +344,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
|
|
|
343
344
|
? mediaUploadOnSuccess
|
|
344
345
|
: undefined,
|
|
345
346
|
mediaSideload: hasUploadPermissions ? mediaSideload : undefined,
|
|
347
|
+
mediaFinalize: hasUploadPermissions ? mediaFinalize : undefined,
|
|
346
348
|
__experimentalBlockPatterns: blockPatterns,
|
|
347
349
|
[ selectBlockPatternsKey ]: ( select ) => {
|
|
348
350
|
const { hasFinishedResolution, getBlockPatternsForPostType } =
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import RevisionDiffPanel from '../revision-diff-panel';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Panel that shows changed block attributes for the selected block
|
|
15
|
+
* when viewing revisions.
|
|
16
|
+
*/
|
|
17
|
+
export default function RevisionBlockDiffPanel() {
|
|
18
|
+
const { block } = useSelect( ( select ) => {
|
|
19
|
+
const { getSelectedBlock } = select( blockEditorStore );
|
|
20
|
+
return {
|
|
21
|
+
block: getSelectedBlock(),
|
|
22
|
+
};
|
|
23
|
+
}, [] );
|
|
24
|
+
|
|
25
|
+
if ( ! block ) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const changedAttributes =
|
|
30
|
+
block.attributes?.__revisionDiffStatus?.changedAttributes;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<RevisionDiffPanel
|
|
34
|
+
title={ __( 'Changed attributes' ) }
|
|
35
|
+
entries={ changedAttributes }
|
|
36
|
+
initialOpen
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { PanelBody } from '@wordpress/components';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import PostPanelRow from '../post-panel-row';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Renders a panel of word-level diffs.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} props
|
|
15
|
+
* @param {string} props.title Panel title.
|
|
16
|
+
* @param {Object} props.entries Map of key → diffWords parts arrays.
|
|
17
|
+
* @param {boolean} props.initialOpen Whether the panel starts open.
|
|
18
|
+
*/
|
|
19
|
+
export default function RevisionDiffPanel( { title, entries, initialOpen } ) {
|
|
20
|
+
if ( ! entries ) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const fields = Object.entries( entries ).map( ( [ key, parts ] ) => (
|
|
25
|
+
<PostPanelRow key={ key } label={ key }>
|
|
26
|
+
<span className="editor-revision-fields-diff__value">
|
|
27
|
+
{ parts.map( ( part, index ) => {
|
|
28
|
+
if ( part.added ) {
|
|
29
|
+
return (
|
|
30
|
+
<ins
|
|
31
|
+
key={ index }
|
|
32
|
+
className="editor-revision-fields-diff__added"
|
|
33
|
+
>
|
|
34
|
+
{ part.value }
|
|
35
|
+
</ins>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if ( part.removed ) {
|
|
39
|
+
return (
|
|
40
|
+
<del
|
|
41
|
+
key={ index }
|
|
42
|
+
className="editor-revision-fields-diff__removed"
|
|
43
|
+
>
|
|
44
|
+
{ part.value }
|
|
45
|
+
</del>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return <span key={ index }>{ part.value }</span>;
|
|
49
|
+
} ) }
|
|
50
|
+
</span>
|
|
51
|
+
</PostPanelRow>
|
|
52
|
+
) );
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<PanelBody title={ title } initialOpen={ initialOpen }>
|
|
56
|
+
{ fields }
|
|
57
|
+
</PanelBody>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.editor-revision-fields-diff__value {
|
|
2
|
+
word-break: break-word;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.editor-revision-fields-diff__added {
|
|
6
|
+
background-color: color-mix(in srgb, currentColor 5%, #00a32a 15%);
|
|
7
|
+
text-decoration: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.editor-revision-fields-diff__removed {
|
|
11
|
+
text-decoration: line-through;
|
|
12
|
+
color: #d63638;
|
|
13
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { diffWords } from 'diff/lib/diff/word';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
import { useMemo } from '@wordpress/element';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import RevisionDiffPanel from '../revision-diff-panel';
|
|
17
|
+
import { store as editorStore } from '../../store';
|
|
18
|
+
import { unlock } from '../../lock-unlock';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Safely stringifies a value for display and comparison.
|
|
22
|
+
*
|
|
23
|
+
* @param {*} value The value to stringify.
|
|
24
|
+
* @return {string} The stringified value.
|
|
25
|
+
*/
|
|
26
|
+
function stringifyValue( value ) {
|
|
27
|
+
if ( value === null || value === undefined ) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
if ( typeof value === 'object' ) {
|
|
31
|
+
return JSON.stringify( value, null, 2 );
|
|
32
|
+
}
|
|
33
|
+
return String( value );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Panel that shows meta field diffs between the current revision and
|
|
38
|
+
* the previous revision in the document sidebar during revision mode.
|
|
39
|
+
*/
|
|
40
|
+
export default function RevisionFieldsDiffPanel() {
|
|
41
|
+
const { revision, previousRevision } = useSelect( ( select ) => {
|
|
42
|
+
const { getCurrentRevision, getPreviousRevision } = unlock(
|
|
43
|
+
select( editorStore )
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
revision: getCurrentRevision(),
|
|
48
|
+
previousRevision: getPreviousRevision(),
|
|
49
|
+
};
|
|
50
|
+
}, [] );
|
|
51
|
+
|
|
52
|
+
const entries = useMemo( () => {
|
|
53
|
+
if ( ! revision ) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const revisionMeta = revision.meta ?? {};
|
|
58
|
+
const previousMeta = previousRevision?.meta ?? {};
|
|
59
|
+
const allMetaKeys = new Set( [
|
|
60
|
+
...Object.keys( revisionMeta ),
|
|
61
|
+
...Object.keys( previousMeta ),
|
|
62
|
+
] );
|
|
63
|
+
|
|
64
|
+
const result = {};
|
|
65
|
+
|
|
66
|
+
for ( const key of allMetaKeys ) {
|
|
67
|
+
const revStr = stringifyValue( revisionMeta[ key ] );
|
|
68
|
+
const prevStr = stringifyValue( previousMeta[ key ] );
|
|
69
|
+
|
|
70
|
+
if ( ! revStr && ! prevStr ) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
result[ key ] = diffWords( prevStr, revStr );
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ( Object.keys( result ).length === 0 ) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return result;
|
|
82
|
+
}, [ revision, previousRevision ] );
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<RevisionDiffPanel
|
|
86
|
+
title={ __( 'Meta' ) }
|
|
87
|
+
entries={ entries }
|
|
88
|
+
initialOpen={ false }
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
}
|