@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,210 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import '@testing-library/jest-dom';
5
+ import { render, screen, waitFor, within } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
7
+ import type { ComponentType } from 'react';
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
+ function PreviewWidget( {
26
+ attributes,
27
+ }: WidgetRenderProps< { label?: string } > ) {
28
+ return <div data-testid="widget-content">{ attributes?.label ?? '—' }</div>;
29
+ }
30
+
31
+ const widgetTypes: WidgetType[] = [
32
+ {
33
+ apiVersion: 1,
34
+ name: 'wordpress/welcome',
35
+ title: 'Welcome',
36
+ renderModule: 'welcome-module',
37
+ example: { attributes: { label: 'welcome-example' } },
38
+ },
39
+ {
40
+ apiVersion: 1,
41
+ name: 'wordpress/notes',
42
+ title: 'Notes',
43
+ renderModule: 'notes-module',
44
+ example: { attributes: { label: 'notes-example' } },
45
+ },
46
+ ];
47
+
48
+ const resolveWidgetModule: ResolveWidgetModule = async () => ( {
49
+ default: PreviewWidget as ComponentType< WidgetRenderProps< unknown > >,
50
+ } );
51
+
52
+ interface HarnessProps {
53
+ initialLayout?: DashboardWidget[];
54
+ onLayoutChange?: ( layout: DashboardWidget[] ) => void;
55
+ }
56
+
57
+ function Harness( {
58
+ initialLayout = [],
59
+ onLayoutChange: onChange,
60
+ }: HarnessProps ) {
61
+ const [ layout, setLayout ] =
62
+ useState< DashboardWidget[] >( initialLayout );
63
+ const [ editMode, setEditMode ] = useState( true );
64
+
65
+ return (
66
+ <WidgetDashboard
67
+ layout={ layout }
68
+ onLayoutChange={ ( next ) => {
69
+ setLayout( next );
70
+ onChange?.( next );
71
+ } }
72
+ widgetTypes={ widgetTypes }
73
+ editMode={ editMode }
74
+ onEditChange={ setEditMode }
75
+ resolveWidgetModule={ resolveWidgetModule }
76
+ />
77
+ );
78
+ }
79
+
80
+ describe( 'WidgetDashboard.WidgetInserter', () => {
81
+ it( 'is hidden until the "Add widget" trigger is clicked', () => {
82
+ render( <Harness /> );
83
+ expect(
84
+ screen.queryByRole( 'dialog', { name: 'Add widget' } )
85
+ ).not.toBeInTheDocument();
86
+ } );
87
+
88
+ it( 'opens after clicking the "Add widget" trigger', async () => {
89
+ const user = userEvent.setup();
90
+ render( <Harness /> );
91
+
92
+ await user.click(
93
+ screen.getByRole( 'button', { name: 'Add widget' } )
94
+ );
95
+
96
+ expect(
97
+ await screen.findByRole( 'dialog', { name: 'Add widget' } )
98
+ ).toBeInTheDocument();
99
+ } );
100
+
101
+ it( 'inserts the selected widget type into the layout on Done', async () => {
102
+ const user = userEvent.setup();
103
+ const onLayoutChange = jest.fn();
104
+ render( <Harness onLayoutChange={ onLayoutChange } /> );
105
+
106
+ await user.click(
107
+ screen.getByRole( 'button', { name: 'Add widget' } )
108
+ );
109
+
110
+ const dialog = await screen.findByRole( 'dialog', {
111
+ name: 'Add widget',
112
+ } );
113
+ const options = within( dialog ).getAllByRole( 'option' );
114
+ expect( options ).toHaveLength( widgetTypes.length );
115
+
116
+ await user.click( options[ 0 ] );
117
+ await user.click(
118
+ within( dialog ).getByRole( 'button', { name: 'Select' } )
119
+ );
120
+
121
+ // Inserts stay in staging until Done.
122
+ expect( onLayoutChange ).not.toHaveBeenCalled();
123
+
124
+ await waitFor( () =>
125
+ expect(
126
+ screen.queryByRole( 'dialog', { name: 'Add widget' } )
127
+ ).not.toBeInTheDocument()
128
+ );
129
+
130
+ await user.click( screen.getByRole( 'button', { name: 'Done' } ) );
131
+
132
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
133
+ const [ updated ] = onLayoutChange.mock.calls[ 0 ];
134
+ expect( updated ).toHaveLength( 1 );
135
+ expect( updated[ 0 ] ).toMatchObject( {
136
+ type: 'wordpress/welcome',
137
+ attributes: { label: 'welcome-example' },
138
+ } );
139
+ expect( updated[ 0 ].uuid ).toEqual( expect.any( String ) );
140
+ } );
141
+
142
+ it( 'inserts multiple widgets via multi-select in a single layout change', async () => {
143
+ const user = userEvent.setup();
144
+ const onLayoutChange = jest.fn();
145
+ render( <Harness onLayoutChange={ onLayoutChange } /> );
146
+
147
+ await user.click(
148
+ screen.getByRole( 'button', { name: 'Add widget' } )
149
+ );
150
+
151
+ const dialog = await screen.findByRole( 'dialog', {
152
+ name: 'Add widget',
153
+ } );
154
+ const options = within( dialog ).getAllByRole( 'option' );
155
+
156
+ await user.click( options[ 0 ] );
157
+ await user.click( options[ 1 ] );
158
+
159
+ await user.click(
160
+ within( dialog ).getByRole( 'button', { name: 'Select' } )
161
+ );
162
+
163
+ await user.click( screen.getByRole( 'button', { name: 'Done' } ) );
164
+
165
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
166
+ const [ updated ] = onLayoutChange.mock.calls[ 0 ];
167
+ expect( updated ).toHaveLength( 2 );
168
+ expect( updated.map( ( w: DashboardWidget ) => w.type ) ).toEqual( [
169
+ 'wordpress/welcome',
170
+ 'wordpress/notes',
171
+ ] );
172
+ } );
173
+
174
+ it( 'preserves existing widgets when appending new ones', async () => {
175
+ const user = userEvent.setup();
176
+ const onLayoutChange = jest.fn();
177
+ const existing: DashboardWidget = {
178
+ uuid: 'existing-1',
179
+ type: 'wordpress/welcome',
180
+ attributes: { label: 'kept' },
181
+ placement: { width: 1, height: 1 },
182
+ };
183
+
184
+ render(
185
+ <Harness
186
+ initialLayout={ [ existing ] }
187
+ onLayoutChange={ onLayoutChange }
188
+ />
189
+ );
190
+
191
+ await user.click(
192
+ screen.getByRole( 'button', { name: 'Add widget' } )
193
+ );
194
+
195
+ const dialog = await screen.findByRole( 'dialog', {
196
+ name: 'Add widget',
197
+ } );
198
+ await user.click( within( dialog ).getAllByRole( 'option' )[ 1 ] );
199
+ await user.click(
200
+ within( dialog ).getByRole( 'button', { name: 'Select' } )
201
+ );
202
+
203
+ await user.click( screen.getByRole( 'button', { name: 'Done' } ) );
204
+
205
+ const [ updated ] = onLayoutChange.mock.calls[ 0 ];
206
+ expect( updated ).toHaveLength( 2 );
207
+ expect( updated[ 0 ] ).toEqual( existing );
208
+ expect( updated[ 1 ] ).toMatchObject( { type: 'wordpress/notes' } );
209
+ } );
210
+ } );
@@ -0,0 +1,199 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import '@testing-library/jest-dom';
5
+ import { render, screen, waitFor, within } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
7
+ import type { ComponentType } from 'react';
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
+ }: WidgetRenderProps< { greeting?: string } > ) {
30
+ return <p data-testid="greeting">{ attributes?.greeting ?? '' }</p>;
31
+ }
32
+
33
+ const widgetTypes: WidgetType[] = [
34
+ {
35
+ apiVersion: 1,
36
+ name: 'test/greet',
37
+ title: 'Greet',
38
+ renderModule: 'greet-module',
39
+ attributes: [ { id: 'greeting', label: 'Greeting', type: 'text' } ],
40
+ example: { attributes: { greeting: 'hi' } },
41
+ },
42
+ ];
43
+
44
+ const resolveWidgetModule: ResolveWidgetModule = async () => ( {
45
+ default: TestWidget as ComponentType< WidgetRenderProps< unknown > >,
46
+ } );
47
+
48
+ const initialLayout: DashboardWidget< Attrs >[] = [
49
+ {
50
+ uuid: 'w1',
51
+ type: 'test/greet',
52
+ attributes: { greeting: 'hello' },
53
+ placement: { width: 2, height: 2 },
54
+ },
55
+ ];
56
+
57
+ function Harness( {
58
+ onLayoutChange,
59
+ }: {
60
+ onLayoutChange?: ( layout: DashboardWidget[] ) => void;
61
+ } ) {
62
+ const [ layout, setLayout ] =
63
+ useState< DashboardWidget[] >( initialLayout );
64
+ const [ editMode, setEditMode ] = useState( false );
65
+
66
+ return (
67
+ <WidgetDashboard
68
+ layout={ layout }
69
+ onLayoutChange={ ( next ) => {
70
+ setLayout( next );
71
+ onLayoutChange?.( next );
72
+ } }
73
+ widgetTypes={ widgetTypes }
74
+ editMode={ editMode }
75
+ onEditChange={ setEditMode }
76
+ resolveWidgetModule={ resolveWidgetModule }
77
+ />
78
+ );
79
+ }
80
+
81
+ describe( 'WidgetDashboard widget settings', () => {
82
+ it( 'surfaces a per-instance settings gear in normal mode', async () => {
83
+ render( <Harness /> );
84
+
85
+ expect( await screen.findByTestId( 'greeting' ) ).toBeInTheDocument();
86
+ expect(
87
+ screen.getByRole( 'button', { name: 'Widget settings' } )
88
+ ).toBeInTheDocument();
89
+ } );
90
+
91
+ it( 'hides the gear while the layout is being edited', async () => {
92
+ const user = userEvent.setup();
93
+ render( <Harness /> );
94
+ await screen.findByTestId( 'greeting' );
95
+
96
+ await user.click( screen.getByRole( 'button', { name: 'Customize' } ) );
97
+
98
+ expect(
99
+ screen.queryByRole( 'button', { name: 'Widget settings' } )
100
+ ).not.toBeInTheDocument();
101
+ } );
102
+
103
+ it( 'stages attribute edits behind the drawer and publishes them on Save', async () => {
104
+ const user = userEvent.setup();
105
+ const onLayoutChange = jest.fn();
106
+ render( <Harness onLayoutChange={ onLayoutChange } /> );
107
+ await screen.findByTestId( 'greeting' );
108
+
109
+ await user.click(
110
+ screen.getByRole( 'button', { name: 'Widget settings' } )
111
+ );
112
+
113
+ const dialog = await screen.findByRole( 'dialog', {
114
+ name: 'Greet settings',
115
+ } );
116
+
117
+ const input = within( dialog ).getByRole( 'textbox' );
118
+ await user.clear( input );
119
+ await user.type( input, 'updated' );
120
+
121
+ // The live preview behind the drawer reflects the staged edit…
122
+ expect( screen.getByTestId( 'greeting' ) ).toHaveTextContent(
123
+ 'updated'
124
+ );
125
+ // …but nothing is published until Save.
126
+ expect( onLayoutChange ).not.toHaveBeenCalled();
127
+
128
+ await user.click(
129
+ within( dialog ).getByRole( 'button', { name: 'Save' } )
130
+ );
131
+
132
+ expect( onLayoutChange ).toHaveBeenCalledTimes( 1 );
133
+ const [ updated ] = onLayoutChange.mock.calls[ 0 ];
134
+ expect( updated[ 0 ] ).toMatchObject( {
135
+ uuid: 'w1',
136
+ type: 'test/greet',
137
+ attributes: { greeting: 'updated' },
138
+ } );
139
+
140
+ await waitFor( () =>
141
+ expect(
142
+ screen.queryByRole( 'dialog', { name: 'Greet settings' } )
143
+ ).not.toBeInTheDocument()
144
+ );
145
+ } );
146
+
147
+ it( 'discards staged edits when the drawer is dismissed', async () => {
148
+ const user = userEvent.setup();
149
+ const onLayoutChange = jest.fn();
150
+ render( <Harness onLayoutChange={ onLayoutChange } /> );
151
+ await screen.findByTestId( 'greeting' );
152
+
153
+ await user.click(
154
+ screen.getByRole( 'button', { name: 'Widget settings' } )
155
+ );
156
+ const dialog = await screen.findByRole( 'dialog', {
157
+ name: 'Greet settings',
158
+ } );
159
+ const input = within( dialog ).getByRole( 'textbox' );
160
+ await user.clear( input );
161
+ await user.type( input, 'updated' );
162
+
163
+ await user.click(
164
+ within( dialog ).getByRole( 'button', { name: 'Cancel' } )
165
+ );
166
+
167
+ expect( onLayoutChange ).not.toHaveBeenCalled();
168
+ expect( screen.getByTestId( 'greeting' ) ).toHaveTextContent( 'hello' );
169
+ } );
170
+
171
+ it( 'shows no gear for a type that declares no attributes', async () => {
172
+ render(
173
+ <WidgetDashboard
174
+ layout={ [
175
+ {
176
+ uuid: 'w1',
177
+ type: 'test/plain',
178
+ placement: { width: 1, height: 1 },
179
+ },
180
+ ] }
181
+ onLayoutChange={ () => {} }
182
+ widgetTypes={ [
183
+ {
184
+ apiVersion: 1,
185
+ name: 'test/plain',
186
+ title: 'Plain',
187
+ renderModule: 'greet-module',
188
+ },
189
+ ] }
190
+ resolveWidgetModule={ resolveWidgetModule }
191
+ />
192
+ );
193
+ await screen.findByTestId( 'greeting' );
194
+
195
+ expect(
196
+ screen.queryByRole( 'button', { name: /settings/i } )
197
+ ).not.toBeInTheDocument();
198
+ } );
199
+ } );
package/src/types.ts ADDED
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Dashboard-specific types: `DashboardWidget`, grid settings, and the
3
+ * `WidgetDashboard` prop bag.
4
+ *
5
+ * The widget contract types (`WidgetName`, `WidgetType`, `WidgetRenderProps`,
6
+ * `ResolveWidgetModule`) live in `@wordpress/widget-primitives` and are
7
+ * imported from there directly; this module does not re-export them.
8
+ */
9
+
10
+ /**
11
+ * External dependencies
12
+ */
13
+ import type { ReactNode } from 'react';
14
+
15
+ /**
16
+ * WordPress dependencies
17
+ */
18
+ import type {
19
+ DashboardGridLayoutItem,
20
+ DashboardLanesLayoutItem,
21
+ } from '@wordpress/grid';
22
+ import type {
23
+ WidgetName,
24
+ WidgetType,
25
+ ResolveWidgetModule,
26
+ } from '@wordpress/widget-primitives';
27
+
28
+ export type GridTilePlacement = Omit< DashboardGridLayoutItem, 'key' >;
29
+ export type MasonryTilePlacement = Omit< DashboardLanesLayoutItem, 'key' >;
30
+
31
+ /**
32
+ * Storage shape for a widget's placement.
33
+ *
34
+ * Structurally a union of every supported per-model shape, but the
35
+ * intended invariant is stronger than the type suggests: every
36
+ * placement in a given layout must match the shape of the currently
37
+ * active `gridSettings.model`. `migrateLayout` is the only correct
38
+ * way to transition placements across model changes; the render
39
+ * layer is allowed to trust the active model and treat each
40
+ * placement as the matching shape.
41
+ *
42
+ * The type system cannot enforce that invariant on its own (there is
43
+ * no discriminator on the placement itself), so consider this union a
44
+ * declaration of which shapes are *valid*, not which shape any given
45
+ * placement happens to be at runtime.
46
+ */
47
+ export type DashboardTilePlacement = GridTilePlacement | MasonryTilePlacement;
48
+
49
+ /**
50
+ * A widget placed on the dashboard.
51
+ *
52
+ * A `WidgetType` describes the blueprint. A `DashboardWidget` is a
53
+ * concrete placement of that type on a specific dashboard: its unique
54
+ * id, the type it references, user-configured attributes, and its
55
+ * `placement` in the grid.
56
+ */
57
+ export interface DashboardWidget< Item = unknown > {
58
+ /**
59
+ * Unique instance identifier.
60
+ */
61
+ uuid: string;
62
+
63
+ /**
64
+ * Widget type name — must match a `WidgetType.name` in `widgetTypes`.
65
+ */
66
+ type: WidgetName;
67
+
68
+ /**
69
+ * User-configured attributes for this instance.
70
+ */
71
+ attributes?: Item;
72
+
73
+ /**
74
+ * Grid-model-specific placement (column/row spans, ordering,
75
+ * etc.). Must match the shape implied by the dashboard's active
76
+ * `gridSettings.model`; see `DashboardTilePlacement` for the
77
+ * invariant and `migrateLayout` for the transition mechanism.
78
+ */
79
+ placement?: DashboardTilePlacement;
80
+ }
81
+
82
+ /**
83
+ * Identity of a widget within the rendering tree. Returned by
84
+ * `useWidgetContext()`; `null` when called outside a widget render subtree.
85
+ */
86
+ export interface WidgetContextValue {
87
+ /**
88
+ * Widget instance id.
89
+ */
90
+ uuid: string;
91
+
92
+ /**
93
+ * Widget type name.
94
+ */
95
+ name: WidgetName;
96
+
97
+ /**
98
+ * Index of the widget in the `layout` array.
99
+ */
100
+ index: number;
101
+ }
102
+
103
+ /**
104
+ * Identifier for the active grid model. Drives which `@wordpress/grid`
105
+ * surface the dashboard mounts and which per-model settings the
106
+ * `WidgetGridSettings` union admits.
107
+ *
108
+ * Model names describe user-facing concepts. The mapping to the
109
+ * underlying `@wordpress/grid` component is an implementation detail
110
+ * resolved in the render layer; `'masonry'` is rendered today through
111
+ * `DashboardLanes` (skyline placement) but could swap to a future
112
+ * native `display: grid-lanes` path without affecting the model name.
113
+ */
114
+ export type WidgetGridModel = 'grid' | 'masonry';
115
+
116
+ /**
117
+ * Maximum column count for the widget dashboard on wide containers.
118
+ * Not exposed in layout settings; container width steps the count down
119
+ * to two and one column at fixed breakpoints.
120
+ */
121
+ export const WIDGET_DASHBOARD_COLUMN_COUNT = 4;
122
+
123
+ /**
124
+ * Settings common to every grid model. Column count is resolved from
125
+ * the dashboard container width (see
126
+ * `utils/resolve-dashboard-column-count`). `columns` and `minColumnWidth`
127
+ * on this type remain for persisted payloads and `@wordpress/grid`
128
+ * compatibility; the dashboard ignores user-facing values for both.
129
+ *
130
+ * `spacing` is intentionally absent: the gap between tiles is
131
+ * presentational and lives with the design-system theme/density, not
132
+ * with per-dashboard settings. The grid surface keeps the prop for
133
+ * programmatic overrides, but the dashboard does not propagate it.
134
+ */
135
+ interface BaseWidgetGridSettings {
136
+ /**
137
+ * Target column count (cap). The dashboard always uses
138
+ * {@link WIDGET_DASHBOARD_COLUMN_COUNT}; persisted values are ignored.
139
+ */
140
+ columns?: number;
141
+
142
+ /**
143
+ * Per-tile minimum width in pixels. Unused by the dashboard; column
144
+ * count is derived from container width instead.
145
+ */
146
+ minColumnWidth?: number;
147
+ }
148
+
149
+ /**
150
+ * 2D packed grid settings. Items declare explicit width and height
151
+ * spans; rows use a uniform track height via `rowHeight`.
152
+ */
153
+ export interface WidgetGridLayoutSettings extends BaseWidgetGridSettings {
154
+ model?: 'grid';
155
+
156
+ /**
157
+ * Row height in pixels (`200` small, `300` medium, `400` large). Every
158
+ * tile in a row fills the row vertically.
159
+ */
160
+ rowHeight?: number;
161
+ }
162
+
163
+ /**
164
+ * Masonry settings. Heights are content-driven; resize is
165
+ * horizontal-only. `flowTolerance` tunes how aggressively the placer
166
+ * preserves source order vs. minimizing empty regions.
167
+ */
168
+ export interface WidgetMasonryLayoutSettings extends BaseWidgetGridSettings {
169
+ model: 'masonry';
170
+
171
+ /**
172
+ * Pixel tolerance for source-order tiebreaking when two candidate
173
+ * columns have similar baselines.
174
+ */
175
+ flowTolerance?: number;
176
+ }
177
+
178
+ /**
179
+ * Discriminated union of supported grid-model configurations.
180
+ *
181
+ * When `model` is omitted the dashboard treats the settings as the
182
+ * 2D packed grid (`'grid'`) for backwards compatibility with the
183
+ * pre-union shape.
184
+ */
185
+ export type WidgetGridSettings =
186
+ | WidgetGridLayoutSettings
187
+ | WidgetMasonryLayoutSettings;
188
+
189
+ /**
190
+ * Props for `WidgetDashboard`.
191
+ *
192
+ * The consumer owns the committed layout state; the dashboard maintains
193
+ * a staging copy internally for in-progress edits, and `onLayoutChange`
194
+ * fires only when the user commits via the Done action.
195
+ */
196
+ export interface WidgetDashboardProps {
197
+ /**
198
+ * Widget instances to render. Consumer owns this state.
199
+ */
200
+ layout: DashboardWidget[];
201
+
202
+ /**
203
+ * Called when the user commits in-progress edits via the Done action.
204
+ * Receives the full layout array as it should be persisted. In-progress
205
+ * mutations (reorder, resize, add, remove, attribute edits) accumulate
206
+ * in the dashboard's internal staging layer and do not fire this
207
+ * callback until commit.
208
+ */
209
+ onLayoutChange: ( layout: DashboardWidget[] ) => void;
210
+
211
+ /**
212
+ * Called when the layout is reset to the default.
213
+ */
214
+ onLayoutReset?: () => void;
215
+
216
+ /**
217
+ * Widget types available for rendering. The dashboard never queries a
218
+ * store directly — consumers scope and filter via this prop.
219
+ */
220
+ widgetTypes: WidgetType[];
221
+
222
+ /**
223
+ * When true, widget types are still loading. Instances whose type is
224
+ * not yet in `widgetTypes` show a loading state instead of missing.
225
+ */
226
+ isResolvingWidgetTypes?: boolean;
227
+
228
+ /**
229
+ * Whether the dashboard is in edit mode (enables drag/resize).
230
+ */
231
+ editMode?: boolean;
232
+
233
+ /**
234
+ * Called when edit mode toggles via `WidgetDashboard.Actions`.
235
+ */
236
+ onEditChange?: ( next: boolean ) => void;
237
+
238
+ /**
239
+ * Overrides the default `import()` resolution of
240
+ * `WidgetType.renderModule`. Useful for tests, Storybook, or future
241
+ * remote-URL loading.
242
+ */
243
+ resolveWidgetModule?: ResolveWidgetModule;
244
+
245
+ /**
246
+ * Grid model configuration. See `WidgetGridSettings` for the shape.
247
+ */
248
+ gridSettings?: WidgetGridSettings;
249
+
250
+ /**
251
+ * Called when the user commits in-progress grid-settings edits via
252
+ * the Done action. The dashboard maintains a staging copy of
253
+ * settings internally; mutations stay local until commit. When
254
+ * omitted, the `Layout settings` button in the customize toolbar is
255
+ * hidden, since there is nowhere to persist the change.
256
+ */
257
+ onGridSettingsChange?: ( gridSettings: WidgetGridSettings ) => void;
258
+
259
+ children?: ReactNode;
260
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { v4 as uuid } from 'uuid';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import type { WidgetType } from '@wordpress/widget-primitives';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import type { DashboardWidget, GridTilePlacement } from '../../types';
15
+
16
+ const DEFAULT_PLACEMENT: GridTilePlacement = {
17
+ width: 1,
18
+ height: 2,
19
+ order: 0,
20
+ };
21
+
22
+ /**
23
+ * Create a new dashboard widget from a widget type.
24
+ *
25
+ * Generates a unique id and applies default placement. If no initial
26
+ * attributes are provided, falls back to the type's `example.attributes`
27
+ * (matching the `widget.json` schema).
28
+ *
29
+ * @param widgetType Source widget type.
30
+ * @param initialAttributes Initial attributes; default to the type's example.
31
+ */
32
+ export function createDashboardWidget< T >(
33
+ widgetType: WidgetType,
34
+ initialAttributes?: T
35
+ ): DashboardWidget< T > {
36
+ return {
37
+ uuid: uuid(),
38
+ type: widgetType.name,
39
+ attributes:
40
+ initialAttributes ?? ( widgetType.example?.attributes as T ),
41
+ placement: DEFAULT_PLACEMENT,
42
+ };
43
+ }
@@ -0,0 +1 @@
1
+ export { createDashboardWidget } from './create-dashboard-widget';