Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-habitat

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-habitat - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6-beta

.travis.yml

40

lib/Bootstrapper.d.ts

@@ -0,13 +1,47 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import { IBootstrapper } from "./interfaces/IBootstrapper";
import { IContainer } from './interfaces/IContainer';
import { IDOMFactory } from './interfaces/IDOMFactory';
/**
* Bootstrapper class
*/
export declare class Bootstrapper implements IBootstrapper {
_componentSelector: string;
/**
* The dom container
* Note for es5 support we cannot have the private accessor here
*/
_container: IContainer;
domFactory: IDOMFactory;
/**
* The component selector namespace
*/
componentSelector: string;
/**
* The dom factory
* @type {ReactDOMFactory}
*/
factory: IDOMFactory;
/**
* The raw dom elements
*/
firstClassElements: NodeListOf<Element>;
/**
* Constructor
*/
constructor();
readonly componentSelector: string;
/**
* Set the container
* @param {IContainer} container - The container
*/
setContainer(container: IContainer): void;
/**
* Wires up components inside the container
* @private
*/
_wireUpComponents(): void;
}

48

lib/Bootstrapper.js

@@ -0,27 +1,53 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
var Habitat_1 = require('./Habitat');
var ReactDOMFactory_1 = require('./factories/ReactDOMFactory');
/**
* Bootstrapper class
*/
var Bootstrapper = (function () {
/**
* Constructor
*/
function Bootstrapper() {
/**
* The component selector namespace
*/
this.componentSelector = 'data-component';
/**
* The dom factory
* @type {ReactDOMFactory}
*/
this.factory = new ReactDOMFactory_1.ReactDOMFactory();
// Sanity check
if (!window || (!window && !window.document)) {
throw new Error('ReactBootstrapper requires a DOM but cannot see one :(');
}
this.domFactory = new ReactDOMFactory_1.ReactDOMFactory();
this._componentSelector = 'data-component';
// Find all the elements in the dom with the component selector attribute
this.firstClassElements = window.document.querySelectorAll("[" + this.componentSelector + "]");
}
Object.defineProperty(Bootstrapper.prototype, "componentSelector", {
get: function () {
return this._componentSelector;
},
enumerable: true,
configurable: true
});
/**
* Set the container
* @param {IContainer} container - The container
*/
Bootstrapper.prototype.setContainer = function (container) {
// Save the container
this._container = container;
// Wire up the components from the container
this._wireUpComponents();
};
/**
* Wires up components inside the container
* @private
*/
Bootstrapper.prototype._wireUpComponents = function () {
// Iterate over component elements in the dom
for (var i = 0; i < this.firstClassElements.length; ++i) {
var ele = this.firstClassElements[i], componentName = ele.getAttribute(this._componentSelector), component = this._container.getComponent(componentName);
var ele = this.firstClassElements[i], componentName = ele.getAttribute(this.componentSelector), component = this._container.component(componentName);
if (!component) {

@@ -31,3 +57,3 @@ console.warn("Cannot resolve component \"" + componentName + "\". Did you forget to register it in the container?");

}
this.domFactory.inject(component, Habitat_1.Habitat.parseProps(ele), Habitat_1.Habitat.createHabitat(ele, this.domFactory.identifier()));
this.factory.inject(component, Habitat_1.Habitat.parseProps(ele), Habitat_1.Habitat.createHabitat(ele, this.factory.identifier()));
}

@@ -34,0 +60,0 @@ };

@@ -0,1 +1,8 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";

@@ -2,0 +9,0 @@ var __extends = (this && this.__extends) || function (d, b) {

@@ -0,9 +1,35 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import { IContainer } from './interfaces/IContainer';
/**
* The Container class
*/
export declare class Container implements IContainer {
/**
* A dictionary to hold references to registered components
*/
_components: {
[id: string]: any;
};
/**
* Constructor
*/
constructor();
/**
* Register a new component
* @param name
* @param comp
*/
registerComponent(name: string, comp: any): void;
getComponent(name: string): any;
/**
* Returns a component for name
* @param name
* @returns {any}
*/
component(name: string): any;
}

@@ -0,10 +1,33 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
/**
* The Container class
*/
var Container = (function () {
/**
* Constructor
*/
function Container() {
this._components = {};
}
/**
* Register a new component
* @param name
* @param comp
*/
Container.prototype.registerComponent = function (name, comp) {
this._components[name] = comp;
};
Container.prototype.getComponent = function (name) {
/**
* Returns a component for name
* @param name
* @returns {any}
*/
Container.prototype.component = function (name) {
return this._components[name];

@@ -11,0 +34,0 @@ };

@@ -0,1 +1,8 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";

@@ -2,0 +9,0 @@ var React = require('react');

@@ -0,6 +1,22 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* The Habitat class
*/
export declare class Habitat {
/**
* Returns a dictionary of properties and values defined on an element
*/
static parseProps(ele: Element): {
[id: string]: any;
};
/**
* Creates a new habitat in the dom
*/
static createHabitat(ele: Element, type: string): Element;
}

@@ -0,8 +1,24 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
/**
* The Habitat class
*/
var Habitat = (function () {
function Habitat() {
}
/**
* Returns a dictionary of properties and values defined on an element
*/
Habitat.parseProps = function (ele) {
// Default props with reference to the initiating node
var _props = {};
// Save a reference to the original node
_props['fnNode'] = ele;
// Populate custom props from reading any ele attributes that start with 'data-prop-'
for (var i = 0; i < ele.attributes.length; i++) {

@@ -13,2 +29,3 @@ var a = ele.attributes[i];

}
// Convert prop name from hyphens to camel case
var name_1 = a.name

@@ -18,2 +35,3 @@ .replace('data-prop-', '')

var value = a.value || '';
// Parse bool
if (typeof value === 'string' && value.toLocaleLowerCase() === 'false') {

@@ -25,2 +43,3 @@ value = false;

}
// Parse json
if (typeof value === 'string' && value.length > 2 &&

@@ -35,4 +54,8 @@ (value[0] === '{' && value[value.length - 1] === '}') ||

};
/**
* Creates a new habitat in the dom
*/
Habitat.createHabitat = function (ele, type) {
var tag;
// If tag is a block level element, then replicate it with the portal
switch (ele.tagName) {

@@ -47,6 +70,9 @@ case 'span':

var className = ele.getAttribute('data-habitat-class') || null;
// Keep references to habitats
habitat.setAttribute('data-habitat', type);
// Set habitat class name if any
if (className) {
habitat.className = "" + className;
}
// inject habitat
if (ele === window.document.body) {

@@ -58,6 +84,12 @@ document.body.appendChild(habitat);

}
// Determine if we should keep target element in the dom
if (ele.tagName !== 'input' || ele.tagName !== 'textarea') {
// Not an input so assumed we dont need to keep the targe
// element around
ele.parentNode.removeChild(ele);
}
else {
// The element is an input, leave it in the
// dom to allow passing data back to the backend again but we can
// hide it
ele.setAttribute('style', 'display:none;');

@@ -64,0 +96,0 @@ }

@@ -0,1 +1,2 @@

/// <reference path='../typings/main.d.ts'/>
"use strict";

@@ -2,0 +3,0 @@ // Modern

@@ -0,8 +1,32 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import { IContainer } from './IContainer';
import { IDOMFactory } from "./IDOMFactory";
/**
* The Bootstrapper interface
*/
export interface IBootstrapper {
factory: IDOMFactory;
setContainer: (container: IContainer) => void;
/**
* Application did start event
*/
appDidStart?: () => void;
/**
* Application will sleep event
*/
appWillSleep?: () => void;
/**
* Application did awake event
*/
appDidAwake?: () => void;
/**
* Application will terminate event
*/
appWillTerminate?: () => void;
}

@@ -0,1 +1,8 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";

@@ -0,4 +1,23 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* The container interface
*/
export interface IContainer {
/**
* Register a new component in the container
* @param {string} name - The key that identifies this component
* @param {*} comp - The component class
*/
registerComponent: (name: string, comp: any) => void;
getComponent: (name: string) => any;
/**
* Get a registered component for a key
* @param {string} name - The key name of the component that has been registered
*/
component: (name: string) => any;
}

@@ -0,1 +1,8 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";

@@ -0,4 +1,23 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* The DOM Factory
*/
export interface IDOMFactory {
/**
* An identifier string for the type of components this injects
*/
identifier: () => string;
inject?: (module: any, props: {}, target: Element) => void;
/**
* The inject method after a wire-up has been requested
* @param {*} module - The component
* @param {object} props - The components properties
* @param {Element} target - The element to inject the component into
*/
inject: (module: any, props: {}, target: Element) => void;
}

@@ -0,1 +1,8 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
{
"name": "react-habitat",
"version": "0.1.5",
"version": "0.1.6-beta",
"description": "A React DOM Bootstrapper designed to harmonise a hybrid application",

@@ -8,3 +8,6 @@ "main": "lib/index.js",

"test": "karma start --single-run --browsers PhantomJS",
"build": "tsc"
"build": "tsc",
"prepublish": "npm run build",
"prebuild": "npm run test"
},

@@ -11,0 +14,0 @@ "repository": {

![Deloitte Digital](https://raw.githubusercontent.com/DeloitteDigital/DDBreakpoints/master/docs/deloittedigital-logo-white.png)
# React Habitat
# React Habitat ![Build Status](https://travis-ci.org/DeloitteDigitalAPAC/react-habitat.svg?branch=develop)

@@ -8,3 +8,3 @@ ## React Habitat <3 Your CMS

React Habitat is designed for integrating React with your CMS. It's based of some basic
[container programming principles](https://en.wikipedia.org/wiki/Container_abstract_data_type) and brings peace and order to your DOM.
[container programming principles](https://en.wikipedia.org/wiki/Container_(abstract_data_type)) and brings peace and order to your DOM.
This framework exists so you can get on with the fun stuff!

@@ -11,0 +11,0 @@

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -22,10 +21,25 @@

export class Bootstrapper implements IBootstrapper {
/**
* The dom container
* Note for es5 support we cannot have the private accessor here
*/
_container: IContainer;
// Note for es5 support we cannot have the private accessor here
_componentSelector: string;
_container: IContainer;
/**
* The component selector namespace
*/
componentSelector: string = 'data-component';
domFactory: IDOMFactory;
/**
* The dom factory
* @type {ReactDOMFactory}
*/
factory: IDOMFactory = new ReactDOMFactory();
/**
* The raw dom elements
*/
firstClassElements: NodeListOf<Element>;

@@ -44,8 +58,2 @@

// Set the DOM factory
this.domFactory = new ReactDOMFactory();
// Set the selector name space
this._componentSelector = 'data-component';
// Find all the elements in the dom with the component selector attribute

@@ -56,10 +64,2 @@ this.firstClassElements = window.document.querySelectorAll(`[${this.componentSelector}]`);

/**
* Get's the component selector, this is used
* @returns {string}
*/
get componentSelector():string {
return this._componentSelector;
}
/**
* Set the container

@@ -81,3 +81,3 @@ * @param {IContainer} container - The container

*/
_wireUpComponents():void {
_wireUpComponents(): void {

@@ -88,4 +88,4 @@ // Iterate over component elements in the dom

var ele = this.firstClassElements[i],
componentName = ele.getAttribute(this._componentSelector),
component = this._container.getComponent(componentName);
componentName = ele.getAttribute(this.componentSelector),
component = this._container.component(componentName);

@@ -97,6 +97,6 @@ if (!component) {

this.domFactory.inject(
this.factory.inject(
component,
Habitat.parseProps(ele),
Habitat.createHabitat(ele, this.domFactory.identifier()));
Habitat.createHabitat(ele, this.factory.identifier()));
}

@@ -103,0 +103,0 @@

@@ -0,1 +1,9 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import {IBootstrapper} from '../interfaces/IBootstrapper';

@@ -42,3 +50,3 @@ import {Bootstrapper} from '../Bootstrapper';

/*
*
*
*/

@@ -45,0 +53,0 @@ export var createBootstrapper = function(spec: {[id: string] : any}) {

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -23,2 +22,3 @@

/**

@@ -30,3 +30,3 @@ * Constructor

}
/**

@@ -46,3 +46,3 @@ * Register a new component

*/
getComponent(name:string) {
component(name:string) {
return this._components[name];

@@ -49,0 +49,0 @@ }

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -10,0 +9,0 @@

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -10,0 +9,0 @@

@@ -5,8 +5,8 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import {IContainer} from './IContainer';
import {IDOMFactory} from "./IDOMFactory";

@@ -18,2 +18,3 @@ /**

factory: IDOMFactory;

@@ -20,0 +21,0 @@ setContainer:(container:IContainer) => void;

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -27,4 +26,4 @@

*/
getComponent:(name:string) => any;
component:(name:string) => any;
}

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -27,4 +26,4 @@

*/
inject?:(module: any, props: {}, target: Element) => void;
inject: (module: any, props: {}, target: Element) => void;
}

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -10,0 +9,0 @@

@@ -0,1 +1,9 @@

/**
* Copyright 2016-present, Deloitte Digital.
* All rights reserved.
*
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import {createBootstrapper} from '../../src/classic/createBootstrapper';

@@ -2,0 +10,0 @@ import {MochComponent} from '../mochs/MochComponent';

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -34,3 +33,3 @@

expect(container).toBeDefined();
expect(container.getComponent('aComponent')).toBe(MochComponent);
expect(container.component('aComponent')).toBe(MochComponent);
});

@@ -45,3 +44,3 @@

expect(container).toBeDefined();
expect(container.getComponent('aComponent')).toBe(MochComponentTwo);
expect(container.component('aComponent')).toBe(MochComponentTwo);
});

@@ -55,4 +54,4 @@

expect(container.getComponent('aComponent')).toBe(MochComponent);
expect(container.getComponent('aComponent2')).toBe(MochComponentTwo);
expect(container.component('aComponent')).toBe(MochComponent);
expect(container.component('aComponent2')).toBe(MochComponentTwo);
});

@@ -59,0 +58,0 @@

@@ -5,5 +5,4 @@ /**

*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the BSD-3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/

@@ -10,0 +9,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc