$
This commit is contained in:
7
node_modules/@riotjs/hot-reload/.codeclimate.yml
generated
vendored
Normal file
7
node_modules/@riotjs/hot-reload/.codeclimate.yml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
engines:
|
||||
eslint:
|
||||
enabled: true
|
||||
|
||||
ratings:
|
||||
paths:
|
||||
- "lib/index.js"
|
8
node_modules/@riotjs/hot-reload/.eslintrc
generated
vendored
Normal file
8
node_modules/@riotjs/hot-reload/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
extends: eslint-config-riot
|
||||
|
||||
parserOptions:
|
||||
ecmaVersion: 2018
|
||||
sourceType: 'module'
|
||||
|
||||
globals:
|
||||
chai: true
|
25
node_modules/@riotjs/hot-reload/.github/workflows/test.yml
generated
vendored
Normal file
25
node_modules/@riotjs/hot-reload/.github/workflows/test.yml
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, dev ]
|
||||
pull_request:
|
||||
branches: [ dev ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x, 15.x, 16.x, 17.x]
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Local Unit Test ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm i
|
||||
- run: npm test
|
21
node_modules/@riotjs/hot-reload/LICENSE
generated
vendored
Normal file
21
node_modules/@riotjs/hot-reload/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Riot
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
35
node_modules/@riotjs/hot-reload/README.md
generated
vendored
Normal file
35
node_modules/@riotjs/hot-reload/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Riot hot reload api
|
||||
|
||||
[](https://github.com/riot/hot-reload/)
|
||||
|
||||
[![Build Status][ci-image]][ci-url]
|
||||
[![NPM version][npm-version-image]][npm-url]
|
||||
[![NPM downloads][npm-downloads-image]][npm-url]
|
||||
[![MIT License][license-image]][license-url]
|
||||
|
||||
Api that will extend riot making your tags hot reloadable.
|
||||
|
||||
## Important
|
||||
|
||||
If you are using Riot.js < 4.0.0 please check the [v3 branch](https://github.com/riot/hot-reload/tree/v3)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import reload from '@riotjs/hot-reload'
|
||||
import Component from './my-component'
|
||||
// refresh all the DOM nodes called 'my-component' without losing their state
|
||||
reload(Component)
|
||||
```
|
||||
|
||||
|
||||
|
||||
[ci-image]:https://img.shields.io/github/workflow/status/riot/hot-reload/test?style=flat-square
|
||||
[ci-url]:https://github.com/riot/hot-reload/actions
|
||||
[license-image]: https://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
|
||||
[license-url]: LICENSE.txt
|
||||
[npm-version-image]: https://img.shields.io/npm/v/@riotjs/hot-reload.svg?style=flat-square
|
||||
[npm-downloads-image]: https://img.shields.io/npm/dm/@riotjs/hot-reload.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/@riotjs/hot-reload
|
||||
[codeclimate-image]: https://codeclimate.com/github/riot/hot-reload/badges/issue_count.svg
|
||||
[codeclimate-url]: https://codeclimate.com/github/riot/hot-reload
|
46
node_modules/@riotjs/hot-reload/index.js
generated
vendored
Normal file
46
node_modules/@riotjs/hot-reload/index.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('riot'), require('bianco.query')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'riot', 'bianco.query'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.riotHotReload = {}, global.riot, global.$));
|
||||
})(this, (function (exports, riot, $) { 'use strict';
|
||||
|
||||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
||||
|
||||
var $__default = /*#__PURE__*/_interopDefaultLegacy($);
|
||||
|
||||
const { cssManager } = riot.__;
|
||||
const { DOM_COMPONENT_INSTANCE_PROPERTY } = riot.__.globals;
|
||||
|
||||
function reload(componentAPI) {
|
||||
const {name} = componentAPI;
|
||||
|
||||
if (!name) {
|
||||
console.warn('Anonymous components can not be reloaded'); // eslint-disable-line
|
||||
return []
|
||||
}
|
||||
|
||||
return $__default["default"](`${name}, [is=${name}]`).map(el => {
|
||||
const oldTag = el[DOM_COMPONENT_INSTANCE_PROPERTY];
|
||||
|
||||
// early return in case there is no riot instance found
|
||||
if (!oldTag) return
|
||||
|
||||
// remove the tag template from the DOM
|
||||
oldTag.unmount(true);
|
||||
// delete the old css from the css manager
|
||||
cssManager.remove(name);
|
||||
|
||||
// create the new tag
|
||||
const newTag = riot.component(componentAPI)(el, oldTag.props);
|
||||
newTag.update(oldTag.state);
|
||||
|
||||
return newTag
|
||||
})
|
||||
}
|
||||
|
||||
exports["default"] = reload;
|
||||
exports.reload = reload;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
}));
|
41
node_modules/@riotjs/hot-reload/package.json
generated
vendored
Normal file
41
node_modules/@riotjs/hot-reload/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"author": "Gianluca Guarini https://github.com/GianlucaGuarini",
|
||||
"bugs": {
|
||||
"url": "https://github.com/riot/hot-reload/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"bianco.query": "^1.1.4"
|
||||
},
|
||||
"description": "Riot Hot Reload Api",
|
||||
"devDependencies": {
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.22.0",
|
||||
"eslint-config-riot": "^3.0.0",
|
||||
"esm": "^3.2.25",
|
||||
"jsdom": "^20.0.0",
|
||||
"jsdom-global": "3.0.2",
|
||||
"mocha": "^8.4.0",
|
||||
"riot": "^7.0.3",
|
||||
"rollup": "^2.78.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"riot": "^6.0.0 || ^7.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/riot/hot-reload#readme",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "@riotjs/hot-reload",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/riot/hot-reload.git"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "npm i riot --no-save",
|
||||
"lint": "eslint src test",
|
||||
"build": "rollup -c",
|
||||
"pretest": "npm run build",
|
||||
"test": "npm run lint && mocha -r esm test",
|
||||
"prepublishOnly": "npm run build && npm run test"
|
||||
},
|
||||
"version": "6.0.1"
|
||||
}
|
10
node_modules/@riotjs/hot-reload/rollup.config.js
generated
vendored
Normal file
10
node_modules/@riotjs/hot-reload/rollup.config.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export default {
|
||||
input: 'src/index.js',
|
||||
output: {
|
||||
file: 'index.js',
|
||||
format: 'umd',
|
||||
name: 'riotHotReload'
|
||||
},
|
||||
interop: false,
|
||||
external: ['riot']
|
||||
}
|
34
node_modules/@riotjs/hot-reload/src/index.js
generated
vendored
Normal file
34
node_modules/@riotjs/hot-reload/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import {__, component} from 'riot'
|
||||
import $ from 'bianco.query'
|
||||
|
||||
const { cssManager } = __
|
||||
const { DOM_COMPONENT_INSTANCE_PROPERTY } = __.globals
|
||||
|
||||
export function reload(componentAPI) {
|
||||
const {name} = componentAPI
|
||||
|
||||
if (!name) {
|
||||
console.warn('Anonymous components can not be reloaded') // eslint-disable-line
|
||||
return []
|
||||
}
|
||||
|
||||
return $(`${name}, [is=${name}]`).map(el => {
|
||||
const oldTag = el[DOM_COMPONENT_INSTANCE_PROPERTY]
|
||||
|
||||
// early return in case there is no riot instance found
|
||||
if (!oldTag) return
|
||||
|
||||
// remove the tag template from the DOM
|
||||
oldTag.unmount(true)
|
||||
// delete the old css from the css manager
|
||||
cssManager.remove(name)
|
||||
|
||||
// create the new tag
|
||||
const newTag = component(componentAPI)(el, oldTag.props)
|
||||
newTag.update(oldTag.state)
|
||||
|
||||
return newTag
|
||||
})
|
||||
}
|
||||
|
||||
export default reload
|
74
node_modules/@riotjs/hot-reload/test/index.js
generated
vendored
Normal file
74
node_modules/@riotjs/hot-reload/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import {__, component} from 'riot'
|
||||
import {expect} from 'chai'
|
||||
import hotReload from '../'
|
||||
import jsDOMGlobal from 'jsdom-global'
|
||||
|
||||
describe('core', () => {
|
||||
before(() => {
|
||||
jsDOMGlobal()
|
||||
})
|
||||
|
||||
it('riot.reload keeps the tags state', (done) => {
|
||||
const api = {
|
||||
name: 'timer',
|
||||
exports: {
|
||||
state: {
|
||||
count: 0
|
||||
},
|
||||
onBeforeMount() {
|
||||
this.interval = setInterval(() => {
|
||||
this.state.count ++
|
||||
}, 100)
|
||||
},
|
||||
onUnmounted() {
|
||||
clearInterval(this.interval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const div = document.createElement('div')
|
||||
document.body.appendChild(div)
|
||||
|
||||
component(api)(div)
|
||||
|
||||
setTimeout(function() {
|
||||
const el = hotReload(api)[0]
|
||||
|
||||
expect(el.state.count).to.be.equal(2)
|
||||
el.unmount()
|
||||
done()
|
||||
}, 210)
|
||||
})
|
||||
|
||||
it('riot.reload will reload the css properly', () => {
|
||||
const api = {
|
||||
name: 'css-demo',
|
||||
css: ':host { color: rgb(255, 255, 255); }'
|
||||
}
|
||||
|
||||
const div = document.createElement('div')
|
||||
document.body.appendChild(div)
|
||||
|
||||
component(api)(div)
|
||||
|
||||
expect(__.cssManager.CSS_BY_NAME.get('css-demo')).to.match(/rgb\(255, 255, 255\)/)
|
||||
|
||||
hotReload({
|
||||
name: 'css-demo',
|
||||
css: ':host { color: rgb(0, 0, 0); }'
|
||||
})
|
||||
|
||||
expect(__.cssManager.CSS_BY_NAME.get('css-demo')).to.match(/rgb\(0, 0, 0\)/)
|
||||
})
|
||||
|
||||
it('components not compatible with riot will be ignored', () => {
|
||||
const div = document.createElement('div')
|
||||
document.body.appendChild(div)
|
||||
|
||||
div.setAttribute('is', 'not-riot')
|
||||
|
||||
expect(() => hotReload({
|
||||
name: 'not-riot'
|
||||
})).to.not.throw()
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user