@wordpress/block-editor 12.8.1 → 12.9.1-next.5a1d1283.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 (124) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +5 -12
  3. package/build/components/block-list/block-outline.native.js +4 -3
  4. package/build/components/block-list/block-outline.native.js.map +1 -1
  5. package/build/components/block-list/index.js +4 -3
  6. package/build/components/block-list/index.js.map +1 -1
  7. package/build/components/block-popover/inbetween.js +4 -5
  8. package/build/components/block-popover/inbetween.js.map +1 -1
  9. package/build/components/block-popover/index.js +3 -2
  10. package/build/components/block-popover/index.js.map +1 -1
  11. package/build/components/color-style-selector/index.js +1 -1
  12. package/build/components/color-style-selector/index.js.map +1 -1
  13. package/build/components/inserter/reusable-blocks-tab.native.js +7 -4
  14. package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  15. package/build/components/inserter/search-results.native.js +10 -8
  16. package/build/components/inserter/search-results.native.js.map +1 -1
  17. package/build/components/link-control/index.js +2 -7
  18. package/build/components/link-control/index.js.map +1 -1
  19. package/build/components/link-control/settings.js +2 -1
  20. package/build/components/link-control/settings.js.map +1 -1
  21. package/build/components/list-view/block-select-button.js +48 -7
  22. package/build/components/list-view/block-select-button.js.map +1 -1
  23. package/build/components/list-view/drop-indicator.js +3 -3
  24. package/build/components/list-view/drop-indicator.js.map +1 -1
  25. package/build/components/list-view/index.js +14 -8
  26. package/build/components/list-view/index.js.map +1 -1
  27. package/build/components/list-view/use-list-view-images.js +5 -4
  28. package/build/components/list-view/use-list-view-images.js.map +1 -1
  29. package/build/components/preview-options/index.js +3 -1
  30. package/build/components/preview-options/index.js.map +1 -1
  31. package/build/components/provider/index.js +3 -1
  32. package/build/components/provider/index.js.map +1 -1
  33. package/build/components/use-block-commands/index.js +74 -63
  34. package/build/components/use-block-commands/index.js.map +1 -1
  35. package/build/components/warning/index.js +1 -1
  36. package/build/components/warning/index.js.map +1 -1
  37. package/build/hooks/auto-inserting-blocks.js +174 -0
  38. package/build/hooks/auto-inserting-blocks.js.map +1 -0
  39. package/build/hooks/index.js +1 -0
  40. package/build/hooks/index.js.map +1 -1
  41. package/build/hooks/style.js +64 -22
  42. package/build/hooks/style.js.map +1 -1
  43. package/build/hooks/utils.js +4 -0
  44. package/build/hooks/utils.js.map +1 -1
  45. package/build-module/components/block-list/block-outline.native.js +4 -3
  46. package/build-module/components/block-list/block-outline.native.js.map +1 -1
  47. package/build-module/components/block-list/index.js +4 -3
  48. package/build-module/components/block-list/index.js.map +1 -1
  49. package/build-module/components/block-popover/inbetween.js +4 -5
  50. package/build-module/components/block-popover/inbetween.js.map +1 -1
  51. package/build-module/components/block-popover/index.js +3 -2
  52. package/build-module/components/block-popover/index.js.map +1 -1
  53. package/build-module/components/color-style-selector/index.js +1 -1
  54. package/build-module/components/color-style-selector/index.js.map +1 -1
  55. package/build-module/components/inserter/reusable-blocks-tab.native.js +8 -4
  56. package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  57. package/build-module/components/inserter/search-results.native.js +11 -8
  58. package/build-module/components/inserter/search-results.native.js.map +1 -1
  59. package/build-module/components/link-control/index.js +2 -7
  60. package/build-module/components/link-control/index.js.map +1 -1
  61. package/build-module/components/link-control/settings.js +2 -1
  62. package/build-module/components/link-control/settings.js.map +1 -1
  63. package/build-module/components/list-view/block-select-button.js +48 -7
  64. package/build-module/components/list-view/block-select-button.js.map +1 -1
  65. package/build-module/components/list-view/drop-indicator.js +3 -3
  66. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  67. package/build-module/components/list-view/index.js +14 -8
  68. package/build-module/components/list-view/index.js.map +1 -1
  69. package/build-module/components/list-view/use-list-view-images.js +5 -4
  70. package/build-module/components/list-view/use-list-view-images.js.map +1 -1
  71. package/build-module/components/preview-options/index.js +3 -1
  72. package/build-module/components/preview-options/index.js.map +1 -1
  73. package/build-module/components/provider/index.js +3 -1
  74. package/build-module/components/provider/index.js.map +1 -1
  75. package/build-module/components/use-block-commands/index.js +74 -63
  76. package/build-module/components/use-block-commands/index.js.map +1 -1
  77. package/build-module/components/warning/index.js +2 -2
  78. package/build-module/components/warning/index.js.map +1 -1
  79. package/build-module/hooks/auto-inserting-blocks.js +167 -0
  80. package/build-module/hooks/auto-inserting-blocks.js.map +1 -0
  81. package/build-module/hooks/index.js +1 -0
  82. package/build-module/hooks/index.js.map +1 -1
  83. package/build-module/hooks/style.js +63 -21
  84. package/build-module/hooks/style.js.map +1 -1
  85. package/build-module/hooks/utils.js +4 -0
  86. package/build-module/hooks/utils.js.map +1 -1
  87. package/build-style/content-rtl.css +8 -7
  88. package/build-style/content.css +8 -7
  89. package/build-style/style-rtl.css +4 -4
  90. package/build-style/style.css +4 -4
  91. package/package.json +32 -32
  92. package/src/components/block-list/block-outline.native.js +5 -2
  93. package/src/components/block-list/content.scss +2 -3
  94. package/src/components/block-list/index.js +4 -3
  95. package/src/components/block-popover/inbetween.js +4 -3
  96. package/src/components/block-popover/index.js +3 -2
  97. package/src/components/button-block-appender/content.scss +8 -0
  98. package/src/components/color-style-selector/index.js +1 -1
  99. package/src/components/inserter/reusable-blocks-tab.native.js +7 -2
  100. package/src/components/inserter/search-results.native.js +13 -9
  101. package/src/components/link-control/index.js +2 -5
  102. package/src/components/link-control/settings.js +1 -0
  103. package/src/components/link-control/style.scss +5 -5
  104. package/src/components/link-control/test/index.js +1 -0
  105. package/src/components/list-view/block-select-button.js +67 -15
  106. package/src/components/list-view/drop-indicator.js +4 -5
  107. package/src/components/list-view/index.js +19 -13
  108. package/src/components/list-view/use-list-view-images.js +8 -4
  109. package/src/components/observe-typing/README.md +2 -2
  110. package/src/components/preview-options/index.js +2 -0
  111. package/src/components/provider/index.js +8 -1
  112. package/src/components/use-block-commands/index.js +92 -88
  113. package/src/components/warning/index.js +2 -2
  114. package/src/hooks/auto-inserting-blocks.js +232 -0
  115. package/src/hooks/index.js +1 -0
  116. package/src/hooks/style.js +85 -35
  117. package/src/hooks/utils.js +4 -0
  118. package/build/utils/pre-parse-patterns.js +0 -68
  119. package/build/utils/pre-parse-patterns.js.map +0 -1
  120. package/build-module/utils/pre-parse-patterns.js +0 -61
  121. package/build-module/utils/pre-parse-patterns.js.map +0 -1
  122. package/src/components/url-popover/test/__snapshots__/index.js.snap +0 -133
  123. package/src/components/url-popover/test/index.js +0 -75
  124. package/src/utils/pre-parse-patterns.js +0 -69
