diff --git a/main/.editorconfig b/main/.editorconfig new file mode 100644 index 0000000..7cae5d5 --- /dev/null +++ b/main/.editorconfig @@ -0,0 +1,14 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# https://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab diff --git a/main/.gitignore b/main/.gitignore new file mode 100644 index 0000000..02e3282 --- /dev/null +++ b/main/.gitignore @@ -0,0 +1,36 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Coverage directory used by tools like istanbul +coverage + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Output of `npm pack` +*.tgz + +# Output of `wp-scripts plugin-zip` +*.zip + +# dotenv environment variables file +.env + +#IDE folders +.idea +.vscode + +artifacts diff --git a/main/assets/humidity.png b/main/assets/humidity.png new file mode 100644 index 0000000..b975e15 Binary files /dev/null and b/main/assets/humidity.png differ diff --git a/main/assets/wind.png b/main/assets/wind.png new file mode 100644 index 0000000..1028d57 Binary files /dev/null and b/main/assets/wind.png differ diff --git a/main/build/block.json b/main/build/block.json new file mode 100644 index 0000000..e124967 --- /dev/null +++ b/main/build/block.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "create-block/weatherblock", + "version": "0.1.0", + "title": "Weather Block", + "category": "widgets", + "icon": "smiley", + "description": "Example static block scaffolded with Create Block tool.", + "attributes": { + "cityName": { + "type": "string" + }, + "measure": { + "type": "string" + } + }, + "supports": { + "html": false + }, + "textdomain": "weatherblock", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css" +} \ No newline at end of file diff --git a/main/build/index.asset.php b/main/build/index.asset.php new file mode 100644 index 0000000..8ce2308 --- /dev/null +++ b/main/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '8ac6586d8ee73f12621c'); diff --git a/main/build/index.css b/main/build/index.css new file mode 100644 index 0000000..9e33d9b --- /dev/null +++ b/main/build/index.css @@ -0,0 +1,14 @@ +/*!****************************************************************************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[3].use[2]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[3].use[3]!./src/editor.scss ***! + \****************************************************************************************************************************************************************************************************************************************/ +/** + * The following styles get applied inside the editor only. + * + * Replace them with your own styles or remove the file completely. + */ +.wp-block-create-block-weatherblock { + border-radius: 2rem; + box-shadow: 5px 10px 8px #888888; +} + +/*# sourceMappingURL=index.css.map*/ \ No newline at end of file diff --git a/main/build/index.css.map b/main/build/index.css.map new file mode 100644 index 0000000..4f3db00 --- /dev/null +++ b/main/build/index.css.map @@ -0,0 +1 @@ +{"version":3,"file":"index.css","mappings":";;;AAAA;;;;EAAA;AAMA;EACC;EACA;AAAD,C","sources":["webpack://weatherblock/./src/editor.scss"],"sourcesContent":["/**\n * The following styles get applied inside the editor only.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.wp-block-create-block-weatherblock {\n\tborder-radius: 2rem;\n\tbox-shadow: 5px 10px 8px #888888;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/main/build/index.js b/main/build/index.js new file mode 100644 index 0000000..7bbf07f --- /dev/null +++ b/main/build/index.js @@ -0,0 +1,353 @@ +/******/ (() => { // webpackBootstrap +/******/ "use strict"; +/******/ var __webpack_modules__ = ({ + +/***/ "./src/edit.js": +/*!*********************!*\ + !*** ./src/edit.js ***! + \*********************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (/* binding */ Edit) +/* harmony export */ }); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); + + +/** + * Retrieves the translation of text. + * + * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ + */ + + + + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ + +function Edit(props) { + const { + attributes, + setAttributes + } = props; + const { + cityName, + measure + } = attributes; + const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockProps)(); + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", blockProps, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, "Type the city\u2019s name below, and get the wheather information."), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.TextControl, { + label: "City name", + value: cityName, + onChange: newCityName => setAttributes({ + cityName: newCityName + }) + })); +} + +/***/ }), + +/***/ "./src/index.js": +/*!**********************!*\ + !*** ./src/index.js ***! + \**********************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); +/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./style.scss */ "./src/style.scss"); +/* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./edit */ "./src/edit.js"); +/* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./block.json */ "./src/block.json"); + + +/** + * Internal dependencies + */ + + + +(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_3__, { + /** + * @see ./edit.js + */ + edit: _edit__WEBPACK_IMPORTED_MODULE_2__["default"], + + /** + * @see ./save.js + */ + save: () => null +}); + +/***/ }), + +/***/ "./src/editor.scss": +/*!*************************!*\ + !*** ./src/editor.scss ***! + \*************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +// extracted by mini-css-extract-plugin + + +/***/ }), + +/***/ "./src/style.scss": +/*!************************!*\ + !*** ./src/style.scss ***! + \************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +// extracted by mini-css-extract-plugin + + +/***/ }), + +/***/ "@wordpress/block-editor": +/*!*************************************!*\ + !*** external ["wp","blockEditor"] ***! + \*************************************/ +/***/ ((module) => { + +module.exports = window["wp"]["blockEditor"]; + +/***/ }), + +/***/ "@wordpress/blocks": +/*!********************************!*\ + !*** external ["wp","blocks"] ***! + \********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["blocks"]; + +/***/ }), + +/***/ "@wordpress/components": +/*!************************************!*\ + !*** external ["wp","components"] ***! + \************************************/ +/***/ ((module) => { + +module.exports = window["wp"]["components"]; + +/***/ }), + +/***/ "@wordpress/element": +/*!*********************************!*\ + !*** external ["wp","element"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["element"]; + +/***/ }), + +/***/ "@wordpress/i18n": +/*!******************************!*\ + !*** external ["wp","i18n"] ***! + \******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["i18n"]; + +/***/ }), + +/***/ "./src/block.json": +/*!************************!*\ + !*** ./src/block.json ***! + \************************/ +/***/ ((module) => { + +module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"create-block/weatherblock","version":"0.1.0","title":"Weather Block","category":"widgets","icon":"smiley","description":"Example static block scaffolded with Create Block tool.","attributes":{"cityName":{"type":"string"},"measure":{"type":"string"}},"supports":{"html":false},"textdomain":"weatherblock","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css"}'); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = __webpack_modules__; +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/chunk loaded */ +/******/ (() => { +/******/ var deferred = []; +/******/ __webpack_require__.O = (result, chunkIds, fn, priority) => { +/******/ if(chunkIds) { +/******/ priority = priority || 0; +/******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1]; +/******/ deferred[i] = [chunkIds, fn, priority]; +/******/ return; +/******/ } +/******/ var notFulfilled = Infinity; +/******/ for (var i = 0; i < deferred.length; i++) { +/******/ var chunkIds = deferred[i][0]; +/******/ var fn = deferred[i][1]; +/******/ var priority = deferred[i][2]; +/******/ var fulfilled = true; +/******/ for (var j = 0; j < chunkIds.length; j++) { +/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) { +/******/ chunkIds.splice(j--, 1); +/******/ } else { +/******/ fulfilled = false; +/******/ if(priority < notFulfilled) notFulfilled = priority; +/******/ } +/******/ } +/******/ if(fulfilled) { +/******/ deferred.splice(i--, 1) +/******/ var r = fn(); +/******/ if (r !== undefined) result = r; +/******/ } +/******/ } +/******/ return result; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/jsonp chunk loading */ +/******/ (() => { +/******/ // no baseURI +/******/ +/******/ // object to store loaded and loading chunks +/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched +/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded +/******/ var installedChunks = { +/******/ "index": 0, +/******/ "./style-index": 0 +/******/ }; +/******/ +/******/ // no chunk on demand loading +/******/ +/******/ // no prefetching +/******/ +/******/ // no preloaded +/******/ +/******/ // no HMR +/******/ +/******/ // no HMR manifest +/******/ +/******/ __webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0); +/******/ +/******/ // install a JSONP callback for chunk loading +/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => { +/******/ var chunkIds = data[0]; +/******/ var moreModules = data[1]; +/******/ var runtime = data[2]; +/******/ // add "moreModules" to the modules object, +/******/ // then flag all "chunkIds" as loaded and fire callback +/******/ var moduleId, chunkId, i = 0; +/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) { +/******/ for(moduleId in moreModules) { +/******/ if(__webpack_require__.o(moreModules, moduleId)) { +/******/ __webpack_require__.m[moduleId] = moreModules[moduleId]; +/******/ } +/******/ } +/******/ if(runtime) var result = runtime(__webpack_require__); +/******/ } +/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data); +/******/ for(;i < chunkIds.length; i++) { +/******/ chunkId = chunkIds[i]; +/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) { +/******/ installedChunks[chunkId][0](); +/******/ } +/******/ installedChunks[chunkId] = 0; +/******/ } +/******/ return __webpack_require__.O(result); +/******/ } +/******/ +/******/ var chunkLoadingGlobal = self["webpackChunkweatherblock"] = self["webpackChunkweatherblock"] || []; +/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0)); +/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal)); +/******/ })(); +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module depends on other loaded chunks and execution need to be delayed +/******/ var __webpack_exports__ = __webpack_require__.O(undefined, ["./style-index"], () => (__webpack_require__("./src/index.js"))) +/******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__); +/******/ +/******/ })() +; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/main/build/index.js.map b/main/build/index.js.map new file mode 100644 index 0000000..24d868d --- /dev/null +++ b/main/build/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGe,SAASG,IAAT,CAAcC,KAAd,EAAqB;EAEnC,MAAM;IAAEC,UAAF;IAAcC;EAAd,IAAgCF,KAAtC;EAEA,MAAM;IAAEG,QAAF;IAAYC;EAAZ,IAAwBH,UAA9B;EAEA,MAAMI,UAAU,GAAGR,sEAAa,EAAhC;EAEA,OACC,yEAASQ,UAAT,EACC,kJADD,EAEC,kEAAC,8DAAD;IACC,KAAK,EAAC,WADP;IAEC,KAAK,EAAEF,QAFR;IAGC,QAAQ,EAAGG,WAAD,IAAiBJ,aAAa,CAAC;MAAEC,QAAQ,EAAEG;IAAZ,CAAD;EAHzC,EAFD,CADD;AAWA;;;;;;;;;;;;;;;;ACvCD;AACA;AAEA;AACA;AACA;;AAEA;AACA;AAGAC,oEAAiB,CAAEC,wCAAF,EAAQ;EACxB;AACD;AACA;EACCC,IAAI,EAAEV,6CAJkB;;EAKxB;AACD;AACA;EACCW,IAAI,EAAE,MAAM;AARY,CAAR,CAAjB;;;;;;;;;;;ACXA;;;;;;;;;;;;ACAA;;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;UAEA;UACA;;;;;WCzBA;WACA;WACA;WACA;WACA,+BAA+B,wCAAwC;WACvE;WACA;WACA;WACA;WACA,iBAAiB,qBAAqB;WACtC;WACA;WACA;WACA;WACA,kBAAkB,qBAAqB;WACvC;WACA;WACA,KAAK;WACL;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;WC7BA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;WCNA;;WAEA;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA,MAAM,qBAAqB;WAC3B;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;WACA;WACA;;;;;UEnDA;UACA;UACA;UACA;UACA","sources":["webpack://weatherblock/./src/edit.js","webpack://weatherblock/./src/index.js","webpack://weatherblock/./src/editor.scss?d4ae","webpack://weatherblock/./src/style.scss?5612","webpack://weatherblock/external window [\"wp\",\"blockEditor\"]","webpack://weatherblock/external window [\"wp\",\"blocks\"]","webpack://weatherblock/external window [\"wp\",\"components\"]","webpack://weatherblock/external window [\"wp\",\"element\"]","webpack://weatherblock/external window [\"wp\",\"i18n\"]","webpack://weatherblock/webpack/bootstrap","webpack://weatherblock/webpack/runtime/chunk loaded","webpack://weatherblock/webpack/runtime/compat get default export","webpack://weatherblock/webpack/runtime/define property getters","webpack://weatherblock/webpack/runtime/hasOwnProperty shorthand","webpack://weatherblock/webpack/runtime/make namespace object","webpack://weatherblock/webpack/runtime/jsonp chunk loading","webpack://weatherblock/webpack/before-startup","webpack://weatherblock/webpack/startup","webpack://weatherblock/webpack/after-startup"],"sourcesContent":["/**\n * Retrieves the translation of text.\n *\n * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/\n */\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport './editor.scss';\nimport { TextControl } from '@wordpress/components';\n\n/**\n * The edit function describes the structure of your block in the context of the\n * editor. This represents what the editor will render when the block is used.\n *\n * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit\n *\n * @return {WPElement} Element to render.\n */\n\n\nexport default function Edit(props) {\n\n\tconst { attributes, setAttributes } = props\n\n\tconst { cityName, measure } = attributes\n\n\tconst blockProps = useBlockProps()\n\n\treturn (\n\t\t
\n\t\t\t

