@wordpress/widget-dashboard 0.2.0 → 0.3.1-next.v.202607070741.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +10 -16
  3. package/build/components/actions/actions.cjs +2 -19
  4. package/build/components/actions/actions.cjs.map +3 -3
  5. package/build/components/commands/commands.cjs +1 -60
  6. package/build/components/commands/commands.cjs.map +2 -2
  7. package/build/{utils/grid-model-change → components/widget-attribute-controls}/index.cjs +7 -9
  8. package/build/components/widget-attribute-controls/index.cjs.map +7 -0
  9. package/build/components/widget-attribute-controls/widget-attribute-controls.cjs +93 -0
  10. package/build/components/widget-attribute-controls/widget-attribute-controls.cjs.map +7 -0
  11. package/build/components/widget-chrome/widget-chrome.cjs +16 -63
  12. package/build/components/widget-chrome/widget-chrome.cjs.map +2 -2
  13. package/build/components/{layout-settings → widget-frame}/index.cjs +9 -7
  14. package/build/components/widget-frame/index.cjs.map +7 -0
  15. package/build/components/widget-frame/widget-frame.cjs +193 -0
  16. package/build/components/widget-frame/widget-frame.cjs.map +7 -0
  17. package/build/{utils/migrate-layout → components/widget-header}/index.cjs +7 -7
  18. package/build/components/widget-header/index.cjs.map +7 -0
  19. package/build/components/widget-header/widget-header-infotip.cjs +166 -0
  20. package/build/components/widget-header/widget-header-infotip.cjs.map +7 -0
  21. package/build/components/widget-header/widget-header.cjs +173 -0
  22. package/build/components/widget-header/widget-header.cjs.map +7 -0
  23. package/build/components/{widget-settings/utils/get-admin-menu-inset.cjs → widget-layout-controls/index.cjs} +8 -18
  24. package/build/components/widget-layout-controls/index.cjs.map +7 -0
  25. package/build/components/{widgets/widget-layout-toolbar.cjs → widget-layout-controls/widget-layout-controls.cjs} +9 -100
  26. package/build/components/widget-layout-controls/widget-layout-controls.cjs.map +7 -0
  27. package/build/components/widget-picker/widget-picker.cjs +5 -93
  28. package/build/components/widget-picker/widget-picker.cjs.map +3 -3
  29. package/build/components/widget-preview-chrome/index.cjs +31 -0
  30. package/build/components/widget-preview-chrome/index.cjs.map +7 -0
  31. package/build/components/{widget-settings/widget-settings-toolbar.cjs → widget-preview-chrome/widget-preview-chrome.cjs} +41 -23
  32. package/build/components/widget-preview-chrome/widget-preview-chrome.cjs.map +7 -0
  33. package/build/components/widget-settings/index.cjs +3 -3
  34. package/build/components/widget-settings/index.cjs.map +1 -1
  35. package/build/components/widget-settings/utils/index.cjs +0 -3
  36. package/build/components/widget-settings/utils/index.cjs.map +2 -2
  37. package/build/components/widget-settings/widget-settings-trigger.cjs +22 -28
  38. package/build/components/widget-settings/widget-settings-trigger.cjs.map +2 -2
  39. package/build/components/widget-settings/widget-settings.cjs +40 -57
  40. package/build/components/widget-settings/widget-settings.cjs.map +2 -2
  41. package/build/components/widget-toolbar/widget-toolbar.cjs +7 -4
  42. package/build/components/widget-toolbar/widget-toolbar.cjs.map +2 -2
  43. package/build/components/widgets/widgets.cjs +14 -7
  44. package/build/components/widgets/widgets.cjs.map +2 -2
  45. package/build/context/dashboard-context.cjs +31 -80
  46. package/build/context/dashboard-context.cjs.map +2 -2
  47. package/build/context/ui-context.cjs +2 -18
  48. package/build/context/ui-context.cjs.map +2 -2
  49. package/build/types.cjs.map +1 -1
  50. package/build/utils/index.cjs +2 -5
  51. package/build/utils/index.cjs.map +2 -2
  52. package/build/widget-dashboard.cjs +0 -4
  53. package/build/widget-dashboard.cjs.map +2 -2
  54. package/build-module/components/actions/actions.mjs +3 -20
  55. package/build-module/components/actions/actions.mjs.map +2 -2
  56. package/build-module/components/commands/commands.mjs +2 -67
  57. package/build-module/components/commands/commands.mjs.map +2 -2
  58. package/build-module/components/widget-attribute-controls/index.mjs +6 -0
  59. package/build-module/components/widget-attribute-controls/index.mjs.map +7 -0
  60. package/build-module/components/widget-attribute-controls/widget-attribute-controls.mjs +68 -0
  61. package/build-module/components/widget-attribute-controls/widget-attribute-controls.mjs.map +7 -0
  62. package/build-module/components/widget-chrome/widget-chrome.mjs +17 -70
  63. package/build-module/components/widget-chrome/widget-chrome.mjs.map +2 -2
  64. package/build-module/components/widget-frame/index.mjs +7 -0
  65. package/build-module/components/widget-frame/index.mjs.map +7 -0
  66. package/build-module/components/widget-frame/widget-frame.mjs +157 -0
  67. package/build-module/components/widget-frame/widget-frame.mjs.map +7 -0
  68. package/build-module/components/widget-header/index.mjs +6 -0
  69. package/build-module/components/widget-header/index.mjs.map +7 -0
  70. package/build-module/components/widget-header/widget-header-infotip.mjs +141 -0
  71. package/build-module/components/widget-header/widget-header-infotip.mjs.map +7 -0
  72. package/build-module/components/widget-header/widget-header.mjs +138 -0
  73. package/build-module/components/widget-header/widget-header.mjs.map +7 -0
  74. package/build-module/components/widget-layout-controls/index.mjs +6 -0
  75. package/build-module/components/widget-layout-controls/index.mjs.map +7 -0
  76. package/build-module/components/widget-layout-controls/widget-layout-controls.mjs +90 -0
  77. package/build-module/components/widget-layout-controls/widget-layout-controls.mjs.map +7 -0
  78. package/build-module/components/widget-picker/widget-picker.mjs +6 -94
  79. package/build-module/components/widget-picker/widget-picker.mjs.map +3 -3
  80. package/build-module/components/widget-preview-chrome/index.mjs +6 -0
  81. package/build-module/components/widget-preview-chrome/index.mjs.map +7 -0
  82. package/build-module/components/{widget-settings/widget-settings-toolbar.mjs → widget-preview-chrome/widget-preview-chrome.mjs} +37 -19
  83. package/build-module/components/widget-preview-chrome/widget-preview-chrome.mjs.map +7 -0
  84. package/build-module/components/widget-settings/index.mjs +2 -2
  85. package/build-module/components/widget-settings/index.mjs.map +1 -1
  86. package/build-module/components/widget-settings/utils/index.mjs +0 -2
  87. package/build-module/components/widget-settings/utils/index.mjs.map +2 -2
  88. package/build-module/components/widget-settings/widget-settings-trigger.mjs +23 -29
  89. package/build-module/components/widget-settings/widget-settings-trigger.mjs.map +2 -2
  90. package/build-module/components/widget-settings/widget-settings.mjs +40 -57
  91. package/build-module/components/widget-settings/widget-settings.mjs.map +2 -2
  92. package/build-module/components/widget-toolbar/widget-toolbar.mjs +7 -4
  93. package/build-module/components/widget-toolbar/widget-toolbar.mjs.map +2 -2
  94. package/build-module/components/widgets/widgets.mjs +14 -7
  95. package/build-module/components/widgets/widgets.mjs.map +2 -2
  96. package/build-module/context/dashboard-context.mjs +31 -80
  97. package/build-module/context/dashboard-context.mjs.map +2 -2
  98. package/build-module/context/ui-context.mjs +2 -18
  99. package/build-module/context/ui-context.mjs.map +2 -2
  100. package/build-module/types.mjs.map +1 -1
  101. package/build-module/utils/index.mjs +1 -3
  102. package/build-module/utils/index.mjs.map +2 -2
  103. package/build-module/widget-dashboard.mjs +0 -4
  104. package/build-module/widget-dashboard.mjs.map +2 -2
  105. package/build-types/components/actions/actions.d.ts.map +1 -1
  106. package/build-types/components/commands/commands.d.ts.map +1 -1
  107. package/build-types/components/widget-attribute-controls/index.d.ts +2 -0
  108. package/build-types/components/widget-attribute-controls/index.d.ts.map +1 -0
  109. package/build-types/components/widget-attribute-controls/widget-attribute-controls.d.ts +23 -0
  110. package/build-types/components/widget-attribute-controls/widget-attribute-controls.d.ts.map +1 -0
  111. package/build-types/components/widget-chrome/widget-chrome.d.ts +8 -8
  112. package/build-types/components/widget-chrome/widget-chrome.d.ts.map +1 -1
  113. package/build-types/components/widget-frame/index.d.ts +3 -0
  114. package/build-types/components/widget-frame/index.d.ts.map +1 -0
  115. package/build-types/components/widget-frame/widget-frame.d.ts +25 -0
  116. package/build-types/components/widget-frame/widget-frame.d.ts.map +1 -0
  117. package/build-types/components/widget-header/index.d.ts +3 -0
  118. package/build-types/components/widget-header/index.d.ts.map +1 -0
  119. package/build-types/components/widget-header/widget-header-infotip.d.ts +20 -0
  120. package/build-types/components/widget-header/widget-header-infotip.d.ts.map +1 -0
  121. package/build-types/components/widget-header/widget-header.d.ts +38 -0
  122. package/build-types/components/widget-header/widget-header.d.ts.map +1 -0
  123. package/build-types/components/widget-layout-controls/index.d.ts +3 -0
  124. package/build-types/components/widget-layout-controls/index.d.ts.map +1 -0
  125. package/build-types/components/widget-layout-controls/widget-layout-controls.d.ts +14 -0
  126. package/build-types/components/widget-layout-controls/widget-layout-controls.d.ts.map +1 -0
  127. package/build-types/components/widget-picker/widget-picker.d.ts.map +1 -1
  128. package/build-types/components/widget-preview-chrome/index.d.ts +3 -0
  129. package/build-types/components/widget-preview-chrome/index.d.ts.map +1 -0
  130. package/build-types/components/widget-preview-chrome/widget-preview-chrome.d.ts +15 -0
  131. package/build-types/components/widget-preview-chrome/widget-preview-chrome.d.ts.map +1 -0
  132. package/build-types/components/widget-settings/index.d.ts +2 -2
  133. package/build-types/components/widget-settings/utils/index.d.ts +0 -1
  134. package/build-types/components/widget-settings/utils/index.d.ts.map +1 -1
  135. package/build-types/components/widget-settings/widget-settings-trigger.d.ts +4 -3
  136. package/build-types/components/widget-settings/widget-settings-trigger.d.ts.map +1 -1
  137. package/build-types/components/widget-settings/widget-settings.d.ts +2 -2
  138. package/build-types/components/widget-settings/widget-settings.d.ts.map +1 -1
  139. package/build-types/components/widget-toolbar/widget-toolbar.d.ts +10 -7
  140. package/build-types/components/widget-toolbar/widget-toolbar.d.ts.map +1 -1
  141. package/build-types/components/widgets/widgets.d.ts.map +1 -1
  142. package/build-types/context/dashboard-context.d.ts +23 -40
  143. package/build-types/context/dashboard-context.d.ts.map +1 -1
  144. package/build-types/context/ui-context.d.ts +0 -18
  145. package/build-types/context/ui-context.d.ts.map +1 -1
  146. package/build-types/types.d.ts +9 -15
  147. package/build-types/types.d.ts.map +1 -1
  148. package/build-types/utils/index.d.ts +0 -1
  149. package/build-types/utils/index.d.ts.map +1 -1
  150. package/build-types/widget-dashboard.d.ts +5 -5
  151. package/build-types/widget-dashboard.d.ts.map +1 -1
  152. package/package.json +17 -17
  153. package/src/components/actions/actions.tsx +2 -22
  154. package/src/components/commands/commands.tsx +3 -70
  155. package/src/components/widget-attribute-controls/index.ts +1 -0
  156. package/src/components/widget-attribute-controls/widget-attribute-controls.tsx +108 -0
  157. package/src/components/widget-chrome/widget-chrome.module.css +3 -68
  158. package/src/components/widget-chrome/widget-chrome.tsx +19 -130
  159. package/src/components/widget-frame/index.ts +2 -0
  160. package/src/components/widget-frame/widget-frame.module.css +17 -0
  161. package/src/components/widget-frame/widget-frame.tsx +138 -0
  162. package/src/components/widget-header/index.ts +2 -0
  163. package/src/components/widget-header/widget-header-infotip.tsx +82 -0
  164. package/src/components/widget-header/widget-header.module.css +76 -0
  165. package/src/components/widget-header/widget-header.tsx +101 -0
  166. package/src/components/widget-layout-controls/index.ts +2 -0
  167. package/src/components/{widgets/widget-layout-toolbar.tsx → widget-layout-controls/widget-layout-controls.tsx} +12 -13
  168. package/src/components/widget-picker/widget-picker.tsx +5 -10
  169. package/src/components/widget-preview-chrome/index.ts +2 -0
  170. package/src/components/widget-preview-chrome/widget-preview-chrome.module.css +22 -0
  171. package/src/components/widget-preview-chrome/widget-preview-chrome.tsx +65 -0
  172. package/src/components/widget-settings/index.ts +2 -2
  173. package/src/components/widget-settings/utils/index.ts +0 -1
  174. package/src/components/widget-settings/widget-settings-trigger.tsx +36 -43
  175. package/src/components/widget-settings/widget-settings.tsx +7 -26
  176. package/src/components/widget-toolbar/widget-toolbar.module.css +6 -9
  177. package/src/components/widget-toolbar/widget-toolbar.tsx +14 -8
  178. package/src/components/widgets/widgets.module.css +0 -1
  179. package/src/components/widgets/widgets.tsx +30 -8
  180. package/src/context/dashboard-context.tsx +70 -133
  181. package/src/context/ui-context.tsx +1 -39
  182. package/src/test/actions.test.tsx +7 -77
  183. package/src/test/commands.test.tsx +6 -45
  184. package/src/test/staging.test.tsx +82 -144
  185. package/src/test/widget-dashboard.test.tsx +24 -0
  186. package/src/types.ts +9 -16
  187. package/src/utils/index.ts +0 -1
  188. package/src/widget-dashboard.tsx +4 -8
  189. package/build/components/layout-settings/index.cjs.map +0 -7
  190. package/build/components/layout-settings/layout-model-edit-field/index.cjs +0 -186
  191. package/build/components/layout-settings/layout-model-edit-field/index.cjs.map +0 -7
  192. package/build/components/layout-settings/layout-model-edit-field/thumbnail-grid.cjs +0 -53
  193. package/build/components/layout-settings/layout-model-edit-field/thumbnail-grid.cjs.map +0 -7
  194. package/build/components/layout-settings/layout-model-edit-field/thumbnail-masonry.cjs +0 -53
  195. package/build/components/layout-settings/layout-model-edit-field/thumbnail-masonry.cjs.map +0 -7
  196. package/build/components/layout-settings/layout-settings.cjs +0 -207
  197. package/build/components/layout-settings/layout-settings.cjs.map +0 -7
  198. package/build/components/widget-settings/utils/get-admin-menu-inset.cjs.map +0 -7
  199. package/build/components/widget-settings/widget-settings-toolbar.cjs.map +0 -7
  200. package/build/components/widgets/widget-layout-toolbar.cjs.map +0 -7
  201. package/build/utils/grid-model-change/grid-model-change.cjs +0 -56
  202. package/build/utils/grid-model-change/grid-model-change.cjs.map +0 -7
  203. package/build/utils/grid-model-change/index.cjs.map +0 -7
  204. package/build/utils/migrate-layout/index.cjs.map +0 -7
  205. package/build/utils/migrate-layout/migrate-layout.cjs +0 -94
  206. package/build/utils/migrate-layout/migrate-layout.cjs.map +0 -7
  207. package/build-module/components/layout-settings/index.mjs +0 -6
  208. package/build-module/components/layout-settings/index.mjs.map +0 -7
  209. package/build-module/components/layout-settings/layout-model-edit-field/index.mjs +0 -151
  210. package/build-module/components/layout-settings/layout-model-edit-field/index.mjs.map +0 -7
  211. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-grid.mjs +0 -28
  212. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-grid.mjs.map +0 -7
  213. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-masonry.mjs +0 -28
  214. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-masonry.mjs.map +0 -7
  215. package/build-module/components/layout-settings/layout-settings.mjs +0 -187
  216. package/build-module/components/layout-settings/layout-settings.mjs.map +0 -7
  217. package/build-module/components/widget-settings/utils/get-admin-menu-inset.mjs +0 -16
  218. package/build-module/components/widget-settings/utils/get-admin-menu-inset.mjs.map +0 -7
  219. package/build-module/components/widget-settings/widget-settings-toolbar.mjs.map +0 -7
  220. package/build-module/components/widgets/widget-layout-toolbar.mjs +0 -181
  221. package/build-module/components/widgets/widget-layout-toolbar.mjs.map +0 -7
  222. package/build-module/utils/grid-model-change/grid-model-change.mjs +0 -30
  223. package/build-module/utils/grid-model-change/grid-model-change.mjs.map +0 -7
  224. package/build-module/utils/grid-model-change/index.mjs +0 -7
  225. package/build-module/utils/grid-model-change/index.mjs.map +0 -7
  226. package/build-module/utils/migrate-layout/index.mjs +0 -6
  227. package/build-module/utils/migrate-layout/index.mjs.map +0 -7
  228. package/build-module/utils/migrate-layout/migrate-layout.mjs +0 -69
  229. package/build-module/utils/migrate-layout/migrate-layout.mjs.map +0 -7
  230. package/build-types/components/layout-settings/index.d.ts +0 -2
  231. package/build-types/components/layout-settings/index.d.ts.map +0 -1
  232. package/build-types/components/layout-settings/layout-model-edit-field/index.d.ts +0 -17
  233. package/build-types/components/layout-settings/layout-model-edit-field/index.d.ts.map +0 -1
  234. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-grid.d.ts +0 -6
  235. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-grid.d.ts.map +0 -1
  236. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-masonry.d.ts +0 -6
  237. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-masonry.d.ts.map +0 -1
  238. package/build-types/components/layout-settings/layout-settings.d.ts +0 -14
  239. package/build-types/components/layout-settings/layout-settings.d.ts.map +0 -1
  240. package/build-types/components/widget-settings/utils/get-admin-menu-inset.d.ts +0 -17
  241. package/build-types/components/widget-settings/utils/get-admin-menu-inset.d.ts.map +0 -1
  242. package/build-types/components/widget-settings/widget-settings-toolbar.d.ts +0 -20
  243. package/build-types/components/widget-settings/widget-settings-toolbar.d.ts.map +0 -1
  244. package/build-types/components/widgets/widget-layout-toolbar.d.ts +0 -14
  245. package/build-types/components/widgets/widget-layout-toolbar.d.ts.map +0 -1
  246. package/build-types/utils/grid-model-change/grid-model-change.d.ts +0 -20
  247. package/build-types/utils/grid-model-change/grid-model-change.d.ts.map +0 -1
  248. package/build-types/utils/grid-model-change/index.d.ts +0 -2
  249. package/build-types/utils/grid-model-change/index.d.ts.map +0 -1
  250. package/build-types/utils/migrate-layout/index.d.ts +0 -2
  251. package/build-types/utils/migrate-layout/index.d.ts.map +0 -1
  252. package/build-types/utils/migrate-layout/migrate-layout.d.ts +0 -36
  253. package/build-types/utils/migrate-layout/migrate-layout.d.ts.map +0 -1
  254. package/src/components/layout-settings/index.ts +0 -1
  255. package/src/components/layout-settings/layout-model-edit-field/index.tsx +0 -98
  256. package/src/components/layout-settings/layout-model-edit-field/style.module.css +0 -34
  257. package/src/components/layout-settings/layout-model-edit-field/thumbnail-grid.tsx +0 -28
  258. package/src/components/layout-settings/layout-model-edit-field/thumbnail-masonry.tsx +0 -28
  259. package/src/components/layout-settings/layout-settings.tsx +0 -217
  260. package/src/components/widget-picker/widget-picker.module.css +0 -11
  261. package/src/components/widget-settings/utils/get-admin-menu-inset.ts +0 -30
  262. package/src/components/widget-settings/widget-settings-toolbar.module.css +0 -25
  263. package/src/components/widget-settings/widget-settings-toolbar.tsx +0 -45
  264. package/src/components/widgets/widget-layout-toolbar.module.css +0 -6
  265. package/src/utils/grid-model-change/grid-model-change.ts +0 -53
  266. package/src/utils/grid-model-change/index.ts +0 -1
  267. package/src/utils/migrate-layout/index.ts +0 -1
  268. package/src/utils/migrate-layout/migrate-layout.ts +0 -156
  269. package/src/utils/migrate-layout/test/migrate-layout.test.ts +0 -114
