🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-web-component

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-web-component - npm Package Compare versions

Comparing version

to
1.3.0

.babelrc

17

package.json
{
"name": "react-web-component",
"version": "1.0.14",
"version": "1.3.0",
"description": "Create Web Components with React",
"main": "src/index.js",
"types": "index.d.ts",
"author": "Lukas Bombach <lukas.bombach@googlemail.com>",
"license": "MIT",
"repository": "WeltN24/react-web-component",
"scripts": {
"build": "babel src/dev -d src --presets minify"
},
"dependencies": {
"react-dom": "^16.0.0",
"react-shadow-dom-retarget-events": "^1.0.8"
},
"peerDependencies": {
"react-dom": "^16.2.0"
},
"devDependencies": {
"@types/react": "^16.0.38",
"babel-cli": "^6.26.0",
"babel-minify": "^0.3.0",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.3.0"
}
}

@@ -48,2 +48,12 @@ <p align="center">

By default the `shadowRoot` is enabled. This allows for styles isolation and prevents component styles from
*bleeding out* to other parts of the application. It also prevents outer styles from affecting the web component you are creating.
In case that you want your component to inherit styles from the parent you can opt-out of the shadowRoot.
To do that you can pass an **optional** parameter to the `create` method:
```js
ReactWebComponent.create(<App />, 'my-component', true);
```
It is also possible to create multiple web components in a single project and pass on props:

@@ -50,0 +60,0 @@

8

src/getStyleElementsFromReactWebComponentStyleLoader.js

@@ -1,7 +0,1 @@

module.exports = function getStyleElementsFromReactWebComponentStyleLoader() {
try {
return require('react-web-component-style-loader/exports').styleElements;
} catch (e) {
return [];
}
};
'use strict';module.exports=function(){try{return require('react-web-component-style-loader/exports').styleElements}catch(a){return[]}};

@@ -1,79 +0,1 @@

const ReactDOM = require('react-dom');
const retargetEvents = require('react-shadow-dom-retarget-events');
const getStyleElementsFromReactWebComponentStyleLoader = require('./getStyleElementsFromReactWebComponentStyleLoader');
module.exports = {
/**
* todo fix jsdoc type of app
* @param {*} app
* @param {string} tagName
*/
create: function(app, tagName) {
var appInstance;
const lifeCycleHooks = {
attachedCallback: 'webComponentAttached',
connectedCallback: 'webComponentConnected',
disconnectedCallback: 'webComponentDisconnected',
attributeChangedCallback: 'webComponentAttributeChanged',
adoptedCallback: 'webComponentAdopted'
};
function callConstructorHook(webComponentInstance) {
if (appInstance['webComponentConstructed']) {
appInstance['webComponentConstructed'].apply(appInstance, [webComponentInstance])
}
}
function callLifeCycleHook(hook, params) {
const instanceParams = params || [];
const instanceMethod = lifeCycleHooks[hook];
if (instanceMethod && appInstance[instanceMethod]) {
appInstance[instanceMethod].apply(appInstance, instanceParams)
}
}
const proto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function() {
const shadowRoot = this.createShadowRoot();
const mountPoint = document.createElement('div');
const styles = getStyleElementsFromReactWebComponentStyleLoader();
const webComponentInstance = this;
for (var i = 0; i < styles.length; i++) {
shadowRoot.appendChild(styles[i].cloneNode(true));
}
shadowRoot.appendChild(mountPoint);
ReactDOM.render(app, mountPoint, function () {
appInstance = this;
callConstructorHook(webComponentInstance);
callLifeCycleHook('attachedCallback');
});
retargetEvents(shadowRoot);
},
},
connectedCallback: {
value: function() {
callLifeCycleHook('connectedCallback');
},
},
disconnectedCallback: {
value: function() {
callLifeCycleHook('disconnectedCallback');
},
},
attributeChangedCallback: {
value: function(attributeName, oldValue, newValue, namespace) {
callLifeCycleHook('attributeChangedCallback', [attributeName, oldValue, newValue, namespace]);
},
},
adoptedCallback: {
value: function(oldDocument, newDocument) {
callLifeCycleHook('adoptedCallback', [oldDocument, newDocument]);
},
},
});
document.registerElement(tagName, { prototype: proto });
},
};
'use strict';var ReactDOM=require('react-dom'),retargetEvents=require('react-shadow-dom-retarget-events'),getStyleElementsFromReactWebComponentStyleLoader=require('./getStyleElementsFromReactWebComponentStyleLoader'),extractAttributes=require('./extractAttributes');module.exports={create:function create(a,b){function c(a){f.webComponentConstructed&&f.webComponentConstructed.apply(f,[a])}function d(a,b){var c=g[a];c&&f&&f[c]&&f[c].apply(f,b||[])}var e=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2],f=void 0,g={attachedCallback:'webComponentAttached',connectedCallback:'webComponentConnected',disconnectedCallback:'webComponentDisconnected',attributeChangedCallback:'webComponentAttributeChanged',adoptedCallback:'webComponentAdopted'},h=Object.create(HTMLElement.prototype,{attachedCallback:{value:function value(){var b=this,g=b;if(e){b=b.createShadowRoot(),g=document.createElement('div');var h=getStyleElementsFromReactWebComponentStyleLoader();h.forEach(function(a){b.appendChild(a.cloneNode(b))}),b.appendChild(g),retargetEvents(b)}ReactDOM.render(a,g,function(){f=this,f.props=extractAttributes(b),c(b),d('attachedCallback')})}},connectedCallback:{value:function value(){d('connectedCallback')}},disconnectedCallback:{value:function value(){d('disconnectedCallback')}},attributeChangedCallback:{value:function value(a,b,c,e){d('attributeChangedCallback',[a,b,c,e])}},adoptedCallback:{value:function value(a,b){d('adoptedCallback',[a,b])}}});document.registerElement(b,{prototype:h})}};

Sorry, the diff of this file is not supported yet