@wordpress/block-editor 15.3.1-next.836ecdcae.0 → 15.3.1-next.a730c9c8c.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/build/autocompleters/block.js +2 -4
  2. package/build/autocompleters/block.js.map +1 -1
  3. package/build/components/block-card/index.js +4 -2
  4. package/build/components/block-card/index.js.map +1 -1
  5. package/build/components/block-inspector/edit-contents-button.js +54 -0
  6. package/build/components/block-inspector/edit-contents-button.js.map +1 -0
  7. package/build/components/block-inspector/index.js +5 -1
  8. package/build/components/block-inspector/index.js.map +1 -1
  9. package/build/components/block-list/index.js +3 -1
  10. package/build/components/block-list/index.js.map +1 -1
  11. package/build/components/block-popover/use-popover-scroll.js +11 -2
  12. package/build/components/block-popover/use-popover-scroll.js.map +1 -1
  13. package/build/components/block-switcher/index.js +13 -8
  14. package/build/components/block-switcher/index.js.map +1 -1
  15. package/build/components/block-toolbar/index.js +5 -2
  16. package/build/components/block-toolbar/index.js.map +1 -1
  17. package/build/components/block-tools/insertion-point.js +10 -0
  18. package/build/components/block-tools/insertion-point.js.map +1 -1
  19. package/build/components/block-variation-transforms/index.js +10 -6
  20. package/build/components/block-variation-transforms/index.js.map +1 -1
  21. package/build/components/border-radius-control/utils.js.map +1 -1
  22. package/build/components/global-styles/border-panel.js +6 -6
  23. package/build/components/global-styles/border-panel.js.map +1 -1
  24. package/build/components/link-control/search-item.js +30 -12
  25. package/build/components/link-control/search-item.js.map +1 -1
  26. package/build/components/url-popover/image-url-input-ui.js +7 -2
  27. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  28. package/build/components/writing-flow/use-clipboard-handler.js +6 -1
  29. package/build/components/writing-flow/use-clipboard-handler.js.map +1 -1
  30. package/build/store/private-selectors.js +9 -21
  31. package/build/store/private-selectors.js.map +1 -1
  32. package/build/store/reducer.js +114 -0
  33. package/build/store/reducer.js.map +1 -1
  34. package/build/store/selectors.js +16 -30
  35. package/build/store/selectors.js.map +1 -1
  36. package/build/store/utils.js +18 -0
  37. package/build/store/utils.js.map +1 -1
  38. package/build/utils/block-bindings.js +1 -1
  39. package/build/utils/block-bindings.js.map +1 -1
  40. package/build-module/autocompleters/block.js +3 -5
  41. package/build-module/autocompleters/block.js.map +1 -1
  42. package/build-module/components/block-card/index.js +4 -2
  43. package/build-module/components/block-card/index.js.map +1 -1
  44. package/build-module/components/block-inspector/edit-contents-button.js +47 -0
  45. package/build-module/components/block-inspector/edit-contents-button.js.map +1 -0
  46. package/build-module/components/block-inspector/index.js +5 -1
  47. package/build-module/components/block-inspector/index.js.map +1 -1
  48. package/build-module/components/block-list/index.js +3 -1
  49. package/build-module/components/block-list/index.js.map +1 -1
  50. package/build-module/components/block-popover/use-popover-scroll.js +11 -2
  51. package/build-module/components/block-popover/use-popover-scroll.js.map +1 -1
  52. package/build-module/components/block-switcher/index.js +13 -8
  53. package/build-module/components/block-switcher/index.js.map +1 -1
  54. package/build-module/components/block-toolbar/index.js +5 -2
  55. package/build-module/components/block-toolbar/index.js.map +1 -1
  56. package/build-module/components/block-tools/insertion-point.js +11 -1
  57. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  58. package/build-module/components/block-variation-transforms/index.js +10 -6
  59. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  60. package/build-module/components/border-radius-control/utils.js.map +1 -1
  61. package/build-module/components/global-styles/border-panel.js +6 -6
  62. package/build-module/components/global-styles/border-panel.js.map +1 -1
  63. package/build-module/components/link-control/search-item.js +30 -12
  64. package/build-module/components/link-control/search-item.js.map +1 -1
  65. package/build-module/components/url-popover/image-url-input-ui.js +9 -4
  66. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  67. package/build-module/components/writing-flow/use-clipboard-handler.js +6 -1
  68. package/build-module/components/writing-flow/use-clipboard-handler.js.map +1 -1
  69. package/build-module/store/private-selectors.js +9 -21
  70. package/build-module/store/private-selectors.js.map +1 -1
  71. package/build-module/store/reducer.js +114 -0
  72. package/build-module/store/reducer.js.map +1 -1
  73. package/build-module/store/selectors.js +16 -30
  74. package/build-module/store/selectors.js.map +1 -1
  75. package/build-module/store/utils.js +17 -0
  76. package/build-module/store/utils.js.map +1 -1
  77. package/build-module/utils/block-bindings.js +1 -1
  78. package/build-module/utils/block-bindings.js.map +1 -1
  79. package/build-style/style-rtl.css +9 -5
  80. package/build-style/style.css +9 -5
  81. package/package.json +34 -34
  82. package/src/autocompleters/block.js +6 -11
  83. package/src/components/block-card/index.js +11 -1
  84. package/src/components/block-inspector/edit-contents-button.js +46 -0
  85. package/src/components/block-inspector/index.js +6 -1
  86. package/src/components/block-inspector/style.scss +5 -0
  87. package/src/components/block-list/index.js +7 -1
  88. package/src/components/block-popover/use-popover-scroll.js +10 -2
  89. package/src/components/block-switcher/index.js +13 -4
  90. package/src/components/block-toolbar/index.js +11 -5
  91. package/src/components/block-toolbar/style.scss +3 -5
  92. package/src/components/block-tools/insertion-point.js +19 -1
  93. package/src/components/block-variation-transforms/index.js +39 -27
  94. package/src/components/border-radius-control/test/utils.js +71 -0
  95. package/src/components/border-radius-control/utils.js +1 -0
  96. package/src/components/global-styles/border-panel.js +7 -6
  97. package/src/components/link-control/search-item.js +31 -12
  98. package/src/components/link-control/style.scss +0 -1
  99. package/src/components/link-control/test/index.js +14 -2
  100. package/src/components/url-popover/image-url-input-ui.js +18 -2
  101. package/src/components/writing-flow/use-clipboard-handler.js +6 -0
  102. package/src/store/private-selectors.js +12 -24
  103. package/src/store/reducer.js +188 -0
  104. package/src/store/selectors.js +38 -59
  105. package/src/store/test/reducer.js +398 -0
  106. package/src/store/test/selectors.js +65 -192
  107. package/src/store/utils.js +21 -0
  108. package/src/utils/block-bindings.js +1 -1
