submodule fix

This commit is contained in:
Rene
2019-07-31 00:00:46 +02:00
parent 2c5cc23919
commit 2b90b89598
38 changed files with 24809 additions and 2 deletions
@@ -0,0 +1,303 @@
.header {
background: #36befd;
background: -moz-linear-gradient(-45deg, #36befd 1%, #6461f6 100%);
background: -webkit-linear-gradient(-45deg, #36befd 1%, #6461f6 100%);
background: linear-gradient(135deg, #36befd 1%, #6461f6 100%);
margin: 0;
color: #fff;
letter-spacing: 0.1pt;
text-shadow: 0px 1px 3px rgba(0, 0, 255, 0.1);
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
height: 76px;
box-shadow: 0 15px 20px -15px rgba(57, 120, 253, 0.15), 0 55px 50px -35px rgba(47, 78, 249, 0.12);
position: relative;
z-index: 1;
}
.header code {
border-radius: 4px;
margin: 2px;
display: block;
padding: 0.5em;
background: #fff;
font-size: 10pt;
margin: 0px auto;
box-shadow: 0px 1px 3px rgba(0, 0, 255, 0.15);
}
.header code .code-keyword {
color: #0059FF;
font-weight: bold;
}
.header code .code-char {
color: #4D4D4C;
}
.header code .code-variable {
color: #3778AD;
}
.header code .code-string {
color: #279737;
font-weight: 400;
}
.content {
min-height: calc(100vh - 76px);
position: relative;
display: flex;
flex-direction: column;
flex-flow: column;
flex-wrap: wrap;
}
.content-section {
position: relative;
padding: 40px 0px;
background: #fff;
z-index: 1;
overflow: hidden;
}
.content-section:last-child {
flex-grow: 1;
}
.content-section:before,
.content-section:after {
content: '';
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
}
.content-section:nth-child(2n - 1) {
background: #f6f8fb;
}
.content-section:nth-child(2n - 1):before,
.content-section:nth-child(2n - 1):after {
background: #fff;
}
.content-section:nth-child(2n + 0) {
background: #fff;
}
.content-section:nth-child(2n + 0):before,
.content-section:nth-child(2n + 0):after {
background: #f6f8fb;
}
.content-section.skew:before,
.content-section.skew:after {
transform: skewY(-7deg);
}
.content-section.skew + .content-section:before,
.content-section.skew + .content-section:after {
transform: skewY(-7deg);
}
.content-section skew + .content-section.skew:before,
.content-section.skew + .content-section.skew:before {
top: 0;
}
.content-section + .content-section.skew:before {
top: -50vw;
}
.content-section.skew + .content-section:after {
bottom: -50vw;
}
.content-section + .content-section:after {
top: 0;
}
.content-section.skew + .content-section.skew:after {
bottom: 0;
}
.content-section.skew:first-child:before {
top: -50vw !important;
}
.content-section.skew:last-child:after {
bottom: -50vw !important;
}
.content-section-content-framework > span {
font-weight: bold;
font-size: 30pt;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
.content-section-content-framework > span:not(:nth-child(2)) {
display: inline-block;
color: transparent;
height: 190px;
width: 190px;
vertical-align:middle;
}
.content-section-title {
margin-bottom: 14px;
}
.content-section-title > h2{
text-align: center;
font-size: 26pt;
color: #39547A;
margin: 24px 0px;
}
.content-section-title > table{
text-align: left;
margin: 0px auto;
}
.content-section-title > table tr {
margin: 10px;
}
.content-section-title > table td {
line-height: 18pt;
}
.content-section-title > table td:first-child {
text-align: right;
font-weight: bold;
vertical-align: top;
}
.content-section-title > table td:first-child span{
margin: 0px 6px;
}
.content-section-title > table td:last-child span {
text-align: left;
color: #36befd;
font-weight: bold;
}
.content-section-content {
display: table;
margin: 0px auto;
}
.content-section-content .os-host,
.content-section-content .os-host-textarea {
border: 2px solid #36befd;
width: 480px;
max-height: 300px;
margin: 10px auto 20px auto;
border-radius: 6px;
padding: 10px;
line-height: 16pt;
}
.content-section-content > .os-host .os-host,
.content-section-content > .os-host-textarea .os-host-textarea {
border: 2px solid #6461f6;
width: auto;
height: auto;
margin: 10px auto;
}
.content-section-content .bonus-content {
display: inline-block;
white-space: pre;
background: #f0f3f6;
padding: 0px 5px;
margin: 2px;
border-radius: 4px !important;
border: 1px solid #DDE3ED;
font-size: 10pt;
font-family: "Lucida Console", Monaco, monospace;
color: #39547A;
}
.content-section-content-buttons {
display: table;
margin: 0px auto;
}
.info-span {
background: #F7F7F7;
padding: 2px 5px;
margin: 2px;
white-space: nowrap;
border-radius: 4px;
border: 1px solid #DEDFE0;
font-weight: bold;
font-size: 10pt;
}
a {
display: inline-block;
text-decoration: none;
position: relative;
color: #36befd;
transition: color 0.3s, text-shadow 0.3s;
text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.05);
padding: 0px 1px;
font-weight: 600;
outline: none !important;
cursor: pointer;
z-index: 0;
}
a:hover {
color: #fff;
text-shadow: 0px 1px 6px rgba(0, 0, 0, 0.16);
}
a:before {
content: '';
position: absolute;
display: block;
bottom: 0;
left: 0;
height: 0%;
width: 100%;
background: transparent;
z-index: -1;
border-bottom: 1px dotted #36befd;
transition: height 0.3s, border 0.3s, background-color 0.15s;
}
a:hover:before {
height: 100%;
background: #36befd;
border-bottom: 1px solid #36befd;
}
.buttons {
display: table;
margin: 0px auto;
}
button {
font-size: 10pt;
line-height: 28pt;
font-family: sans-serif;
font-weight: bold;
color: #555E6B;
line-height: 40px;
border: 1px solid #D6D6D6;
border-radius: 6px;
cursor: pointer;
transition: color 0.3s, background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
padding: 0px 14px;
display: block;
float: left;
margin: 5px;
text-align: center;
background: rgba(0, 0, 0, 0.02);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
min-width: 80px;
outline: none !important;
}
button:hover {
color: #fff;
background: #6461f6;
border-color: #6461f6;
box-shadow: 0 4px 8px -1px rgba(170, 170, 170, 0.45);
}
button:active {
box-shadow: inset 0 4px 9px -1px rgba(0, 0, 0, 0.15);
}
::selection {
color: #fff;
background: #6461f6;
text-shadow: 0px 1px 3px rgba(0, 0, 0, 0.28);
}
img {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
pointer-events: none;
}
.os-logo {
background: transparent url("assets/overlayscrollbars.svg") no-repeat center center;
background-size: 80%;
}
.framework-logo {
background: transparent url("assets/react.svg") no-repeat center center;
background-size: 138%;
}
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
@@ -0,0 +1,176 @@
import './App.css';
import React, { RefObject } from 'react';
import OverlayScrollbars from 'overlayscrollbars';
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
export interface AppState {
componentContent: string;
osComponentOptions: OverlayScrollbars.Options;
}
export default class App extends React.Component<any, AppState> {
framework: string = 'React';
componentClass: string = 'OverlayScrollbarsComponent';
loremIpsumLong: string = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';
loremIpsumMedium: string = 'At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.';
loremIpsumShort: string = 'Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio.';
osComponentRef1: RefObject<OverlayScrollbarsComponent>;
osComponentRef2: RefObject<OverlayScrollbarsComponent>;
constructor(props: any) {
super(props);
this.osComponentRef1 = React.createRef<OverlayScrollbarsComponent>();
this.osComponentRef2 = React.createRef<OverlayScrollbarsComponent>();
this.state = {
componentContent: 'Lorem Ipsum',
osComponentOptions: {
resize: 'both',
paddingAbsolute: true,
scrollbars: {
autoHide: 'never'
}
}
};
}
componentDidMount() {
console.log(`${this.componentClass} (1)`);
console.log(this.osComponentRef1.current);
console.log(`${this.componentClass} (2)`);
console.log(this.osComponentRef2.current);
}
onBtnScrollRandom(event: React.MouseEvent<HTMLButtonElement, MouseEvent>, refArray: Array<RefObject<OverlayScrollbarsComponent>>) {
if (refArray) {
for (let i = 0; i < refArray.length; i++) {
if (refArray[i] && refArray[i].current) {
let osInstance = refArray[i].current!.osInstance();
if (osInstance) {
osInstance.scrollStop().scroll({
x: Math.floor((Math.random() * osInstance.scroll().max.x) + 0),
y: Math.floor((Math.random() * osInstance.scroll().max.y) + 0)
}, 1000, 'easeOutElastic');
}
}
}
}
}
onBtnChangeOptions() {
this.setState({
osComponentOptions: {
resize: this.state.osComponentOptions.resize === 'both' ? 'none' : 'both',
scrollbars: {
autoHide: this.state.osComponentOptions.scrollbars!.autoHide === 'never' ? 'scroll' : 'never',
}
}
});
}
onBtnChangeContent() {
let loremIpsums = [this.loremIpsumLong, this.loremIpsumMedium, this.loremIpsumShort];
let random = Math.floor(Math.random() * loremIpsums.length);
this.setState({
componentContent: this.state.componentContent + "\r\n" + loremIpsums[random]
});
}
onBtnLog() {
console.log(`== ${this.componentClass} (1) ==`);
console.log("Instance:");
console.log(this.osComponentRef1.current!.osInstance());
console.log("Target:");
console.log(this.osComponentRef1.current!.osTarget());
console.log("");
console.log(`== ${this.componentClass} (2) ==`);
console.log("Instance:");
console.log(this.osComponentRef2.current!.osInstance());
console.log("Target:");
console.log(this.osComponentRef2.current!.osTarget());
}
render() {
return (
<div className="App">
<div className="header">
<code>
<span className="code-keyword">import</span>
<span className="code-char">{' { '}</span>
<span className="code-variable">OverlayScrollbarsComponent</span>
<span className="code-char">{' } '}</span>
<span className="code-keyword">from</span>
<span className="code-string">{" 'overlayscrollbars-react'"}</span>
<span className="code-char">;</span>
</code>
</div>
<div className="content">
<div className="content-section skew">
<div className="content-section-content content-section-content-framework">
<span className="framework-logo"></span>
<span>+</span>
<span className="os-logo"></span>
</div>
</div>
<div className="content-section">
<div className="content-section-title">
<h2>Component</h2>
<table>
<tbody>
<tr>
<td><span>Class:</span></td>
<td><span>{this.componentClass}</span></td>
</tr>
<tr>
<td><span>Description:</span></td>
<td>OverlayScrollbars as a {this.framework}-Component.</td>
</tr>
</tbody>
</table>
</div>
<div className="content-section-content">
<OverlayScrollbarsComponent ref={this.osComponentRef1}
options={this.state.osComponentOptions}
style={{ maxHeight: '350px' }}
className={`custom-class-name-test ${this.framework}`}
>
<div className="bonus-content">
{this.state.componentContent}
</div>
{this.loremIpsumShort}
<OverlayScrollbarsComponent ref={this.osComponentRef2}
options={this.state.osComponentOptions}
style={{ maxHeight: '150px' }}
className="custom-class-name-test"
>
<div className="bonus-content">
{this.state.componentContent}
</div>
{this.loremIpsumLong}
<br />
<br />
{this.loremIpsumShort}
</OverlayScrollbarsComponent>
{this.loremIpsumMedium}
<br />
<br />
{this.loremIpsumShort}
<br />
<br />
{this.loremIpsumLong}
</OverlayScrollbarsComponent>
<div className="buttons">
<button onClick={(event) => { this.onBtnScrollRandom.call(this, event, [this.osComponentRef1, this.osComponentRef2]) }}>Scroll</button>
<button onClick={() => { this.onBtnChangeOptions.call(this) }}>Change Options</button>
<button onClick={() => { this.onBtnChangeContent.call(this) }}>Change Content</button>
<button onClick={() => { this.onBtnLog.call(this) }}>Log</button>
</div>
</div>
</div>
</div>
</div>
);
}
}
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="708.75px" height="472.5px" viewBox="0 0 708.75 472.5" enable-background="new 0 0 708.75 472.5" xml:space="preserve">
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="2.7998" y1="236.25" x2="705.9502" y2="236.25">
<stop offset="0" style="stop-color:#36BEFD"/>
<stop offset="1" style="stop-color:#6461F6"/>
</linearGradient>
<path fill="none" stroke="url(#SVGID_1_)" stroke-width="46.9" stroke-linecap="round" stroke-miterlimit="10" d="M577.5,341.25H420
c-16.656,0-31.977,7.648-42.043,20.992c-3.203,4.289-5.781,9.066-7.582,14.102c-1.93,5.52-2.945,11.43-2.945,17.406v1.613
c0.133,5.133,1.133,10.684,2.973,15.867c0.563,1.559,1.215,3.109,1.887,4.449c2.305,4.82,4.809,8.68,7.641,11.902
c10.199,11.98,24.703,18.668,40.07,18.668h157.5c33.348,0,64-15.32,84.09-42.027c9.203-12.305,15.738-26.852,18.859-42.012
c1.348-6.805,2.051-13.914,2.051-20.961s-0.703-14.156-2.09-21.137c-3.082-14.984-9.617-29.531-18.863-41.891
C641.5,251.57,610.848,236.25,577.5,236.25h-105c-28.949,0-52.5-23.551-52.5-52.5s23.551-52.5,52.5-52.5H630
c22.242,0,42.141-14.055,49.512-34.973c1.977-5.645,2.988-11.551,2.988-17.527s-1.012-11.883-3.004-17.57
c-5.699-16.219-19.598-28.961-36.27-33.227c-4.32-1.156-8.684-1.703-13.227-1.703H236.32c-48.633,0-94.285,16.133-132.035,46.664
c-16.566,13.422-30.914,29.133-42.625,46.668c-9.84,14.656-17.723,30.332-23.461,46.633c-5.367,15.273-8.945,30.953-10.629,46.602
c-0.883,7.73-1.32,15.566-1.32,23.434s0.438,15.703,1.301,23.277c1.703,15.805,5.281,31.484,10.656,46.77
c5.73,16.289,13.613,31.965,23.418,46.574c11.746,17.582,26.094,33.293,42.684,46.738c37.727,30.508,83.379,46.641,132.012,46.641
c7.637,0,14.734-0.383,21.695-1.168"/>
<linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="107.7998" y1="236.25" x2="364.7002" y2="236.25">
<stop offset="0" style="stop-color:#36BEFD"/>
<stop offset="1" style="stop-color:#6461F6"/>
</linearGradient>
<circle fill="none" stroke="url(#SVGID_2_)" stroke-width="46.9" stroke-linecap="round" stroke-miterlimit="10" cx="236.25" cy="236.25" r="105"/>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
<g fill="#61DAFB">
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
<circle cx="420.9" cy="296.5" r="45.7"/>
<path d="M520.5 78.1z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

@@ -0,0 +1,11 @@
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 11pt;
color: #31485B;
box-sizing: border-box;
}
* {
box-sizing: inherit;
}
@@ -0,0 +1,16 @@
import 'overlayscrollbars/css/OverlayScrollbars.css'
import './index.css';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
import OverlayScrollbars from 'overlayscrollbars';
ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();
OverlayScrollbars(document.body, {
nativeScrollbarsOverlaid: {
initialize: false
}
});
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
@@ -0,0 +1,143 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
type Config = {
onSuccess?: (registration: ServiceWorkerRegistration) => void;
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};
export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
(process as { env: { [key: string]: string } }).env.PUBLIC_URL,
window.location.href
);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl: string, config?: Config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}