@times-design-system/components-wordpress 0.4.0 → 1.2.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.
- package/BLOCK_CREATION_CHECKLIST.md +160 -0
- package/BUILD.md +411 -0
- package/CHANGELOG.md +32 -0
- package/LICENSE +29 -0
- package/README.md +972 -5
- package/TRANSFORMATION_GUIDE.md +635 -0
- package/block.json +10 -0
- package/dist/block.json +10 -0
- package/dist/blocks/ad-container/block.json +28 -0
- package/dist/blocks/ad-container/edit.js +42 -0
- package/dist/blocks/ad-container/index.js +10 -0
- package/dist/blocks/ad-container/save.js +16 -0
- package/dist/blocks/ad-container/style-editor.css +4 -0
- package/dist/blocks/ad-container/style.css +27 -0
- package/dist/blocks/button/block.json +89 -0
- package/dist/blocks/button/edit.js +187 -0
- package/dist/blocks/button/index.js +11 -0
- package/dist/blocks/button/save.js +52 -0
- package/dist/blocks/button/style-editor.css +15 -0
- package/dist/blocks/button/style.css +37 -0
- package/dist/blocks/chip/block.json +57 -0
- package/dist/blocks/chip/edit.js +113 -0
- package/dist/blocks/chip/index.js +10 -0
- package/dist/blocks/chip/save.js +36 -0
- package/dist/blocks/chip/style-editor.css +5 -0
- package/dist/blocks/chip/style.css +48 -0
- package/dist/blocks/divider/block.json +31 -0
- package/dist/blocks/divider/edit.js +42 -0
- package/dist/blocks/divider/index.js +10 -0
- package/dist/blocks/divider/save.js +18 -0
- package/dist/blocks/divider/style-editor.css +4 -0
- package/dist/blocks/divider/style.css +25 -0
- package/dist/blocks/flag/block.json +48 -0
- package/dist/blocks/flag/edit.js +82 -0
- package/dist/blocks/flag/index.js +10 -0
- package/dist/blocks/flag/save.js +25 -0
- package/dist/blocks/flag/style-editor.css +5 -0
- package/dist/blocks/flag/style.css +45 -0
- package/dist/blocks/icon-button/block.json +43 -0
- package/dist/blocks/icon-button/edit.js +82 -0
- package/dist/blocks/icon-button/index.js +10 -0
- package/dist/blocks/icon-button/save.js +29 -0
- package/dist/blocks/icon-button/style-editor.css +5 -0
- package/dist/blocks/icon-button/style.css +32 -0
- package/dist/blocks/input/block.json +47 -0
- package/dist/blocks/input/edit.js +78 -0
- package/dist/blocks/input/index.js +10 -0
- package/dist/blocks/input/save.js +27 -0
- package/dist/blocks/input/style-editor.css +8 -0
- package/dist/blocks/input/style.css +30 -0
- package/dist/blocks/link/block.json +71 -0
- package/dist/blocks/link/edit.js +151 -0
- package/dist/blocks/link/index.js +10 -0
- package/dist/blocks/link/save.js +46 -0
- package/dist/blocks/link/style-editor.css +5 -0
- package/dist/blocks/link/style.css +66 -0
- package/dist/blocks/text/block.json +32 -0
- package/dist/blocks/text/edit.js +56 -0
- package/dist/blocks/text/index.js +10 -0
- package/dist/blocks/text/save.js +18 -0
- package/dist/blocks/text/style-editor.css +4 -0
- package/dist/blocks/text/style.css +20 -0
- package/dist/blocks/toast/block.json +39 -0
- package/dist/blocks/toast/edit.js +85 -0
- package/dist/blocks/toast/index.js +10 -0
- package/dist/blocks/toast/save.js +29 -0
- package/dist/blocks/toast/style-editor.css +4 -0
- package/dist/blocks/toast/style.css +51 -0
- package/dist/index.cjs +2232 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +2196 -255
- package/dist/index.js.map +1 -1
- package/dist/plugin.php +79 -0
- package/dist/utils/classBuilder.js +53 -0
- package/package.json +39 -7
- package/plugin.php +79 -0
- package/rollup.config.js +39 -22
- package/scripts/build-plugin.cjs +121 -0
- package/scripts/create-block.sh +141 -0
- package/src/blocks/ad-container/block.json +28 -0
- package/src/blocks/ad-container/edit.js +42 -0
- package/src/blocks/ad-container/index.js +10 -0
- package/src/blocks/ad-container/save.js +16 -0
- package/src/blocks/ad-container/style-editor.css +4 -0
- package/src/blocks/ad-container/style.css +27 -0
- package/src/blocks/button/block.json +89 -0
- package/src/blocks/button/edit.js +187 -0
- package/src/blocks/button/index.js +11 -0
- package/src/blocks/button/save.js +52 -0
- package/src/blocks/button/style-editor.css +15 -0
- package/src/blocks/button/style.css +37 -0
- package/src/blocks/chip/block.json +57 -0
- package/src/blocks/chip/edit.js +113 -0
- package/src/blocks/chip/index.js +10 -0
- package/src/blocks/chip/save.js +36 -0
- package/src/blocks/chip/style-editor.css +5 -0
- package/src/blocks/chip/style.css +48 -0
- package/src/blocks/divider/block.json +31 -0
- package/src/blocks/divider/edit.js +42 -0
- package/src/blocks/divider/index.js +10 -0
- package/src/blocks/divider/save.js +18 -0
- package/src/blocks/divider/style-editor.css +4 -0
- package/src/blocks/divider/style.css +25 -0
- package/src/blocks/flag/block.json +48 -0
- package/src/blocks/flag/edit.js +82 -0
- package/src/blocks/flag/index.js +10 -0
- package/src/blocks/flag/save.js +25 -0
- package/src/blocks/flag/style-editor.css +5 -0
- package/src/blocks/flag/style.css +45 -0
- package/src/blocks/icon-button/block.json +43 -0
- package/src/blocks/icon-button/edit.js +82 -0
- package/src/blocks/icon-button/index.js +10 -0
- package/src/blocks/icon-button/save.js +29 -0
- package/src/blocks/icon-button/style-editor.css +5 -0
- package/src/blocks/icon-button/style.css +32 -0
- package/src/blocks/input/block.json +47 -0
- package/src/blocks/input/edit.js +78 -0
- package/src/blocks/input/index.js +10 -0
- package/src/blocks/input/save.js +27 -0
- package/src/blocks/input/style-editor.css +8 -0
- package/src/blocks/input/style.css +30 -0
- package/src/blocks/link/block.json +71 -0
- package/src/blocks/link/edit.js +151 -0
- package/src/blocks/link/index.js +10 -0
- package/src/blocks/link/save.js +46 -0
- package/src/blocks/link/style-editor.css +5 -0
- package/src/blocks/link/style.css +66 -0
- package/src/blocks/text/block.json +32 -0
- package/src/blocks/text/edit.js +56 -0
- package/src/blocks/text/index.js +10 -0
- package/src/blocks/text/save.js +18 -0
- package/src/blocks/text/style-editor.css +4 -0
- package/src/blocks/text/style.css +20 -0
- package/src/blocks/toast/block.json +39 -0
- package/src/blocks/toast/edit.js +85 -0
- package/src/blocks/toast/index.js +10 -0
- package/src/blocks/toast/save.js +29 -0
- package/src/blocks/toast/style-editor.css +4 -0
- package/src/blocks/toast/style.css +51 -0
- package/src/index.js +15 -12
- package/src/utils/classBuilder.js +53 -0
- package/tsconfig.json +4 -4
- package/__tests__/wordpress.test.js +0 -0
- package/dist/AdContainer/AdContainer.d.ts +0 -9
- package/dist/Article/ArticleMetaContainer/ArticleMetaContainer.d.ts +0 -8
- package/dist/Article/UpNextArticles/UpNextArticles.d.ts +0 -13
- package/dist/Button/Button.d.ts +0 -15
- package/dist/CommentsDisabled/CommentsDisabled.d.ts +0 -10
- package/dist/CommentsDisabled/CommentsDisabled.stories.d.ts +0 -44
- package/dist/CommentsDisabled/index.d.ts +0 -2
- package/dist/Divider/Divider.d.ts +0 -15
- package/dist/Input/Input.d.ts +0 -25
- package/dist/Link/Link.d.ts +0 -18
- package/dist/Text/Text.d.ts +0 -14
- package/dist/index.cjs.js +0 -299
- package/dist/index.cjs.js.map +0 -1
- package/dist/styles.css +0 -151
- package/dist/typographyStyles.css +0 -30
- package/dist/utils/cn.d.ts +0 -1
- package/dist/utils/hooks.d.ts +0 -8
- package/src/AdContainer/AdContainer.tsx +0 -31
- package/src/AdContainer/styles.css +0 -58
- package/src/Article/ArticleMetaContainer/ArticleMetaContainer.tsx +0 -14
- package/src/Article/ArticleMetaContainer/styles.css +0 -151
- package/src/Article/UpNextArticles/UpNextArticles.tsx +0 -69
- package/src/Article/UpNextArticles/styles.css +0 -151
- package/src/Button/Button.tsx +0 -36
- package/src/Button/styles.css +0 -30
- package/src/CommentsDisabled/CommentsDisabled.stories.tsx +0 -178
- package/src/CommentsDisabled/CommentsDisabled.tsx +0 -63
- package/src/CommentsDisabled/IMPLEMENTATION_SUMMARY.md +0 -305
- package/src/CommentsDisabled/README.md +0 -284
- package/src/CommentsDisabled/TOKEN_MAPPING.md +0 -269
- package/src/CommentsDisabled/index.ts +0 -2
- package/src/CommentsDisabled/styles.css +0 -82
- package/src/Divider/Divider.tsx +0 -41
- package/src/Divider/styles.css +0 -80
- package/src/Input/Input.tsx +0 -62
- package/src/Input/styles.css +0 -69
- package/src/Link/Link.tsx +0 -49
- package/src/Link/styles.css +0 -111
- package/src/Text/Text.tsx +0 -38
- package/src/Text/styles.css +0 -30
- package/src/Text/typographyStyles.css +0 -30
- package/src/utils/cn.js +0 -3
- package/src/utils/cn.tsx +0 -3
- package/src/utils/hooks.ts +0 -34
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Block Creation Checklist
|
|
2
|
+
|
|
3
|
+
Use this checklist when creating each new WordPress block from a React component.
|
|
4
|
+
|
|
5
|
+
## 1. Analysis
|
|
6
|
+
|
|
7
|
+
- [ ] Reviewed React component in `packages/components-react/src/<ComponentName>/`
|
|
8
|
+
- [ ] Listed all props and their types
|
|
9
|
+
- [ ] Identified variant combinations (enums)
|
|
10
|
+
- [ ] Checked for external dependencies (icons, utilities)
|
|
11
|
+
- [ ] Noted any special styling requirements
|
|
12
|
+
|
|
13
|
+
## 2. Setup
|
|
14
|
+
|
|
15
|
+
- [ ] Created directory: `src/blocks/<component-name>/`
|
|
16
|
+
- [ ] Created `block.json` manifest
|
|
17
|
+
- [ ] Created `index.js` registration file
|
|
18
|
+
- [ ] Created `edit.js` editor component
|
|
19
|
+
- [ ] Created `save.js` frontend component
|
|
20
|
+
- [ ] Created `style.css` frontend styles
|
|
21
|
+
- [ ] Created `style-editor.css` (if needed)
|
|
22
|
+
|
|
23
|
+
## 3. block.json
|
|
24
|
+
|
|
25
|
+
- [ ] Set `name` to `times/<component-name>`
|
|
26
|
+
- [ ] Set descriptive `title`
|
|
27
|
+
- [ ] Added all React props as `attributes`
|
|
28
|
+
- [ ] Set appropriate `type` for each attribute
|
|
29
|
+
- [ ] Added `enum` arrays for variant props
|
|
30
|
+
- [ ] Set sensible `default` values
|
|
31
|
+
- [ ] Added clear `description` for each attribute
|
|
32
|
+
- [ ] Configured `supports` object (spacing, align, etc.)
|
|
33
|
+
|
|
34
|
+
## 4. edit.js
|
|
35
|
+
|
|
36
|
+
- [ ] Imported `useBlockProps` from `@wordpress/block-editor`
|
|
37
|
+
- [ ] Imported `InspectorControls` from `@wordpress/block-editor`
|
|
38
|
+
- [ ] Imported appropriate components from `@wordpress/components`
|
|
39
|
+
- [ ] Used `buildButtonClass` or similar utility from `src/utils/`
|
|
40
|
+
- [ ] Added `InspectorControls` with `PanelBody`
|
|
41
|
+
- [ ] Created control for each attribute
|
|
42
|
+
- [ ] Called `setAttributes()` for each control
|
|
43
|
+
- [ ] Rendered preview of component in editor
|
|
44
|
+
- [ ] Added editor styles import
|
|
45
|
+
|
|
46
|
+
## 5. save.js
|
|
47
|
+
|
|
48
|
+
- [ ] Used `useBlockProps.save()`
|
|
49
|
+
- [ ] Returned valid, deterministic HTML
|
|
50
|
+
- [ ] Output matches React component structure
|
|
51
|
+
- [ ] No event handlers or dynamic behavior
|
|
52
|
+
- [ ] Included proper ARIA attributes
|
|
53
|
+
|
|
54
|
+
## 6. Styling
|
|
55
|
+
|
|
56
|
+
- [ ] Updated `style.css` with component styles
|
|
57
|
+
- [ ] Used CSS custom properties for design tokens
|
|
58
|
+
- [ ] Followed BEM naming: `.tds-<component>`, `.tds-<component>--modifier`
|
|
59
|
+
- [ ] Tested styles on editor and frontend
|
|
60
|
+
- [ ] Added `style-editor.css` for editor-specific overrides (if needed)
|
|
61
|
+
|
|
62
|
+
## 7. Utilities
|
|
63
|
+
|
|
64
|
+
- [ ] Created helper functions in `src/utils/` (if needed)
|
|
65
|
+
- [ ] Added `classBuilder` for className generation (if complex)
|
|
66
|
+
- [ ] Documented utility functions with JSDoc
|
|
67
|
+
|
|
68
|
+
## 8. Integration
|
|
69
|
+
|
|
70
|
+
- [ ] Added block import to `src/index.js`
|
|
71
|
+
- [ ] Updated `src/utils/classBuilder.js` with new utilities
|
|
72
|
+
- [ ] Verified block appears in Gutenberg inserter
|
|
73
|
+
- [ ] Tested all attribute controls in block inspector
|
|
74
|
+
- [ ] Verified block saves correctly
|
|
75
|
+
- [ ] Tested frontend rendering
|
|
76
|
+
|
|
77
|
+
## 9. Quality Assurance
|
|
78
|
+
|
|
79
|
+
- [ ] No console errors or warnings
|
|
80
|
+
- [ ] Accessibility tested (keyboard nav, screen readers)
|
|
81
|
+
- [ ] Mobile-responsive layout tested
|
|
82
|
+
- [ ] Dark mode compatibility (if applicable)
|
|
83
|
+
- [ ] Block HTML validates without errors
|
|
84
|
+
- [ ] Tested with different content lengths
|
|
85
|
+
|
|
86
|
+
## 10. Documentation
|
|
87
|
+
|
|
88
|
+
- [ ] Updated this checklist
|
|
89
|
+
- [ ] Added block to component list in TRANSFORMATION_GUIDE.md
|
|
90
|
+
- [ ] Documented any special handling or considerations
|
|
91
|
+
- [ ] Added block to component inventory
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Component Transformation Order
|
|
96
|
+
|
|
97
|
+
Track which components have been transformed:
|
|
98
|
+
|
|
99
|
+
- [x] Button (Reference implementation)
|
|
100
|
+
- [x] Text
|
|
101
|
+
- [x] Divider
|
|
102
|
+
- [x] Input
|
|
103
|
+
- [x] Link
|
|
104
|
+
- [x] IconButton
|
|
105
|
+
- [x] Chip
|
|
106
|
+
- [x] Flag
|
|
107
|
+
- [x] Toast
|
|
108
|
+
- [x] AdContainer
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Quick Reference: Prop Type → Block Attribute
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
React Type → Block.json Type & Example
|
|
116
|
+
─────────────────────────────────────────────────
|
|
117
|
+
string → "type": "string", "default": ""
|
|
118
|
+
boolean → "type": "boolean", "default": false
|
|
119
|
+
enum (union) → "enum": ["a", "b"], "default": "a"
|
|
120
|
+
number → "type": "number", "default": 0
|
|
121
|
+
Event handler → Not supported (use editor preview only)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Common Issues & Solutions
|
|
127
|
+
|
|
128
|
+
### Issue: Block doesn't appear in inserter
|
|
129
|
+
|
|
130
|
+
**Solution**: Verify `block.json` has `name: "times/..."` and `index.js` imports block registration
|
|
131
|
+
|
|
132
|
+
### Issue: Attributes not persisting
|
|
133
|
+
|
|
134
|
+
**Solution**: Check attribute names match exactly in `block.json`, `edit.js`, `save.js`
|
|
135
|
+
|
|
136
|
+
### Issue: Styles not loading
|
|
137
|
+
|
|
138
|
+
**Solution**: Verify CSS paths in `block.json` and ensure theme-scss is in dependencies
|
|
139
|
+
|
|
140
|
+
### Issue: Inspector controls not working
|
|
141
|
+
|
|
142
|
+
**Solution**: Verify `setAttributes()` is called with correct attribute name and value
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Helpful Commands
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Create new block scaffold
|
|
150
|
+
./scripts/create-block.sh <component-name>
|
|
151
|
+
|
|
152
|
+
# Build for development
|
|
153
|
+
npm run dev
|
|
154
|
+
|
|
155
|
+
# Build for production
|
|
156
|
+
npm run build
|
|
157
|
+
|
|
158
|
+
# Validate JSON
|
|
159
|
+
npm run test
|
|
160
|
+
```
|
package/BUILD.md
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
# WordPress Blocks Build Guide
|
|
2
|
+
|
|
3
|
+
This document explains the build process for the Times Design System WordPress blocks package.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The build process transforms source components into a WordPress plugin distribution with the following steps:
|
|
8
|
+
|
|
9
|
+
1. **Clean** — Remove old builds
|
|
10
|
+
2. **Rollup Bundle** — Compile JavaScript, copy block files
|
|
11
|
+
3. **Plugin Organization** — Arrange files for WordPress
|
|
12
|
+
|
|
13
|
+
## Build Process
|
|
14
|
+
|
|
15
|
+
### Step 1: Install Dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
cd packages/components-wordpress
|
|
19
|
+
npm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Required for build**:
|
|
23
|
+
|
|
24
|
+
- `rollup` — Module bundler
|
|
25
|
+
- `@rollup/plugin-*` — Rollup plugins for various file types
|
|
26
|
+
- `rollup-plugin-copy` — Copy static files
|
|
27
|
+
- `rollup-plugin-postcss` — Process CSS
|
|
28
|
+
- `@babel/*` — JavaScript transpilation
|
|
29
|
+
- `typescript` — TypeScript support
|
|
30
|
+
|
|
31
|
+
### Step 2: Build
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm run build
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This runs:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run clean # Remove old dist/
|
|
41
|
+
npm run build:rollup # Rollup bundling + copy
|
|
42
|
+
npm run build:plugin # Organize plugin structure
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Output**: `dist/` folder with:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
dist/
|
|
49
|
+
├── plugin.php # WordPress plugin entry
|
|
50
|
+
├── block.json # Root manifest
|
|
51
|
+
├── index.js # ES module
|
|
52
|
+
├── index.cjs # CommonJS
|
|
53
|
+
├── index.css # Compiled styles
|
|
54
|
+
├── blocks/ # Block files
|
|
55
|
+
│ ├── button/
|
|
56
|
+
│ │ ├── block.json
|
|
57
|
+
│ │ ├── index.js
|
|
58
|
+
│ │ ├── edit.js
|
|
59
|
+
│ │ ├── save.js
|
|
60
|
+
│ │ ├── style.css
|
|
61
|
+
│ │ └── style-editor.css
|
|
62
|
+
│ └── [more blocks]/
|
|
63
|
+
└── utils/
|
|
64
|
+
└── classBuilder.js
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Step 3: Development Build
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm run dev
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Watches for changes and rebuilds automatically. Used during development.
|
|
74
|
+
|
|
75
|
+
## Build Configuration
|
|
76
|
+
|
|
77
|
+
### rollup.config.js
|
|
78
|
+
|
|
79
|
+
The main build configuration:
|
|
80
|
+
|
|
81
|
+
**Input**: `src/index.js`
|
|
82
|
+
|
|
83
|
+
**Outputs**:
|
|
84
|
+
|
|
85
|
+
- `dist/index.js` — ES module (for bundlers)
|
|
86
|
+
- `dist/index.cjs` — CommonJS (for Node)
|
|
87
|
+
|
|
88
|
+
**Plugins**:
|
|
89
|
+
|
|
90
|
+
1. **resolve** — Resolves node modules
|
|
91
|
+
- Handles `.js`, `.jsx`, `.ts`, `.tsx`, `.json`
|
|
92
|
+
- Uses browser resolution
|
|
93
|
+
2. **commonjs** — Converts CommonJS to ES modules
|
|
94
|
+
3. **json** — Allows importing JSON files
|
|
95
|
+
4. **typescript** — Transpiles TypeScript
|
|
96
|
+
- Outputs type declarations to `dist/`
|
|
97
|
+
5. **postcss** — Processes CSS
|
|
98
|
+
- Extracts to `dist/index.css`
|
|
99
|
+
- Minifies CSS
|
|
100
|
+
- Creates sourcemaps
|
|
101
|
+
6. **babel** — Transpiles JavaScript
|
|
102
|
+
- Supports ES6+
|
|
103
|
+
- JSX support
|
|
104
|
+
7. **copy** — Copies static files
|
|
105
|
+
- `src/blocks/**/*` → `dist/blocks/`
|
|
106
|
+
- `src/utils/**/*.js` → `dist/utils/`
|
|
107
|
+
- `src/**/*.css` → `dist/`
|
|
108
|
+
- `plugin.php` → `dist/plugin.php`
|
|
109
|
+
- `block.json` → `dist/block.json`
|
|
110
|
+
|
|
111
|
+
**External Dependencies** (not bundled):
|
|
112
|
+
|
|
113
|
+
- `@wordpress/blocks`
|
|
114
|
+
- `@wordpress/block-editor`
|
|
115
|
+
- `@wordpress/components`
|
|
116
|
+
- `@wordpress/element`
|
|
117
|
+
|
|
118
|
+
These are assumed to be available in WordPress.
|
|
119
|
+
|
|
120
|
+
### scripts/build-plugin.js
|
|
121
|
+
|
|
122
|
+
Post-build script that:
|
|
123
|
+
|
|
124
|
+
1. ✅ Verifies plugin structure
|
|
125
|
+
2. ✅ Checks all blocks have required files
|
|
126
|
+
3. ✅ Reports missing utilities
|
|
127
|
+
4. ✅ Displays build summary
|
|
128
|
+
5. ✅ Validates plugin.php exists
|
|
129
|
+
6. ✅ Verifies block.json manifests
|
|
130
|
+
|
|
131
|
+
## File Structure for Build
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
src/
|
|
135
|
+
├── index.js # Main entry (registers all blocks)
|
|
136
|
+
├── blocks/
|
|
137
|
+
│ ├── button/
|
|
138
|
+
│ │ ├── block.json # ← Copied to dist/blocks/button/
|
|
139
|
+
│ │ ├── index.js # ← Copied to dist/blocks/button/
|
|
140
|
+
│ │ ├── edit.js # ← Copied to dist/blocks/button/
|
|
141
|
+
│ │ ├── save.js # ← Copied to dist/blocks/button/
|
|
142
|
+
│ │ ├── style.css # ← Copied to dist/blocks/button/
|
|
143
|
+
│ │ └── style-editor.css # ← Copied to dist/blocks/button/
|
|
144
|
+
│ └── [more blocks]/
|
|
145
|
+
├── utils/
|
|
146
|
+
│ └── classBuilder.js # ← Copied to dist/utils/
|
|
147
|
+
└── [other files]
|
|
148
|
+
|
|
149
|
+
plugin.php # ← Copied to dist/
|
|
150
|
+
block.json # ← Copied to dist/
|
|
151
|
+
rollup.config.js # ← Build config (not copied)
|
|
152
|
+
package.json # ← Package info (not copied)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## What Gets Bundled vs Copied
|
|
156
|
+
|
|
157
|
+
### Bundled (by Rollup)
|
|
158
|
+
|
|
159
|
+
- `src/index.js` → `dist/index.js` and `dist/index.cjs`
|
|
160
|
+
- All JavaScript imports in index.js
|
|
161
|
+
- CSS (extracted to `dist/index.css`)
|
|
162
|
+
|
|
163
|
+
### Copied (by Rollup copy plugin)
|
|
164
|
+
|
|
165
|
+
- `src/blocks/**/*` → `dist/blocks/`
|
|
166
|
+
- `src/utils/**/*.js` → `dist/utils/`
|
|
167
|
+
- `plugin.php` → `dist/plugin.php`
|
|
168
|
+
- `block.json` → `dist/block.json`
|
|
169
|
+
|
|
170
|
+
## Troubleshooting Build
|
|
171
|
+
|
|
172
|
+
### Error: Cannot find module '@rollup/plugin-\*'
|
|
173
|
+
|
|
174
|
+
**Solution**: Install missing dependencies
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
npm install --save-dev @rollup/plugin-babel @rollup/plugin-typescript rollup-plugin-copy rollup-plugin-postcss
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Error: Block not found in dist/blocks/
|
|
181
|
+
|
|
182
|
+
**Check**:
|
|
183
|
+
|
|
184
|
+
1. Block folder exists in `src/blocks/<block-name>/`
|
|
185
|
+
2. `block.json` exists in block folder
|
|
186
|
+
3. `src/index.js` imports the block: `import './blocks/<block-name>/index.js'`
|
|
187
|
+
4. Run build again: `npm run build`
|
|
188
|
+
|
|
189
|
+
### Error: "Cannot compile CSS"
|
|
190
|
+
|
|
191
|
+
**Solution**:
|
|
192
|
+
|
|
193
|
+
1. Ensure PostCSS is installed: `npm install --save-dev rollup-plugin-postcss`
|
|
194
|
+
2. Check CSS syntax is valid
|
|
195
|
+
3. Clear dist: `npm run clean`
|
|
196
|
+
4. Rebuild: `npm run build`
|
|
197
|
+
|
|
198
|
+
### dist/blocks/ is empty
|
|
199
|
+
|
|
200
|
+
**Check**:
|
|
201
|
+
|
|
202
|
+
1. Rollup config `copy` targets are correct
|
|
203
|
+
2. Block files exist in `src/blocks/`
|
|
204
|
+
3. Rollup is using correct config: `rollup -c`
|
|
205
|
+
4. No permissions issues on dist/ folder
|
|
206
|
+
|
|
207
|
+
## Distribution
|
|
208
|
+
|
|
209
|
+
### For WordPress Plugin Users
|
|
210
|
+
|
|
211
|
+
The contents of `dist/` are ready to distribute:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Zip for distribution
|
|
215
|
+
cd dist
|
|
216
|
+
zip -r times-design-system-blocks.zip .
|
|
217
|
+
|
|
218
|
+
# Or copy to WordPress
|
|
219
|
+
cp -r dist/* /path/to/wordpress/wp-content/plugins/times-design-system-blocks/
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### For NPM Package Users
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Build for publishing
|
|
226
|
+
npm run build
|
|
227
|
+
|
|
228
|
+
# Publish to npm registry
|
|
229
|
+
npm publish
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Development Workflow
|
|
233
|
+
|
|
234
|
+
### Adding a New Block
|
|
235
|
+
|
|
236
|
+
1. Create block directory:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
./scripts/create-block.sh myblock
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
2. Edit files in `src/blocks/myblock/`:
|
|
243
|
+
- `block.json` — Add attributes
|
|
244
|
+
- `edit.js` — Add inspector controls
|
|
245
|
+
- `save.js` — Add frontend HTML
|
|
246
|
+
- `style.css` — Add styles
|
|
247
|
+
|
|
248
|
+
3. Register in `src/index.js`:
|
|
249
|
+
|
|
250
|
+
```javascript
|
|
251
|
+
import './blocks/myblock/index.js';
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
4. Build and test:
|
|
255
|
+
```bash
|
|
256
|
+
npm run build
|
|
257
|
+
# Test in WordPress
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Modifying Existing Block
|
|
261
|
+
|
|
262
|
+
1. Edit files in `src/blocks/<block-name>/`
|
|
263
|
+
2. Save changes
|
|
264
|
+
3. If running `npm run dev`, changes auto-rebuild
|
|
265
|
+
4. If not, manually run `npm run build`
|
|
266
|
+
5. Test changes in WordPress
|
|
267
|
+
|
|
268
|
+
### Testing Before Build
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Validate Rollup config
|
|
272
|
+
npx rollup --help
|
|
273
|
+
|
|
274
|
+
# Test individual file compilation
|
|
275
|
+
npx rollup --input src/index.js --format esm
|
|
276
|
+
|
|
277
|
+
# Check file sizes
|
|
278
|
+
npm run build && du -sh dist/*
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Performance Tips
|
|
282
|
+
|
|
283
|
+
### Reduce Bundle Size
|
|
284
|
+
|
|
285
|
+
1. **Remove unused blocks**:
|
|
286
|
+
- Comment out imports in `src/index.js`
|
|
287
|
+
- Rebuild: `npm run build`
|
|
288
|
+
|
|
289
|
+
2. **Use external dependencies**:
|
|
290
|
+
- WordPress packages are external (not bundled)
|
|
291
|
+
- Keep them that way for smaller bundle
|
|
292
|
+
|
|
293
|
+
3. **Minify CSS**:
|
|
294
|
+
- PostCSS config already minifies
|
|
295
|
+
- CSS is extracted to separate file
|
|
296
|
+
|
|
297
|
+
### Build Speed
|
|
298
|
+
|
|
299
|
+
1. **Incremental build** (during dev):
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
npm run dev # Only rebuilds changed files
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
2. **Skip type checking**:
|
|
306
|
+
- In `rollup.config.js`, set `typescript: false`
|
|
307
|
+
- Only for development!
|
|
308
|
+
|
|
309
|
+
3. **Parallel builds**:
|
|
310
|
+
- Use `npm-run-all` for multiple builds in parallel
|
|
311
|
+
|
|
312
|
+
## CI/CD Integration
|
|
313
|
+
|
|
314
|
+
### GitHub Actions Example
|
|
315
|
+
|
|
316
|
+
```yaml
|
|
317
|
+
name: Build WordPress Blocks
|
|
318
|
+
|
|
319
|
+
on:
|
|
320
|
+
push:
|
|
321
|
+
branches: [main]
|
|
322
|
+
paths: ['packages/components-wordpress/**']
|
|
323
|
+
|
|
324
|
+
jobs:
|
|
325
|
+
build:
|
|
326
|
+
runs-on: ubuntu-latest
|
|
327
|
+
steps:
|
|
328
|
+
- uses: actions/checkout@v3
|
|
329
|
+
- uses: actions/setup-node@v3
|
|
330
|
+
with:
|
|
331
|
+
node-version: '18'
|
|
332
|
+
|
|
333
|
+
- name: Install dependencies
|
|
334
|
+
run: |
|
|
335
|
+
cd packages/components-wordpress
|
|
336
|
+
npm install
|
|
337
|
+
|
|
338
|
+
- name: Build
|
|
339
|
+
run: |
|
|
340
|
+
cd packages/components-wordpress
|
|
341
|
+
npm run build
|
|
342
|
+
|
|
343
|
+
- name: Verify output
|
|
344
|
+
run: |
|
|
345
|
+
test -d packages/components-wordpress/dist/blocks
|
|
346
|
+
test -f packages/components-wordpress/dist/plugin.php
|
|
347
|
+
|
|
348
|
+
- name: Upload artifact
|
|
349
|
+
uses: actions/upload-artifact@v3
|
|
350
|
+
with:
|
|
351
|
+
name: wordpress-blocks
|
|
352
|
+
path: packages/components-wordpress/dist/
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Debugging
|
|
356
|
+
|
|
357
|
+
### Enable Verbose Output
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# Rollup verbose mode
|
|
361
|
+
npx rollup -c --verbose
|
|
362
|
+
|
|
363
|
+
# Node debug
|
|
364
|
+
DEBUG=* npm run build
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Check Generated Files
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
# List dist structure
|
|
371
|
+
tree dist/
|
|
372
|
+
|
|
373
|
+
# Check file sizes
|
|
374
|
+
ls -lh dist/**/*
|
|
375
|
+
|
|
376
|
+
# Verify block.json syntax
|
|
377
|
+
cat dist/blocks/button/block.json | jq .
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### Common Issues Checklist
|
|
381
|
+
|
|
382
|
+
- [ ] All dependencies installed: `npm install`
|
|
383
|
+
- [ ] Rollup config valid: `npx rollup --help`
|
|
384
|
+
- [ ] Source files exist in `src/blocks/`
|
|
385
|
+
- [ ] `block.json` is valid JSON
|
|
386
|
+
- [ ] Imports in `src/index.js` match block folder names
|
|
387
|
+
- [ ] CSS files have valid syntax
|
|
388
|
+
- [ ] No TypeScript errors in `*.ts` files
|
|
389
|
+
- [ ] plugin.php exists in root
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## Quick Commands Reference
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
npm run clean # Remove dist/
|
|
397
|
+
npm run build:rollup # Run Rollup bundler
|
|
398
|
+
npm run build:plugin # Run plugin organizer
|
|
399
|
+
npm run build # Full build (clean + rollup + plugin)
|
|
400
|
+
npm run dev # Watch mode for development
|
|
401
|
+
npm run test # Run tests
|
|
402
|
+
npm run prepublishOnly # Runs before npm publish
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
For more details on WordPress plugin structure, see:
|
|
408
|
+
|
|
409
|
+
- [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
|
|
410
|
+
- [Gutenberg Blocks](https://developer.wordpress.org/block-editor/)
|
|
411
|
+
- [TRANSFORMATION_GUIDE.md](./TRANSFORMATION_GUIDE.md)
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.2.0](https://github.com/newsuk/times-design-system/compare/@times-design-system/components-wordpress@0.7.1...@times-design-system/components-wordpress@1.2.0) (2026-05-27)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **TDS-000:** tsconfig fix and ramp-colors-reference.csv workflow rem… ([#72](https://github.com/newsuk/times-design-system/issues/72)) ([fef4a9f](https://github.com/newsuk/times-design-system/commit/fef4a9fd802ae179cefefd8a62b0346cb2d43663))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **TDS-82:** wp components build ([#68](https://github.com/newsuk/times-design-system/issues/68)) ([8967055](https://github.com/newsuk/times-design-system/commit/8967055af77db6df4c29eab0f028499b36f425d1))
|
|
15
|
+
|
|
16
|
+
## [0.7.1](https://github.com/newsuk/times-design-system/compare/@times-design-system/components-wordpress@0.7.0...@times-design-system/components-wordpress@0.7.1) (2026-05-26)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @times-design-system/components-wordpress
|
|
19
|
+
|
|
20
|
+
# [0.7.0](https://github.com/newsuk/times-design-system/compare/@times-design-system/components-wordpress@0.6.0...@times-design-system/components-wordpress@0.7.0) (2026-05-11)
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
- **TDS-76:** update theme reconciliation and publish components for … ([#65](https://github.com/newsuk/times-design-system/issues/65)) ([031e63a](https://github.com/newsuk/times-design-system/commit/031e63a9bf39218b1cf4d82bc763cac2f1c60e0a))
|
|
25
|
+
|
|
26
|
+
# [0.6.0](https://github.com/newsuk/times-design-system/compare/@times-design-system/components-wordpress@0.5.0...@times-design-system/components-wordpress@0.6.0) (2026-04-14)
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
- **TDS-74:** beta component development ([#49](https://github.com/newsuk/times-design-system/issues/49)) ([f98ecaa](https://github.com/newsuk/times-design-system/commit/f98ecaad96b12292d0ab4a7fae73328215d3e945))
|
|
31
|
+
|
|
32
|
+
# [0.5.0](https://github.com/newsuk/times-design-system/compare/@times-design-system/components-wordpress@0.4.0...@times-design-system/components-wordpress@0.5.0) (2026-03-23)
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
- **TDS-72:** repo review ([#46](https://github.com/newsuk/times-design-system/issues/46)) ([e46785a](https://github.com/newsuk/times-design-system/commit/e46785a49ab436598e508e9c934df0cea47a24e8))
|
|
37
|
+
|
|
6
38
|
# 0.4.0 (2026-02-05)
|
|
7
39
|
|
|
8
40
|
### Features
|
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017, News UK & Ireland Ltd
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|