@@ -2267,6 +2267,29 @@ function getDerivedBlockEditingModesForTree(
2267
2267
  syncedPatternClientIds.push( clientId );
2268
2268
  }
2269
2269
  } );
2270
+ const contentOnlyTemplateLockedClientIds = Object.keys(
2271
+ state.blockListSettings
2272
+ ).filter(
2273
+ ( clientId ) =>
2274
+ state.blockListSettings[ clientId ]?.templateLock === 'contentOnly'
2275
+ );
2276
+ // Use array.from for better back compat. Older versions of the iterator returned
2277
+ // from `keys()` didn't have the `filter` method.
2278
+ const unsyncedPatternClientIds =
2279
+ !! window?.__experimentalContentOnlyPatternInsertion
2280
+ ? Array.from( state.blocks.attributes.keys() ).filter(
2281
+ ( clientId ) =>
2282
+ state.blocks.attributes.get( clientId )?.metadata
2283
+ ?.patternName
2284
+ )
2285
+ : [];
2286
+ const contentOnlyParents = [
2287
+ ...contentOnlyTemplateLockedClientIds,
2288
+ ...unsyncedPatternClientIds,
2289
+ ...( window?.__experimentalContentOnlyPatternInsertion
2290
+ ? templatePartClientIds
2291
+ : [] ),
2292
+ ];
2270
2293
 
2271
2294
  traverseBlockTree( state, treeClientId, ( block ) => {
2272
2295
  const { clientId, name: blockName } = block;
@@ -2457,6 +2480,22 @@ function getDerivedBlockEditingModesForTree(
2457
2480
  derivedBlockEditingModes.set( clientId, 'disabled' );
2458
2481
  }
2459
2482
  }
2483
+
2484
+ // Handle `templateLock=contentOnly` blocks and unsynced patterns.
2485
+ if ( contentOnlyParents.length ) {
2486
+ const hasContentOnlyParent = !! findParentInClientIdsList(
2487
+ state,
2488
+ clientId,
2489
+ contentOnlyParents
2490
+ );
2491
+ if ( hasContentOnlyParent ) {
2492
+ if ( isContentBlock( blockName ) ) {
2493
+ derivedBlockEditingModes.set( clientId, 'contentOnly' );
2494
+ } else {
2495
+ derivedBlockEditingModes.set( clientId, 'disabled' );
2496
+ }
2497
+ }
2498
+ }
2460
2499
  } );
