@wordpress/editor 14.22.0 → 14.24.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 (79) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/collab-sidebar/comment-form.js +3 -1
  3. package/build/components/collab-sidebar/comment-form.js.map +1 -1
  4. package/build/components/editor-interface/index.js +11 -6
  5. package/build/components/editor-interface/index.js.map +1 -1
  6. package/build/components/post-author/check.js +3 -7
  7. package/build/components/post-author/check.js.map +1 -1
  8. package/build/components/post-author/panel.js +10 -2
  9. package/build/components/post-author/panel.js.map +1 -1
  10. package/build/components/post-publish-panel/postpublish.js +11 -3
  11. package/build/components/post-publish-panel/postpublish.js.map +1 -1
  12. package/build/components/post-template/swap-template-button.js +18 -4
  13. package/build/components/post-template/swap-template-button.js.map +1 -1
  14. package/build/components/template-part-menu-items/convert-to-template-part.js +4 -1
  15. package/build/components/template-part-menu-items/convert-to-template-part.js.map +1 -1
  16. package/build/components/visual-editor/index.js +1 -2
  17. package/build/components/visual-editor/index.js.map +1 -1
  18. package/build/store/private-actions.js +2 -1
  19. package/build/store/private-actions.js.map +1 -1
  20. package/build/store/utils/notice-builder.js +2 -1
  21. package/build/store/utils/notice-builder.js.map +1 -1
  22. package/build/utils/search-templates.js +75 -0
  23. package/build/utils/search-templates.js.map +1 -0
  24. package/build-module/components/collab-sidebar/comment-form.js +4 -2
  25. package/build-module/components/collab-sidebar/comment-form.js.map +1 -1
  26. package/build-module/components/editor-interface/index.js +11 -6
  27. package/build-module/components/editor-interface/index.js.map +1 -1
  28. package/build-module/components/post-author/check.js +3 -7
  29. package/build-module/components/post-author/check.js.map +1 -1
  30. package/build-module/components/post-author/panel.js +10 -2
  31. package/build-module/components/post-author/panel.js.map +1 -1
  32. package/build-module/components/post-publish-panel/postpublish.js +12 -4
  33. package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
  34. package/build-module/components/post-template/swap-template-button.js +19 -5
  35. package/build-module/components/post-template/swap-template-button.js.map +1 -1
  36. package/build-module/components/template-part-menu-items/convert-to-template-part.js +4 -1
  37. package/build-module/components/template-part-menu-items/convert-to-template-part.js.map +1 -1
  38. package/build-module/components/visual-editor/index.js +1 -2
  39. package/build-module/components/visual-editor/index.js.map +1 -1
  40. package/build-module/store/private-actions.js +2 -1
  41. package/build-module/store/private-actions.js.map +1 -1
  42. package/build-module/store/utils/notice-builder.js +2 -1
  43. package/build-module/store/utils/notice-builder.js.map +1 -1
  44. package/build-module/utils/search-templates.js +68 -0
  45. package/build-module/utils/search-templates.js.map +1 -0
  46. package/build-style/style-rtl.css +146 -28
  47. package/build-style/style.css +146 -28
  48. package/build-types/components/collab-sidebar/comment-form.d.ts.map +1 -1
  49. package/build-types/components/editor-interface/index.d.ts.map +1 -1
  50. package/build-types/components/post-author/check.d.ts.map +1 -1
  51. package/build-types/components/post-author/panel.d.ts.map +1 -1
  52. package/build-types/components/post-publish-panel/postpublish.d.ts.map +1 -1
  53. package/build-types/components/post-template/swap-template-button.d.ts.map +1 -1
  54. package/build-types/components/template-part-menu-items/convert-to-template-part.d.ts.map +1 -1
  55. package/build-types/components/visual-editor/index.d.ts.map +1 -1
  56. package/build-types/store/private-actions.d.ts.map +1 -1
  57. package/build-types/store/utils/notice-builder.d.ts.map +1 -1
  58. package/build-types/utils/search-templates.d.ts +10 -0
  59. package/build-types/utils/search-templates.d.ts.map +1 -0
  60. package/package.json +37 -37
  61. package/src/components/collab-sidebar/comment-form.js +3 -1
  62. package/src/components/editor-interface/index.js +17 -15
  63. package/src/components/editor-interface/style.scss +1 -2
  64. package/src/components/post-author/check.js +2 -7
  65. package/src/components/post-author/panel.js +10 -2
  66. package/src/components/post-author/test/check.js +3 -11
  67. package/src/components/post-publish-panel/postpublish.js +19 -3
  68. package/src/components/post-publish-panel/style.scss +3 -1
  69. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +82 -12
  70. package/src/components/post-template/style.scss +10 -0
  71. package/src/components/post-template/swap-template-button.js +23 -6
  72. package/src/components/template-part-menu-items/convert-to-template-part.js +5 -2
  73. package/src/components/visual-editor/index.js +0 -1
  74. package/src/components/visual-editor/style.scss +6 -29
  75. package/src/store/private-actions.js +1 -0
  76. package/src/store/utils/notice-builder.js +1 -0
  77. package/src/store/utils/test/notice-builder.js +3 -1
  78. package/src/utils/search-templates.js +77 -0
  79. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,77 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import removeAccents from 'remove-accents';
