@wordpress/widget-dashboard 0.1.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 (443) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +241 -0
  4. package/build/components/actions/actions.cjs +265 -0
  5. package/build/components/actions/actions.cjs.map +7 -0
  6. package/build/components/actions/index.cjs +31 -0
  7. package/build/components/actions/index.cjs.map +7 -0
  8. package/build/components/actions-menu/actions-menu.cjs +92 -0
  9. package/build/components/actions-menu/actions-menu.cjs.map +7 -0
  10. package/build/components/actions-menu/index.cjs +31 -0
  11. package/build/components/actions-menu/index.cjs.map +7 -0
  12. package/build/components/commands/commands.cjs +177 -0
  13. package/build/components/commands/commands.cjs.map +7 -0
  14. package/build/components/commands/index.cjs +33 -0
  15. package/build/components/commands/index.cjs.map +7 -0
  16. package/build/components/commands/use-pending-when-edit-mode.cjs +57 -0
  17. package/build/components/commands/use-pending-when-edit-mode.cjs.map +7 -0
  18. package/build/components/layout-settings/index.cjs +31 -0
  19. package/build/components/layout-settings/index.cjs.map +7 -0
  20. package/build/components/layout-settings/layout-model-edit-field/index.cjs +186 -0
  21. package/build/components/layout-settings/layout-model-edit-field/index.cjs.map +7 -0
  22. package/build/components/layout-settings/layout-model-edit-field/thumbnail-grid.cjs +53 -0
  23. package/build/components/layout-settings/layout-model-edit-field/thumbnail-grid.cjs.map +7 -0
  24. package/build/components/layout-settings/layout-model-edit-field/thumbnail-masonry.cjs +53 -0
  25. package/build/components/layout-settings/layout-model-edit-field/thumbnail-masonry.cjs.map +7 -0
  26. package/build/components/layout-settings/layout-settings.cjs +207 -0
  27. package/build/components/layout-settings/layout-settings.cjs.map +7 -0
  28. package/build/components/no-widgets-state/index.cjs +31 -0
  29. package/build/components/no-widgets-state/index.cjs.map +7 -0
  30. package/build/components/no-widgets-state/no-widgets-state.cjs +140 -0
  31. package/build/components/no-widgets-state/no-widgets-state.cjs.map +7 -0
  32. package/build/components/reset-confirmation/index.cjs +31 -0
  33. package/build/components/reset-confirmation/index.cjs.map +7 -0
  34. package/build/components/reset-confirmation/reset-confirmation.cjs +62 -0
  35. package/build/components/reset-confirmation/reset-confirmation.cjs.map +7 -0
  36. package/build/components/widget-chrome/index.cjs +31 -0
  37. package/build/components/widget-chrome/index.cjs.map +7 -0
  38. package/build/components/widget-chrome/widget-chrome.cjs +277 -0
  39. package/build/components/widget-chrome/widget-chrome.cjs.map +7 -0
  40. package/build/components/widget-inserter/index.cjs +31 -0
  41. package/build/components/widget-inserter/index.cjs.map +7 -0
  42. package/build/components/widget-inserter/widget-inserter.cjs +78 -0
  43. package/build/components/widget-inserter/widget-inserter.cjs.map +7 -0
  44. package/build/components/widget-picker/index.cjs +31 -0
  45. package/build/components/widget-picker/index.cjs.map +7 -0
  46. package/build/components/widget-picker/widget-picker.cjs +209 -0
  47. package/build/components/widget-picker/widget-picker.cjs.map +7 -0
  48. package/build/components/widget-render/index.cjs +31 -0
  49. package/build/components/widget-render/index.cjs.map +7 -0
  50. package/build/components/widget-render/widget-render.cjs +62 -0
  51. package/build/components/widget-render/widget-render.cjs.map +7 -0
  52. package/build/components/widget-settings/index.cjs +37 -0
  53. package/build/components/widget-settings/index.cjs.map +7 -0
  54. package/build/components/widget-settings/utils/get-admin-menu-inset.cjs +41 -0
  55. package/build/components/widget-settings/utils/get-admin-menu-inset.cjs.map +7 -0
  56. package/build/components/widget-settings/utils/get-widget-settings.cjs +38 -0
  57. package/build/components/widget-settings/utils/get-widget-settings.cjs.map +7 -0
  58. package/build/components/widget-settings/utils/index.cjs +34 -0
  59. package/build/components/widget-settings/utils/index.cjs.map +7 -0
  60. package/build/components/widget-settings/widget-settings-toolbar.cjs +138 -0
  61. package/build/components/widget-settings/widget-settings-toolbar.cjs.map +7 -0
  62. package/build/components/widget-settings/widget-settings-trigger.cjs +82 -0
  63. package/build/components/widget-settings/widget-settings-trigger.cjs.map +7 -0
  64. package/build/components/widget-settings/widget-settings.cjs +269 -0
  65. package/build/components/widget-settings/widget-settings.cjs.map +7 -0
  66. package/build/components/widget-toolbar/index.cjs +31 -0
  67. package/build/components/widget-toolbar/index.cjs.map +7 -0
  68. package/build/components/widget-toolbar/widget-toolbar.cjs +148 -0
  69. package/build/components/widget-toolbar/widget-toolbar.cjs.map +7 -0
  70. package/build/components/widgets/index.cjs +31 -0
  71. package/build/components/widgets/index.cjs.map +7 -0
  72. package/build/components/widgets/widget-layout-toolbar.cjs +206 -0
  73. package/build/components/widgets/widget-layout-toolbar.cjs.map +7 -0
  74. package/build/components/widgets/widget-resize-handle.cjs +163 -0
  75. package/build/components/widgets/widget-resize-handle.cjs.map +7 -0
  76. package/build/components/widgets/widgets.cjs +277 -0
  77. package/build/components/widgets/widgets.cjs.map +7 -0
  78. package/build/context/dashboard-context.cjs +234 -0
  79. package/build/context/dashboard-context.cjs.map +7 -0
  80. package/build/context/ui-context.cjs +77 -0
  81. package/build/context/ui-context.cjs.map +7 -0
  82. package/build/context/widget-context.cjs +44 -0
  83. package/build/context/widget-context.cjs.map +7 -0
  84. package/build/hooks/use-dashboard-container-column-count.cjs +61 -0
  85. package/build/hooks/use-dashboard-container-column-count.cjs.map +7 -0
  86. package/build/index.cjs +45 -0
  87. package/build/index.cjs.map +7 -0
  88. package/build/lock-unlock.cjs +37 -0
  89. package/build/lock-unlock.cjs.map +7 -0
  90. package/build/types.cjs +31 -0
  91. package/build/types.cjs.map +7 -0
  92. package/build/utils/create-dashboard-widget/create-dashboard-widget.cjs +44 -0
  93. package/build/utils/create-dashboard-widget/create-dashboard-widget.cjs.map +7 -0
  94. package/build/utils/create-dashboard-widget/index.cjs +31 -0
  95. package/build/utils/create-dashboard-widget/index.cjs.map +7 -0
  96. package/build/utils/default-grid/default-grid.cjs +37 -0
  97. package/build/utils/default-grid/default-grid.cjs.map +7 -0
  98. package/build/utils/default-grid/index.cjs +31 -0
  99. package/build/utils/default-grid/index.cjs.map +7 -0
  100. package/build/utils/grid-model-change/grid-model-change.cjs +56 -0
  101. package/build/utils/grid-model-change/grid-model-change.cjs.map +7 -0
  102. package/build/utils/grid-model-change/index.cjs +33 -0
  103. package/build/utils/grid-model-change/index.cjs.map +7 -0
  104. package/build/utils/index.cjs +34 -0
  105. package/build/utils/index.cjs.map +7 -0
  106. package/build/utils/migrate-layout/index.cjs +31 -0
  107. package/build/utils/migrate-layout/index.cjs.map +7 -0
  108. package/build/utils/migrate-layout/migrate-layout.cjs +94 -0
  109. package/build/utils/migrate-layout/migrate-layout.cjs.map +7 -0
  110. package/build/utils/normalize-grid-settings/index.cjs +31 -0
  111. package/build/utils/normalize-grid-settings/index.cjs.map +7 -0
  112. package/build/utils/normalize-grid-settings/normalize-grid-settings.cjs +46 -0
  113. package/build/utils/normalize-grid-settings/normalize-grid-settings.cjs.map +7 -0
  114. package/build/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.cjs +49 -0
  115. package/build/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.cjs.map +7 -0
  116. package/build/utils/row-height-presets/index.cjs +39 -0
  117. package/build/utils/row-height-presets/index.cjs.map +7 -0
  118. package/build/utils/row-height-presets/row-height-presets.cjs +63 -0
  119. package/build/utils/row-height-presets/row-height-presets.cjs.map +7 -0
  120. package/build/widget-dashboard.cjs +86 -0
  121. package/build/widget-dashboard.cjs.map +7 -0
  122. package/build/wordpress-commands.d.cjs +2 -0
  123. package/build/wordpress-commands.d.cjs.map +7 -0
  124. package/build-module/components/actions/actions.mjs +240 -0
  125. package/build-module/components/actions/actions.mjs.map +7 -0
  126. package/build-module/components/actions/index.mjs +6 -0
  127. package/build-module/components/actions/index.mjs.map +7 -0
  128. package/build-module/components/actions-menu/actions-menu.mjs +67 -0
  129. package/build-module/components/actions-menu/actions-menu.mjs.map +7 -0
  130. package/build-module/components/actions-menu/index.mjs +6 -0
  131. package/build-module/components/actions-menu/index.mjs.map +7 -0
  132. package/build-module/components/commands/commands.mjs +160 -0
  133. package/build-module/components/commands/commands.mjs.map +7 -0
  134. package/build-module/components/commands/index.mjs +7 -0
  135. package/build-module/components/commands/index.mjs.map +7 -0
  136. package/build-module/components/commands/use-pending-when-edit-mode.mjs +32 -0
  137. package/build-module/components/commands/use-pending-when-edit-mode.mjs.map +7 -0
  138. package/build-module/components/layout-settings/index.mjs +6 -0
  139. package/build-module/components/layout-settings/index.mjs.map +7 -0
  140. package/build-module/components/layout-settings/layout-model-edit-field/index.mjs +151 -0
  141. package/build-module/components/layout-settings/layout-model-edit-field/index.mjs.map +7 -0
  142. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-grid.mjs +28 -0
  143. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-grid.mjs.map +7 -0
  144. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-masonry.mjs +28 -0
  145. package/build-module/components/layout-settings/layout-model-edit-field/thumbnail-masonry.mjs.map +7 -0
  146. package/build-module/components/layout-settings/layout-settings.mjs +187 -0
  147. package/build-module/components/layout-settings/layout-settings.mjs.map +7 -0
  148. package/build-module/components/no-widgets-state/index.mjs +6 -0
  149. package/build-module/components/no-widgets-state/index.mjs.map +7 -0
  150. package/build-module/components/no-widgets-state/no-widgets-state.mjs +115 -0
  151. package/build-module/components/no-widgets-state/no-widgets-state.mjs.map +7 -0
  152. package/build-module/components/reset-confirmation/index.mjs +6 -0
  153. package/build-module/components/reset-confirmation/index.mjs.map +7 -0
  154. package/build-module/components/reset-confirmation/reset-confirmation.mjs +37 -0
  155. package/build-module/components/reset-confirmation/reset-confirmation.mjs.map +7 -0
  156. package/build-module/components/widget-chrome/index.mjs +6 -0
  157. package/build-module/components/widget-chrome/index.mjs.map +7 -0
  158. package/build-module/components/widget-chrome/widget-chrome.mjs +248 -0
  159. package/build-module/components/widget-chrome/widget-chrome.mjs.map +7 -0
  160. package/build-module/components/widget-inserter/index.mjs +6 -0
  161. package/build-module/components/widget-inserter/index.mjs.map +7 -0
  162. package/build-module/components/widget-inserter/widget-inserter.mjs +53 -0
  163. package/build-module/components/widget-inserter/widget-inserter.mjs.map +7 -0
  164. package/build-module/components/widget-picker/index.mjs +6 -0
  165. package/build-module/components/widget-picker/index.mjs.map +7 -0
  166. package/build-module/components/widget-picker/widget-picker.mjs +184 -0
  167. package/build-module/components/widget-picker/widget-picker.mjs.map +7 -0
  168. package/build-module/components/widget-render/index.mjs +6 -0
  169. package/build-module/components/widget-render/index.mjs.map +7 -0
  170. package/build-module/components/widget-render/widget-render.mjs +37 -0
  171. package/build-module/components/widget-render/widget-render.mjs.map +7 -0
  172. package/build-module/components/widget-settings/index.mjs +10 -0
  173. package/build-module/components/widget-settings/index.mjs.map +7 -0
  174. package/build-module/components/widget-settings/utils/get-admin-menu-inset.mjs +16 -0
  175. package/build-module/components/widget-settings/utils/get-admin-menu-inset.mjs.map +7 -0
  176. package/build-module/components/widget-settings/utils/get-widget-settings.mjs +13 -0
  177. package/build-module/components/widget-settings/utils/get-widget-settings.mjs.map +7 -0
  178. package/build-module/components/widget-settings/utils/index.mjs +8 -0
  179. package/build-module/components/widget-settings/utils/index.mjs.map +7 -0
  180. package/build-module/components/widget-settings/widget-settings-toolbar.mjs +113 -0
  181. package/build-module/components/widget-settings/widget-settings-toolbar.mjs.map +7 -0
  182. package/build-module/components/widget-settings/widget-settings-trigger.mjs +57 -0
  183. package/build-module/components/widget-settings/widget-settings-trigger.mjs.map +7 -0
  184. package/build-module/components/widget-settings/widget-settings.mjs +244 -0
  185. package/build-module/components/widget-settings/widget-settings.mjs.map +7 -0
  186. package/build-module/components/widget-toolbar/index.mjs +6 -0
  187. package/build-module/components/widget-toolbar/index.mjs.map +7 -0
  188. package/build-module/components/widget-toolbar/widget-toolbar.mjs +113 -0
  189. package/build-module/components/widget-toolbar/widget-toolbar.mjs.map +7 -0
  190. package/build-module/components/widgets/index.mjs +6 -0
  191. package/build-module/components/widgets/index.mjs.map +7 -0
  192. package/build-module/components/widgets/widget-layout-toolbar.mjs +181 -0
  193. package/build-module/components/widgets/widget-layout-toolbar.mjs.map +7 -0
  194. package/build-module/components/widgets/widget-resize-handle.mjs +128 -0
  195. package/build-module/components/widgets/widget-resize-handle.mjs.map +7 -0
  196. package/build-module/components/widgets/widgets.mjs +242 -0
  197. package/build-module/components/widgets/widgets.mjs.map +7 -0
  198. package/build-module/context/dashboard-context.mjs +205 -0
  199. package/build-module/context/dashboard-context.mjs.map +7 -0
  200. package/build-module/context/ui-context.mjs +56 -0
  201. package/build-module/context/ui-context.mjs.map +7 -0
  202. package/build-module/context/widget-context.mjs +18 -0
  203. package/build-module/context/widget-context.mjs.map +7 -0
  204. package/build-module/hooks/use-dashboard-container-column-count.mjs +40 -0
  205. package/build-module/hooks/use-dashboard-container-column-count.mjs.map +7 -0
  206. package/build-module/index.mjs +18 -0
  207. package/build-module/index.mjs.map +7 -0
  208. package/build-module/lock-unlock.mjs +11 -0
  209. package/build-module/lock-unlock.mjs.map +7 -0
  210. package/build-module/types.mjs +6 -0
  211. package/build-module/types.mjs.map +7 -0
  212. package/build-module/utils/create-dashboard-widget/create-dashboard-widget.mjs +19 -0
  213. package/build-module/utils/create-dashboard-widget/create-dashboard-widget.mjs.map +7 -0
  214. package/build-module/utils/create-dashboard-widget/index.mjs +6 -0
  215. package/build-module/utils/create-dashboard-widget/index.mjs.map +7 -0
  216. package/build-module/utils/default-grid/default-grid.mjs +12 -0
  217. package/build-module/utils/default-grid/default-grid.mjs.map +7 -0
  218. package/build-module/utils/default-grid/index.mjs +6 -0
  219. package/build-module/utils/default-grid/index.mjs.map +7 -0
  220. package/build-module/utils/grid-model-change/grid-model-change.mjs +30 -0
  221. package/build-module/utils/grid-model-change/grid-model-change.mjs.map +7 -0
  222. package/build-module/utils/grid-model-change/index.mjs +7 -0
  223. package/build-module/utils/grid-model-change/index.mjs.map +7 -0
  224. package/build-module/utils/index.mjs +8 -0
  225. package/build-module/utils/index.mjs.map +7 -0
  226. package/build-module/utils/migrate-layout/index.mjs +6 -0
  227. package/build-module/utils/migrate-layout/index.mjs.map +7 -0
  228. package/build-module/utils/migrate-layout/migrate-layout.mjs +69 -0
  229. package/build-module/utils/migrate-layout/migrate-layout.mjs.map +7 -0
  230. package/build-module/utils/normalize-grid-settings/index.mjs +6 -0
  231. package/build-module/utils/normalize-grid-settings/index.mjs.map +7 -0
  232. package/build-module/utils/normalize-grid-settings/normalize-grid-settings.mjs +21 -0
  233. package/build-module/utils/normalize-grid-settings/normalize-grid-settings.mjs.map +7 -0
  234. package/build-module/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.mjs +22 -0
  235. package/build-module/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.mjs.map +7 -0
  236. package/build-module/utils/row-height-presets/index.mjs +16 -0
  237. package/build-module/utils/row-height-presets/index.mjs.map +7 -0
  238. package/build-module/utils/row-height-presets/row-height-presets.mjs +34 -0
  239. package/build-module/utils/row-height-presets/row-height-presets.mjs.map +7 -0
  240. package/build-module/widget-dashboard.mjs +61 -0
  241. package/build-module/widget-dashboard.mjs.map +7 -0
  242. package/build-module/wordpress-commands.d.mjs +1 -0
  243. package/build-module/wordpress-commands.d.mjs.map +7 -0
  244. package/build-types/components/actions/actions.d.ts +11 -0
  245. package/build-types/components/actions/actions.d.ts.map +1 -0
  246. package/build-types/components/actions/index.d.ts +2 -0
  247. package/build-types/components/actions/index.d.ts.map +1 -0
  248. package/build-types/components/actions-menu/actions-menu.d.ts +22 -0
  249. package/build-types/components/actions-menu/actions-menu.d.ts.map +1 -0
  250. package/build-types/components/actions-menu/index.d.ts +3 -0
  251. package/build-types/components/actions-menu/index.d.ts.map +1 -0
  252. package/build-types/components/commands/commands.d.ts +7 -0
  253. package/build-types/components/commands/commands.d.ts.map +1 -0
  254. package/build-types/components/commands/index.d.ts +2 -0
  255. package/build-types/components/commands/index.d.ts.map +1 -0
  256. package/build-types/components/commands/use-pending-when-edit-mode.d.ts +15 -0
  257. package/build-types/components/commands/use-pending-when-edit-mode.d.ts.map +1 -0
  258. package/build-types/components/layout-settings/index.d.ts +2 -0
  259. package/build-types/components/layout-settings/index.d.ts.map +1 -0
  260. package/build-types/components/layout-settings/layout-model-edit-field/index.d.ts +17 -0
  261. package/build-types/components/layout-settings/layout-model-edit-field/index.d.ts.map +1 -0
  262. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-grid.d.ts +6 -0
  263. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-grid.d.ts.map +1 -0
  264. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-masonry.d.ts +6 -0
  265. package/build-types/components/layout-settings/layout-model-edit-field/thumbnail-masonry.d.ts.map +1 -0
  266. package/build-types/components/layout-settings/layout-settings.d.ts +14 -0
  267. package/build-types/components/layout-settings/layout-settings.d.ts.map +1 -0
  268. package/build-types/components/no-widgets-state/index.d.ts +2 -0
  269. package/build-types/components/no-widgets-state/index.d.ts.map +1 -0
  270. package/build-types/components/no-widgets-state/no-widgets-state.d.ts +17 -0
  271. package/build-types/components/no-widgets-state/no-widgets-state.d.ts.map +1 -0
  272. package/build-types/components/reset-confirmation/index.d.ts +2 -0
  273. package/build-types/components/reset-confirmation/index.d.ts.map +1 -0
  274. package/build-types/components/reset-confirmation/reset-confirmation.d.ts +8 -0
  275. package/build-types/components/reset-confirmation/reset-confirmation.d.ts.map +1 -0
  276. package/build-types/components/widget-chrome/index.d.ts +2 -0
  277. package/build-types/components/widget-chrome/index.d.ts.map +1 -0
  278. package/build-types/components/widget-chrome/widget-chrome.d.ts +22 -0
  279. package/build-types/components/widget-chrome/widget-chrome.d.ts.map +1 -0
  280. package/build-types/components/widget-inserter/index.d.ts +2 -0
  281. package/build-types/components/widget-inserter/index.d.ts.map +1 -0
  282. package/build-types/components/widget-inserter/widget-inserter.d.ts +7 -0
  283. package/build-types/components/widget-inserter/widget-inserter.d.ts.map +1 -0
  284. package/build-types/components/widget-picker/index.d.ts +2 -0
  285. package/build-types/components/widget-picker/index.d.ts.map +1 -0
  286. package/build-types/components/widget-picker/widget-picker.d.ts +26 -0
  287. package/build-types/components/widget-picker/widget-picker.d.ts.map +1 -0
  288. package/build-types/components/widget-render/index.d.ts +2 -0
  289. package/build-types/components/widget-render/index.d.ts.map +1 -0
  290. package/build-types/components/widget-render/widget-render.d.ts +17 -0
  291. package/build-types/components/widget-render/widget-render.d.ts.map +1 -0
  292. package/build-types/components/widget-settings/index.d.ts +5 -0
  293. package/build-types/components/widget-settings/index.d.ts.map +1 -0
  294. package/build-types/components/widget-settings/utils/get-admin-menu-inset.d.ts +17 -0
  295. package/build-types/components/widget-settings/utils/get-admin-menu-inset.d.ts.map +1 -0
  296. package/build-types/components/widget-settings/utils/get-widget-settings.d.ts +10 -0
  297. package/build-types/components/widget-settings/utils/get-widget-settings.d.ts.map +1 -0
  298. package/build-types/components/widget-settings/utils/index.d.ts +3 -0
  299. package/build-types/components/widget-settings/utils/index.d.ts.map +1 -0
  300. package/build-types/components/widget-settings/widget-settings-toolbar.d.ts +20 -0
  301. package/build-types/components/widget-settings/widget-settings-toolbar.d.ts.map +1 -0
  302. package/build-types/components/widget-settings/widget-settings-trigger.d.ts +23 -0
  303. package/build-types/components/widget-settings/widget-settings-trigger.d.ts.map +1 -0
  304. package/build-types/components/widget-settings/widget-settings.d.ts +13 -0
  305. package/build-types/components/widget-settings/widget-settings.d.ts.map +1 -0
  306. package/build-types/components/widget-toolbar/index.d.ts +3 -0
  307. package/build-types/components/widget-toolbar/index.d.ts.map +1 -0
  308. package/build-types/components/widget-toolbar/widget-toolbar.d.ts +16 -0
  309. package/build-types/components/widget-toolbar/widget-toolbar.d.ts.map +1 -0
  310. package/build-types/components/widgets/index.d.ts +2 -0
  311. package/build-types/components/widgets/index.d.ts.map +1 -0
  312. package/build-types/components/widgets/widget-layout-toolbar.d.ts +14 -0
  313. package/build-types/components/widgets/widget-layout-toolbar.d.ts.map +1 -0
  314. package/build-types/components/widgets/widget-resize-handle.d.ts +12 -0
  315. package/build-types/components/widgets/widget-resize-handle.d.ts.map +1 -0
  316. package/build-types/components/widgets/widgets.d.ts +10 -0
  317. package/build-types/components/widgets/widgets.d.ts.map +1 -0
  318. package/build-types/context/dashboard-context.d.ts +111 -0
  319. package/build-types/context/dashboard-context.d.ts.map +1 -0
  320. package/build-types/context/ui-context.d.ts +54 -0
  321. package/build-types/context/ui-context.d.ts.map +1 -0
  322. package/build-types/context/widget-context.d.ts +25 -0
  323. package/build-types/context/widget-context.d.ts.map +1 -0
  324. package/build-types/hooks/use-dashboard-container-column-count.d.ts +15 -0
  325. package/build-types/hooks/use-dashboard-container-column-count.d.ts.map +1 -0
  326. package/build-types/index.d.ts +7 -0
  327. package/build-types/index.d.ts.map +1 -0
  328. package/build-types/lock-unlock.d.ts +2 -0
  329. package/build-types/lock-unlock.d.ts.map +1 -0
  330. package/build-types/types.d.ts +222 -0
  331. package/build-types/types.d.ts.map +1 -0
  332. package/build-types/utils/create-dashboard-widget/create-dashboard-widget.d.ts +20 -0
  333. package/build-types/utils/create-dashboard-widget/create-dashboard-widget.d.ts.map +1 -0
  334. package/build-types/utils/create-dashboard-widget/index.d.ts +2 -0
  335. package/build-types/utils/create-dashboard-widget/index.d.ts.map +1 -0
  336. package/build-types/utils/default-grid/default-grid.d.ts +11 -0
  337. package/build-types/utils/default-grid/default-grid.d.ts.map +1 -0
  338. package/build-types/utils/default-grid/index.d.ts +2 -0
  339. package/build-types/utils/default-grid/index.d.ts.map +1 -0
  340. package/build-types/utils/grid-model-change/grid-model-change.d.ts +20 -0
  341. package/build-types/utils/grid-model-change/grid-model-change.d.ts.map +1 -0
  342. package/build-types/utils/grid-model-change/index.d.ts +2 -0
  343. package/build-types/utils/grid-model-change/index.d.ts.map +1 -0
  344. package/build-types/utils/index.d.ts +3 -0
  345. package/build-types/utils/index.d.ts.map +1 -0
  346. package/build-types/utils/migrate-layout/index.d.ts +2 -0
  347. package/build-types/utils/migrate-layout/index.d.ts.map +1 -0
  348. package/build-types/utils/migrate-layout/migrate-layout.d.ts +36 -0
  349. package/build-types/utils/migrate-layout/migrate-layout.d.ts.map +1 -0
  350. package/build-types/utils/normalize-grid-settings/index.d.ts +2 -0
  351. package/build-types/utils/normalize-grid-settings/index.d.ts.map +1 -0
  352. package/build-types/utils/normalize-grid-settings/normalize-grid-settings.d.ts +11 -0
  353. package/build-types/utils/normalize-grid-settings/normalize-grid-settings.d.ts.map +1 -0
  354. package/build-types/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.d.ts +21 -0
  355. package/build-types/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.d.ts.map +1 -0
  356. package/build-types/utils/row-height-presets/index.d.ts +3 -0
  357. package/build-types/utils/row-height-presets/index.d.ts.map +1 -0
  358. package/build-types/utils/row-height-presets/row-height-presets.d.ts +17 -0
  359. package/build-types/utils/row-height-presets/row-height-presets.d.ts.map +1 -0
  360. package/build-types/widget-dashboard.d.ts +51 -0
  361. package/build-types/widget-dashboard.d.ts.map +1 -0
  362. package/package.json +90 -0
  363. package/src/components/actions/actions.module.css +54 -0
  364. package/src/components/actions/actions.tsx +180 -0
  365. package/src/components/actions/index.ts +1 -0
  366. package/src/components/actions-menu/actions-menu.tsx +104 -0
  367. package/src/components/actions-menu/index.ts +2 -0
  368. package/src/components/commands/commands.tsx +182 -0
  369. package/src/components/commands/index.ts +1 -0
  370. package/src/components/commands/use-pending-when-edit-mode.ts +48 -0
  371. package/src/components/layout-settings/index.ts +1 -0
  372. package/src/components/layout-settings/layout-model-edit-field/index.tsx +98 -0
  373. package/src/components/layout-settings/layout-model-edit-field/style.module.css +34 -0
  374. package/src/components/layout-settings/layout-model-edit-field/thumbnail-grid.tsx +28 -0
  375. package/src/components/layout-settings/layout-model-edit-field/thumbnail-masonry.tsx +28 -0
  376. package/src/components/layout-settings/layout-settings.tsx +217 -0
  377. package/src/components/no-widgets-state/index.ts +1 -0
  378. package/src/components/no-widgets-state/no-widgets-state.module.css +3 -0
  379. package/src/components/no-widgets-state/no-widgets-state.tsx +56 -0
  380. package/src/components/reset-confirmation/index.ts +1 -0
  381. package/src/components/reset-confirmation/reset-confirmation.tsx +44 -0
  382. package/src/components/widget-chrome/index.ts +1 -0
  383. package/src/components/widget-chrome/widget-chrome.module.css +87 -0
  384. package/src/components/widget-chrome/widget-chrome.tsx +255 -0
  385. package/src/components/widget-inserter/index.ts +1 -0
  386. package/src/components/widget-inserter/widget-inserter.tsx +70 -0
  387. package/src/components/widget-picker/index.ts +1 -0
  388. package/src/components/widget-picker/widget-picker.module.css +11 -0
  389. package/src/components/widget-picker/widget-picker.tsx +137 -0
  390. package/src/components/widget-render/index.ts +1 -0
  391. package/src/components/widget-render/widget-render.tsx +58 -0
  392. package/src/components/widget-settings/index.ts +4 -0
  393. package/src/components/widget-settings/utils/get-admin-menu-inset.ts +30 -0
  394. package/src/components/widget-settings/utils/get-widget-settings.ts +22 -0
  395. package/src/components/widget-settings/utils/index.ts +2 -0
  396. package/src/components/widget-settings/widget-settings-toolbar.module.css +25 -0
  397. package/src/components/widget-settings/widget-settings-toolbar.tsx +45 -0
  398. package/src/components/widget-settings/widget-settings-trigger.tsx +96 -0
  399. package/src/components/widget-settings/widget-settings.module.css +8 -0
  400. package/src/components/widget-settings/widget-settings.tsx +200 -0
  401. package/src/components/widget-toolbar/index.ts +2 -0
  402. package/src/components/widget-toolbar/widget-toolbar.module.css +12 -0
  403. package/src/components/widget-toolbar/widget-toolbar.tsx +46 -0
  404. package/src/components/widgets/index.ts +1 -0
  405. package/src/components/widgets/widget-layout-toolbar.module.css +6 -0
  406. package/src/components/widgets/widget-layout-toolbar.tsx +118 -0
  407. package/src/components/widgets/widget-resize-handle.module.css +135 -0
  408. package/src/components/widgets/widget-resize-handle.tsx +60 -0
  409. package/src/components/widgets/widgets.module.css +43 -0
  410. package/src/components/widgets/widgets.tsx +208 -0
  411. package/src/context/dashboard-context.tsx +386 -0
  412. package/src/context/ui-context.tsx +118 -0
  413. package/src/context/widget-context.tsx +45 -0
  414. package/src/hooks/use-dashboard-container-column-count.ts +63 -0
  415. package/src/index.ts +9 -0
  416. package/src/lock-unlock.ts +10 -0
  417. package/src/test/actions.test.tsx +228 -0
  418. package/src/test/commands.test.tsx +176 -0
  419. package/src/test/create-dashboard-widget.test.ts +59 -0
  420. package/src/test/dashboard-context.test.tsx +26 -0
  421. package/src/test/staging.test.tsx +476 -0
  422. package/src/test/widget-dashboard.test.tsx +204 -0
  423. package/src/test/widget-inserter.test.tsx +210 -0
  424. package/src/test/widget-settings.test.tsx +199 -0
  425. package/src/types.ts +260 -0
  426. package/src/utils/create-dashboard-widget/create-dashboard-widget.ts +43 -0
  427. package/src/utils/create-dashboard-widget/index.ts +1 -0
  428. package/src/utils/default-grid/default-grid.ts +17 -0
  429. package/src/utils/default-grid/index.ts +1 -0
  430. package/src/utils/grid-model-change/grid-model-change.ts +53 -0
  431. package/src/utils/grid-model-change/index.ts +1 -0
  432. package/src/utils/index.ts +2 -0
  433. package/src/utils/migrate-layout/index.ts +1 -0
  434. package/src/utils/migrate-layout/migrate-layout.ts +156 -0
  435. package/src/utils/migrate-layout/test/migrate-layout.test.ts +114 -0
  436. package/src/utils/normalize-grid-settings/index.ts +1 -0
  437. package/src/utils/normalize-grid-settings/normalize-grid-settings.ts +38 -0
  438. package/src/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.ts +41 -0
  439. package/src/utils/resolve-dashboard-column-count/test/resolve-dashboard-column-count.test.ts +44 -0
  440. package/src/utils/row-height-presets/index.ts +8 -0
  441. package/src/utils/row-height-presets/row-height-presets.ts +43 -0
  442. package/src/widget-dashboard.tsx +102 -0
  443. package/src/wordpress-commands.d.ts +12 -0
