@teleporthq/teleport-plugin-css
Advanced tools
Comparing version 0.10.2 to 0.10.4
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -37,3 +38,2 @@ }); | ||
}; | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -45,3 +45,3 @@ var teleport_shared_1 = require("@teleporthq/teleport-shared"); | ||
var _a = config || {}, _b = _a.chunkName, chunkName = _b === void 0 ? 'style-chunk' : _b, _c = _a.templateChunkName, templateChunkName = _c === void 0 ? 'template-chunk' : _c, _d = _a.componentDecoratorChunkName, componentDecoratorChunkName = _d === void 0 ? 'component-decorator' : _d, _e = _a.inlineStyleAttributeKey, inlineStyleAttributeKey = _e === void 0 ? 'style' : _e, _f = _a.classAttributeName, classAttributeName = _f === void 0 ? 'class' : _f, _g = _a.templateStyle, templateStyle = _g === void 0 ? 'html' : _g, _h = _a.declareDependency, declareDependency = _h === void 0 ? 'none' : _h, _j = _a.forceScoping, forceScoping = _j === void 0 ? false : _j; | ||
var cssPlugin = function (structure) { return __awaiter(_this, void 0, void 0, function () { | ||
var cssPlugin = function (structure) { return __awaiter(void 0, void 0, void 0, function () { | ||
var uidl, chunks, dependencies, node, templateChunk, componentDecoratorChunk, templateLookup, propsPrefix, jssStylesArray, cssFileName, decoratorAST, decoratorParam; | ||
@@ -71,3 +71,5 @@ return __generator(this, function (_a) { | ||
: elementClassName; | ||
jssStylesArray.push(teleport_plugin_common_1.StyleBuilders.createCSSClass(className, teleport_plugin_common_1.StyleUtils.getContentOfStyleObject(staticStyles))); | ||
jssStylesArray.push( | ||
// @ts-ignore | ||
teleport_plugin_common_1.StyleBuilders.createCSSClass(className, teleport_plugin_common_1.StyleUtils.getContentOfStyleObject(staticStyles))); | ||
if (templateStyle === 'html') { | ||
@@ -74,0 +76,0 @@ teleport_plugin_common_1.HASTUtils.addClassToNode(root, className); |
@@ -13,2 +13,3 @@ import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared'; | ||
// Only JSX based chunks have dynamicRefPrefix (eg: this.props. or props.) | ||
// @ts-ignore | ||
const propsPrefix = templateChunk.meta.dynamicRefPrefix | ||
@@ -31,3 +32,5 @@ ? templateChunk.meta.dynamicRefPrefix.prop | ||
: elementClassName; | ||
jssStylesArray.push(StyleBuilders.createCSSClass(className, StyleUtils.getContentOfStyleObject(staticStyles))); | ||
jssStylesArray.push( | ||
// @ts-ignore | ||
StyleBuilders.createCSSClass(className, StyleUtils.getContentOfStyleObject(staticStyles))); | ||
if (templateStyle === 'html') { | ||
@@ -73,2 +76,3 @@ HASTUtils.addClassToNode(root, className); | ||
const decoratorAST = componentDecoratorChunk.content; | ||
// @ts-ignore | ||
const decoratorParam = decoratorAST.expression.arguments[0]; | ||
@@ -75,0 +79,0 @@ ASTUtils.addPropertyToASTObject(decoratorParam, 'styleUrls', [ |
{ | ||
"name": "@teleporthq/teleport-plugin-css", | ||
"version": "0.10.2", | ||
"version": "0.10.4", | ||
"description": "A plugin for creating the styles into external css files", | ||
@@ -29,7 +29,8 @@ "author": "teleportHQ", | ||
"dependencies": { | ||
"@teleporthq/teleport-plugin-common": "^0.10.2", | ||
"@teleporthq/teleport-shared": "^0.10.1", | ||
"@teleporthq/teleport-types": "^0.10.1" | ||
"@babel/types": "^7.5.5", | ||
"@teleporthq/teleport-plugin-common": "^0.10.4", | ||
"@teleporthq/teleport-shared": "^0.10.4", | ||
"@teleporthq/teleport-types": "^0.10.4" | ||
}, | ||
"gitHead": "91d75226d1fada0ef0ab2b61a7974475ba214fb1" | ||
"gitHead": "b5f838aac54b6af2c6bed73e4044ead5b747ecf4" | ||
} |
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { StyleUtils, StyleBuilders, HASTUtils, ASTUtils } from '@teleporthq/teleport-plugin-common' | ||
import * as types from '@babel/types' | ||
import { | ||
@@ -11,2 +11,3 @@ ComponentPluginFactory, | ||
FileType, | ||
HastNode, | ||
} from '@teleporthq/teleport-types' | ||
@@ -47,7 +48,11 @@ | ||
const templateLookup = templateChunk.meta.nodesLookup | ||
const templateLookup = templateChunk.meta.nodesLookup as Record< | ||
string, | ||
HastNode | types.JSXElement | ||
> | ||
// Only JSX based chunks have dynamicRefPrefix (eg: this.props. or props.) | ||
// @ts-ignore | ||
const propsPrefix: string = templateChunk.meta.dynamicRefPrefix | ||
? templateChunk.meta.dynamicRefPrefix.prop | ||
? (templateChunk.meta.dynamicRefPrefix as Record<string, unknown>).prop | ||
: '' | ||
@@ -75,2 +80,3 @@ | ||
jssStylesArray.push( | ||
// @ts-ignore | ||
StyleBuilders.createCSSClass(className, StyleUtils.getContentOfStyleObject(staticStyles)) | ||
@@ -80,5 +86,5 @@ ) | ||
if (templateStyle === 'html') { | ||
HASTUtils.addClassToNode(root, className) | ||
HASTUtils.addClassToNode(root as HastNode, className) | ||
} else { | ||
ASTUtils.addClassStringOnJSXTag(root, className, classAttributeName) | ||
ASTUtils.addClassStringOnJSXTag(root as types.JSXElement, className, classAttributeName) | ||
} | ||
@@ -95,3 +101,7 @@ } | ||
const inlineStyles = createDynamicInlineStyle(rootStyles) | ||
HASTUtils.addAttributeToNode(root, inlineStyleAttributeKey, `{${inlineStyles}}`) | ||
HASTUtils.addAttributeToNode( | ||
root as HastNode, | ||
inlineStyleAttributeKey, | ||
`{${inlineStyles}}` | ||
) | ||
} else { | ||
@@ -102,3 +112,7 @@ // jsx object expression | ||
) | ||
ASTUtils.addAttributeToJSXTag(root, inlineStyleAttributeKey, inlineStyles) | ||
ASTUtils.addAttributeToJSXTag( | ||
root as types.JSXElement, | ||
inlineStyleAttributeKey, | ||
inlineStyles | ||
) | ||
} | ||
@@ -127,2 +141,3 @@ } | ||
const decoratorAST = componentDecoratorChunk.content | ||
// @ts-ignore | ||
const decoratorParam = decoratorAST.expression.arguments[0] | ||
@@ -129,0 +144,0 @@ ASTUtils.addPropertyToASTObject(decoratorParam, 'styleUrls', [ |
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
562
272818
4