@wordpress/widget-primitives 0.1.1-next.v.202606191442.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 (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +76 -0
  4. package/build/components/widget-render/index.cjs +31 -0
  5. package/build/components/widget-render/index.cjs.map +7 -0
  6. package/build/components/widget-render/widget-render.cjs +50 -0
  7. package/build/components/widget-render/widget-render.cjs.map +7 -0
  8. package/build/hooks/index.cjs +31 -0
  9. package/build/hooks/index.cjs.map +7 -0
  10. package/build/hooks/use-widget-types.cjs +84 -0
  11. package/build/hooks/use-widget-types.cjs.map +7 -0
  12. package/build/index.cjs +34 -0
  13. package/build/index.cjs.map +7 -0
  14. package/build/tools/get-lazy-widget-component/get-lazy-widget-component.cjs +50 -0
  15. package/build/tools/get-lazy-widget-component/get-lazy-widget-component.cjs.map +7 -0
  16. package/build/tools/get-lazy-widget-component/index.cjs +31 -0
  17. package/build/tools/get-lazy-widget-component/index.cjs.map +7 -0
  18. package/build/types.cjs +19 -0
  19. package/build/types.cjs.map +7 -0
  20. package/build-module/components/widget-render/index.mjs +6 -0
  21. package/build-module/components/widget-render/index.mjs.map +7 -0
  22. package/build-module/components/widget-render/widget-render.mjs +25 -0
  23. package/build-module/components/widget-render/widget-render.mjs.map +7 -0
  24. package/build-module/hooks/index.mjs +6 -0
  25. package/build-module/hooks/index.mjs.map +7 -0
  26. package/build-module/hooks/use-widget-types.mjs +59 -0
  27. package/build-module/hooks/use-widget-types.mjs.map +7 -0
  28. package/build-module/index.mjs +8 -0
  29. package/build-module/index.mjs.map +7 -0
  30. package/build-module/tools/get-lazy-widget-component/get-lazy-widget-component.mjs +25 -0
  31. package/build-module/tools/get-lazy-widget-component/get-lazy-widget-component.mjs.map +7 -0
  32. package/build-module/tools/get-lazy-widget-component/index.mjs +6 -0
  33. package/build-module/tools/get-lazy-widget-component/index.mjs.map +7 -0
  34. package/build-module/types.mjs +1 -0
  35. package/build-module/types.mjs.map +7 -0
  36. package/build-types/components/widget-render/index.d.ts +2 -0
  37. package/build-types/components/widget-render/index.d.ts.map +1 -0
  38. package/build-types/components/widget-render/stories/index.story.d.ts +19 -0
  39. package/build-types/components/widget-render/stories/index.story.d.ts.map +1 -0
  40. package/build-types/components/widget-render/widget-render.d.ts +13 -0
  41. package/build-types/components/widget-render/widget-render.d.ts.map +1 -0
  42. package/build-types/hooks/index.d.ts +2 -0
  43. package/build-types/hooks/index.d.ts.map +1 -0
  44. package/build-types/hooks/use-widget-types.d.ts +17 -0
  45. package/build-types/hooks/use-widget-types.d.ts.map +1 -0
  46. package/build-types/index.d.ts +13 -0
  47. package/build-types/index.d.ts.map +1 -0
  48. package/build-types/tools/get-lazy-widget-component/get-lazy-widget-component.d.ts +12 -0
  49. package/build-types/tools/get-lazy-widget-component/get-lazy-widget-component.d.ts.map +1 -0
  50. package/build-types/tools/get-lazy-widget-component/index.d.ts +2 -0
  51. package/build-types/tools/get-lazy-widget-component/index.d.ts.map +1 -0
  52. package/build-types/types.d.ts +169 -0
  53. package/build-types/types.d.ts.map +1 -0
  54. package/package.json +72 -0
  55. package/src/components/widget-render/index.ts +1 -0
  56. package/src/components/widget-render/stories/index.story.tsx +356 -0
  57. package/src/components/widget-render/widget-render.tsx +44 -0
  58. package/src/hooks/index.ts +1 -0
  59. package/src/hooks/use-widget-types.ts +90 -0
  60. package/src/index.ts +21 -0
  61. package/src/stories/introduction.mdx +14 -0
  62. package/src/tools/get-lazy-widget-component/get-lazy-widget-component.ts +62 -0
  63. package/src/tools/get-lazy-widget-component/index.ts +1 -0
  64. package/src/types.ts +196 -0
package/src/types.ts ADDED
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Widget type definitions.
3
+ *
4
+ * Canonical home for widget identity types consumed by the registry and
5
+ * hosts that render widgets.
6
+ *
7
+ * Each type is generic over the widget's attribute object (`Item`), so a
8
+ * widget binds its attribute shape once and gets typed `attributes`,
9
+ * `example`, and `setAttributes`.
10
+ */
11
+
12
+ /**
13
+ * External dependencies
14
+ */
15
+ import type { ComponentProps, ComponentType, ReactElement } from 'react';
16
+ import type { Field } from '@wordpress/dataviews';
17
+
18
+ /**
19
+ * Widget type identifier, structured as `<widget-namespace>/<widget-name>`.
20
+ * Both segments are lowercase, kebab-case.
21
+ */
22
+ export type WidgetName = `${ string }/${ string }`;
23
+
24
+ /**
25
+ * Icon for a widget type: a rendered SVG element, typically one from
26
+ * `@wordpress/icons`.
27
+ */
28
+ export type WidgetIcon = ReactElement< ComponentProps< 'svg' > >;
29
+
30
+ /**
31
+ * Literal contents of a widget's `widget.json` metadata file.
32
+ *
33
+ * Captures the *authoring* shape only; module entry points and style
34
+ * assets are discovered by convention from the widget directory, not
35
+ * declared here.
36
+ */
37
+ export interface WidgetTypeMetadata< Item = unknown > {
38
+ /**
39
+ * Version of the Widget API used by the widget.
40
+ */
41
+ apiVersion: number;
42
+
43
+ /**
44
+ * Stable type identifier.
45
+ */
46
+ name: WidgetName;
47
+
48
+ /**
49
+ * Display title; hosts surface it in pickers and chrome.
50
+ */
51
+ title: string;
52
+
53
+ /**
54
+ * Short description; hosts surface it in pickers and help panels.
55
+ */
56
+ description?: string;
57
+
58
+ /**
59
+ * Visual identifier for the widget type; hosts decide where, and
60
+ * whether, to render it.
61
+ */
62
+ icon?: WidgetIcon;
63
+
64
+ /**
65
+ * Grouping category. Core provides `dashboard`; plugins and themes may
66
+ * register custom categories.
67
+ */
68
+ category?: string;
69
+
70
+ /**
71
+ * Authoring intent about how the widget renders. Not a user-editable
72
+ * attribute.
73
+ *
74
+ * - `'framed'` (default when absent): the widget renders its
75
+ * content only.
76
+ * - `'content-bleed'`: the host's chrome stays visible while the
77
+ * content fills the content area edge-to-edge, with no padding.
78
+ * - `'full-bleed'`: the widget renders edge-to-edge with no
79
+ * surrounding chrome.
80
+ */
81
+ presentation?: 'framed' | 'content-bleed' | 'full-bleed';
82
+
83
+ /**
84
+ * Search aliases hosts use to match the widget in their pickers.
85
+ */
86
+ keywords?: string[];
87
+
88
+ /**
89
+ * Widget version, used for asset cache invalidation.
90
+ */
91
+ version?: string;
92
+
93
+ /**
94
+ * Gettext text domain for translations.
95
+ */
96
+ textdomain?: string;
97
+
98
+ /**
99
+ * Experiment gate; boolean `true`, or a specific experiment name.
100
+ */
101
+ __experimental?: string | boolean;
102
+
103
+ /**
104
+ * Declarative attribute schema, bound to the widget's attribute
105
+ * object via `Item`. Hosts render forms straight from this list
106
+ * via `DataForm`, with no per-widget form wiring.
107
+ */
108
+ attributes?: Field< Item >[];
109
+
110
+ /**
111
+ * Structured example data hosts use for previews, and the default
112
+ * attributes applied when a new instance is created without initial
113
+ * attributes.
114
+ */
115
+ example?: {
116
+ attributes?: Partial< Item >;
117
+ };
118
+ }
119
+
120
+ /**
121
+ * Runtime widget type consumed by hosts.
122
+ *
123
+ * Extends `WidgetTypeMetadata` with runtime-only fields, notably
124
+ * `renderModule`. The PHP layer (`widget-types.php`) emits these in
125
+ * snake_case; `useWidgetTypes` is the single boundary that maps them to
126
+ * camelCase.
127
+ */
128
+ export interface WidgetType< Item = unknown >
129
+ extends WidgetTypeMetadata< Item > {
130
+ /**
131
+ * Script-module identifier resolved to a React component at render
132
+ * time, produced from the conventional `render.*` entry point.
133
+ */
134
+ renderModule: string;
135
+ }
136
+
137
+ /**
138
+ * Props passed to a widget's render component by the host, bound over
139
+ * `Item` so `attributes` and `setAttributes` are typed against the
140
+ * widget's attribute object.
141
+ */
142
+ export interface WidgetRenderProps< Item = unknown > {
143
+ /**
144
+ * User-configured attributes for this widget instance.
145
+ */
146
+ attributes: Item;
147
+
148
+ /**
149
+ * Updates the attributes of this instance. Optional because some
150
+ * hosts render widgets in read-only contexts.
151
+ */
152
+ setAttributes?: ( next: Partial< Item > ) => void;
153
+ }
154
+
155
+ /**
156
+ * Widget render module shape returned by the module resolver.
157
+ */
158
+ export interface WidgetModule {
159
+ default: ComponentType< WidgetRenderProps< unknown > >;
160
+ }
161
+
162
+ /**
163
+ * Resolver function: maps a `WidgetType.renderModule` id to a React
164
+ * component. Override for tests, Storybook, or to load from a non-URL
165
+ * source.
166
+ */
167
+ export type ResolveWidgetModule = (
168
+ moduleId: string
169
+ ) => Promise< WidgetModule >;
170
+
171
+ /**
172
+ * Per-widget data a host feeds to `useWidgetTypes`, in snake_case wire
173
+ * format. Matches the `/wp/v2/widget-modules` REST shape, so a WordPress
174
+ * host can pass core-data records unchanged.
175
+ */
176
+ export interface WidgetModuleRecord {
177
+ /**
178
+ * Stable widget type identifier.
179
+ */
180
+ name: string;
181
+
182
+ /**
183
+ * Script-module id resolved to the render component at render time.
184
+ */
185
+ render_module?: string | null;
186
+
187
+ /**
188
+ * Script-module id dynamically imported for the widget's live metadata.
189
+ */
190
+ widget_module?: string | null;
191
+
192
+ /**
193
+ * Authoring presentation hint; overrides the metadata module's value.
194
+ */
195
+ presentation?: WidgetTypeMetadata[ 'presentation' ] | null;
196
+ }