├── LICENSE ├── README.md ├── amd ├── build │ ├── app-lazy.min.js │ ├── app-lazy.min.js.LICENSE.txt │ └── index.html └── src │ └── app-lazy.js ├── index.php ├── lang └── en │ └── local_reactjs.php ├── lib.php ├── pix ├── icon.png └── icon.svg ├── react ├── index.d.ts ├── package.json ├── public │ └── index.html ├── src │ ├── App.tsx │ └── index.tsx ├── tsconfig.json └── webpack.config.js ├── settings.php └── version.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 SmartApp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # moodle-local_reactjs 2 | Moodle ReactJS - gives you ability to use ReactJS inside any moodle page. 3 | 4 | ## Note for devs: 5 | 6 | You'll need to set up npm dependencies ***directly*** at the react 7 | directory. 8 | 9 | E.g: 10 | 11 | > your_moodle_dir/local/reactjs/react 12 | 13 | Run command in your module folder 14 | 15 | > npm install 16 | 17 | ## How to compile multiple modules for different pages 18 | 19 | Current `webpack.config.js` isn't able to split code into modules. 20 | To implement this feature you have to add different entry points to 21 | your config file 22 | 23 | ## How to include moodle JS libraries to your React App 24 | `webpack.config.js` connects moodle JS libraries, so you 25 | can use them in your code following this example: 26 | 27 | import React, { useState } from 'react'; 28 | import * as Str from 'core/str'; 29 | 30 | function App() { 31 | const [title, setTitle] = useState(''); 32 | 33 | const getTitle = async (key: string) => setTitle(await Str.get_string(key)); 34 | getTitle('courses'); 35 | 36 | return ( 37 |
38 | {title} 39 |
40 | ); 41 | } 42 | 43 | export default App; 44 | 45 | Also, you need to add required libraries to the `index.d.ts` file 46 | so TypeScript won't give you any errors during build process: 47 | 48 | declare module 'core/str' { 49 | const call: any; 50 | export default call; 51 | } 52 | 53 | ## How to connect your React App to moodle page 54 | 55 | This can be done via basic moodle js file connection. E.g: 56 | 57 | require_once(__DIR__ . '/../../config.php'); 58 | require_once('lib.php'); 59 | 60 | global $CFG, $DB; 61 | 62 | echo $OUTPUT->header(); 63 | 64 | $PAGE->requires->js_call_amd('local_reactjs/app-lazy', 'init'); 65 | 66 | echo '
'; 67 | 68 | echo $OUTPUT->footer(); 69 | -------------------------------------------------------------------------------- /amd/build/app-lazy.min.js: -------------------------------------------------------------------------------- 1 | /*! For license information please see app-lazy.min.js.LICENSE.txt */ 2 | define((function(){return function(){"use strict";var e={418:function(e){var t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;function l(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,a){for(var o,u,i=l(e),s=1;s