2461
2500
 
2462
2501
  return derivedBlockEditingModes;
@@ -2628,6 +2667,155 @@ export function withDerivedBlockEditingModes( reducer ) {
2628
2667
  }
2629
2668
  break;
2630
2669
  }
2670
+ case 'UPDATE_BLOCK_ATTRIBUTES': {
2671
+ // Handle unsynced patterns which indicate their contentOnly-ness via
2672
+ // the `attributes.metadata.patternName` property.
2673
+ // Check when this is added or removed and update blockEditingModes.
2674
+ const addedBlocks = [];
2675
+ const removedClientIds = [];
2676
+
2677
+ for ( const clientId of action?.clientIds ) {
2678
+ const attributes = action.options?.uniqueByBlock
2679
+ ? action.attributes[ clientId ]
2680
+ : action.attributes;
2681
+
2682
+ if ( ! attributes ) {
2683
+ break;
2684
+ }
2685
+
2686
+ if (
2687
+ // patternName is switching from falsy to truthy, indicating
2688
+ // this block is becoming an unsynced pattern.
2689
+ attributes.metadata?.patternName &&
2690
+ ! state.blocks.attributes.get( clientId )?.metadata
2691
+ ?.patternName
2692
+ ) {
2693
+ addedBlocks.push(
2694
+ nextState.blocks.tree.get( clientId )
2695
+ );
2696
+ } else if (
2697
+ // patternName is switching from truthy to falsy, this block is becoming
2698
+ // a regular block but was an unsynced pattern.
2699
+ // Check that `metadata` is part of the included attributes, as
2700
+ // `updateBlockAttributes` merges attributes, if it isn't present
2701
+ // the previous `metadata` would be retained.
2702
+ attributes.metadata &&
2703
+ ! attributes.metadata?.patternName &&
2704
+ state.blocks.attributes.get( clientId )?.metadata
2705
+ ?.patternName
2706
+ ) {
2707
+ // Include it in 'removedClientIds'.
2708
+ removedClientIds.push( clientId );
2709
+ }
2710
+ }
2711
+
2712
+ if ( ! addedBlocks?.length && ! removedClientIds?.length ) {
2713
+ break;
2714
+ }
2715
+
2716
+ const nextDerivedBlockEditingModes =
2717
+ getDerivedBlockEditingModesUpdates( {
2718
+ prevState: state,
2719
+ nextState,
2720
+ addedBlocks,
2721
+ removedClientIds,
2722
+ isNavMode: false,
2723
+ } );
2724
+ const nextDerivedNavModeBlockEditingModes =
2725
+ getDerivedBlockEditingModesUpdates( {
2726
+ prevState: state,
2727
+ nextState,
2728
+ addedBlocks,
2729
+ removedClientIds,
2730
+ isNavMode: true,
2731
+ } );
2732
+
2733
+ if (
2734
+ nextDerivedBlockEditingModes ||
2735
+ nextDerivedNavModeBlockEditingModes
2736
+ ) {
2737
+ return {
2738
+ ...nextState,
2739
+ derivedBlockEditingModes:
2740
+ nextDerivedBlockEditingModes ??
2741
+ state.derivedBlockEditingModes,
2742
+ derivedNavModeBlockEditingModes:
2743
+ nextDerivedNavModeBlockEditingModes ??
2744
+ state.derivedNavModeBlockEditingModes,
2745
+ };
2746
+ }
2747
+
2748
+ break;
2749
+ }
2750
+ case 'UPDATE_BLOCK_LIST_SETTINGS': {
2751
+ // Handle the addition and removal of contentOnly template locked blocks.
2752
+ const addedBlocks = [];
2753
+ const removedClientIds = [];
2754
+
2755
+ const updates =
2756
+ typeof action.clientId === 'string'
2757
+ ? { [ action.clientId ]: action.settings }
2758
+ : action.clientId;
2759
+
2760
+ for ( const clientId in updates ) {
2761
+ const isNewContentOnlyBlock =
2762
+ state.blockListSettings[ clientId ]?.templateLock !==
2763
+ 'contentOnly' &&
2764
+ nextState.blockListSettings[ clientId ]
2765
+ ?.templateLock === 'contentOnly';
2766
+
2767
+ const wasContentOnlyBlock =
2768
+ state.blockListSettings[ clientId ]?.templateLock ===
2769
+ 'contentOnly' &&
2770
+ nextState.blockListSettings[ clientId ]
2771
+ ?.templateLock !== 'contentOnly';
2772
+
2773
+ if ( isNewContentOnlyBlock ) {
2774
+ addedBlocks.push(
2775
+ nextState.blocks.tree.get( clientId )
2776
+ );
2777
+ } else if ( wasContentOnlyBlock ) {
2778
+ removedClientIds.push( clientId );
2779
+ }
2780
+ }
2781
+
2782
+ if ( ! addedBlocks.length && ! removedClientIds.length ) {
2783
+ break;
2784
+ }
2785
+
2786
+ const nextDerivedBlockEditingModes =
2787
+ getDerivedBlockEditingModesUpdates( {
2788
+ prevState: state,
2789
+ nextState,
2790
+ addedBlocks,
2791
+ removedClientIds,
2792
+ isNavMode: false,
2793
+ } );
2794
+ const nextDerivedNavModeBlockEditingModes =
2795
+ getDerivedBlockEditingModesUpdates( {
2796
+ prevState: state,
2797
+ nextState,
2798
+ addedBlocks,
2799
+ removedClientIds,
2800
+ isNavMode: true,
2801
+ } );
2802
+
2803
+ if (
2804
+ nextDerivedBlockEditingModes ||
2805
+ nextDerivedNavModeBlockEditingModes
2806
+ ) {
2807
+ return {
2808
+ ...nextState,
2809
+ derivedBlockEditingModes:
2810
+ nextDerivedBlockEditingModes ??
2811
+ state.derivedBlockEditingModes,
2812
+ derivedNavModeBlockEditingModes:
2813
+ nextDerivedNavModeBlockEditingModes ??
2814
+ state.derivedNavModeBlockEditingModes,
2815
+ };
2816
+ }
2817
+ break;
2818
+ }
2631
2819
  case 'SET_BLOCK_EDITING_MODE':
