Skip to content

Commit a530505

Browse files
committed
Expose React APIs globally
1 parent 1b9b05b commit a530505

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@sindresorhus/transliterate": "^1.6.0",
3939
"@sveltia/ui": "^0.27.9",
4040
"@sveltia/utils": "^0.8.0",
41+
"create-react-class": "^15.7.0",
4142
"dayjs": "^1.11.18",
4243
"deepmerge": "^4.3.1",
4344
"exifreader": "^4.31.2",
@@ -52,6 +53,8 @@
5253
"parse-entities": "^4.0.2",
5354
"pdfjs-dist": "^5.4.149",
5455
"qrcode": "^1.5.4",
56+
"react": "^19.1.1",
57+
"react-dom": "^19.1.1",
5558
"sanitize-filename": "^1.6.3",
5659
"smol-toml": "^1.4.2",
5760
"svelte-i18n": "^4.0.1",

pnpm-lock.yaml

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import createClass from 'create-react-class';
2+
import { createElement } from 'react';
13
import { mount } from 'svelte';
24

35
import { customPreviewStyleRegistry } from '$lib/services/contents/editor';
@@ -205,6 +207,13 @@ export { init };
205207
window.CMS = CMS;
206208
window.initCMS = init;
207209

210+
// Expose React APIs for custom widgets, custom preview templates and custom editor components
211+
// @see https://decapcms.org/docs/custom-widgets/
212+
// @see https://decapcms.org/docs/customization/
213+
window.createClass = createClass;
214+
window.createElement = createElement;
215+
window.h = createElement;
216+
208217
// Automatically initialize the CMS if manual initialization is not requested AND the script is NOT
209218
// a module; We can’t just use `document.currentScript` for module detection because the earlier
210219
// versions of Sveltia CMS were built and shipped as modules

src/lib/types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ interface Window {
33
CMS_MANUAL_INIT?: boolean;
44
initCMS: Function;
55
showDirectoryPicker: Function;
6+
// React
7+
createClass: Function;
8+
createElement: Function;
9+
h: Function;
610
}
711

812
interface Navigator {

0 commit comments

Comments
 (0)