@@ -0,0 +1,232 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { addFilter } from '@wordpress/hooks';
6
+ import { Fragment } from '@wordpress/element';
7
+ import { PanelBody, ToggleControl } from '@wordpress/components';
8
+ import { createHigherOrderComponent } from '@wordpress/compose';
9
+ import { createBlock, store as blocksStore } from '@wordpress/blocks';
10
+ import { useDispatch, useSelect } from '@wordpress/data';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import { InspectorControls } from '../components';
16
+ import { store as blockEditorStore } from '../store';
17
+
18
+ function AutoInsertingBlocksControl( props ) {
19
+ const { autoInsertedBlocksForCurrentBlock, groupedAutoInsertedBlocks } =
20
+ useSelect(
21
+ ( select ) => {
22
+ const { getBlockTypes } = select( blocksStore );
23
+ const _autoInsertedBlocksForCurrentBlock =
24
+ getBlockTypes()?.filter(
25
+ ( { autoInsert } ) =>
26
+ autoInsert && props.blockName in autoInsert
27
+ );
28
+
29
+ // Group by block namespace (i.e. prefix before the slash).
30
+ const _groupedAutoInsertedBlocks =
31
+ _autoInsertedBlocksForCurrentBlock?.reduce(
32
+ ( groups, block ) => {
33
+ const [ namespace ] = block.name.split( '/' );
34
+ if ( ! groups[ namespace ] ) {
35
+ groups[ namespace ] = [];
36
+ }
37
+ groups[ namespace ].push( block );
38
+ return groups;
39
+ },
40
+ {}
41
+ );
42
+
43
+ return {
44
+ autoInsertedBlocksForCurrentBlock:
45
+ _autoInsertedBlocksForCurrentBlock,
46
+ groupedAutoInsertedBlocks: _groupedAutoInsertedBlocks,
47
+ };
48
+ },
49
+ [ props.blockName ]
50
+ );
51
+
52
+ const {
53
+ autoInsertedBlockClientIds,
54
+ blockIndex,
55
+ rootClientId,
56
+ innerBlocksLength,
57
+ } = useSelect(
58
+ ( select ) => {
59
+ const { getBlock, getBlockIndex, getBlockRootClientId } =
60
+ select( blockEditorStore );
61
+ const _rootClientId = getBlockRootClientId( props.clientId );
62
+
63
+ const _autoInsertedBlockClientIds =
64
+ autoInsertedBlocksForCurrentBlock.reduce(
65
+ ( clientIds, block ) => {
66
+ const relativePosition =
67
+ block?.autoInsert?.[ props.blockName ];
68
+ let candidates;
69
+
70
+ switch ( relativePosition ) {
71
+ case 'before':
72
+ case 'after':
73
+ // Any of the current block's siblings (with the right block type) qualifies
74
+ // as an auto-inserted block (inserted `before` or `after` the current one),
75
+ // as the block might've been auto-inserted and then moved around a bit by the user.
76
+ candidates =
77
+ getBlock( _rootClientId )?.innerBlocks;
78
+ break;
79
+
80
+ case 'first_child':
81
+ case 'last_child':
82
+ // Any of the current block's child blocks (with the right block type) qualifies
83
+ // as an auto-inserted first or last child block, as the block might've been
84
+ // auto-inserted and then moved around a bit by the user.
85
+ candidates = getBlock(
86
+ props.clientId
87
+ ).innerBlocks;
88
+ break;
89
+ }
90
+
91
+ const autoInsertedBlock = candidates?.find(
92
+ ( { name } ) => name === block.name
93
+ );
94
+
95
+ if ( autoInsertedBlock ) {
96
+ clientIds[ block.name ] =
97
+ autoInsertedBlock.clientId;
98
+ }
99
+
100
+ // TOOD: If no auto-inserted block was found in any of its designated locations,
101
+ // we want to check if it's present elsewhere in the block tree.
102
+ // If it is, we'd consider it manually inserted and would want to remove the
103
+ // corresponding toggle from the block inspector panel.
104
+
105
+ return clientIds;
106
+ },
107
+ {}
108
+ );
109
+
110
+ return {
111
+ blockIndex: getBlockIndex( props.clientId ),
112
+ innerBlocksLength: getBlock( props.clientId )?.innerBlocks
113
+ ?.length,
114
+ rootClientId: _rootClientId,
115
+ autoInsertedBlockClientIds: _autoInsertedBlockClientIds,
116
+ };
117
+ },
118
+ [ autoInsertedBlocksForCurrentBlock, props.blockName, props.clientId ]
119
+ );
120
+
121
+ const { insertBlock, removeBlock } = useDispatch( blockEditorStore );
122
+
123
+ if ( ! autoInsertedBlocksForCurrentBlock.length ) {
124
+ return null;
125
+ }
126
+
127
+ const insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {
128
+ switch ( relativePosition ) {
129
+ case 'before':
130
+ case 'after':
131
+ insertBlock(
132
+ block,
133
+ relativePosition === 'after' ? blockIndex + 1 : blockIndex,
134
+ rootClientId, // Insert as a child of the current block's parent
135
+ false
136
+ );
137
+ break;
138
+
139
+ case 'first_child':
140
+ case 'last_child':
141
+ insertBlock(
142
+ block,
143
+ // TODO: It'd be great if insertBlock() would accept negative indices for insertion.
144
+ relativePosition === 'first_child' ? 0 : innerBlocksLength,
145
+ props.clientId, // Insert as a child of the current block.
146
+ false
147
+ );
148
+ break;
149
+ }
150
+ };
151
+
152
+ return (
153
+ <InspectorControls>
154
+ <PanelBody title={ __( 'Plugins' ) } initialOpen={ true }>
155
+ { Object.keys( groupedAutoInsertedBlocks ).map( ( vendor ) => {
156
+ return (
157
+ <Fragment key={ vendor }>
158
+ <h3>{ vendor }</h3>
159
+ { groupedAutoInsertedBlocks[ vendor ].map(
160
+ ( block ) => {
161
+ // TODO: Display block icon.
162
+ // <BlockIcon icon={ block.icon } />
163
+
164
+ const checked =
165
+ block.name in
166
+ autoInsertedBlockClientIds;
167
+
168
+ return (
169
+ <ToggleControl
170
+ checked={ checked }
171
+ key={ block.title }
172
+ label={ block.title }
173
+ onChange={ () => {
174
+ if ( ! checked ) {
175
+ // Create and insert block.
176
+ const relativePosition =
177
+ block.autoInsert[
178
+ props.blockName
179
+ ];
180
+ insertBlockIntoDesignatedLocation(
181
+ createBlock(
182
+ block.name
183
+ ),
184
+ relativePosition
185
+ );
186
+ return;
187
+ }
188
+
189
+ // Remove block.
190
+ const clientId =
191
+ autoInsertedBlockClientIds[
192
+ block.name
193
+ ];
194
+ removeBlock( clientId, false );
195
+ } }
196
+ />
197
+ );
198
+ }
199
+ ) }
200
+ </Fragment>
201
+ );
202
+ } ) }
203
+ </PanelBody>
204
+ </InspectorControls>
205
+ );
206
+ }
207
+
208
+ export const withAutoInsertingBlocks = createHigherOrderComponent(
209
+ ( BlockEdit ) => {
210
+ return ( props ) => {
211
+ const blockEdit = <BlockEdit key="edit" { ...props } />;
212
+ return (
213
+ <>
214
+ { blockEdit }
215
+ <AutoInsertingBlocksControl
216
+ blockName={ props.name }
217
+ clientId={ props.clientId }
218
+ />
219
+ </>
220
+ );
221
+ };
222
+ },
223
+ 'withAutoInsertingBlocks'
224
+ );
225
+
226
+ if ( window?.__experimentalAutoInsertingBlocks ) {
227
+ addFilter(
228
+ 'editor.BlockEdit',
229
+ 'core/auto-inserting-blocks/with-inspector-control',
230
+ withAutoInsertingBlocks
231
+ );
232
+ }
@@ -22,6 +22,7 @@ import './metadata';
22
22
  import './metadata-name';