2632
2820
  case 'UNSET_BLOCK_EDITING_MODE':
2633
2821
  case 'SET_HAS_CONTROLLED_INNER_BLOCKS': {
@@ -30,6 +30,7 @@ import {
30
30
  getInsertBlockTypeDependants,
31
31
  getParsedPattern,
32
32
  getGrammar,
33
+ mapUserPattern,
33
34
  } from './utils';
34
35
  import { orderBy } from '../utils/sorting';
35
36
  import { STORE_NAME } from './constants';
@@ -2155,27 +2156,31 @@ export const getInserterItems = createRegistrySelector( ( select ) =>
2155
2156
  foreground: 'var(--wp-block-synced-color)',
2156
2157
  }
2157
2158
  : symbol;
2158
- const id = `core/block/${ reusableBlock.id }`;
2159
- const { time, count = 0 } = getInsertUsage( state, id ) || {};
2159
+ const userPattern = mapUserPattern( reusableBlock );
2160
+ const { time, count = 0 } =
2161
+ getInsertUsage( state, userPattern.name ) || {};
2160
2162
  const frecency = calculateFrecency( time, count );
2161
2163
 
2162
2164
  return {
2163
- id,
2165
+ id: userPattern.name,
2164
2166
  name: 'core/block',
2165
2167
  initialAttributes: { ref: reusableBlock.id },
2166
- title: reusableBlock.title?.raw,
2168
+ title: userPattern.title,
2167
2169
  icon,
2168
2170
  category: 'reusable',
2169
2171
  keywords: [ 'reusable' ],
2170
2172
  isDisabled: false,
2171
2173
  utility: 1, // Deprecated.
2172
2174
  frecency,
2173
- content: reusableBlock.content?.raw,
2174
- syncStatus: reusableBlock.wp_pattern_sync_status,
2175
+ content: userPattern.content,
2176
+ get blocks() {
2177
+ return getParsedPattern( userPattern ).blocks;
2178
+ },
2179
+ syncStatus: userPattern.syncStatus,
2175
2180
  };
2176
2181
  };
2177
2182
 
