From d5c378da5594ae3a1e09024228d95c11fcbb325c Mon Sep 17 00:00:00 2001 From: Tony Arcangelini Date: Sat, 18 May 2024 02:21:52 +0200 Subject: [PATCH] Switch to TypeScript and adjust sync script --- package-lock.json | 32 ++++++++++++++++++++ package.json | 3 +- src/scale-section/{edit.js => edit.tsx} | 0 src/scale-section/index.js | 39 ------------------------- src/scale-section/index.ts | 21 +++++++++++++ src/scale-section/{save.js => save.tsx} | 4 ++- 6 files changed, 58 insertions(+), 41 deletions(-) rename src/scale-section/{edit.js => edit.tsx} (100%) delete mode 100644 src/scale-section/index.js create mode 100644 src/scale-section/index.ts rename src/scale-section/{save.js => save.tsx} (82%) diff --git a/package-lock.json b/package-lock.json index 2182a93..c2d570b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "GPL-2.0-or-later", "dependencies": { + "@types/wordpress__block-editor": "^11.5.14", "@wordpress/block-editor": "^12.26.0", "@wordpress/components": "^27.6.0", "chalk": "^4.1.2", @@ -4213,6 +4214,37 @@ "node": ">=0.10.0" } }, + "node_modules/@types/wordpress__block-editor": { + "version": "11.5.14", + "resolved": "https://registry.npmjs.org/@types/wordpress__block-editor/-/wordpress__block-editor-11.5.14.tgz", + "integrity": "sha512-qW1yD9Nrsy6x4cxMYCSXW6v74bXfcstPQeOV+uQbMejd5zxrBGytH9OQvcrIJrDquPzDf5+We8VqnsIWTF/Rpg==", + "dependencies": { + "@types/react": "*", + "@types/wordpress__blocks": "*", + "@wordpress/components": "^27.2.0", + "@wordpress/data": "^9.13.0", + "@wordpress/element": "^5.0.0", + "@wordpress/keycodes": "^3.54.0", + "react-autosize-textarea": "^7.1.0" + } + }, + "node_modules/@types/wordpress__blocks": { + "version": "12.5.14", + "resolved": "https://registry.npmjs.org/@types/wordpress__blocks/-/wordpress__blocks-12.5.14.tgz", + "integrity": "sha512-eXEnCRKYu+39KEJ/OYpoYxWTATxI+eJHd+meMGZ14hYydFtxA0Y8M7zJT8D8f4klBo8wINLvP7zrO8vYrjWjPQ==", + "dependencies": { + "@types/react": "*", + "@types/wordpress__shortcode": "*", + "@wordpress/components": "^27.2.0", + "@wordpress/data": "^9.13.0", + "@wordpress/element": "^5.0.0" + } + }, + "node_modules/@types/wordpress__shortcode": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/@types/wordpress__shortcode/-/wordpress__shortcode-2.3.6.tgz", + "integrity": "sha512-H8BVov7QWyLLoxCaI9QyZVC4zTi1mFkZ+eEKiXBCFlaJ0XV8UVfQk+cAetqD5mWOeWv2d4b8uzzyn0TTQ/ep2g==" + }, "node_modules/@types/ws": { "version": "8.5.10", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", diff --git a/package.json b/package.json index 54c7f6b..b5cbec4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "GPL-2.0-or-later", "scripts": { "build": "wp-scripts build --webpack-src-dir=src/scale-section --output-path=build/scale-section && wp-scripts build --webpack-src-dir=src/weather --output-path=build/weather", - "sync": "rsync -avz ./build $RSYNC_DESTINATION", + "sync": "rsync -avz --exclude={'.github','node_modules','src','.*','package*','webpack*'} ./ $RSYNC_DESTINATION", "start": "wp-scripts start --webpack-src-dir=src/scale-section --output-path=build/scale-section && wp-scripts start --webpack-src-dir=src/weather --output-path=build/weather", "lint:js": "wp-scripts lint-js", "lint:css": "wp-scripts lint-style", @@ -17,6 +17,7 @@ "npm": "^10.8.0" }, "dependencies": { + "@types/wordpress__block-editor": "^11.5.14", "@wordpress/block-editor": "^12.26.0", "@wordpress/components": "^27.6.0", "chalk": "^4.1.2", diff --git a/src/scale-section/edit.js b/src/scale-section/edit.tsx similarity index 100% rename from src/scale-section/edit.js rename to src/scale-section/edit.tsx diff --git a/src/scale-section/index.js b/src/scale-section/index.js deleted file mode 100644 index ade1e47..0000000 --- a/src/scale-section/index.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Registers a new block provided a unique name and an object defining its behavior. - * - * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ - */ -import { registerBlockType } from '@wordpress/blocks'; - -/** - * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. - * All files containing `style` keyword are bundled together. The code used - * gets applied both to the front of your site and to the editor. - * - * @see https://www.npmjs.com/package/@wordpress/scripts#using-css - */ -import './style.scss'; - -/** - * Internal dependencies - */ -import Edit from './edit'; -import save from './save'; -import metadata from './block.json'; - -/** - * Every block starts by registering a new block type definition. - * - * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ - */ -registerBlockType( metadata.name, { - /** - * @see ./edit.js - */ - edit: Edit, - - /** - * @see ./save.js - */ - save, -} ); diff --git a/src/scale-section/index.ts b/src/scale-section/index.ts new file mode 100644 index 0000000..8eea7fd --- /dev/null +++ b/src/scale-section/index.ts @@ -0,0 +1,21 @@ + +import { registerBlockType } from '@wordpress/blocks'; + +import './style.scss'; + +import Edit from './edit'; +import save from './save'; +import metadata from './block.json'; + +// @ts-expect-error - TS doesn't know about the block.json +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit, + + /** + * @see ./save.js + */ + save, +} ); diff --git a/src/scale-section/save.js b/src/scale-section/save.tsx similarity index 82% rename from src/scale-section/save.js rename to src/scale-section/save.tsx index 1cb23e3..0042f11 100644 --- a/src/scale-section/save.js +++ b/src/scale-section/save.tsx @@ -1,6 +1,8 @@ import { useBlockProps, RichText } from '@wordpress/block-editor'; -export default function save( { attributes } ) { +import React from 'react'; + +export default function Save( { attributes } ) { const { content, height } = attributes; const blockProps = useBlockProps.save( { style: { height: `${ height }px` },