23
23
  import './behaviors';
24
24
  import './custom-fields';
25
+ import './auto-inserting-blocks';
25
26
 
26
27
  export { useCustomSides } from './dimensions';
27
28
  export { useLayoutClasses, useLayoutStyles } from './layout';
@@ -34,6 +34,7 @@ import {
34
34
  } from './dimensions';
35
35
  import useDisplayBlockControls from '../components/use-display-block-controls';
36
36
  import { shouldSkipSerialization } from './utils';
37
+ import { scopeSelector } from '../components/global-styles/utils';
37
38
  import { useBlockEditingMode } from '../components/block-editing-mode';
38
39
 
39
40
  const styleSupportKeys = [
@@ -371,6 +372,18 @@ export const withBlockControls = createHigherOrderComponent(
371
372
  'withToolbarControls'
372
373
  );
373
374
 
375
+ // Defines which element types are supported, including their hover styles or
376
+ // any other elements that have been included under a single element type
377
+ // e.g. heading and h1-h6.
378
+ const elementTypes = [
379
+ { elementType: 'button' },
380
+ { elementType: 'link', pseudo: [ ':hover' ] },
381
+ {
382
+ elementType: 'heading',
383
+ elements: [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ],
384
+ },
385
+ ];
386
+
374
387
  /**
375
388
  * Override the default block element to include elements styles.
376
389
  *
@@ -383,47 +396,84 @@ const withElementsStyles = createHigherOrderComponent(
383
396
  BlockListBlock
384
397
  ) }`;
385
398
 
386
- const skipLinkColorSerialization = shouldSkipSerialization(
387
- props.name,
388
- COLOR_SUPPORT_KEY,
389
- 'link'
390
- );
399
+ // The .editor-styles-wrapper selector is required on elements styles. As it is
400
+ // added to all other editor styles, not providing it causes reset and global
401
+ // styles to override element styles because of higher specificity.
402
+ const baseElementSelector = `.editor-styles-wrapper .${ blockElementsContainerIdentifier }`;
403
+ const blockElementStyles = props.attributes.style?.elements;
391
404
 
392
405
  const styles = useMemo( () => {
393
- // The .editor-styles-wrapper selector is required on elements styles. As it is
394
- // added to all other editor styles, not providing it causes reset and global
395
- // styles to override element styles because of higher specificity.
396
- const elements = [
397
- {
398
- styles: ! skipLinkColorSerialization
399
- ? props.attributes.style?.elements?.link
400
- : undefined,
401
- selector: `.editor-styles-wrapper .${ blockElementsContainerIdentifier } ${ ELEMENTS.link }`,
402
- },
403
- {
404
- styles: ! skipLinkColorSerialization
405
- ? props.attributes.style?.elements?.link?.[ ':hover' ]
406
- : undefined,
407
- selector: `.editor-styles-wrapper .${ blockElementsContainerIdentifier } ${ ELEMENTS.link }:hover`,
408
- },
409
- ];
410
- const elementCssRules = [];
411
- for ( const { styles: elementStyles, selector } of elements ) {
406
+ if ( ! blockElementStyles ) {
407
+ return;
408
+ }
409
+
410
+ const elementCSSRules = [];
411
+
412
+ elementTypes.forEach( ( { elementType, pseudo, elements } ) => {
413
+ const skipSerialization = shouldSkipSerialization(
414
+ props.name,
415
+ COLOR_SUPPORT_KEY,
416
+ elementType
417
+ );
418
+
419
+ if ( skipSerialization ) {
420
+ return;
421
+ }
422
+
423
+ const elementStyles = blockElementStyles?.[ elementType ];
424
+
425
+ // Process primary element type styles.
412
426
  if ( elementStyles ) {
413
- const cssRule = compileCSS( elementStyles, {
414
- selector,
427
+ const selector = scopeSelector(
428
+ baseElementSelector,
429
+ ELEMENTS[ elementType ]
430
+ );
431
+
432
+ elementCSSRules.push(
433
+ compileCSS( elementStyles, { selector } )
434
+ );
435
+
436
+ // Process any interactive states for the element type.
437
+ if ( pseudo ) {
438
+ pseudo.forEach( ( pseudoSelector ) => {
439
+ if ( elementStyles[ pseudoSelector ] ) {
440
+ elementCSSRules.push(
441
+ compileCSS(
442
+ elementStyles[ pseudoSelector ],
443
+ {
444
+ selector: scopeSelector(
445
+ baseElementSelector,
446
+ `${ ELEMENTS[ elementType ] }${ pseudoSelector }`
447
+ ),
448
+ }
449
+ )
450
+ );
451
+ }
452
+ } );
453
+ }
454
+ }
455
+
456
+ // Process related elements e.g. h1-h6 for headings
457
+ if ( elements ) {
458
+ elements.forEach( ( element ) => {
459
+ if ( blockElementStyles[ element ] ) {
460
+ elementCSSRules.push(
461
+ compileCSS( blockElementStyles[ element ], {
462
+ selector: scopeSelector(
463
+ baseElementSelector,
464
+ ELEMENTS[ element ]
465
+ ),
466
+ } )
467
+ );
468
+ }
415
469
  } );
416
- elementCssRules.push( cssRule );
417
470
  }
418
- }
419
- return elementCssRules.length > 0
420
- ? elementCssRules.join( '' )
471
+ } );
472
+
473
+ return elementCSSRules.length > 0
474
+ ? elementCSSRules.join( '' )
421
475
  : undefined;
422
- }, [
423
- props.attributes.style?.elements,
424
- blockElementsContainerIdentifier,
425
- skipLinkColorSerialization,
426
- ] );
476
+ }, [ baseElementSelector, blockElementStyles, props.name ] );
427
477
 
428
478
  const element = useContext( BlockList.__unstableElementContext );
429
479
 
@@ -166,6 +166,8 @@ export function useBlockSettings( name, parentLayout ) {
166
166
  const isBackgroundEnabled = useSetting( 'color.background' );
167
167
  const isLinkEnabled = useSetting( 'color.link' );
168
168
  const isTextEnabled = useSetting( 'color.text' );
169
+ const isHeadingEnabled = useSetting( 'color.heading' );
170
+ const isButtonEnabled = useSetting( 'color.button' );
169
171
 
170
172
  const rawSettings = useMemo( () => {
171
173
  return {
@@ -193,6 +195,8 @@ export function useBlockSettings( name, parentLayout ) {
193
195
  customDuotone,
194
196
  background: isBackgroundEnabled,
195
197
  link: isLinkEnabled,
198
+ heading: isHeadingEnabled,
199
+ button: isButtonEnabled,
196
200
  text: isTextEnabled,
197
201
  },
198
202
  typography: {
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.usePreParsePatterns = usePreParsePatterns;
7
- var _data = require("@wordpress/data");
8
- var _element = require("@wordpress/element");
9
- var _store = require("../store");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- const requestIdleCallback = (() => {
19
- if (typeof window === 'undefined') {
20
- return callback => {
21
- setTimeout(() => callback(Date.now()), 0);
22
- };
23
- }
24
- return window.requestIdleCallback || window.requestAnimationFrame;
25
- })();
26
- const cancelIdleCallback = (() => {
27
- if (typeof window === 'undefined') {
28
- return clearTimeout;
29
- }
30
- return window.cancelIdleCallback || window.cancelAnimationFrame;
31
- })();
32
- function usePreParsePatterns() {
33
- const {
34
- patterns,
35
- isPreviewMode
36
- } = (0, _data.useSelect)(_select => {
37
- const {
38
- __experimentalBlockPatterns,
39
- __unstableIsPreviewMode
40
- } = _select(_store.store).getSettings();
41
- return {
42
- patterns: __experimentalBlockPatterns,
43
- isPreviewMode: __unstableIsPreviewMode
44
- };
45
- }, []);
46
- (0, _element.useEffect)(() => {
47
- if (isPreviewMode) {
48
- return;
49
- }
50
- if (!patterns?.length) {
51
- return;
52
- }
53
- let handle;
54
- let index = -1;
55
- const callback = () => {
56
- index++;
57
- if (index >= patterns.length) {
58
- return;
59
- }
60
- (0, _data.select)(_store.store).__experimentalGetParsedPattern(patterns[index].name);
61
- handle = requestIdleCallback(callback);
62
- };
63
- handle = requestIdleCallback(callback);
64
- return () => cancelIdleCallback(handle);
65
- }, [patterns, isPreviewMode]);
66
- return null;
67
- }
68
- //# sourceMappingURL=pre-parse-patterns.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_data","require","_element","_store","requestIdleCallback","window","callback","setTimeout","Date","now","requestAnimationFrame","cancelIdleCallback","clearTimeout","cancelAnimationFrame","usePreParsePatterns","patterns","isPreviewMode","useSelect","_select","__experimentalBlockPatterns","__unstableIsPreviewMode","blockEditorStore","getSettings","useEffect","length","handle","index","select","__experimentalGetParsedPattern","name"],"sources":["@wordpress/block-editor/src/utils/pre-parse-patterns.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, select } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\n\nconst requestIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback || window.requestAnimationFrame;\n} )();\n\nconst cancelIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn clearTimeout;\n\t}\n\n\treturn window.cancelIdleCallback || window.cancelAnimationFrame;\n} )();\n\nexport function usePreParsePatterns() {\n\tconst { patterns, isPreviewMode } = useSelect( ( _select ) => {\n\t\tconst { __experimentalBlockPatterns, __unstableIsPreviewMode } =\n\t\t\t_select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tpatterns: __experimentalBlockPatterns,\n\t\t\tisPreviewMode: __unstableIsPreviewMode,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isPreviewMode ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( ! patterns?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet handle;\n\t\tlet index = -1;\n\n\t\tconst callback = () => {\n\t\t\tindex++;\n\t\t\tif ( index >= patterns.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tpatterns[ index ].name\n\t\t\t);\n\n\t\t\thandle = requestIdleCallback( callback );\n\t\t};\n\n\t\thandle = requestIdleCallback( callback );\n\t\treturn () => cancelIdleCallback( handle );\n\t}, [ patterns, isPreviewMode ] );\n\n\treturn null;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMG,mBAAmB,GAAG,CAAE,MAAM;EACnC,IAAK,OAAOC,MAAM,KAAK,WAAW,EAAG;IACpC,OAASC,QAAQ,IAAM;MACtBC,UAAU,CAAE,MAAMD,QAAQ,CAAEE,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,EAAE,CAAE,CAAC;IAC9C,CAAC;EACF;EAEA,OAAOJ,MAAM,CAACD,mBAAmB,IAAIC,MAAM,CAACK,qBAAqB;AAClE,CAAC,EAAG,CAAC;AAEL,MAAMC,kBAAkB,GAAG,CAAE,MAAM;EAClC,IAAK,OAAON,MAAM,KAAK,WAAW,EAAG;IACpC,OAAOO,YAAY;EACpB;EAEA,OAAOP,MAAM,CAACM,kBAAkB,IAAIN,MAAM,CAACQ,oBAAoB;AAChE,CAAC,EAAG,CAAC;AAEE,SAASC,mBAAmBA,CAAA,EAAG;EACrC,MAAM;IAAEC,QAAQ;IAAEC;EAAc,CAAC,GAAG,IAAAC,eAAS,EAAIC,OAAO,IAAM;IAC7D,MAAM;MAAEC,2BAA2B;MAAEC;IAAwB,CAAC,GAC7DF,OAAO,CAAEG,YAAiB,CAAC,CAACC,WAAW,CAAC,CAAC;IAC1C,OAAO;MACNP,QAAQ,EAAEI,2BAA2B;MACrCH,aAAa,EAAEI;IAChB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,IAAAG,kBAAS,EAAE,MAAM;IAChB,IAAKP,aAAa,EAAG;MACpB;IACD;IACA,IAAK,CAAED,QAAQ,EAAES,MAAM,EAAG;MACzB;IACD;IAEA,IAAIC,MAAM;IACV,IAAIC,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMpB,QAAQ,GAAGA,CAAA,KAAM;MACtBoB,KAAK,EAAE;MACP,IAAKA,KAAK,IAAIX,QAAQ,CAACS,MAAM,EAAG;QAC/B;MACD;MAEA,IAAAG,YAAM,EAAEN,YAAiB,CAAC,CAACO,8BAA8B,CACxDb,QAAQ,CAAEW,KAAK,CAAE,CAACG,IACnB,CAAC;MAEDJ,MAAM,GAAGrB,mBAAmB,CAAEE,QAAS,CAAC;IACzC,CAAC;IAEDmB,MAAM,GAAGrB,mBAAmB,CAAEE,QAAS,CAAC;IACxC,OAAO,MAAMK,kBAAkB,CAAEc,MAAO,CAAC;EAC1C,CAAC,EAAE,CAAEV,QAAQ,EAAEC,aAAa,CAAG,CAAC;EAEhC,OAAO,IAAI;AACZ"}
@@ -1,61 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useSelect, select } from '@wordpress/data';
5
- import { useEffect } from '@wordpress/element';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { store as blockEditorStore } from '../store';
11
- const requestIdleCallback = (() => {
12
- if (typeof window === 'undefined') {
13
- return callback => {
14
- setTimeout(() => callback(Date.now()), 0);
15
- };
16
- }
17
- return window.requestIdleCallback || window.requestAnimationFrame;
18
- })();
19
- const cancelIdleCallback = (() => {
20
- if (typeof window === 'undefined') {
21
- return clearTimeout;
22
- }
23
- return window.cancelIdleCallback || window.cancelAnimationFrame;
24
- })();
25
- export function usePreParsePatterns() {
26
- const {
27
- patterns,
28
- isPreviewMode
29
- } = useSelect(_select => {
30
- const {
31
- __experimentalBlockPatterns,
32
- __unstableIsPreviewMode
33
- } = _select(blockEditorStore).getSettings();
34
- return {
35
- patterns: __experimentalBlockPatterns,
36
- isPreviewMode: __unstableIsPreviewMode
37
- };
38
- }, []);
39
- useEffect(() => {
40
- if (isPreviewMode) {
41
- return;
42
- }
43
- if (!patterns?.length) {
44
- return;
45
- }
46
- let handle;
47
- let index = -1;
48
- const callback = () => {
49
- index++;
50
- if (index >= patterns.length) {
51
- return;
52
- }
53
- select(blockEditorStore).__experimentalGetParsedPattern(patterns[index].name);
54
- handle = requestIdleCallback(callback);
55
- };
56
- handle = requestIdleCallback(callback);
57
- return () => cancelIdleCallback(handle);
58
- }, [patterns, isPreviewMode]);
59
- return null;
60
- }
61
- //# sourceMappingURL=pre-parse-patterns.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useSelect","select","useEffect","store","blockEditorStore","requestIdleCallback","window","callback","setTimeout","Date","now","requestAnimationFrame","cancelIdleCallback","clearTimeout","cancelAnimationFrame","usePreParsePatterns","patterns","isPreviewMode","_select","__experimentalBlockPatterns","__unstableIsPreviewMode","getSettings","length","handle","index","__experimentalGetParsedPattern","name"],"sources":["@wordpress/block-editor/src/utils/pre-parse-patterns.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, select } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\n\nconst requestIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback || window.requestAnimationFrame;\n} )();\n\nconst cancelIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn clearTimeout;\n\t}\n\n\treturn window.cancelIdleCallback || window.cancelAnimationFrame;\n} )();\n\nexport function usePreParsePatterns() {\n\tconst { patterns, isPreviewMode } = useSelect( ( _select ) => {\n\t\tconst { __experimentalBlockPatterns, __unstableIsPreviewMode } =\n\t\t\t_select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tpatterns: __experimentalBlockPatterns,\n\t\t\tisPreviewMode: __unstableIsPreviewMode,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isPreviewMode ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( ! patterns?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet handle;\n\t\tlet index = -1;\n\n\t\tconst callback = () => {\n\t\t\tindex++;\n\t\t\tif ( index >= patterns.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tpatterns[ index ].name\n\t\t\t);\n\n\t\t\thandle = requestIdleCallback( callback );\n\t\t};\n\n\t\thandle = requestIdleCallback( callback );\n\t\treturn () => cancelIdleCallback( handle );\n\t}, [ patterns, isPreviewMode ] );\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,iBAAiB;AACnD,SAASC,SAAS,QAAQ,oBAAoB;;AAE9C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AAEpD,MAAMC,mBAAmB,GAAG,CAAE,MAAM;EACnC,IAAK,OAAOC,MAAM,KAAK,WAAW,EAAG;IACpC,OAASC,QAAQ,IAAM;MACtBC,UAAU,CAAE,MAAMD,QAAQ,CAAEE,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,EAAE,CAAE,CAAC;IAC9C,CAAC;EACF;EAEA,OAAOJ,MAAM,CAACD,mBAAmB,IAAIC,MAAM,CAACK,qBAAqB;AAClE,CAAC,EAAG,CAAC;AAEL,MAAMC,kBAAkB,GAAG,CAAE,MAAM;EAClC,IAAK,OAAON,MAAM,KAAK,WAAW,EAAG;IACpC,OAAOO,YAAY;EACpB;EAEA,OAAOP,MAAM,CAACM,kBAAkB,IAAIN,MAAM,CAACQ,oBAAoB;AAChE,CAAC,EAAG,CAAC;AAEL,OAAO,SAASC,mBAAmBA,CAAA,EAAG;EACrC,MAAM;IAAEC,QAAQ;IAAEC;EAAc,CAAC,GAAGjB,SAAS,CAAIkB,OAAO,IAAM;IAC7D,MAAM;MAAEC,2BAA2B;MAAEC;IAAwB,CAAC,GAC7DF,OAAO,CAAEd,gBAAiB,CAAC,CAACiB,WAAW,CAAC,CAAC;IAC1C,OAAO;MACNL,QAAQ,EAAEG,2BAA2B;MACrCF,aAAa,EAAEG;IAChB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEPlB,SAAS,CAAE,MAAM;IAChB,IAAKe,aAAa,EAAG;MACpB;IACD;IACA,IAAK,CAAED,QAAQ,EAAEM,MAAM,EAAG;MACzB;IACD;IAEA,IAAIC,MAAM;IACV,IAAIC,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMjB,QAAQ,GAAGA,CAAA,KAAM;MACtBiB,KAAK,EAAE;MACP,IAAKA,KAAK,IAAIR,QAAQ,CAACM,MAAM,EAAG;QAC/B;MACD;MAEArB,MAAM,CAAEG,gBAAiB,CAAC,CAACqB,8BAA8B,CACxDT,QAAQ,CAAEQ,KAAK,CAAE,CAACE,IACnB,CAAC;MAEDH,MAAM,GAAGlB,mBAAmB,CAAEE,QAAS,CAAC;IACzC,CAAC;IAEDgB,MAAM,GAAGlB,mBAAmB,CAAEE,QAAS,CAAC;IACxC,OAAO,MAAMK,kBAAkB,CAAEW,MAAO,CAAC;EAC1C,CAAC,EAAE,CAAEP,QAAQ,EAAEC,aAAa,CAAG,CAAC;EAEhC,OAAO,IAAI;AACZ"}
@@ -1,133 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`URLPopover matches the snapshot in its default state 1`] = `
4
- <div>
5
- <span>
6
- <div
7
- class="components-popover block-editor-url-popover is-positioned"
8
- style="position: absolute; top: 0px; left: 0px; transform: none;"
9
- tabindex="-1"
10
- >
11
- <div
12
- class="components-popover__content"
13
- style="max-height: 0px; overflow: auto;"
14
- >
15
- <div
16
- class="block-editor-url-popover__input-container"
17
- >
18
- <div
19
- class="block-editor-url-popover__row"
20
- >
21
- <div>
22
- Editor
23
- </div>
24
- <button
25
- aria-expanded="false"
26
- aria-label="Link settings"
27
- class="components-button block-editor-url-popover__settings-toggle has-icon"
28
- type="button"
29
- >
30
- <svg
31
- aria-hidden="true"
32
- focusable="false"
33
- height="24"
34
- viewBox="0 0 24 24"
35
- width="24"
36
- xmlns="http://www.w3.org/2000/svg"
37
- >
38
- <path
39
- d="M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"
40
- />
41
- </svg>
42
- </button>
43
- </div>
44
- </div>
45
- </div>
46
- </div>
47
- </span>
48
- </div>
49
- `;
50
-
51
- exports[`URLPopover matches the snapshot when the settings are toggled open 1`] = `
52
- <div>
53
- <span>
54
- <div
55
- class="components-popover block-editor-url-popover is-positioned"
56
- style="position: absolute; top: 0px; left: 0px; transform: none;"
57
- tabindex="-1"
58
- >
59
- <div
60
- class="components-popover__content"
61
- style="max-height: 0px; overflow: auto;"
62
- >
63
- <div
64
- class="block-editor-url-popover__input-container"
65
- >
66
- <div
67
- class="block-editor-url-popover__row"
68
- >
69
- <div>
70
- Editor
71
- </div>
72
- <button
73
- aria-expanded="true"
74
- aria-label="Link settings"
75
- class="components-button block-editor-url-popover__settings-toggle has-icon"
76
- type="button"
77
- >
78
- <svg
79
- aria-hidden="true"
80
- focusable="false"
81
- height="24"
82
- viewBox="0 0 24 24"
83
- width="24"
84
- xmlns="http://www.w3.org/2000/svg"
85
- >
86
- <path
87
- d="M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"
88
- />
89
- </svg>
90
- </button>
91
- </div>
92
- <div
93
- class="block-editor-url-popover__row block-editor-url-popover__settings"
94
- >
95
- <div>
96
- Settings
97
- </div>
98
- </div>
99
- </div>
100
- </div>
101
- </div>
102
- </span>
103
- </div>
104
- `;
105
-
106
- exports[`URLPopover matches the snapshot when there are no settings 1`] = `
107
- <div>
108
- <span>
109
- <div
110
- class="components-popover block-editor-url-popover is-positioned"
111
- style="position: absolute; top: 0px; left: 0px; transform: none;"
112
- tabindex="-1"
113
- >
114
- <div
115
- class="components-popover__content"
116
- style="max-height: 0px; overflow: auto;"
117
- >
118
- <div
119
- class="block-editor-url-popover__input-container"
120
- >
121
- <div
122
- class="block-editor-url-popover__row"
123
- >
124
- <div>
125
- Editor
126
- </div>
127
- </div>
128
- </div>
129
- </div>
130
- </div>
131
- </span>
132
- </div>
133
- `;