@@ -0,0 +1,476 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import '@testing-library/jest-dom';
5
+ import { act, render } from '@testing-library/react';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { useEffect, useState } from '@wordpress/element';
11
+ import type { WidgetType } from '@wordpress/widget-primitives';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { useDashboardInternalContext } from '../context/dashboard-context';
17
+ import { WidgetDashboard } from '../widget-dashboard';
18
+ import type { DashboardWidget, WidgetGridSettings } from '../types';
19
+
20
+ const widgetTypes: WidgetType[] = [];
21
+
22
+ const initialLayout: DashboardWidget[] = [
23
+ { uuid: 'a', type: 'core/test', placement: { width: 1, height: 1 } },
24
+ { uuid: 'b', type: 'core/test', placement: { width: 1, height: 1 } },
25
+ ];
26
+
27
+ interface ProbeApi {
28
+ layout: DashboardWidget[];
29
+ gridSettings: WidgetGridSettings;
30
+ hasUncommittedChanges: boolean;
31
+ editMode: boolean;
32
+ mutate: ( next: DashboardWidget[] ) => void;
33
+ mutateGridSettings: ( next: WidgetGridSettings ) => void;
34
+ commit: ( options?: { exitEditMode?: boolean } ) => void;
35
+ cancel: ( options?: {
36
+ exitEditMode?: boolean;
37
+ revertLayout?: boolean;
38
+ } ) => void;
39
+ }
40
+
41
+ const probeRef: { current: ProbeApi | null } = { current: null };
42
+
43
+ function Probe() {
44
+ const ctx = useDashboardInternalContext();
45
+ useEffect( () => {
46
+ probeRef.current = {
47
+ layout: ctx.layout,
48
+ gridSettings: ctx.gridSettings,
49
+ hasUncommittedChanges: ctx.hasUncommittedChanges,
50
+ editMode: ctx.editMode,
51
+ mutate: ctx.onLayoutChange,
52
+ mutateGridSettings: ctx.onGridSettingsChange,
53
+ commit: ctx.commit,
54
+ cancel: ctx.cancel,
55
+ };
56
+ } );
57
+ return null;
58
+ }
59
+
60
+ function readProbe(): ProbeApi {
61
+ if ( ! probeRef.current ) {
62
+ throw new Error( 'Probe not mounted yet' );
63
+ }
64
+ return probeRef.current;
65
+ }
66
+
67
+ interface HarnessProps {
68
+ layout: DashboardWidget[];
69
+ onLayoutChange: ( next: DashboardWidget[] ) => void;
70
+ gridSettings?: WidgetGridSettings;
71
+ onGridSettingsChange?: ( next: WidgetGridSettings ) => void;
72
+ }
73
+
74
+ function Harness( {
75
+ layout,
76
+ onLayoutChange,
77
+ gridSettings,
78
+ onGridSettingsChange,
79
+ }: HarnessProps ) {
80
+ const [ editMode, setEditMode ] = useState( true );
81
+
82
+ return (
83
+ <WidgetDashboard
84
+ layout={ layout }
85
+ onLayoutChange={ onLayoutChange }
86
+ gridSettings={ gridSettings }
87
+ onGridSettingsChange={ onGridSettingsChange }
88
+ widgetTypes={ widgetTypes }
89
+ editMode={ editMode }
90
+ onEditChange={ setEditMode }
91
+ >
92
+ <Probe />
93
+ </WidgetDashboard>
94
+ );
95
+ }
96
+
97
+ describe( 'WidgetDashboard staging layer', () => {
98
+ it( 'keeps mutations in staging without firing onLayoutChange', () => {
99
+ const onLayoutChange = jest.fn();
100
+ render(
101
+ <Harness
102
+ layout={ initialLayout }
103
+ onLayoutChange={ onLayoutChange }
104
+ />
105
+ );
106
+
107
+ expect( readProbe().hasUncommittedChanges ).toBe( false );
108
+
109
+ const moved: DashboardWidget[] = [
110
+ { ...initialLayout[ 1 ] },
111
+ { ...initialLayout[ 0 ] },
112
+ ];
113
+
114
+ act( () => {
115
+ readProbe().mutate( moved );
116
+ } );
117
+
118
+ expect( onLayoutChange ).not.toHaveBeenCalled();
119
+ expect( readProbe().hasUncommittedChanges ).toBe( true );
120
+ expect( readProbe().layout.map( ( w ) => w.uuid ) ).toEqual( [
121
+ 'b',
122
+ 'a',
123
+ ] );
124
+ } );
125
+
126
+ it( 'fires onLayoutChange with the staged layout on commit', () => {
127
+ const onLayoutChange = jest.fn();
128
+ render(
129
+ <Harness
130
+ layout={ initialLayout }
131
+ onLayoutChange={ onLayoutChange }
132
+ />
133
+ );
134
+
135
+ const next: DashboardWidget[] = [
136
+ ...initialLayout,
137
+ {
138
+ uuid: 'c',
139
+ type: 'core/test',
140
+ placement: { width: 1, height: 1 },
141
+ },
142
+ ];
143
+
144
+ act( () => {
145
+ readProbe().mutate( next );
146
+ } );
147
+
148
+ act( () => {
149
+ readProbe().commit();
150
+ } );
151
+
152
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
153
+ expect(
154
+ onLayoutChange.mock.calls[ 0 ][ 0 ].map(
155
+ ( w: DashboardWidget ) => w.uuid
156
+ )
157
+ ).toEqual( [ 'a', 'b', 'c' ] );
158
+ } );
159
+
160
+ it( 'restores staging to the committed layout on cancel', () => {
161
+ const onLayoutChange = jest.fn();
162
+ render(
163
+ <Harness
164
+ layout={ initialLayout }
165
+ onLayoutChange={ onLayoutChange }
166
+ />
167
+ );
168
+
169
+ act( () => {
170
+ readProbe().mutate( [ initialLayout[ 0 ] ] );
171
+ } );
172
+
173
+ expect( readProbe().hasUncommittedChanges ).toBe( true );
174
+
175
+ act( () => {
176
+ readProbe().cancel();
177
+ } );
178
+
179
+ expect( readProbe().hasUncommittedChanges ).toBe( false );
180
+ expect( readProbe().layout.map( ( w ) => w.uuid ) ).toEqual( [
181
+ 'a',
182
+ 'b',
183
+ ] );
184
+ expect( onLayoutChange ).not.toHaveBeenCalled();
185
+ } );
186
+
187
+ it( 'reports no uncommitted changes after a swap-and-revert when the visible order is restored', () => {
188
+ const onLayoutChange = jest.fn();
189
+ render(
190
+ <Harness
191
+ layout={ initialLayout }
192
+ onLayoutChange={ onLayoutChange }
193
+ />
194
+ );
195
+
196
+ // Initial: committed has no `order`. After a swap, the grid assigns
197
+ // explicit order values. After re-swapping, the visible order
198
+ // matches initial but the array shape carries explicit orders.
199
+ act( () => {
200
+ readProbe().mutate( [
201
+ {
202
+ ...initialLayout[ 0 ],
203
+ placement: { width: 1, height: 1, order: 0 },
204
+ },
205
+ {
206
+ ...initialLayout[ 1 ],
207
+ placement: { width: 1, height: 1, order: 1 },
208
+ },
209
+ ] );
210
+ } );
211
+
212
+ expect( readProbe().hasUncommittedChanges ).toBe( false );
213
+ } );
214
+
215
+ it( 'commits a canonicalized layout, sorted by order with order stripped', () => {
216
+ const onLayoutChange = jest.fn();
217
+ render(
218
+ <Harness
219
+ layout={ initialLayout }
220
+ onLayoutChange={ onLayoutChange }
221
+ />
222
+ );
223
+
224
+ // Stage a layout where the array is in reverse visual order but
225
+ // the placements carry explicit `order` values that restore the
226
+ // visible "a then b" arrangement.
227
+ act( () => {
228
+ readProbe().mutate( [
229
+ {
230
+ ...initialLayout[ 1 ],
231
+ placement: { width: 1, height: 1, order: 1 },
232
+ },
233
+ {
234
+ ...initialLayout[ 0 ],
235
+ placement: { width: 1, height: 1, order: 0 },
236
+ },
237
+ ] );
238
+ } );
239
+
240
+ // hasUncommittedChanges should be false (visual order is unchanged).
241
+ expect( readProbe().hasUncommittedChanges ).toBe( false );
242
+
243
+ // Now stage a true visual change that also carries `order`, and
244
+ // commit. The publish payload should be sorted by order with the
245
+ // `order` field stripped.
246
+ act( () => {
247
+ readProbe().mutate( [
248
+ {
249
+ ...initialLayout[ 0 ],
250
+ placement: { width: 1, height: 1, order: 1 },
251
+ },
252
+ {
253
+ ...initialLayout[ 1 ],
254
+ placement: { width: 1, height: 1, order: 0 },
255
+ },
256
+ ] );
257
+ } );
258
+
259
+ act( () => {
260
+ readProbe().commit();
261
+ } );
262
+
263
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
264
+ const committed = onLayoutChange.mock.calls[ 0 ][ 0 ];
265
+ expect( committed.map( ( w: DashboardWidget ) => w.uuid ) ).toEqual( [
266
+ 'b',
267
+ 'a',
268
+ ] );
269
+ for ( const widget of committed ) {
270
+ expect( widget.placement ).not.toHaveProperty( 'order' );
271
+ }
272
+ } );
273
+
274
+ it( 'forces edit mode when the layout becomes empty', () => {
275
+ const onLayoutChange = jest.fn();
276
+ const { rerender } = render(
277
+ <Harness
278
+ layout={ initialLayout }
279
+ onLayoutChange={ onLayoutChange }
280
+ />
281
+ );
282
+
283
+ // Empty committed -> auto edit-mode after sync.
284
+ rerender( <Harness layout={ [] } onLayoutChange={ onLayoutChange } /> );
285
+
286
+ expect( readProbe().editMode ).toBe( true );
287
+ } );
288
+
289
+ describe( 'grid settings staging', () => {
290
+ const initialSettings: WidgetGridSettings = {
291
+ model: 'grid',
292
+ rowHeight: 200,
293
+ };
294
+
295
+ it( 'keeps settings mutations in staging without firing onGridSettingsChange', () => {
296
+ const onLayoutChange = jest.fn();
297
+ const onGridSettingsChange = jest.fn();
298
+ render(
299
+ <Harness
300
+ layout={ initialLayout }
301
+ onLayoutChange={ onLayoutChange }
302
+ gridSettings={ initialSettings }
303
+ onGridSettingsChange={ onGridSettingsChange }
304
+ />
305
+ );
306
+
307
+ expect( readProbe().hasUncommittedChanges ).toBe( false );
308
+
309
+ act( () => {
310
+ readProbe().mutateGridSettings( {
311
+ ...initialSettings,
312
+ rowHeight: 300,
313
+ } );
314
+ } );
315
+
316
+ expect( onGridSettingsChange ).not.toHaveBeenCalled();
317
+ expect( readProbe().hasUncommittedChanges ).toBe( true );
318
+ expect( readProbe().gridSettings.rowHeight ).toBe( 300 );
319
+ } );
320
+
321
+ it( 'publishes both layout and settings on commit', () => {
322
+ const onLayoutChange = jest.fn();
323
+ const onGridSettingsChange = jest.fn();
324
+ render(
325
+ <Harness
326
+ layout={ initialLayout }
327
+ onLayoutChange={ onLayoutChange }
328
+ gridSettings={ initialSettings }
329
+ onGridSettingsChange={ onGridSettingsChange }
330
+ />
331
+ );
332
+
333
+ act( () => {
334
+ readProbe().mutate( [ initialLayout[ 0 ] ] );
335
+ readProbe().mutateGridSettings( {
336
+ ...initialSettings,
337
+ model: 'masonry',
338
+ } );
339
+ } );
340
+
341
+ act( () => {
342
+ readProbe().commit();
343
+ } );
344
+
345
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
346
+ expect( onGridSettingsChange ).toHaveBeenCalledTimes( 1 );
347
+ expect( onGridSettingsChange.mock.calls[ 0 ][ 0 ] ).toMatchObject( {
348
+ model: 'masonry',
349
+ } );
350
+ } );
351
+
352
+ it( 'reverts settings on cancel', () => {
353
+ const onLayoutChange = jest.fn();
354
+ const onGridSettingsChange = jest.fn();
355
+ render(
356
+ <Harness
357
+ layout={ initialLayout }
358
+ onLayoutChange={ onLayoutChange }
359
+ gridSettings={ initialSettings }
360
+ onGridSettingsChange={ onGridSettingsChange }
361
+ />
362
+ );
363
+
364
+ act( () => {
365
+ readProbe().mutateGridSettings( {
366
+ ...initialSettings,
367
+ model: 'masonry',
368
+ } );
369
+ } );
370
+
371
+ expect( readProbe().hasUncommittedChanges ).toBe( true );
372
+
373
+ act( () => {
374
+ readProbe().cancel();
375
+ } );
376
+
377
+ expect( onGridSettingsChange ).not.toHaveBeenCalled();
378
+ expect( readProbe().hasUncommittedChanges ).toBe( false );
379
+ expect( readProbe().gridSettings.model ).toBe( 'grid' );
380
+ } );
381
+
382
+ it( 'skips publishing settings when only the layout changed', () => {
383
+ const onLayoutChange = jest.fn();
384
+ const onGridSettingsChange = jest.fn();
385
+ render(
386
+ <Harness
387
+ layout={ initialLayout }
388
+ onLayoutChange={ onLayoutChange }
389
+ gridSettings={ initialSettings }
390
+ onGridSettingsChange={ onGridSettingsChange }
391
+ />
392
+ );
393
+
394
+ act( () => {
395
+ readProbe().mutate( [ initialLayout[ 0 ] ] );
396
+ } );
397
+
398
+ act( () => {
399
+ readProbe().commit();
400
+ } );
401
+
402
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
403
+ expect( onGridSettingsChange ).not.toHaveBeenCalled();
404
+ } );
405
+ } );
406
+
407
+ it( 'reverts only grid settings when cancel passes revertLayout: false', () => {
408
+ const onLayoutChange = jest.fn();
409
+ const onGridSettingsChange = jest.fn();
410
+ const initialSettings: WidgetGridSettings = {
411
+ model: 'grid',
412
+ minColumnWidth: 350,
413
+ rowHeight: 200,
414
+ };
415
+ render(
416
+ <Harness
417
+ layout={ initialLayout }
418
+ onLayoutChange={ onLayoutChange }
419
+ gridSettings={ initialSettings }
420
+ onGridSettingsChange={ onGridSettingsChange }
421
+ />
422
+ );
423
+
424
+ act( () => {
425
+ readProbe().mutate( [ initialLayout[ 0 ] ] );
426
+ readProbe().mutateGridSettings( {
427
+ ...initialSettings,
428
+ minColumnWidth: 420,
429
+ } );
430
+ } );
431
+
432
+ expect( readProbe().hasUncommittedChanges ).toBe( true );
433
+
434
+ act( () => {
435
+ readProbe().cancel( {
436
+ exitEditMode: false,
437
+ revertLayout: false,
438
+ } );
439
+ } );
440
+
441
+ expect( readProbe().hasUncommittedChanges ).toBe( true );
442
+ expect( readProbe().layout ).toHaveLength( 1 );
443
+ expect( readProbe().gridSettings.minColumnWidth ).toBe( 350 );
444
+ } );
445
+
446
+ it( 'stays in edit mode when commit or cancel passes exitEditMode: false', () => {
447
+ const onLayoutChange = jest.fn();
448
+ render(
449
+ <Harness
450
+ layout={ initialLayout }
451
+ onLayoutChange={ onLayoutChange }
452
+ />
453
+ );
454
+
455
+ act( () => {
456
+ readProbe().mutate( [ initialLayout[ 0 ] ] );
457
+ } );
458
+
459
+ act( () => {
460
+ readProbe().commit( { exitEditMode: false } );
461
+ } );
462
+
463
+ expect( readProbe().editMode ).toBe( true );
464
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
465
+
466
+ act( () => {
467
+ readProbe().mutate( [ initialLayout[ 0 ] ] );
468
+ } );
469
+
470
+ act( () => {
471
+ readProbe().cancel( { exitEditMode: false } );
472
+ } );
473
+
474
+ expect( readProbe().editMode ).toBe( true );
475
+ } );
476
+ } );
@@ -0,0 +1,204 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import '@testing-library/jest-dom';
5
+ import type { ComponentType } from 'react';
6
+ import { render, screen } from '@testing-library/react';
7
+ import userEvent from '@testing-library/user-event';
8
+
9
+ /**
10
+ * WordPress dependencies
11
+ */
12
+ import { useState } from '@wordpress/element';
13
+ import type {
14
+ ResolveWidgetModule,
15
+ WidgetRenderProps,
16
+ WidgetType,
17
+ } from '@wordpress/widget-primitives';
18
+
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+ import { WidgetDashboard } from '../widget-dashboard';
23
+ import type { DashboardWidget } from '../types';
24
+
25
+ type Attrs = { greeting: string };
26
+
27
+ function TestWidget( {
28
+ attributes,
29
+ setAttributes,
30
+ }: WidgetRenderProps< Attrs > ) {
31
+ return (
32
+ <div>
33
+ <p data-testid="greeting">{ attributes.greeting }</p>
34
+ <button
35
+ onClick={ () => setAttributes?.( { greeting: 'updated' } ) }
36
+ >
37
+ Update
38
+ </button>
39
+ </div>
40
+ );
41
+ }
42
+
43
+ const widgetTypes: WidgetType[] = [
44
+ {
45
+ apiVersion: 1,
46
+ name: 'test/greet',
47
+ title: 'Greet',
48
+ renderModule: 'test-greet-module',
49
+ },
50
+ ];
51
+
52
+ const resolveWidgetModule: ResolveWidgetModule = async ( id ) => {
53
+ if ( id === 'test-greet-module' ) {
54
+ return {
55
+ default: TestWidget as ComponentType<
56
+ WidgetRenderProps< unknown >
57
+ >,
58
+ };
59
+ }
60
+ throw new Error( `Unknown module: ${ id }` );
61
+ };
62
+
63
+ const initialLayout: DashboardWidget< Attrs >[] = [
64
+ {
65
+ uuid: 'w1',
66
+ type: 'test/greet',
67
+ attributes: { greeting: 'hello' },
68
+ placement: { width: 2, height: 2 },
69
+ },
70
+ ];
71
+
72
+ function Harness( {
73
+ onLayoutChange,
74
+ }: {
75
+ onLayoutChange?: ( layout: DashboardWidget[] ) => void;
76
+ } ) {
77
+ const [ layout, setLayout ] = useState( initialLayout );
78
+ const [ editMode, setEditMode ] = useState( false );
79
+
80
+ return (
81
+ <WidgetDashboard
82
+ layout={ layout }
83
+ onLayoutChange={ ( next ) => {
84
+ setLayout( next as DashboardWidget< Attrs >[] );
85
+ onLayoutChange?.( next );
86
+ } }
87
+ widgetTypes={ widgetTypes }
88
+ resolveWidgetModule={ resolveWidgetModule }
89
+ editMode={ editMode }
90
+ onEditChange={ setEditMode }
91
+ />
92
+ );
93
+ }
94
+
95
+ describe( 'WidgetDashboard', () => {
96
+ it( 'resolves the widget module and renders attributes', async () => {
97
+ render( <Harness /> );
98
+
99
+ expect( await screen.findByTestId( 'greeting' ) ).toHaveTextContent(
100
+ 'hello'
101
+ );
102
+ } );
103
+
104
+ it( 'threads setAttributes into onLayoutChange on commit with merged attributes', async () => {
105
+ const onChange = jest.fn();
106
+ render( <Harness onLayoutChange={ onChange } /> );
107
+
108
+ const button = await screen.findByRole( 'button', {
109
+ name: 'Update',
110
+ } );
111
+ await userEvent.click( button );
112
+
113
+ // Attribute changes stay in staging until commit.
114
+ expect( onChange ).not.toHaveBeenCalled();
115
+ expect( screen.getByTestId( 'greeting' ) ).toHaveTextContent(
116
+ 'updated'
117
+ );
118
+
119
+ // Enter edit mode to surface the Done button, then commit.
120
+ await userEvent.click(
121
+ screen.getByRole( 'button', { name: 'Customize' } )
122
+ );
123
+ await userEvent.click( screen.getByRole( 'button', { name: 'Done' } ) );
124
+
125
+ expect( onChange ).toHaveBeenCalledTimes( 1 );
126
+ const [ updated ] = onChange.mock.calls[ 0 ];
127
+ expect( updated ).toHaveLength( 1 );
128
+ expect( updated[ 0 ] ).toMatchObject( {
129
+ uuid: 'w1',
130
+ type: 'test/greet',
131
+ attributes: { greeting: 'updated' },
132
+ } );
133
+ } );
134
+
135
+ it( 'shows a loading placeholder while widget types are resolving', () => {
136
+ render(
137
+ <WidgetDashboard
138
+ layout={ [
139
+ {
140
+ uuid: 'w1',
141
+ type: 'test/greet',
142
+ placement: { width: 1, height: 1 },
143
+ },
144
+ ] }
145
+ onLayoutChange={ () => {} }
146
+ widgetTypes={ [] }
147
+ isResolvingWidgetTypes
148
+ resolveWidgetModule={ resolveWidgetModule }
149
+ />
150
+ );
151
+
152
+ expect(
153
+ screen.getByRole( 'region', { name: 'Loading' } )
154
+ ).toBeInTheDocument();
155
+ expect(
156
+ screen.queryByText( 'Widget is no longer available.' )
157
+ ).not.toBeInTheDocument();
158
+ } );
159
+
160
+ it( 'shows an unavailable placeholder for an unknown widget type (no crash)', () => {
161
+ render(
162
+ <WidgetDashboard
163
+ layout={ [
164
+ {
165
+ uuid: 'w1',
166
+ type: 'does/not-exist',
167
+ placement: { width: 1, height: 1 },
168
+ },
169
+ ] }
170
+ onLayoutChange={ () => {} }
171
+ widgetTypes={ widgetTypes }
172
+ resolveWidgetModule={ resolveWidgetModule }
173
+ />
174
+ );
175
+ expect( screen.queryByTestId( 'greeting' ) ).not.toBeInTheDocument();
176
+ expect(
177
+ screen.getByRole( 'region', { name: 'Missing widget' } )
178
+ ).toBeInTheDocument();
179
+ expect(
180
+ screen.getByText( 'Widget is no longer available.' )
181
+ ).toBeInTheDocument();
182
+ expect( screen.getByText( 'does/not-exist' ) ).toBeInTheDocument();
183
+ expect(
184
+ screen.queryByRole( 'heading', { level: 2 } )
185
+ ).not.toBeInTheDocument();
186
+ } );
187
+
188
+ it( 'renders the NoWidgetsState compound when layout is empty', () => {
189
+ render(
190
+ <WidgetDashboard
191
+ layout={ [] }
192
+ onLayoutChange={ () => {} }
193
+ widgetTypes={ widgetTypes }
194
+ resolveWidgetModule={ resolveWidgetModule }
195
+ >
196
+ <WidgetDashboard.NoWidgetsState>
197
+ <p>Nothing here yet</p>
198
+ </WidgetDashboard.NoWidgetsState>
199
+ <WidgetDashboard.Widgets />
200
+ </WidgetDashboard>
201
+ );
202
+ expect( screen.getByText( 'Nothing here yet' ) ).toBeInTheDocument();
203
+ } );
204
+ } );