@@ -1,30 +0,0 @@
1
- // cspell:ignore adminmenuback
2
- const ADMIN_MENU_ID = 'adminmenuback';
3
-
4
- /**
5
- * Width, in pixels, taken up by the WordPress admin menu
6
- * (`#adminmenuback`) on the inline-start edge of the viewport.
7
- *
8
- * The settings drawer portals to the document body and anchors to a
9
- * viewport edge, so a left-anchored drawer would slide over the fixed
10
- * admin menu. Offsetting the drawer by this value keeps the menu
11
- * uncovered (and reachable) instead of raising the drawer's z-index over
12
- * it.
13
- *
14
- * Defensive: returns `0` when the element is absent (outside wp-admin, or
15
- * in tests/Storybook), so the drawer just anchors to the viewport edge.
16
- *
17
- * @return {number} The admin menu's right edge in px, or `0`.
18
- */
19
- export function getAdminMenuInset(): number {
20
- if ( typeof document === 'undefined' ) {
21
- return 0;
22
- }
23
-
24
- const adminMenu = document.getElementById( ADMIN_MENU_ID );
25
- if ( ! adminMenu ) {
26
- return 0;
27
- }
28
-
29
- return Math.max( 0, adminMenu.getBoundingClientRect().right );
30
- }
@@ -1,25 +0,0 @@
1
- /* Translucent surface so the gear stays legible over any widget background. */
2
- .widgetSettingsToolbar {
3
- background: color-mix(in srgb, var(--wpds-color-background-surface-neutral) 40%, transparent);
4
- opacity: 0;
5
- pointer-events: none;
6
- }
7
-
8
- /*
9
- * Revealed on tile hover or focus. Hidden with opacity, not display, so the
10
- * gear stays in the tab order and `:focus-within` surfaces it for keyboard
11
- * users. The matched ancestor is the grid item, shared by the slot and card.
12
- */
13
- :global([data-wp-grid-item-key]):hover .widgetSettingsToolbar,
14
- :global([data-wp-grid-item-key]):focus-within .widgetSettingsToolbar {
15
- opacity: 1;
16
- pointer-events: auto;
17
- }
18
-
19
- @media not ( prefers-reduced-motion ) {
20
- .widgetSettingsToolbar {
21
- transition:
22
- opacity var(--wpds-motion-duration-sm)
23
- var(--wpds-motion-easing-subtle);
24
- }
25
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import type { WidgetType } from '@wordpress/widget-primitives';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { WidgetToolbar } from '../widget-toolbar';
10
- import { WidgetSettingsTrigger } from './widget-settings-trigger';
11
- import styles from './widget-settings-toolbar.module.css';
12
- import type { DashboardWidget } from '../../types';
13
-
14
- export interface WidgetSettingsToolbarProps {
15
- /** The instance whose settings this toolbar configures. */
16
- widget: DashboardWidget< unknown >;
17
-
18
- /** The instance's widget type, for the trigger label and guard. */
19
- widgetType: WidgetType;
20
- }
21
-
22
- /**
23
- * Normal-mode per-tile toolbar: the gear that opens the settings drawer. Lives
24
- * in the grid's `actionableArea` slot, so it shows for every `presentation`.
25
- * Returns `null` when the type has no attributes.
26
- *
27
- * @param {WidgetSettingsToolbarProps} props Component props.
28
- */
29
- export function WidgetSettingsToolbar( {
30
- widget,
31
- widgetType,
32
- }: WidgetSettingsToolbarProps ): React.ReactNode {
33
- if ( ! widgetType.attributes?.length ) {
34
- return null;
35
- }
36
-
37
- return (
38
- <WidgetToolbar className={ styles.widgetSettingsToolbar }>
39
- <WidgetSettingsTrigger
40
- widget={ widget }
41
- widgetType={ widgetType }
42
- />
43
- </WidgetToolbar>
44
- );
45
- }
@@ -1,6 +0,0 @@
1
- /* Solid surface: shown for the whole customize session, not on hover. */
2
- .widgetLayoutToolbar {
3
- background: var(--wpds-color-background-surface-neutral-strong);
4
- border: 1px solid var(--wpds-color-stroke-surface-neutral-weak);
5
- box-shadow: var(--wpds-elevation-xs);
6
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { migrateLayout } from '../migrate-layout';
5
- import type {
6
- DashboardWidget,
7
- WidgetGridModel,
8
- WidgetGridSettings,
9
- } from '../../types';
10
- import { WIDGET_DASHBOARD_COLUMN_COUNT } from '../../types';
11
-
12
- export function getGridModel( settings: WidgetGridSettings ): WidgetGridModel {
13
- return settings.model ?? 'grid';
14
- }
15
-
16
- type ComputeGridModelChangeProps = {
17
- layout: DashboardWidget[];
18
- gridSettings: WidgetGridSettings;
19
- targetModel: WidgetGridModel;
20
- };
21
-
22
- type ComputeGridModelChangeResult = {
23
- layout: DashboardWidget[];
24
- gridSettings: WidgetGridSettings;
25
- } | null;
26
-
27
- /**
28
- * Computes the staged layout and grid settings after a layout-model change.
29
- *
30
- * @param {ComputeGridModelChangeProps} params Layout, current settings, and target model.
31
- * @return {ComputeGridModelChangeResult} Migrated layout and settings, or `null` when the model is unchanged.
32
- */
33
- export function computeGridModelChange( {
34
- layout,
35
- gridSettings,
36
- targetModel,
37
- }: ComputeGridModelChangeProps ): ComputeGridModelChangeResult {
38
- const currentModel = getGridModel( gridSettings );
39
-
40
- if ( currentModel === targetModel ) {
41
- return null;
42
- }
43
-
44
- return {
45
- layout: migrateLayout( layout, currentModel, targetModel, {
46
- columns: WIDGET_DASHBOARD_COLUMN_COUNT,
47
- } ),
48
- gridSettings: {
49
- ...gridSettings,
50
- model: targetModel,
51
- } as WidgetGridSettings,
52
- };
53
- }
@@ -1 +0,0 @@
1
- export { computeGridModelChange, getGridModel } from './grid-model-change';
@@ -1 +0,0 @@
1
- export { migrateLayout } from './migrate-layout';
@@ -1,156 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type {
5
- DashboardWidget,
6
- GridTilePlacement,
7
- MasonryTilePlacement,
8
- WidgetGridModel,
9
- } from '../../types';
10
-
11
- interface MigrationContext {
12
- /**
13
- * Column count of the currently-mounted grid surface. Used to
14
- * resolve `'full'` widths to a concrete numeric span when going
15
- * from the 2D grid model to masonry. When the surface is in
16
- * responsive mode and the runtime column count is unknown,
17
- * callers should pass a sensible fallback (e.g., the default of
18
- * 6 used by `@wordpress/grid`).
19
- */
20
- columns: number;
21
- }
22
-
23
- const FALLBACK_COLUMNS = 6;
24
-
25
- /**
26
- * Coerces a `'fill'`/`'full'`/numeric width into a concrete numeric
27
- * span when migrating from `'grid'` to `'masonry'`. `'fill'` collapses
28
- * to a single column; resolving it against per-row remainder would
29
- * require either DOM measurement or replicating CSS-Grid's auto-flow
30
- * placement, both of which were judged not worth the complexity for
31
- * a one-shot migration the user can correct visually in staging.
32
- *
33
- * @param width Source width from a grid placement.
34
- * @param targetColumns Column count to use for `'full'` widths.
35
- */
36
- function gridWidthToMasonryWidth(
37
- width: GridTilePlacement[ 'width' ],
38
- targetColumns: number
39
- ): number {
40
- if ( width === 'full' ) {
41
- return targetColumns;
42
- }
43
- if ( width === 'fill' || width === undefined ) {
44
- return 1;
45
- }
46
- return width;
47
- }
48
-
49
- /**
50
- * Transforms a single placement from the 2D grid shape to the masonry
51
- * shape. Drops `height` (masonry derives heights from content),
52
- * preserves `order`, leaves `lane` unset so the auto-flow placer
53
- * arranges items by source order.
54
- *
55
- * @param placement Source grid placement.
56
- * @param context Migration context (column count).
57
- */
58
- function migratePlacementGridToMasonry(
59
- placement: GridTilePlacement | undefined,
60
- context: MigrationContext
61
- ): MasonryTilePlacement {
62
- if ( ! placement ) {
63
- return {};
64
- }
65
-
66
- const next: MasonryTilePlacement = {};
67
- const width = gridWidthToMasonryWidth( placement.width, context.columns );
68
- if ( width !== 1 ) {
69
- next.width = width;
70
- }
71
- if ( placement.order !== undefined ) {
72
- next.order = placement.order;
73
- }
74
- return next;
75
- }
76
-
77
- /**
78
- * Transforms a single placement from the masonry shape to the 2D grid
79
- * shape. Preserves the numeric width, drops `lane` (the 2D grid
80
- * auto-packs and has no pin-to-column concept), and seeds `height: 1`
81
- * since masonry never persisted a height. The user is expected to
82
- * resize tiles vertically after the migration.
83
- *
84
- * @param placement Source masonry placement.
85
- */
86
- function migratePlacementMasonryToGrid(
87
- placement: MasonryTilePlacement | undefined
88
- ): GridTilePlacement {
89
- if ( ! placement ) {
90
- return { height: 1 };
91
- }
92
-
93
- const next: GridTilePlacement = { height: 1 };
94
- if ( placement.width !== undefined ) {
95
- next.width = placement.width;
96
- }
97
- if ( placement.order !== undefined ) {
98
- next.order = placement.order;
99
- }
100
- return next;
101
- }
102
-
103
- /**
104
- * Migrates every widget's `placement` between grid models.
105
- *
106
- * The two storage shapes overlap on `width` and `order` but diverge
107
- * on the rest: 2D grid carries `height` and discriminated string
108
- * widths (`'fill'`/`'full'`), lanes carries `lane` and only numeric
109
- * widths. Each conversion loses information that the target model
110
- * cannot represent. The caller is responsible for surfacing the
111
- * result to the user in a way that lets them correct visually.
112
- *
113
- * When `from === to`, the input is returned unchanged.
114
- *
115
- * @param widgets Widgets to migrate.
116
- * @param from Source model. `undefined` is treated as `'grid'`.
117
- * @param to Target model.
118
- * @param context Information that depends on the live render (today
119
- * only `columns`).
120
- */
121
- export function migrateLayout(
122
- widgets: DashboardWidget[],
123
- from: WidgetGridModel | undefined,
124
- to: WidgetGridModel,
125
- context: Partial< MigrationContext > = {}
126
- ): DashboardWidget[] {
127
- const resolvedFrom: WidgetGridModel = from ?? 'grid';
128
- if ( resolvedFrom === to ) {
129
- return widgets;
130
- }
131
-
132
- const resolvedContext: MigrationContext = {
133
- columns: context.columns ?? FALLBACK_COLUMNS,
134
- };
135
-
136
- if ( resolvedFrom === 'grid' && to === 'masonry' ) {
137
- return widgets.map( ( widget ) => ( {
138
- ...widget,
139
- placement: migratePlacementGridToMasonry(
140
- widget.placement as GridTilePlacement | undefined,
141
- resolvedContext
142
- ),
143
- } ) );
144
- }
145
-
146
- if ( resolvedFrom === 'masonry' && to === 'grid' ) {
147
- return widgets.map( ( widget ) => ( {
148
- ...widget,
149
- placement: migratePlacementMasonryToGrid(
150
- widget.placement as MasonryTilePlacement | undefined
151
- ),
152
- } ) );
153
- }
154
-
155
- return widgets;
156
- }
@@ -1,114 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { migrateLayout } from '../migrate-layout';
5
- import type { DashboardWidget } from '../../../types';
6
-
7
- function widget( uuid: string, placement: object | undefined = undefined ) {
8
- return {
9
- uuid,
10
- type: 'core/test' as const,
11
- placement,
12
- } as DashboardWidget;
13
- }
14
-
15
- describe( 'migrateLayout', () => {
16
- it( 'returns input unchanged when source and target match', () => {
17
- const layout: DashboardWidget[] = [
18
- widget( 'a', { width: 2, height: 1 } ),
19
- ];
20
- expect( migrateLayout( layout, 'grid', 'grid' ) ).toBe( layout );
21
- } );
22
-
23
- it( 'treats undefined source as grid', () => {
24
- const layout: DashboardWidget[] = [
25
- widget( 'a', { width: 'full', height: 1 } ),
26
- ];
27
- const migrated = migrateLayout( layout, undefined, 'masonry', {
28
- columns: 4,
29
- } );
30
- expect( migrated[ 0 ].placement ).toEqual( { width: 4 } );
31
- } );
32
-
33
- describe( 'grid to masonry', () => {
34
- it( "expands 'full' to the target column count", () => {
35
- const layout: DashboardWidget[] = [
36
- widget( 'a', { width: 'full', height: 1 } ),
37
- ];
38
- const migrated = migrateLayout( layout, 'grid', 'masonry', {
39
- columns: 6,
40
- } );
41
- expect( migrated[ 0 ].placement ).toEqual( { width: 6 } );
42
- } );
43
-
44
- it( "collapses 'fill' to a single column", () => {
45
- const layout: DashboardWidget[] = [
46
- widget( 'a', { width: 'fill', height: 2 } ),
47
- ];
48
- const migrated = migrateLayout( layout, 'grid', 'masonry', {
49
- columns: 6,
50
- } );
51
- expect( migrated[ 0 ].placement ).toEqual( {} );
52
- } );
53
-
54
- it( 'preserves numeric width and drops height and explicit width=1', () => {
55
- const layout: DashboardWidget[] = [
56
- widget( 'a', { width: 3, height: 2, order: 5 } ),
57
- widget( 'b', { width: 1, height: 1 } ),
58
- ];
59
- const migrated = migrateLayout( layout, 'grid', 'masonry', {
60
- columns: 6,
61
- } );
62
- expect( migrated[ 0 ].placement ).toEqual( {
63
- width: 3,
64
- order: 5,
65
- } );
66
- expect( migrated[ 1 ].placement ).toEqual( {} );
67
- } );
68
-
69
- it( 'falls back to a default column count when not provided', () => {
70
- const layout: DashboardWidget[] = [
71
- widget( 'a', { width: 'full', height: 1 } ),
72
- ];
73
- const migrated = migrateLayout( layout, 'grid', 'masonry' );
74
- expect( migrated[ 0 ].placement ).toEqual( { width: 6 } );
75
- } );
76
-
77
- it( 'handles widgets without a placement', () => {
78
- const layout: DashboardWidget[] = [ widget( 'a' ) ];
79
- const migrated = migrateLayout( layout, 'grid', 'masonry' );
80
- expect( migrated[ 0 ].placement ).toEqual( {} );
81
- } );
82
- } );
83
-
84
- describe( 'masonry to grid', () => {
85
- it( 'seeds height=1 and preserves width and order', () => {
86
- const layout: DashboardWidget[] = [
87
- widget( 'a', { width: 2, order: 1 } ),
88
- ];
89
- const migrated = migrateLayout( layout, 'masonry', 'grid' );
90
- expect( migrated[ 0 ].placement ).toEqual( {
91
- width: 2,
92
- height: 1,
93
- order: 1,
94
- } );
95
- } );
96
-
97
- it( 'drops the lane field', () => {
98
- const layout: DashboardWidget[] = [
99
- widget( 'a', { width: 1, lane: 2 } ),
100
- ];
101
- const migrated = migrateLayout( layout, 'masonry', 'grid' );
102
- expect( migrated[ 0 ].placement ).toEqual( {
103
- width: 1,
104
- height: 1,
105
- } );
106
- } );
107
-
108
- it( 'handles widgets without a placement', () => {
109
- const layout: DashboardWidget[] = [ widget( 'a' ) ];
110
- const migrated = migrateLayout( layout, 'masonry', 'grid' );
111
- expect( migrated[ 0 ].placement ).toEqual( { height: 1 } );
112
- } );
113
- } );
114
- } );