motion
Version:
motion - moving development forward
68 lines (57 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.POSITION_TYPE = undefined;
exports.collectViews = collectViews;
exports.pointWithinRange = pointWithinRange;
exports.getObjectAtPosition = getObjectAtPosition;
exports.getRowFromText = getRowFromText;
var _babel = require('../gulp/babel');
var _scanner = require('../gulp/scanner');
var _cache = require('../cache');
var _cache2 = _interopRequireDefault(_cache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const NEWLINE_REGEX = /\r\n|\n|\r/g;
const POSITION_TYPE = exports.POSITION_TYPE = {
VIEW_TOP: 'VIEW_TOP',
VIEW_JSX: 'VIEW_JSX',
STYLE: 'STYLE'
};
function collectViews(contents) {
const filePath = '__editor__';
try {
let views = {};
_scanner.Scanner.pre(filePath, contents, function (contents) {
(0, _babel.motionFile)({
contents,
path: filePath,
relative: filePath,
sourceMap: false
});
});
return _cache2.default.getFileMeta(filePath) || {};
} catch (_) {
if (typeof _.pos !== 'undefined') {
// Syntax error
return {};
} else throw _;
}
}
function pointWithinRange(point, range) {
return point.isGreaterThan(range[0]) && point.isLessThan(range[1]);
}
function getObjectAtPosition(objects, position) {
for (const key in objects) {
const value = objects[key];
if (pointWithinRange(position, value.location)) {
return value;
}
}
return null;
}
function getRowFromText(text, row) {
const rowText = text.split(NEWLINE_REGEX)[row];
return rowText || '';
}
//# sourceMappingURL=helpers.js.map