Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
synchronize reps from mc
Browse files Browse the repository at this point in the history
  • Loading branch information
juliandescottes committed Jan 19, 2017
1 parent b2a1b13 commit 55916c9
Show file tree
Hide file tree
Showing 32 changed files with 360 additions and 123 deletions.
27 changes: 21 additions & 6 deletions src/reps/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"use strict";

// Dependencies
const React = require("react");
const Caption = React.createFactory(require("./caption"));
const {
createFactories,
wrapRender,
} = require("./rep-utils");
const { Caption } = createFactories(require("./caption"));
const { MODE } = require("./constants");

// Shortcuts
Expand All @@ -16,6 +22,8 @@ let ArrayRep = React.createClass({
propTypes: {
// @TODO Change this to Object.values once it's supported in Node's version of V8
mode: React.PropTypes.oneOf(Object.keys(MODE).map(key => MODE[key])),
objectLink: React.PropTypes.func,
object: React.PropTypes.array.isRequired,
},

getTitle: function (object, context) {
Expand Down Expand Up @@ -105,7 +113,7 @@ let ArrayRep = React.createClass({
onClickBracket: function (event) {
},

render: function () {
render: wrapRender(function () {
let {
object,
mode = MODE.SHORT,
Expand Down Expand Up @@ -147,7 +155,7 @@ let ArrayRep = React.createClass({
)
)
);
},
}),
});

/**
Expand All @@ -156,8 +164,14 @@ let ArrayRep = React.createClass({
let ItemRep = React.createFactory(React.createClass({
displayName: "ItemRep",

render: function () {
const Rep = React.createFactory(require("./rep"));
propTypes: {
object: React.PropTypes.any.isRequired,
delim: React.PropTypes.string.isRequired,
mode: React.PropTypes.symbol,
},

render: wrapRender(function () {
const { Rep } = createFactories(require("./rep"));

let object = this.props.object;
let delim = this.props.delim;
Expand All @@ -168,14 +182,15 @@ let ItemRep = React.createFactory(React.createClass({
delim
)
);
}
})
}));

function supportsObject(object, type) {
return Array.isArray(object) ||
Object.prototype.toString.call(object) === "[object Arguments]";
}

// Exports from this module
module.exports = {
rep: ArrayRep,
supportsObject: supportsObject
Expand Down
21 changes: 14 additions & 7 deletions src/reps/attribute.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// ReactJS
const React = require("react");

// Reps
const { isGrip } = require("./rep-utils");
const StringRep = React.createFactory(require("./string").rep);
const {
createFactories,
isGrip,
wrapRender,
} = require("./rep-utils");
const { StringRep } = require("./string");

// Shortcuts
const { span } = React.DOM;
const { rep: StringRepFactory } = createFactories(StringRep);

/**
* Renders DOM attribute
Expand All @@ -14,14 +20,15 @@ let Attribute = React.createClass({
displayName: "Attr",

propTypes: {
object: React.PropTypes.object.isRequired
object: React.PropTypes.object.isRequired,
objectLink: React.PropTypes.func,
},

getTitle: function (grip) {
return grip.preview.nodeName;
},

render: function () {
render: wrapRender(function () {
let object = this.props.object;
let value = object.preview.value;
let objectLink = this.props.objectLink || span;
Expand All @@ -35,11 +42,11 @@ let Attribute = React.createClass({
span({className: "attrEqual"},
"="
),
StringRep({object: value})
StringRepFactory({object: value})
)
)
);
},
}),
});

// Registration
Expand All @@ -55,4 +62,4 @@ function supportsObject(grip, type) {
module.exports = {
rep: Attribute,
supportsObject: supportsObject
};
};
12 changes: 10 additions & 2 deletions src/reps/caption.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// Dependencies
const React = require("react");
const DOM = React.DOM;

const { wrapRender } = require("./rep-utils");

/**
* Renders a caption. This template is used by other components
* that needs to distinguish between a simple text/value and a label.
*/
const Caption = React.createClass({
displayName: "Caption",

render: function () {
propTypes: {
object: React.PropTypes.object,
},

render: wrapRender(function () {
return (
DOM.span({"className": "caption"}, this.props.object)
);
},
}),
});

// Exports from this module
module.exports = Caption;
13 changes: 10 additions & 3 deletions src/reps/comment-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Dependencies
const React = require("react");
const { isGrip, cropString, cropMultipleLines } = require("./rep-utils");
const {
isGrip,
cropString,
cropMultipleLines,
wrapRender,
} = require("./rep-utils");
const { MODE } = require("./constants");
const nodeConstants = require("../shared/dom-node-constants");

Expand All @@ -18,7 +24,7 @@ const CommentNode = React.createClass({
mode: React.PropTypes.oneOf(Object.keys(MODE).map(key => MODE[key])),
},

render: function () {
render: wrapRender(function () {
let {
object,
mode = MODE.SHORT
Expand All @@ -32,7 +38,7 @@ const CommentNode = React.createClass({
}

return span({className: "objectBox theme-comment"}, `<!-- ${textContent} -->`);
},
}),
});

// Registration
Expand All @@ -43,6 +49,7 @@ function supportsObject(object, type) {
return object.preview && object.preview.nodeType === nodeConstants.COMMENT_NODE;
}

// Exports from this module
module.exports = {
rep: CommentNode,
supportsObject: supportsObject
Expand Down
15 changes: 11 additions & 4 deletions src/reps/date-time.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// ReactJS
const React = require("react");

// Reps
const { isGrip } = require("./rep-utils");
const {
isGrip,
wrapRender,
} = require("./rep-utils");

// Shortcuts
const { span } = React.DOM;
Expand All @@ -13,7 +17,8 @@ let DateTime = React.createClass({
displayName: "Date",

propTypes: {
object: React.PropTypes.object.isRequired
object: React.PropTypes.object.isRequired,
objectLink: React.PropTypes.func,
},

getTitle: function (grip) {
Expand All @@ -25,7 +30,7 @@ let DateTime = React.createClass({
return "";
},

render: function () {
render: wrapRender(function () {
let grip = this.props.object;
let date;
try {
Expand All @@ -38,8 +43,9 @@ let DateTime = React.createClass({
} catch (e) {
date = span({className: "objectBox"}, "Invalid Date");
}

return date;
},
}),
});

// Registration
Expand All @@ -52,6 +58,7 @@ function supportsObject(grip, type) {
return (type == "Date" && grip.preview);
}

// Exports from this module
module.exports = {
rep: DateTime,
supportsObject: supportsObject
Expand Down
15 changes: 11 additions & 4 deletions src/reps/document.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// ReactJS
const React = require("react");

// Reps
const { isGrip, getURLDisplayString } = require("./rep-utils");
const {
isGrip,
getURLDisplayString,
wrapRender,
} = require("./rep-utils");

// Shortcuts
const { span } = React.DOM;
Expand All @@ -13,7 +18,8 @@ let Document = React.createClass({
displayName: "Document",

propTypes: {
object: React.PropTypes.object.isRequired
object: React.PropTypes.object.isRequired,
objectLink: React.PropTypes.func,
},

getLocation: function (grip) {
Expand All @@ -36,7 +42,7 @@ let Document = React.createClass({
return doc.location.href;
},

render: function () {
render: wrapRender(function () {
let grip = this.props.object;

return (
Expand All @@ -47,7 +53,7 @@ let Document = React.createClass({
)
)
);
},
}),
});

// Registration
Expand All @@ -60,6 +66,7 @@ function supportsObject(object, type) {
return (object.preview && type == "HTMLDocument");
}

// Exports from this module
module.exports = {
rep: Document,
supportsObject: supportsObject
Expand Down
14 changes: 11 additions & 3 deletions src/reps/element-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// ReactJS
const React = require("react");

// Utils
const { isGrip } = require("./rep-utils");
const {
isGrip,
wrapRender,
} = require("./rep-utils");
const { MODE } = require("./constants");
const nodeConstants = require("../shared/dom-node-constants");

Expand All @@ -18,6 +22,9 @@ const ElementNode = React.createClass({
object: React.PropTypes.object.isRequired,
// @TODO Change this to Object.values once it's supported in Node's version of V8
mode: React.PropTypes.oneOf(Object.keys(MODE).map(key => MODE[key])),
onDOMNodeMouseOver: React.PropTypes.func,
onDOMNodeMouseOut: React.PropTypes.func,
objectLink: React.PropTypes.func,
},

getElements: function (grip, mode) {
Expand Down Expand Up @@ -78,7 +85,7 @@ const ElementNode = React.createClass({
];
},

render: function () {
render: wrapRender(function () {
let {
object,
mode,
Expand All @@ -104,7 +111,7 @@ const ElementNode = React.createClass({
return objectLink({object},
span(baseConfig, ...elements)
);
},
}),
});

// Registration
Expand All @@ -115,6 +122,7 @@ function supportsObject(object, type) {
return object.preview && object.preview.nodeType === nodeConstants.ELEMENT_NODE;
}

// Exports from this module
module.exports = {
rep: ElementNode,
supportsObject: supportsObject
Expand Down
12 changes: 9 additions & 3 deletions src/reps/error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// ReactJS
const React = require("react");
// Utils
const { isGrip } = require("./rep-utils");
const {
isGrip,
wrapRender,
} = require("./rep-utils");
const { MODE } = require("./constants");
// Shortcuts
const { span } = React.DOM;
Expand All @@ -15,9 +19,10 @@ const ErrorRep = React.createClass({
object: React.PropTypes.object.isRequired,
// @TODO Change this to Object.values once it's supported in Node's version of V8
mode: React.PropTypes.oneOf(Object.keys(MODE).map(key => MODE[key])),
objectLink: React.PropTypes.func,
},

render: function () {
render: wrapRender(function () {
let object = this.props.object;
let preview = object.preview;
let name = preview && preview.name
Expand All @@ -43,7 +48,7 @@ const ErrorRep = React.createClass({
span({}, content)
)
);
},
}),
});

// Registration
Expand All @@ -54,6 +59,7 @@ function supportsObject(object, type) {
return (object.preview && type === "Error");
}

// Exports from this module
module.exports = {
rep: ErrorRep,
supportsObject: supportsObject
Expand Down
Loading

0 comments on commit 55916c9

Please sign in to comment.