@teleporthq/teleport-plugin-react-base-component
Advanced tools
Comparing version 0.31.0-alpha.0 to 0.31.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -40,3 +17,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -68,3 +45,2 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
var teleport_types_1 = require("@teleporthq/teleport-types"); | ||
var types = __importStar(require("@babel/types")); | ||
var constants_1 = require("./constants"); | ||
@@ -74,10 +50,9 @@ var createReactComponentPlugin = function (config) { | ||
var reactComponentPlugin = function (structure) { return __awaiter(void 0, void 0, void 0, function () { | ||
var uidl, dependencies, options, projectResources, _a, stateDefinitions, _b, propDefinitions, nodesLookup, windowImports, jsxParams, jsxOptions, jsxTagStructure, componentName, pureComponent, routerAST, componentBody; | ||
var uidl, dependencies, _a, stateDefinitions, _b, propDefinitions, nodesLookup, windowImports, jsxParams, jsxOptions, jsxTagStructure, componentName, pureComponent; | ||
return __generator(this, function (_c) { | ||
uidl = structure.uidl, dependencies = structure.dependencies, options = structure.options; | ||
projectResources = options.projectResources; | ||
uidl = structure.uidl, dependencies = structure.dependencies; | ||
_a = uidl.stateDefinitions, stateDefinitions = _a === void 0 ? {} : _a, _b = uidl.propDefinitions, propDefinitions = _b === void 0 ? {} : _b; | ||
dependencies.React = constants_1.REACT_LIBRARY_DEPENDENCY; | ||
if (Object.keys(stateDefinitions).length > 0) { | ||
dependencies.useState = teleport_shared_1.Constants.USE_STATE_DEPENDENCY; | ||
dependencies.useState = constants_1.USE_STATE_DEPENDENCY; | ||
} | ||
@@ -91,3 +66,2 @@ nodesLookup = {}; | ||
dependencies: dependencies, | ||
projectResources: projectResources, | ||
windowImports: windowImports, | ||
@@ -109,12 +83,4 @@ }; | ||
pureComponent = teleport_plugin_common_1.ASTUtils.createPureComponent(componentName, stateDefinitions, jsxTagStructure, windowImports); | ||
if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.useRouter) { | ||
routerAST = types.variableDeclaration('const', [ | ||
types.variableDeclarator(types.identifier('router'), types.callExpression(types.identifier('useRouter'), [])), | ||
]); | ||
componentBody = pureComponent.declarations[0] | ||
.init.body; | ||
componentBody.body.unshift(routerAST); | ||
} | ||
if (Object.keys(windowImports).length) { | ||
dependencies.useEffect = teleport_shared_1.Constants.USE_STATE_DEPENDENCY; | ||
dependencies.useEffect = constants_1.USE_STATE_DEPENDENCY; | ||
} | ||
@@ -121,0 +87,0 @@ structure.chunks.push({ |
@@ -16,3 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -39,18 +39,16 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
import { createDOMInjectionNode } from './utils'; | ||
import { Constants, UIDLUtils } from '@teleporthq/teleport-shared'; | ||
import { UIDLUtils } from '@teleporthq/teleport-shared'; | ||
import { createJSXSyntax, ASTBuilders, ASTUtils, } from '@teleporthq/teleport-plugin-common'; | ||
import { ChunkType, FileType, } from '@teleporthq/teleport-types'; | ||
import * as types from '@babel/types'; | ||
import { DEFAULT_COMPONENT_CHUNK_NAME, DEFAULT_EXPORT_CHUNK_NAME, DEFAULT_IMPORT_CHUNK_NAME, REACT_LIBRARY_DEPENDENCY, } from './constants'; | ||
import { DEFAULT_COMPONENT_CHUNK_NAME, DEFAULT_EXPORT_CHUNK_NAME, DEFAULT_IMPORT_CHUNK_NAME, REACT_LIBRARY_DEPENDENCY, USE_STATE_DEPENDENCY, } from './constants'; | ||
export var createReactComponentPlugin = function (config) { | ||
var _a = config || {}, _b = _a.componentChunkName, componentChunkName = _b === void 0 ? DEFAULT_COMPONENT_CHUNK_NAME : _b, _c = _a.exportChunkName, exportChunkName = _c === void 0 ? DEFAULT_EXPORT_CHUNK_NAME : _c, _d = _a.importChunkName, importChunkName = _d === void 0 ? DEFAULT_IMPORT_CHUNK_NAME : _d; | ||
var reactComponentPlugin = function (structure) { return __awaiter(void 0, void 0, void 0, function () { | ||
var uidl, dependencies, options, projectResources, _a, stateDefinitions, _b, propDefinitions, nodesLookup, windowImports, jsxParams, jsxOptions, jsxTagStructure, componentName, pureComponent, routerAST, componentBody; | ||
var uidl, dependencies, _a, stateDefinitions, _b, propDefinitions, nodesLookup, windowImports, jsxParams, jsxOptions, jsxTagStructure, componentName, pureComponent; | ||
return __generator(this, function (_c) { | ||
uidl = structure.uidl, dependencies = structure.dependencies, options = structure.options; | ||
projectResources = options.projectResources; | ||
uidl = structure.uidl, dependencies = structure.dependencies; | ||
_a = uidl.stateDefinitions, stateDefinitions = _a === void 0 ? {} : _a, _b = uidl.propDefinitions, propDefinitions = _b === void 0 ? {} : _b; | ||
dependencies.React = REACT_LIBRARY_DEPENDENCY; | ||
if (Object.keys(stateDefinitions).length > 0) { | ||
dependencies.useState = Constants.USE_STATE_DEPENDENCY; | ||
dependencies.useState = USE_STATE_DEPENDENCY; | ||
} | ||
@@ -64,3 +62,2 @@ nodesLookup = {}; | ||
dependencies: dependencies, | ||
projectResources: projectResources, | ||
windowImports: windowImports, | ||
@@ -82,12 +79,4 @@ }; | ||
pureComponent = ASTUtils.createPureComponent(componentName, stateDefinitions, jsxTagStructure, windowImports); | ||
if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.useRouter) { | ||
routerAST = types.variableDeclaration('const', [ | ||
types.variableDeclarator(types.identifier('router'), types.callExpression(types.identifier('useRouter'), [])), | ||
]); | ||
componentBody = pureComponent.declarations[0] | ||
.init.body; | ||
componentBody.body.unshift(routerAST); | ||
} | ||
if (Object.keys(windowImports).length) { | ||
dependencies.useEffect = Constants.USE_STATE_DEPENDENCY; | ||
dependencies.useEffect = USE_STATE_DEPENDENCY; | ||
} | ||
@@ -94,0 +83,0 @@ structure.chunks.push({ |
{ | ||
"name": "@teleporthq/teleport-plugin-react-base-component", | ||
"version": "0.31.0-alpha.0", | ||
"version": "0.31.0", | ||
"description": "A plugin for handling the skeleton/baseline of a React component", | ||
@@ -28,7 +28,7 @@ "author": "teleportHQ", | ||
"@babel/types": "^7.5.5", | ||
"@teleporthq/teleport-plugin-common": "^0.31.0-alpha.0", | ||
"@teleporthq/teleport-shared": "^0.31.0-alpha.0", | ||
"@teleporthq/teleport-types": "^0.31.0-alpha.0" | ||
"@teleporthq/teleport-plugin-common": "^0.31.0", | ||
"@teleporthq/teleport-shared": "^0.31.0", | ||
"@teleporthq/teleport-types": "^0.31.0" | ||
}, | ||
"gitHead": "a5289f88f2d0cf8aae4b93bf05777c5492dd86b2" | ||
"gitHead": "37c3970566832845c57f0ef11088a9214af720b2" | ||
} |
import { createDOMInjectionNode } from './utils' | ||
import { Constants, UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { | ||
@@ -23,2 +23,3 @@ createJSXSyntax, | ||
REACT_LIBRARY_DEPENDENCY, | ||
USE_STATE_DEPENDENCY, | ||
} from './constants' | ||
@@ -40,4 +41,3 @@ | ||
const reactComponentPlugin: ComponentPlugin = async (structure) => { | ||
const { uidl, dependencies, options } = structure | ||
const { projectResources } = options | ||
const { uidl, dependencies } = structure | ||
const { stateDefinitions = {}, propDefinitions = {} } = uidl | ||
@@ -48,3 +48,3 @@ | ||
if (Object.keys(stateDefinitions).length > 0) { | ||
dependencies.useState = Constants.USE_STATE_DEPENDENCY | ||
dependencies.useState = USE_STATE_DEPENDENCY | ||
} | ||
@@ -62,3 +62,2 @@ | ||
dependencies, | ||
projectResources, | ||
windowImports, | ||
@@ -89,18 +88,4 @@ } | ||
if (dependencies?.useRouter) { | ||
const routerAST = types.variableDeclaration('const', [ | ||
types.variableDeclarator( | ||
types.identifier('router'), | ||
types.callExpression(types.identifier('useRouter'), []) | ||
), | ||
]) | ||
const componentBody = ( | ||
(pureComponent.declarations[0] as types.VariableDeclarator) | ||
.init as types.ArrowFunctionExpression | ||
).body as types.BlockStatement | ||
componentBody.body.unshift(routerAST) | ||
} | ||
if (Object.keys(windowImports).length) { | ||
dependencies.useEffect = Constants.USE_STATE_DEPENDENCY | ||
dependencies.useEffect = USE_STATE_DEPENDENCY | ||
} | ||
@@ -107,0 +92,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
81228
541