diff --git a/.editorconfig b/.editorconfig index a127657e3..9ac2a53b9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,13 +1,13 @@ -# editorconfig.org -root = true - -[*] -charset = utf-8 -end_of_line = crlf -indent_size = 4 -indent_style = tab -insert_final_newline = true - -[*.json] -indent_size = 2 -indent_style = space \ No newline at end of file +# editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = tab +insert_final_newline = true + +[*.json] +indent_size = 2 +indent_style = space diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..90b9f343a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +* text eol=lf +*.png binary +*.exe binary +*.dll binary + diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..a958ae0e2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,24 @@ +Thanks for filing a bug! To save time, if you're having trouble using the library, please check off the items you have tried. If you are just asking a question, skip right to the bottom. + +### Please verify these steps before filing an issue, and check them off as you go +- [ ] The relevant native JavascriptEngineSwitcher library packages are installed (such as `JavaScriptEngineSwitcher.V8.Native.win-x64`) +- [ ] The VC++ 2017 runtime is installed +- [ ] The value of `SetUseReact` and `SetUseBabel` is correct in `ReactConfig.cs` or `Startup.cs` +- [ ] I've looked at the sample projects in this repo to verify that my app is configured correctly + +### I'm using these library versions: +- `ReactJS.NET`: +- `JavaScriptEngineSwitcher`: +- `react` and `react-dom`: (N/A if using bundled react, or version number) +- `webpack`: (N/A if using bundled react) +- `node`: (N/A if using bundled react) + +### Runtime environment: +- OS: (Mac, Windows, Linux flavor. Include 32-bit/64-bit and version) +- .NET Framework or .NET Core Version: + +### Steps to reproduce + +------- + +(Describe your issue here) diff --git a/.github/workflows/dotnet-core-desktop.yml b/.github/workflows/dotnet-core-desktop.yml new file mode 100644 index 000000000..194ac738e --- /dev/null +++ b/.github/workflows/dotnet-core-desktop.yml @@ -0,0 +1,64 @@ +name: .NET Core Desktop + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + + build: + + strategy: + matrix: + configuration: [Debug, Release] + + runs-on: windows-latest # For a list of available runner types, refer to + # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Install .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.x + + - name: Use Node.js 12 + uses: actions/setup-node@v1 + with: + node-version: 12 + + - name: Setup MSBuild.exe + uses: microsoft/setup-msbuild@2008f912f56e61277eefaac6d1888b750582aa16 + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + + - name: Build + run: msbuild build.proj /p:PackageOutputDir="${{ env.GITHUB_WORKSPACE }}/nuget-output" /p:Configuration=${{ matrix.configuration }} + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + Configuration: ${{ matrix.configuration }} + + - name: Upload build artifacts + uses: actions/upload-artifact@v1 + with: + name: Nuget Package + path: "${{ env.GITHUB_WORKSPACE }}/nuget-output" diff --git a/.gitignore b/.gitignore index 0f0ebe783..b32bd32fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ _old/ src/SharedAssemblyVersionInfo.cs *.nupkg +*.snupkg src/**/*.nuspec !src/template.nuspec site/jekyll/_site @@ -10,9 +11,10 @@ src/React.Sample.Webpack/build *.generated.js *.generated.js.map *.generated.min.js -src/React.Sample.CoreMvc/wwwroot/js/Sample.js *.lock.json .vs/ +results/ +dist/ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/LICENSE b/LICENSE index 3cac634d4..10d9a688c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,28 +1,21 @@ -BSD License for ReactJS.NET +MIT License for ReactJS.NET -Copyright (c) 2014, Facebook, Inc. All rights reserved. +Copyright (c) Facebook, Inc. and its affiliates. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name Facebook nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/PATENTS b/PATENTS deleted file mode 100644 index 755baf53f..000000000 --- a/PATENTS +++ /dev/null @@ -1,33 +0,0 @@ -Additional Grant of Patent Rights Version 2 - -"Software" means the ReactJS.NET software distributed by Facebook, Inc. - -Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software -("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable -(subject to the termination provision below) license under any Necessary -Claims, to make, have made, use, sell, offer to sell, import, and otherwise -transfer the Software. For avoidance of doubt, no license is granted under -Facebook's rights in any patent claims that are infringed by (i) modifications -to the Software made by you or any third party or (ii) the Software in -combination with any software or other technology. - -The license granted hereunder will terminate, automatically and without notice, -if you (or any of your subsidiaries, corporate affiliates or agents) initiate -directly or indirectly, or take a direct financial interest in, any Patent -Assertion: (i) against Facebook or any of its subsidiaries or corporate -affiliates, (ii) against any party if such Patent Assertion arises in whole or -in part from any software, technology, product or service of Facebook or any of -its subsidiaries or corporate affiliates, or (iii) against any party relating -to the Software. Notwithstanding the foregoing, if Facebook or any of its -subsidiaries or corporate affiliates files a lawsuit alleging patent -infringement against you in the first instance, and you respond by filing a -patent infringement counterclaim in that lawsuit against that party that is -unrelated to the Software, the license granted hereunder will not terminate -under section (i) of this paragraph due to such counterclaim. - -A "Necessary Claim" is a claim of a patent owned by Facebook that is -necessarily infringed by the Software standing alone. - -A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, -or contributory infringement or inducement to infringe any patent, including a -cross-claim or counterclaim. diff --git a/README.md b/README.md index 0576e909b..8a6674e56 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,55 @@ -[ReactJS.NET](http://reactjs.net/) -=========== +# [ReactJS.NET](http://reactjs.net/) -ReactJS.NET is a library that makes it easier to use [Babel](http://babeljs.io/) along with Facebook's [React](http://facebook.github.io/react/) and [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) from C#. +ReactJS.NET is a library that makes it easier to use [Babel](http://babeljs.io/) along with Facebook's [React](https://reactjs.org/) and [JSX](https://reactjs.org/docs/jsx-in-depth.html) from C#. -[](https://ci.appveyor.com/project/Daniel15/react-net/branch/master) + [](https://www.nuget.org/packages/React.Core/) [](https://www.nuget.org/packages/React.Core/) -Features -======== - * On-the-fly [JSX to JavaScript compilation](http://reactjs.net/getting-started/usage.html) via [Babel](http://babeljs.io/) - * JSX to JavaScript compilation via popular minification/combination - libraries: - * [ASP.NET Bundling and Minification](http://reactjs.net/guides/weboptimizer.html) - * [Cassette](http://reactjs.net/guides/cassette.html) - * [Webpack](http://reactjs.net/guides/webpack.html) - * [MSBuild](http://reactjs.net/guides/msbuild.html) - * [Server-side component rendering](http://reactjs.net/guides/server-side-rendering.html) - to make your initial render super-fast (experimental!) - * [Runs on Linux](http://reactjs.net/guides/mono.html) via Mono and V8 - * Supports both ASP.NET 4.0/4.5 and ASP.NET Core 1.0 +# Features -Quick Start -=========== -Install the package -``` -Install-Package React.Web.Mvc4 # For ASP.NET MVC 4 or 5 -Install-Package React.AspNet # For ASP.NET Core MVC 1.0 -``` +- On-the-fly [JSX to JavaScript compilation](http://reactjs.net/getting-started/usage.html) via [Babel](http://babeljs.io/) -Create JSX files -```javascript -// /Scripts/HelloWorld.jsx -var HelloWorld = React.createClass({ - render: function () { - return ( -
](/img/tutorial/newproject_core.png)
-3. In the "New ASP.NET Core Web Application" dialog, select the Web Application template. Also, click "Change Authentication" and select "No Authentication"
- [
](/img/tutorial/new_webapp.png)
-
-Note: We are using .NET Framework in this tutorial, but you can instead use .NET Core if you want to be able to run your site on Linux or Mac OS. Currently .NET Core is missing some of the functionality provided by .NET Framework, so it is recommended to use .NET Framework unless you have a reason to use .NET Core specifically (eg. cross-platform support).
-
-### Remove example content
-
-The default Web Application template includes some example content that we don't need. Delete the following files:
-
- - `Controllers\HomeController.cs`
- - `Views\Home` and `Views\Shared` folders
- - `bundleconfig.json`
- - `Project_Readme.html`
-
-### Install ReactJS.NET
-
-We need to install ReactJS.NET to the newly-created project. This is accomplished using NuGet, a package manager for .NET. Right-click on the "ReactDemo" project in the Solution Explorer and select "Manage NuGet Packages". Click the "Browse" tab, search for "React.AspNet", and install the **React.AspNet** package.
-
-[
](/img/tutorial/nuget_core.png)
-
-We also need to modify the `Startup.cs` file to initialize ReactJS.NET. You can learn more about this on the [Getting Started on ASP.NET Core](/getting-started/aspnetcore.html) page. Open `Startup.cs` and perform the following changes:
-
-At the top of the file, add:
-
-```csharp
-using Microsoft.AspNetCore.Http;
-using React.AspNet;
-```
-
-Directly above:
-
-```csharp
-// Add framework services.
-services.AddMvc();
-```
-
-Add:
-
-```csharp
-services.AddSingleton
-
-If you see this, congratulations! You've just built your first React component. You can leave the application running while you continue this tutorial. Simply change the JSX file and refresh to see your changes.
-
-#### JSX Syntax
-
-The first thing you'll notice is the XML-ish syntax in your JavaScript. We have a simple precompiler that translates the syntactic sugar to this plain JavaScript:
-
-```javascript
-var CommentBox = React.createClass({displayName: 'CommentBox',
- render: function() {
- return (
- React.createElement('div', {className: "commentBox"},
- "Hello, world! I am a CommentBox."
- )
- );
- }
-});
-ReactDOM.render(
- React.createElement(CommentBox, null),
- document.getElementById('content')
-);
-```
-
-Its use is optional but we've found JSX syntax easier to use than plain JavaScript. Read more on the [JSX Syntax article](http://facebook.github.io/react/docs/jsx-in-depth.html).
-
-#### What's going on
-
-We pass some methods in a JavaScript object to `React.createClass()` to create a new React component. The most important of these methods is called `render` which returns a tree of React components that will eventually render to HTML.
-
-The ``This is ``another`` comment`
`". We want those tags to actually render as HTML. - -That's React protecting you from an [XSS attack](https://en.wikipedia.org/wiki/Cross-site_scripting). There's a way to get around it but the framework warns you not to use it: - -```javascript{2-6,14} -var Comment = React.createClass({ - rawMarkup: function() { - var md = new Remarkable(); - var rawMarkup = md.render(this.props.children.toString()); - return { __html: rawMarkup }; - }, - - render: function() { - return ( -
-
-### Fetching from the server
-
-Now that we have a data source, we can replace the hard-coded data with the dynamic data from the server. We will remove the data prop and replace it with a URL to fetch:
-
-```javascript{2}
-ReactDOM.render(
-
Comments
-Daniel Lo Nigro
-Hello ReactJS.NET World!
-Comments
-- {this.props.author} -
- {this.props.children} -- {this.props.author} -
- {md.render(this.props.children.toString())} -`This is ``another`` comment`
`". We want those tags to actually render as HTML. - -That's React protecting you from an [XSS attack](https://en.wikipedia.org/wiki/Cross-site_scripting). There's a way to get around it but the framework warns you not to use it: - -```javascript{2-6,14} -var Comment = React.createClass({ - rawMarkup: function() { - var md = new Remarkable(); - var rawMarkup = md.render(this.props.children.toString()); - return { __html: rawMarkup }; - }, - - render: function() { - return ( -- {this.props.author} -
- -Comments
-Comments
-Comments
-Comments
-Comments
-Comments
-Comments
-Comments
-Comments
-Daniel Lo Nigro
-Hello ReactJS.NET World!
-ReactJS.NET makes it easier to use Facebook's - [React](http://facebook.github.io/react/) and - [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) from C# and + [React](https://reactjs.org/) and + [JSX](https://reactjs.org/docs/jsx-in-depth.html) from C# and other .NET languages, focusing specifically on ASP.NET MVC (although it also works in other environments). It supports both ASP.NET 4 (with MVC 4 or 5), and ASP.NET Core MVC. It is cross-platform and can run on Linux via Mono or .NET Core. - Take a look at [the tutorial](/getting-started/tutorial.html) to see how + Take a look at [the tutorial](/tutorials/aspnetcore.html) to see how easy it is to get started with React and ReactJS.NET!
@@ -48,16 +49,18 @@ id: home ```javascript // /Scripts/HelloWorld.jsx -var HelloWorld = React.createClass({ +class HelloWorld extends React.Component { render: function() { return
Comments
+{this.props.author}
+ {this.props.children} +{this.props.author}
+ {md.render(this.props.children.toString())} +`This is ``another`` comment`
`". We want those tags to actually render as HTML. + +That's React protecting you from an [XSS attack](https://en.wikipedia.org/wiki/Cross-site_scripting). There's a way to get around it but the framework warns you not to use it: + +```javascript{2-6,13} +class Comment extends React.Component { + rawMarkup() { + const md = new Remarkable(); + const rawMarkup = md.render(this.props.children.toString()); + return { __html: rawMarkup }; + } + render() { + return ( +{this.props.author}
+ +Comments
+Comments
+Comments
+Comments
+Comments
+Comments
+Comments
+Comments
+{this.props.author}
+ +Comments
+Daniel Lo Nigro
+ Hello ReactJS.NET World! +Comments
+{this.props.author}
+ {this.props.children} +{this.props.author}
+ {md.render(this.props.children.toString())} +`This is ``another`` comment`
`". We want those tags to actually render as HTML. + +That's React protecting you from an [XSS attack](https://en.wikipedia.org/wiki/Cross-site_scripting). There's a way to get around it but the framework warns you not to use it: + +```javascript{2-6,13} +class Comment extends React.Component { + rawMarkup() { + const md = new Remarkable(); + const rawMarkup = md.render(this.props.children.toString()); + return { __html: rawMarkup }; + } + render() { + return ( +{this.props.author}
+ +Comments
+Comments
+Comments
+Comments
+Comments
+Comments
+Comments
+Comments
+Daniel Lo Nigro
+Hello ReactJS.NET World!
+- This is an example of ReactJS.NET's server-side rendering. The initial state of this - comments box is rendered server-side, and additional data is loaded via AJAX and rendered - client-side. -
- - - @Html.React("CommentsBox", new { initialComments = Model.Comments }) - - - - - - - - @Html.ReactInitJavaScript() - - diff --git a/src/React.Sample.CoreMvc/web.config b/src/React.Sample.CoreMvc/web.config deleted file mode 100644 index 05ac0e36d..000000000 --- a/src/React.Sample.CoreMvc/web.config +++ /dev/null @@ -1,9 +0,0 @@ - -Comments
-- {commentNodes} -
- {this.renderMoreLink()} -Comments
-- {commentNodes} -
- {this.renderMoreLink()} -Comments
+{commentNodes}
+ {renderMoreLink()} ++
ASP.NET MVC Sample
++
+ This is an example of ReactJS.NET's server-side rendering. The initial state of this + comments box is rendered server-side, and additional data is loaded via AJAX and rendered + client-side. +
+ + @Html.React("CommentsBox", new { initialComments = Model.Comments, page = Model.Page }) + + + + + + @Scripts.Render("~/bundles/main") + + @Html.ReactInitJavaScript() +Comments
-- {commentNodes} -
- {this.renderMoreLink()} -- This is an example of ReactJS.NET's server-side rendering. The initial state of this - comments box is rendered server-side, and additional data is loaded via AJAX and rendered - client-side. -
- - - @Html.React("Components.CommentsBox", new { initialComments = Model.Comments }) - - - - - - - - @Html.ReactInitJavaScript() - - diff --git a/src/React.Sample.Webpack/Views/Web.config b/src/React.Sample.Webpack/Views/Web.config deleted file mode 100644 index d393a03eb..000000000 --- a/src/React.Sample.Webpack/Views/Web.config +++ /dev/null @@ -1,59 +0,0 @@ - - -Comments