Type the city’s name below, and get the wheather information.

\n\t\t\t setAttributes({ cityName: newCityName})}\n\t\t\t/>\t\n\t\t\t\n\t\t
\n\t);\n}","import { registerBlockType } from '@wordpress/blocks';\nimport './style.scss';\n\n/**\n * Internal dependencies\n */\n\nimport Edit from './edit';\nimport name from './block.json';\n\n\nregisterBlockType( name, {\n\t/**\n\t * @see ./edit.js\n\t */\n\tedit: Edit,\n\t/**\n\t * @see ./save.js\n\t */\n\tsave: () => null,\n\t\n});\n","// extracted by mini-css-extract-plugin\nexport {};","// extracted by mini-css-extract-plugin\nexport {};","module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"blocks\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar chunkIds = deferred[i][0];\n\t\tvar fn = deferred[i][1];\n\t\tvar priority = deferred[i][2];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// no baseURI\n\n// object to store loaded and loading chunks\n// undefined = chunk not loaded, null = chunk preloaded/prefetched\n// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded\nvar installedChunks = {\n\t\"index\": 0,\n\t\"./style-index\": 0\n};\n\n// no chunk on demand loading\n\n// no prefetching\n\n// no preloaded\n\n// no HMR\n\n// no HMR manifest\n\n__webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);\n\n// install a JSONP callback for chunk loading\nvar webpackJsonpCallback = (parentChunkLoadingFunction, data) => {\n\tvar chunkIds = data[0];\n\tvar moreModules = data[1];\n\tvar runtime = data[2];\n\t// add \"moreModules\" to the modules object,\n\t// then flag all \"chunkIds\" as loaded and fire callback\n\tvar moduleId, chunkId, i = 0;\n\tif(chunkIds.some((id) => (installedChunks[id] !== 0))) {\n\t\tfor(moduleId in moreModules) {\n\t\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t\t}\n\t\t}\n\t\tif(runtime) var result = runtime(__webpack_require__);\n\t}\n\tif(parentChunkLoadingFunction) parentChunkLoadingFunction(data);\n\tfor(;i < chunkIds.length; i++) {\n\t\tchunkId = chunkIds[i];\n\t\tif(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {\n\t\t\tinstalledChunks[chunkId][0]();\n\t\t}\n\t\tinstalledChunks[chunkId] = 0;\n\t}\n\treturn __webpack_require__.O(result);\n}\n\nvar chunkLoadingGlobal = self[\"webpackChunkweatherblock\"] = self[\"webpackChunkweatherblock\"] || [];\nchunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));\nchunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));","","// startup\n// Load entry module and return exports\n// This entry module depends on other loaded chunks and execution need to be delayed\nvar __webpack_exports__ = __webpack_require__.O(undefined, [\"./style-index\"], () => (__webpack_require__(\"./src/index.js\")))\n__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n",""],"names":["__","useBlockProps","TextControl","Edit","props","attributes","setAttributes","cityName","measure","blockProps","newCityName","registerBlockType","name","edit","save"],"sourceRoot":""} \ No newline at end of file diff --git a/main/build/style-index.css b/main/build/style-index.css new file mode 100644 index 0000000..21e686f --- /dev/null +++ b/main/build/style-index.css @@ -0,0 +1,48 @@ +/*!***************************************************************************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[3].use[2]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[3].use[3]!./src/style.scss ***! + \***************************************************************************************************************************************************************************************************************************************/ +/** + * The following styles get applied both on the front of your site + * and in the editor. + * + * Replace them with your own styles or remove the file completely. + */ +.wp-block-create-block-weatherblock, .weather-card { + border-radius: 2rem; + box-shadow: 5px 10px 8px #888888; + background-color: #dedbd9; + color: #000000; + padding: 2rem; +} +.wp-block-create-block-weatherblock .main-weather, .weather-card .main-weather { + display: flex; + justify-content: space-evenly; +} +.wp-block-create-block-weatherblock .main-weather h3, .weather-card .main-weather h3 { + font-size: 3.5rem; + font-weight: 900; + margin-bottom: 0; +} +.wp-block-create-block-weatherblock .main-weather .weather-icon, .weather-card .main-weather .weather-icon { + display: flex; + align-items: center; +} +.wp-block-create-block-weatherblock .temp-info, .weather-card .temp-info { + display: grid; + grid-template-columns: repeat(3, 1fr); + justify-items: center; +} +.wp-block-create-block-weatherblock .temp-info img, .weather-card .temp-info img { + width: 20%; +} +.wp-block-create-block-weatherblock .temp-info span, .weather-card .temp-info span { + font-size: 3rem; +} +.wp-block-create-block-weatherblock .temp-info .humidity, .wp-block-create-block-weatherblock .temp-info .wind, .weather-card .temp-info .humidity, .weather-card .temp-info .wind { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +/*# sourceMappingURL=style-index.css.map*/ \ No newline at end of file diff --git a/main/build/style-index.css.map b/main/build/style-index.css.map new file mode 100644 index 0000000..3a90680 --- /dev/null +++ b/main/build/style-index.css.map @@ -0,0 +1 @@ +{"version":3,"file":"./style-index.css","mappings":";;;AAAA;;;;;EAAA;AAOA;EACC;EACA;EACA;EACA;EACA;AAAD;AACC;EACC;EACA;AACF;AAAE;EACC;EACA;EACA;AAEH;AAAE;EACC;EACA;AAEH;AACC;EACC;EACG;EACH;AACF;AAAE;EAAI;AAGN;AAFE;EACC;AAIH;AAFE;EACC;EACA;EACA;EACA;AAIH,C","sources":["webpack://weatherblock/./src/style.scss"],"sourcesContent":["/**\n * The following styles get applied both on the front of your site\n * and in the editor.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.wp-block-create-block-weatherblock, .weather-card {\n\tborder-radius: 2rem;\n\tbox-shadow: 5px 10px 8px #888888;\n\tbackground-color: #dedbd9;\n\tcolor: #000000;\n\tpadding: 2rem;\n\t.main-weather{\n\t\tdisplay: flex;\n\t\tjustify-content: space-evenly;\n\t\th3{\t\n\t\t\tfont-size: 3.5rem;\n\t\t\tfont-weight: 900;\n\t\t\tmargin-bottom: 0;\n\t\t}\n\t\t.weather-icon{\n\t\t\tdisplay: flex;\n\t\t\talign-items: center;\n\t\t}\n\t}\n\t.temp-info{\n\t\tdisplay: grid;\n \tgrid-template-columns: repeat(3, 1fr);\n\t\tjustify-items: center;\n\t\timg{width: 20%;}\n\t\tspan{\n\t\t\tfont-size: 3rem;\n\t\t}\n\t\t.humidity, .wind{\n\t\t\tdisplay: flex;\n\t\t\tflex-direction: column;\n\t\t\tjustify-content: center;\n\t\t\talign-items: center;\n\t\t}\n\t}\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/main/package-lock.json b/main/package-lock.json new file mode 100644 index 0000000..e69de29 diff --git a/main/package.json b/main/package.json new file mode 100644 index 0000000..1a23a53 --- /dev/null +++ b/main/package.json @@ -0,0 +1,25 @@ +{ + "name": "weatherblock", + "version": "0.1.0", + "description": "Example static block scaffolded with Create Block tool.", + "author": "The WordPress Contributors", + "license": "GPL-2.0-or-later", + "main": "build/index.js", + "scripts": { + "build": "wp-scripts build", + "format": "wp-scripts format", + "lint:css": "wp-scripts lint-style", + "lint:js": "wp-scripts lint-js", + "packages-update": "wp-scripts packages-update", + "plugin-zip": "wp-scripts plugin-zip", + "start": "wp-scripts start", + "test:e2e": "wp-scripts test-e2e", + "env:start": "wp-env start", + "env:stop": " wp-env start" + }, + "devDependencies": { + "@wordpress/e2e-test-utils": "^7.5.0", + "@wordpress/e2e-tests": "^4.3.0", + "@wordpress/scripts": "^23.0.0" + } +} diff --git a/main/readme.md b/main/readme.md new file mode 100644 index 0000000..73de743 --- /dev/null +++ b/main/readme.md @@ -0,0 +1,23 @@ +# Weather Block +Contributors: Alex Cuadra +Tags: block weather +Tested up to: 5.9 +Stable tag: 0.1.0 +License: GPL-2.0-or-later +License URI: https://www.gnu.org/licenses/gpl-2.0.html + + +## == Description == + +This is a simple block that give the weather in a city that you input. + +## == Installation == + +This section describes how to install the plugin and get it working. + +e.g. + +1. Upload the plugin files to the `/wp-content/plugins/weatherblock` directory, or install the plugin through the WordPress plugins screen directly. +1. Activate the plugin through the 'Plugins' screen in WordPress + + diff --git a/main/src/block.json b/main/src/block.json new file mode 100644 index 0000000..58d329e --- /dev/null +++ b/main/src/block.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "create-block/weatherblock", + "version": "0.1.0", + "title": "Weather Block", + "category": "widgets", + "icon": "smiley", + "description": "Example static block scaffolded with Create Block tool.", + "attributes": { + "cityName":{ + "type": "string" + }, + "background_color": { + "type": "string", + "default": "#cdcdcd" + } + }, + "supports": { + "html": false + }, + "textdomain": "weatherblock", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css" +} \ No newline at end of file diff --git a/main/src/components/CityNameInput.js b/main/src/components/CityNameInput.js new file mode 100644 index 0000000..7eea90a --- /dev/null +++ b/main/src/components/CityNameInput.js @@ -0,0 +1,27 @@ +import React from 'react' + + +const CityNameInput = (props) => { + + const { + label, + value, + onChange, + type = 'text', + } = props; + + const onChangeValue = ( event ) => onChange( event.target.value ); + + return ( + <> +
+ + + ) +} + +export default CityNameInput; diff --git a/main/src/edit.js b/main/src/edit.js new file mode 100644 index 0000000..dd995a0 --- /dev/null +++ b/main/src/edit.js @@ -0,0 +1,56 @@ +/** + * Retrieves the translation of text. + * + * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ + */ +import { __ } from '@wordpress/i18n'; +import { useBlockProps } from '@wordpress/block-editor'; +import './editor.scss'; +import { TextControl } from '@wordpress/components'; +import {CityNameInput} from 'components/CityNameInput' + +/** + * The edit function describes the structure of your block in the context of the + * editor. This represents what the editor will render when the block is used. + * + * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ + + +export default function Edit(props) { + + const { attributes, setAttributes } = props + + const { cityName } = attributes + + const onChangeBackColor = (color) => { + setAttributes({background_color: color}) + } + + const blockProps = useBlockProps() + + return ( +
+ +
+ + Color de fondo + + +
+
+
+

Type the city’s name below, and get the wheather information.

+ setAttributes({ cityName: newCityName})} + /> +
+
+ ); +} \ No newline at end of file diff --git a/main/src/editor.scss b/main/src/editor.scss new file mode 100644 index 0000000..8db57f2 --- /dev/null +++ b/main/src/editor.scss @@ -0,0 +1,10 @@ +/** + * The following styles get applied inside the editor only. + * + * Replace them with your own styles or remove the file completely. + */ + +.wp-block-create-block-weatherblock { + border-radius: 2rem; + box-shadow: 5px 10px 8px #888888; +} diff --git a/main/src/index.js b/main/src/index.js new file mode 100644 index 0000000..54222fc --- /dev/null +++ b/main/src/index.js @@ -0,0 +1,52 @@ +import { registerBlockType } from '@wordpress/blocks'; +import './style.scss'; + +/** + * Internal dependencies + */ + +import Edit from './edit'; +import name from './block.json'; + + +registerBlockType( name, { + /** + * @see ./edit.js + */ + edit: Edit, + /** + * @see ./save.js + */ + save: () => null, + + transforms: { + from: [ + { + type: 'shortcode', + tag:'weather', + transform({attributes: {cityname}}){ + return createBlock('create-block/weatherblock', { + cityName: cityname + }) + } + }, + ], + + }, + + // transforms: { + // from: [ + // { + // type: 'block', + // blocks:['core/shortcode'], + // transform({attributes: {cityname}}){ + // return createBlock('create-block/weatherblock', { + // cityName: cityname + // }) + // } + // }, + // ], + + // }, + +}); diff --git a/main/src/save.js b/main/src/save.js new file mode 100644 index 0000000..31115a4 --- /dev/null +++ b/main/src/save.js @@ -0,0 +1,34 @@ +/** + * Retrieves the translation of text. + * + * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ + */ +import { __ } from '@wordpress/i18n'; + +/** + * React hook that is used to mark the block wrapper element. + * It provides all the necessary props like the class name. + * + * @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps + */ +import { useBlockProps } from '@wordpress/block-editor'; + +/** + * The save function defines the way in which the different attributes should + * be combined into the final markup, which is then serialized by the block + * editor into `post_content`. + * + * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save + * + * @return {WPElement} Element to render. + */ +export default function save() { + return ( +

+ {__( + 'Weather Block – hello from the saved content!', + 'weatherblock' + )} +

+ ); +} diff --git a/main/src/style.scss b/main/src/style.scss new file mode 100644 index 0000000..685589a --- /dev/null +++ b/main/src/style.scss @@ -0,0 +1,42 @@ +/** + * The following styles get applied both on the front of your site + * and in the editor. + * + * Replace them with your own styles or remove the file completely. + */ + +.wp-block-create-block-weatherblock, .weather-card { + border-radius: 2rem; + box-shadow: 5px 10px 8px #888888; + background-color: #dedbd9; + color: #000000; + padding: 2rem; + .main-weather{ + display: flex; + justify-content: space-evenly; + h3{ + font-size: 3.5rem; + font-weight: 900; + margin-bottom: 0; + } + .weather-icon{ + display: flex; + align-items: center; + } + } + .temp-info{ + display: grid; + grid-template-columns: repeat(3, 1fr); + justify-items: center; + img{width: 20%;} + span{ + font-size: 3rem; + } + .humidity, .wind{ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + } + } +} diff --git a/main/test/weatherblock.spec.js b/main/test/weatherblock.spec.js new file mode 100644 index 0000000..5d11479 --- /dev/null +++ b/main/test/weatherblock.spec.js @@ -0,0 +1,31 @@ + + +import { createNewPost, insertBlock, wpDataSelect, enablePageDialogAccept, getEditedPostContent, getCurrentPostContent } from '@wordpress/e2e-test-utils' + +jest.setTimeout(30000) + +describe('Pruebas en bloqueclima', () => { + beforeAll( async () => { + await enablePageDialogAccept(); + }) + + beforeEach( async () => { + await createNewPost() + }) + + it('deberia insertar el bloque en el editor', async () => { + + + await insertBlock( 'Bloqueclima' ); + + expect(await page.$( '[data-type="create-block/bloqueclima"]' ) ).not.toBeNull(); + + console.log(await wpDataSelect()) + + expect ( await getEditedPostContent() ).toEqual('') + + }) + + + +}) \ No newline at end of file diff --git a/main/weatherblock.php b/main/weatherblock.php new file mode 100644 index 0000000..6b9f8a0 --- /dev/null +++ b/main/weatherblock.php @@ -0,0 +1,96 @@ + 'render_weather_widget' + ) ); +} +add_action( 'init', 'create_block_weatherblock_block_init' ); + +function render_weather_widget($attributes, $content, $block){ + + $cityname = $attributes['cityName'] ? $attributes['cityName'] : 'managua'; + + + //API variables + $url = 'https://api.openweathermap.org/data/2.5/weather'; + $apiKey = '6b1cd5a24a18ee83c55372465790bed5'; + + $fullUrl = $url . '?q=' . $cityname . '&appid=' . $apiKey; + $response = wp_remote_get($fullUrl); + + + if (is_wp_error($response)) { + error_log("Error: ". $response->get_error_message()); + return false; + } + + if ($cityname !== ''){ + + $body = wp_remote_retrieve_body($response); + + $data = json_decode($body); + + + $city = $data->name; + $temp = $data->main->temp; + $cityweather = $data->weather[0]->description; + $hummidity = $data->main->humidity; + $speed = $data->wind->speed; + $weatherIcon = $data->weather[0]->icon; + + + ob_start(); + ?> +
+
+
+

+

+
+
+ +
+
+ +
+

F

+
+ +

+
+
+ +

+
+
+
+ + +