UNPKG

alm

Version:

The best IDE for TypeScript

67 lines (66 loc) 2.51 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var ui = require("../../ui"); var monacoUtils = require("../monacoUtils"); var CommonEditorRegistry = monaco.CommonEditorRegistry; var EditorAction = monaco.EditorAction; var EditorContextKeys = monaco.EditorContextKeys; /* Test: const styles = { box-sizing: border-box; outline: none; padding: 0; margin: 0; } */ var CssToTsAction = /** @class */ (function (_super) { __extends(CssToTsAction, _super); function CssToTsAction() { return _super.call(this, { id: 'editor.action.cssToTs', label: 'CSS to TS', alias: 'CSS to TS', precondition: EditorContextKeys.Writable, }) || this; } CssToTsAction.prototype.run = function (accessor, editor) { var filePath = editor.filePath; var selection = editor.getSelection(); if (!selection.isEmpty()) { var oldText = editor.getModel().getValueInRange(selection); var _a = convert(oldText), asLines = _a.asLines, asString = _a.asString; // put in the new thing monacoUtils.replaceSelection({ editor: editor, newText: asString }); // format the new thing monacoUtils.format({ editor: editor }); } else { ui.notifyWarningNormalDisappear('Please select the CSS you want converted to TS and try again 🌹'); } }; return CssToTsAction; }(EditorAction)); CommonEditorRegistry.registerEditorAction(new CssToTsAction()); /** * Take a look at : * https://github.com/reactjs/react-magic * https://www.npmjs.com/package/htmltojsx */ var htmlToJsx_1 = require("../../htmlToJsx/htmlToJsx"); function convert(content) { var style = new htmlToJsx_1.StyleParser(content); var asLines = style.toJSXString().split(',').map(function (x) { return x.trim(); }); var asString = asLines.join(',\n'); return { asLines: asLines, asString: asString }; } exports.convert = convert;