@jackuait/blok 0.3.1-beta.0 → 0.3.1-beta.3
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/README.md +2 -2
- package/codemod/README.md +177 -0
- package/codemod/migrate-editorjs-to-blok.js +496 -0
- package/codemod/package.json +32 -0
- package/codemod/test.js +299 -0
- package/dist/{blok-e-cML09O.mjs → blok-DVGmVJt8.mjs} +4480 -4339
- package/dist/blok.mjs +1 -1
- package/dist/blok.umd.js +35 -27
- package/dist/{index-BeLqsXna.mjs → index-6boN1DB4.mjs} +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jackuait/blok-codemod",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Codemod to migrate from EditorJS to Blok",
|
|
5
|
+
"main": "migrate-editorjs-to-blok.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"blok-codemod": "./migrate-editorjs-to-blok.js",
|
|
8
|
+
"migrate-editorjs-to-blok": "./migrate-editorjs-to-blok.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"blok",
|
|
12
|
+
"editorjs",
|
|
13
|
+
"codemod",
|
|
14
|
+
"migration",
|
|
15
|
+
"editor",
|
|
16
|
+
"rich-text"
|
|
17
|
+
],
|
|
18
|
+
"author": "Jack Uait",
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/jackuait/blok.git",
|
|
23
|
+
"directory": "codemod"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=14.0.0"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"migrate-editorjs-to-blok.js",
|
|
30
|
+
"README.md"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/codemod/test.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the EditorJS to Blok codemod
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
applyTransforms,
|
|
7
|
+
IMPORT_TRANSFORMS,
|
|
8
|
+
TYPE_TRANSFORMS,
|
|
9
|
+
CLASS_NAME_TRANSFORMS,
|
|
10
|
+
CSS_CLASS_TRANSFORMS,
|
|
11
|
+
DATA_ATTRIBUTE_TRANSFORMS,
|
|
12
|
+
SELECTOR_TRANSFORMS,
|
|
13
|
+
HOLDER_TRANSFORMS,
|
|
14
|
+
TOOL_CONFIG_TRANSFORMS,
|
|
15
|
+
} = require('./migrate-editorjs-to-blok');
|
|
16
|
+
|
|
17
|
+
// Test helper
|
|
18
|
+
function test(name, fn) {
|
|
19
|
+
try {
|
|
20
|
+
fn();
|
|
21
|
+
console.log(`✅ ${name}`);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.log(`❌ ${name}`);
|
|
24
|
+
console.log(` ${error.message}`);
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function assertEqual(actual, expected, message = '') {
|
|
30
|
+
if (actual !== expected) {
|
|
31
|
+
throw new Error(`${message}\nExpected: ${expected}\nActual: ${actual}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Import Tests
|
|
37
|
+
// ============================================================================
|
|
38
|
+
|
|
39
|
+
console.log('\n📦 Import Transformations\n');
|
|
40
|
+
|
|
41
|
+
test('transforms @editorjs/editorjs import', () => {
|
|
42
|
+
const input = `import EditorJS from '@editorjs/editorjs';`;
|
|
43
|
+
const { result } = applyTransforms(input, IMPORT_TRANSFORMS);
|
|
44
|
+
assertEqual(result, `import EditorJS from '@jackuait/blok';`);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('transforms require statement', () => {
|
|
48
|
+
const input = `const EditorJS = require('@editorjs/editorjs');`;
|
|
49
|
+
const { result } = applyTransforms(input, IMPORT_TRANSFORMS);
|
|
50
|
+
assertEqual(result, `const EditorJS = require('@jackuait/blok');`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('transforms @editorjs/header import', () => {
|
|
54
|
+
const input = `import Header from '@editorjs/header';`;
|
|
55
|
+
const { result } = applyTransforms(input, IMPORT_TRANSFORMS);
|
|
56
|
+
assertEqual(result, `// Header is now bundled with Blok: use Blok.Header\n`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('transforms @editorjs/paragraph import', () => {
|
|
60
|
+
const input = `import Paragraph from '@editorjs/paragraph';`;
|
|
61
|
+
const { result } = applyTransforms(input, IMPORT_TRANSFORMS);
|
|
62
|
+
assertEqual(result, `// Paragraph is now bundled with Blok: use Blok.Paragraph\n`);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ============================================================================
|
|
66
|
+
// Type Tests
|
|
67
|
+
// ============================================================================
|
|
68
|
+
|
|
69
|
+
console.log('\n🔤 Type Transformations\n');
|
|
70
|
+
|
|
71
|
+
test('transforms EditorConfig type', () => {
|
|
72
|
+
const input = `const config: EditorConfig = {};`;
|
|
73
|
+
const { result } = applyTransforms(input, TYPE_TRANSFORMS);
|
|
74
|
+
assertEqual(result, `const config: BlokConfig = {};`);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('transforms EditorJS.EditorConfig type', () => {
|
|
78
|
+
const input = `const config: EditorJS.EditorConfig = {};`;
|
|
79
|
+
const { result } = applyTransforms(input, TYPE_TRANSFORMS);
|
|
80
|
+
assertEqual(result, `const config: BlokConfig = {};`);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// ============================================================================
|
|
84
|
+
// Class Name Tests
|
|
85
|
+
// ============================================================================
|
|
86
|
+
|
|
87
|
+
console.log('\n📝 Class Name Transformations\n');
|
|
88
|
+
|
|
89
|
+
test('transforms new EditorJS() constructor', () => {
|
|
90
|
+
const input = `const editor = new EditorJS({ holder: 'editor' });`;
|
|
91
|
+
const { result } = applyTransforms(input, CLASS_NAME_TRANSFORMS);
|
|
92
|
+
assertEqual(result, `const editor = new Blok({ holder: 'editor' });`);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('transforms EditorJS type annotation', () => {
|
|
96
|
+
const input = `let editor: EditorJS;`;
|
|
97
|
+
const { result } = applyTransforms(input, CLASS_NAME_TRANSFORMS);
|
|
98
|
+
assertEqual(result, `let editor: Blok;`);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('transforms generic type parameter', () => {
|
|
102
|
+
const input = `const ref = useRef<EditorJS>(null);`;
|
|
103
|
+
const { result } = applyTransforms(input, CLASS_NAME_TRANSFORMS);
|
|
104
|
+
assertEqual(result, `const ref = useRef<Blok>(null);`);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// CSS Class Tests
|
|
109
|
+
// ============================================================================
|
|
110
|
+
|
|
111
|
+
console.log('\n🎨 CSS Class Transformations\n');
|
|
112
|
+
|
|
113
|
+
test('transforms .codex-editor class', () => {
|
|
114
|
+
const input = `.codex-editor { color: red; }`;
|
|
115
|
+
const { result } = applyTransforms(input, CSS_CLASS_TRANSFORMS);
|
|
116
|
+
assertEqual(result, `.blok-editor { color: red; }`);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('transforms .codex-editor--narrow modifier', () => {
|
|
120
|
+
const input = `.codex-editor--narrow { width: 100%; }`;
|
|
121
|
+
const { result } = applyTransforms(input, CSS_CLASS_TRANSFORMS);
|
|
122
|
+
assertEqual(result, `.blok-editor--narrow { width: 100%; }`);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('transforms .ce-block class', () => {
|
|
126
|
+
const input = `.ce-block { margin: 10px; }`;
|
|
127
|
+
const { result } = applyTransforms(input, CSS_CLASS_TRANSFORMS);
|
|
128
|
+
assertEqual(result, `[data-blok-testid="block-wrapper"] { margin: 10px; }`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('transforms .ce-block--selected class', () => {
|
|
132
|
+
const input = `.ce-block--selected { background: blue; }`;
|
|
133
|
+
const { result } = applyTransforms(input, CSS_CLASS_TRANSFORMS);
|
|
134
|
+
assertEqual(result, `[data-blok-selected="true"] { background: blue; }`);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('transforms .ce-toolbar class', () => {
|
|
138
|
+
const input = `document.querySelector('.ce-toolbar')`;
|
|
139
|
+
const { result } = applyTransforms(input, CSS_CLASS_TRANSFORMS);
|
|
140
|
+
assertEqual(result, `document.querySelector('[data-blok-testid="toolbar"]')`);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('transforms .ce-inline-toolbar class', () => {
|
|
144
|
+
const input = `.ce-inline-toolbar { display: flex; }`;
|
|
145
|
+
const { result } = applyTransforms(input, CSS_CLASS_TRANSFORMS);
|
|
146
|
+
assertEqual(result, `[data-blok-testid="inline-toolbar"] { display: flex; }`);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// ============================================================================
|
|
150
|
+
// Data Attribute Tests
|
|
151
|
+
// ============================================================================
|
|
152
|
+
|
|
153
|
+
console.log('\n🏷️ Data Attribute Transformations\n');
|
|
154
|
+
|
|
155
|
+
test('transforms data-id attribute', () => {
|
|
156
|
+
const input = `<div data-id="abc123">`;
|
|
157
|
+
const { result } = applyTransforms(input, DATA_ATTRIBUTE_TRANSFORMS);
|
|
158
|
+
assertEqual(result, `<div data-blok-id="abc123">`);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('transforms data-item-name attribute', () => {
|
|
162
|
+
const input = `<button data-item-name="bold">`;
|
|
163
|
+
const { result } = applyTransforms(input, DATA_ATTRIBUTE_TRANSFORMS);
|
|
164
|
+
assertEqual(result, `<button data-blok-item-name="bold">`);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('transforms data-empty attribute', () => {
|
|
168
|
+
const input = `<div data-empty="true">`;
|
|
169
|
+
const { result } = applyTransforms(input, DATA_ATTRIBUTE_TRANSFORMS);
|
|
170
|
+
assertEqual(result, `<div data-blok-empty="true">`);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('transforms data-cy=editorjs selector', () => {
|
|
174
|
+
const input = `[data-cy="editorjs"]`;
|
|
175
|
+
const { result } = applyTransforms(input, DATA_ATTRIBUTE_TRANSFORMS);
|
|
176
|
+
assertEqual(result, `[data-blok-testid="blok-editor"]`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// ============================================================================
|
|
180
|
+
// Selector Tests
|
|
181
|
+
// ============================================================================
|
|
182
|
+
|
|
183
|
+
console.log('\n🔍 Selector Transformations\n');
|
|
184
|
+
|
|
185
|
+
test('transforms [data-id=] selector', () => {
|
|
186
|
+
const input = `document.querySelector('[data-id="123"]')`;
|
|
187
|
+
const { result } = applyTransforms(input, SELECTOR_TRANSFORMS);
|
|
188
|
+
assertEqual(result, `document.querySelector('[data-blok-id="123"]')`);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('transforms [data-item-name=] selector', () => {
|
|
192
|
+
const input = `page.locator('[data-item-name="delete"]')`;
|
|
193
|
+
const { result } = applyTransforms(input, SELECTOR_TRANSFORMS);
|
|
194
|
+
assertEqual(result, `page.locator('[data-blok-item-name="delete"]')`);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// ============================================================================
|
|
198
|
+
// Holder Tests
|
|
199
|
+
// ============================================================================
|
|
200
|
+
|
|
201
|
+
console.log('\n🏠 Holder Transformations\n');
|
|
202
|
+
|
|
203
|
+
test('transforms id="editorjs" in HTML', () => {
|
|
204
|
+
const input = `<div id="editorjs"></div>`;
|
|
205
|
+
const { result } = applyTransforms(input, HOLDER_TRANSFORMS);
|
|
206
|
+
assertEqual(result, `<div id="blok"></div>`);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('transforms holder config option', () => {
|
|
210
|
+
const input = `{ holder: 'editorjs' }`;
|
|
211
|
+
const { result } = applyTransforms(input, HOLDER_TRANSFORMS);
|
|
212
|
+
assertEqual(result, `{ holder: 'blok' }`);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('transforms getElementById call', () => {
|
|
216
|
+
const input = `document.getElementById('editorjs')`;
|
|
217
|
+
const { result } = applyTransforms(input, HOLDER_TRANSFORMS);
|
|
218
|
+
assertEqual(result, `document.getElementById('blok')`);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// ============================================================================
|
|
222
|
+
// Tool Config Tests
|
|
223
|
+
// ============================================================================
|
|
224
|
+
|
|
225
|
+
console.log('\n🔧 Tool Config Transformations\n');
|
|
226
|
+
|
|
227
|
+
test('transforms class: Header to class: Blok.Header', () => {
|
|
228
|
+
const input = `{ class: Header, config: {} }`;
|
|
229
|
+
const { result } = applyTransforms(input, TOOL_CONFIG_TRANSFORMS);
|
|
230
|
+
assertEqual(result, `{ class: Blok.Header, config: {} }`);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('transforms class: Paragraph to class: Blok.Paragraph', () => {
|
|
234
|
+
const input = `{ class: Paragraph, config: {} }`;
|
|
235
|
+
const { result } = applyTransforms(input, TOOL_CONFIG_TRANSFORMS);
|
|
236
|
+
assertEqual(result, `{ class: Blok.Paragraph, config: {} }`);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('transforms standalone paragraph: Paragraph reference', () => {
|
|
240
|
+
const input = `tools: { paragraph: Paragraph, header: Header }`;
|
|
241
|
+
const { result } = applyTransforms(input, TOOL_CONFIG_TRANSFORMS);
|
|
242
|
+
assertEqual(result, `tools: { paragraph: Blok.Paragraph, header: Blok.Header }`);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// ============================================================================
|
|
246
|
+
// Integration Tests
|
|
247
|
+
// ============================================================================
|
|
248
|
+
|
|
249
|
+
console.log('\n🔗 Integration Tests\n');
|
|
250
|
+
|
|
251
|
+
test('transforms complete EditorJS setup', () => {
|
|
252
|
+
const input = `
|
|
253
|
+
import EditorJS from '@editorjs/editorjs';
|
|
254
|
+
import Header from '@editorjs/header';
|
|
255
|
+
|
|
256
|
+
const editor = new EditorJS({
|
|
257
|
+
holder: 'editorjs',
|
|
258
|
+
tools: {
|
|
259
|
+
header: {
|
|
260
|
+
class: Header,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
`;
|
|
265
|
+
|
|
266
|
+
let result = input;
|
|
267
|
+
result = applyTransforms(result, IMPORT_TRANSFORMS).result;
|
|
268
|
+
result = applyTransforms(result, CLASS_NAME_TRANSFORMS).result;
|
|
269
|
+
result = applyTransforms(result, HOLDER_TRANSFORMS).result;
|
|
270
|
+
result = applyTransforms(result, TOOL_CONFIG_TRANSFORMS).result;
|
|
271
|
+
|
|
272
|
+
// Check key transformations
|
|
273
|
+
if (!result.includes("from '@jackuait/blok'")) {
|
|
274
|
+
throw new Error('Import not transformed');
|
|
275
|
+
}
|
|
276
|
+
if (!result.includes('new Blok(')) {
|
|
277
|
+
throw new Error('Constructor not transformed');
|
|
278
|
+
}
|
|
279
|
+
if (!result.includes("holder: 'blok'")) {
|
|
280
|
+
throw new Error('Holder not transformed');
|
|
281
|
+
}
|
|
282
|
+
if (!result.includes('class: Blok.Header')) {
|
|
283
|
+
throw new Error('Tool class not transformed');
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('does not transform unrelated EditorJS-like strings', () => {
|
|
288
|
+
const input = `const myEditorJSConfig = {};`;
|
|
289
|
+
const { result } = applyTransforms(input, CLASS_NAME_TRANSFORMS);
|
|
290
|
+
// Should not transform variable names containing EditorJS
|
|
291
|
+
assertEqual(result, input);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ============================================================================
|
|
295
|
+
// Summary
|
|
296
|
+
// ============================================================================
|
|
297
|
+
|
|
298
|
+
console.log('\n' + '─'.repeat(50));
|
|
299
|
+
console.log('\n✨ All tests completed!\n');
|