2178
- const syncedPatternInserterItems = canInsertBlockTypeUnmemoized(
2183
+ const patternInserterItems = canInsertBlockTypeUnmemoized(
2179
2184
  state,
2180
2185
  'core/block',
2181
2186
  rootClientId
@@ -2261,7 +2266,7 @@ export const getInserterItems = createRegistrySelector( ( select ) =>
2261
2266
  { core: [], noncore: [] }
2262
2267
  );
2263
2268
  const sortedBlockTypes = [ ...coreItems, ...nonCoreItems ];
2264
- return [ ...sortedBlockTypes, ...syncedPatternInserterItems ];
2269
+ return [ ...sortedBlockTypes, ...patternInserterItems ];
2265
2270
  },
2266
2271
  ( state, rootClientId ) => [
2267
2272
  getBlockTypes(),
@@ -3076,62 +3081,36 @@ export function __unstableIsWithinBlockOverlay( state, clientId ) {
3076
3081
  * @return {BlockEditingMode} The block editing mode. One of `'disabled'`,
3077
3082
  * `'contentOnly'`, or `'default'`.
3078
3083
  */
3079
- export const getBlockEditingMode = createRegistrySelector(
3080
- ( select ) =>
3081
- ( state, clientId = '' ) => {
3082
- // Some selectors that call this provide `null` as the default
3083
- // rootClientId, but the default rootClientId is actually `''`.
3084
- if ( clientId === null ) {
3085
- clientId = '';
3086
- }
3084
+ export function getBlockEditingMode( state, clientId = '' ) {
3085
+ // Some selectors that call this provide `null` as the default
3086
+ // rootClientId, but the default rootClientId is actually `''`.
3087
+ if ( clientId === null ) {
3088
+ clientId = '';
3089
+ }
3087
3090
 
3088
- const isNavMode = isNavigationMode( state );
3089
-
3090
- // If the editor is currently not in navigation mode, check if the clientId
3091
- // has an editing mode set in the regular derived map.
3092
- // There may be an editing mode set here for synced patterns or in zoomed out
3093
- // mode.
3094
- if (
3095
- ! isNavMode &&
3096
- state.derivedBlockEditingModes?.has( clientId )
3097
- ) {
3098
- return state.derivedBlockEditingModes.get( clientId );
3099
- }
3091
+ const isNavMode = isNavigationMode( state );
3100
3092
 
3101
- // If the editor *is* in navigation mode, the block editing mode states
3102
- // are stored in the derivedNavModeBlockEditingModes map.
3103
- if (
3104
- isNavMode &&
3105
- state.derivedNavModeBlockEditingModes?.has( clientId )
3106
- ) {
3107
- return state.derivedNavModeBlockEditingModes.get( clientId );
3108
- }
3093
+ // If the editor is currently not in navigation mode, check if the clientId
3094
+ // has an editing mode set in the regular derived map.
3095
+ // There may be an editing mode set here for synced patterns or in zoomed out
3096
+ // mode.
3097
+ if ( ! isNavMode && state.derivedBlockEditingModes?.has( clientId ) ) {
3098
+ return state.derivedBlockEditingModes.get( clientId );
3099
+ }
3109
3100
 
3110
- // In normal mode, consider that an explicitly set editing mode takes over.
3111
- const blockEditingMode = state.blockEditingModes.get( clientId );
3112
- if ( blockEditingMode ) {
3113
- return blockEditingMode;
3114
- }
3101
+ // If the editor *is* in navigation mode, the block editing mode states
3102
+ // are stored in the derivedNavModeBlockEditingModes map.
3103
+ if ( isNavMode && state.derivedNavModeBlockEditingModes?.has( clientId ) ) {
3104
+ return state.derivedNavModeBlockEditingModes.get( clientId );
3105
+ }
3115
3106
 
3116
- // In normal mode, top level is default mode.
3117
- if ( clientId === '' ) {
3118
- return 'default';
3119
- }
3107
+ // In normal mode, consider that an explicitly set editing mode takes over.
3108
+ if ( state.blockEditingModes.has( clientId ) ) {
3109
+ return state.blockEditingModes.get( clientId );
3110
+ }
3120
3111
 
3121
- const rootClientId = getBlockRootClientId( state, clientId );
3122
- const templateLock = getTemplateLock( state, rootClientId );
3123
- // If the parent of the block is contentOnly locked, check whether it's a content block.
3124
- if ( templateLock === 'contentOnly' ) {
3125
- const name = getBlockName( state, clientId );
3126
- const { hasContentRoleAttribute } = unlock(
3127
- select( blocksStore )
3128
- );
3129
- const isContent = hasContentRoleAttribute( name );
3130
- return isContent ? 'contentOnly' : 'disabled';
3131
- }
3132
- return 'default';
3133
- }
3134
- );
3112
+ return 'default';
3113
+ }
3135
3114
 
3136
3115
  /**
3137
3116
  * Indicates if a block is ungroupable.