5
+
6
+ /**
7
+ * Sanitizes the search input string.
8
+ *
9
+ * @param {string} input The search input to normalize.
10
+ *
11
+ * @return {string} The normalized search input.
12
+ */
13
+ function normalizeSearchInput( input = '' ) {
14
+ // Disregard diacritics.
15
+ input = removeAccents( input );
16
+
17
+ // Trim & Lowercase.
18
+ input = input.trim().toLowerCase();
19
+
20
+ return input;
21
+ }
22
+
23
+ /**
24
+ * Get the search rank for a given template and a specific search term.
25
+ *
26
+ * @param {Object} template Template to rank
27
+ * @param {string} searchValue Search term
28
+ *
29
+ * @return {number} A template search rank
30
+ */
31
+ function getTemplateSearchRank( template, searchValue ) {
32
+ const normalizedSearchValue = normalizeSearchInput( searchValue );
33
+ const normalizedTitle = normalizeSearchInput( template.title );
34
+
35
+ let rank = 0;
36
+
37
+ if ( normalizedSearchValue === normalizedTitle ) {
38
+ rank += 30;
39
+ } else if ( normalizedTitle.startsWith( normalizedSearchValue ) ) {
40
+ rank += 20;
41
+ } else {
42
+ const searchTerms = normalizedSearchValue.split( ' ' );
43
+ const hasMatchedTerms = searchTerms.every( ( searchTerm ) =>
44
+ normalizedTitle.includes( searchTerm )
45
+ );
46
+
47
+ // Prefer template with every search word in the title.
48
+ if ( hasMatchedTerms ) {
49
+ rank += 10;
50
+ }
51
+ }
52
+
53
+ return rank;
54
+ }
55
+
56
+ /**
57
+ * Filters a template list given a search term.
58
+ *
59
+ * @param {Array} templates Item list
60
+ * @param {string} searchValue Search input.
61
+ *
62
+ * @return {Array} Filtered template list.
63
+ */
64
+ export function searchTemplates( templates = [], searchValue = '' ) {
65
+ if ( ! searchValue ) {
66
+ return templates;
67
+ }
68
+
69
+ const rankedTemplates = templates
70
+ .map( ( template ) => {
71
+ return [ template, getTemplateSearchRank( template, searchValue ) ];
72
+ } )
73
+ .filter( ( [ , rank ] ) => rank > 0 );
74
+
75
+ rankedTemplates.sort( ( [ , rank1 ], [ , rank2 ] ) => rank2 - rank1 );
76
+ return rankedTemplates.map( ( [ template ] ) => template );
77
+ }