• Stars
    star
    186
  • Rank 207,383 (Top 5 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔖Visual Studio Code Syntax Highlighting For Single File React And Omi Components - 编写React和Omi单文件组件的VSC语法高亮插件

Snippets

Download Macketplace Github Page Eno Yao Status

Basic Methods

Prefix Method
imp→ import moduleName from 'module'
imn→ import 'module'
imd→ import { destructuredModule } from 'module'
ime→ import * as alias from 'module'
ima→ import { originalName as aliasName} from 'module'
exp→ export default moduleName
exd→ export { destructuredModule } from 'module'
exa→ export { originalName as aliasName} from 'module'
enf→ export const functionName = (params) => { }
edf→ export default (params) => { }
met→ methodName = (params) => { }
fre→ arrayName.forEach(element => { }
fof→ for(let itemName of objectName { }
fin→ for(let itemName in objectName { }
anfn→ (params) => { }
nfn→ const functionName = (params) => { }
dob→ const {propName} = objectToDescruct
dar→ const [propName] = arrayToDescruct
sti→ setInterval(() => { }, intervalTime
sto→ setTimeout(() => { }, delayTime
prom→ return new Promise((resolve, reject) => { }
cmmb→ comment block
cp→ const { } = this.props
cs→ const { } = this.state

React

Prefix Method
imr→ import React from 'react'
imrd→ import ReactDOM from 'react-dom'
imrc→ import React, { Component } from 'react'
imrcp→ import React, { Component } from 'react' & import PropTypes from 'prop-types'
imrpc→ import React, { PureComponent } from 'react'
imrpcp→ import React, { PureComponent } from 'react' & import PropTypes from 'prop-types'
imrm→ import React, { memo } from 'react'
imrmp→ import React, { memo } from 'react' & import PropTypes from 'prop-types'
impt→ import PropTypes from 'prop-types'
imrr→ import { BrowserRouter as Router, Route, NavLink} from 'react-router-dom'
imbr→ import { BrowserRouter as Router} from 'react-router-dom'
imbrc→ import { Route, Switch, NavLink, Link } from react-router-dom'
imbrr→ import { Route } from 'react-router-dom'
imbrs→ import { Switch } from 'react-router-dom'
imbrl→ import { Link } from 'react-router-dom'
imbrnl→ import { NavLink } from 'react-router-dom'
imrs→ import React, { useState } from 'react'
imrse→ import React, { useState, useEffect } from 'react'
redux→ import { connect } from 'react-redux'
rconst→ constructor(props) with this.state
rconc→ constructor(props, context) with this.state
est→ this.state = { }
cwm→ componentWillMount = () => { } DEPRECATED!!!
cdm→ componentDidMount = () => { }
cwr→ componentWillReceiveProps = (nextProps) => { } DEPRECATED!!!
scu→ shouldComponentUpdate = (nextProps, nextState) => { }
cwup→ componentWillUpdate = (nextProps, nextState) => { } DEPRECATED!!!
cdup→ componentDidUpdate = (prevProps, prevState) => { }
cwun→ componentWillUnmount = () => { }
gdsfp→ static getDerivedStateFromProps(nextProps, prevState) { }
gsbu→ getSnapshotBeforeUpdate = (prevProps, prevState) => { }
ren→ render() { return( ) }
sst→ this.setState({ })
ssf→ this.setState((state, props) => return { })
props→ this.props.propName
state→ this.state.stateName
rcontext→ const ${1:contextName} = React.createContext()
cref→ this.${1:refName}Ref = React.createRef()
fref→ const ref = React.createRef()
bnd→ this.methodName = this.methodName.bind(this)

React Hooks

React Native

Prefix Method
imrn→ import { $1 } from 'react-native'
rnstyle→ const styles = StyleSheet.create({})

Redux

Prefix Method
rxaction→ redux action template
rxconst→ export const $1 = '$1'
rxreducer→ redux reducer template
rxselect→ redux selector template

PropTypes

Prefix Method
pta→ PropTypes.array
ptar→ PropTypes.array.isRequired
ptb→ PropTypes.bool
ptbr→ PropTypes.bool.isRequired
ptf→ PropTypes.func
ptfr→ PropTypes.func.isRequired
ptn→ PropTypes.number
ptnr→ PropTypes.number.isRequired
pto→ PropTypes.object
ptor→ PropTypes.object.isRequired
pts→ PropTypes.string
ptsr→ PropTypes.string.isRequired
ptnd→ PropTypes.node
ptndr→ PropTypes.node.isRequired
ptel→ PropTypes.element
ptelr→ PropTypes.element.isRequired
pti→ PropTypes.instanceOf(name)
ptir→ PropTypes.instanceOf(name).isRequired
pte→ PropTypes.oneOf([name])
pter→ PropTypes.oneOf([name]).isRequired
ptet→ PropTypes.oneOfType([name])
ptetr→ PropTypes.oneOfType([name]).isRequired
ptao→ PropTypes.arrayOf(name)
ptaor→ PropTypes.arrayOf(name).isRequired
ptoo→ PropTypes.objectOf(name)
ptoor→ PropTypes.objectOf(name).isRequired
ptsh→ PropTypes.shape({ })
ptshr→ PropTypes.shape({ }).isRequired
ptany→ PropTypes.any
ptypes→ static propTypes = {}

GraphQL

Prefix Method
graphql→ import { compose, graphql } from react-apollo'
expgql-> export default compose(graphql($1, { name: $2 }))($3)

Console

Prefix Method
clg→ console.log(object)
clo→ console.log("object", object)
ctm→ console.time("timeId")
cte→ console.timeEnd("timeId")
cas→ console.assert(expression,object)
ccl→ console.clear()
cco→ console.count(label)
cdi→ console.dir
cer→ console.error(object)
cgr→ console.group(label)
cge→ console.groupEnd()
ctr→ console.trace(object)
cwa→ console.warn
cin→ console.info

Omi

Omi Snippets

Try it Now! Visual Studio Code syntax highlighting for single-file Omi.js components (enabled by omil). Or Download Vsix! to install in Visual Studio Code

下载地址 & Download: https://marketplace.visualstudio.com/items?itemName=Wscats.eno

项目地址 & Source Code : https://github.com/Wscats/omi-snippets

Detailed Documentation

详细文档 & Document: https://github.com/Wscats/omi-docs

Quick Start

  • Install Omi Snippets.
  • Try it with omil✌️😜, a Omi.js components loader based on webpack.
  • Via Marketplace Control: search for Omi Snippets and click install.
  • Manual: clone this repo and install omi-snippets.vsix into your Visual Studio Code.

In addition, if you want to build and install the extension from source, you need to install vsce, like this.

# Then, clone the repository and compile it.
git clone https://github.com/Wscats/omi-snippets
cd omi-snippets
yarn
vsce package

wscats

This will setup a basic webpack + omil project for you, with *.omi or *.eno files and hot-reloading working out of the box!

For example, you can create test.omi in Visual Studio Code before install Omi Snippets

<!-- test.omi -->
<template name="component-name">
    <div>{this.data.name}</div>
</template>
<script>
import style from './style.css';
export default class {
    static css = style
    install(){
        this.data = {
            name: 'Eno Yao',
        }
    }
}
</script>
<style lang="scss">
    div{ color:red; }
</style>

After you save the code in editor(Ctrl+S), it will be converted into test.js

// test.js
import { WeElement, define, h } from "omi";
import style from "./style.css";
const componentName = class extends WeElement {
  render() { return h("div", null, this.data.name); }
  static css =
    `div{color:red;}` + style;
  install() {
    this.data = { name: "Eno Yao" };
  }
};
define("component-name", componentName);

Usage In Omi

A *.omi file is a custom file format that uses HTML-like syntax to describe a Omi component. Each *.omi file consists of three types of top-level language blocks: <template>, <script>, and <style>, and optionally additional custom blocks:

<template lang="html" name="component-name">
  <!-- replace render function -->
  <header onClick="${this.test}">${this.data.title}</header>
</template>
<script>
import style from './_oHeader.css'
export default class {
  static css = style + `p{color:red}` // it will combine scoped css,only support static css = xxx
  test(){ console.log('Hello Eno!') }
  install() {
    this.data = { title: 'Omi' }
  }
}
</script>
<style>
/* scoped css */
header {
  height: 50px;
  background-color: #07c160;
  color: white;
  text-align: center;
  line-height: 50px;
  width: 100%;
}
</style>

Single-File Components Demo

It also supports JSX, if you want to do that, you only write <template> without lang="html" attribute in your component like this:

<template>
  <header onClick={this.test}>{this.data.title}</header>
</template>

JSX Demo

omil supports using non-default languages, such as CSS pre-processors and compile-to-HTML template languages, by specifying the lang attribute for a language block. For example, you install node-sass after you can use Sass for the style of your component like this:

<style lang="scss">
$height: 50px;
$color: #07c160;
header {
  height: $height;
  background-color: $color;
}
</style>

Sass Demo

Support React

npm install styled-components --save

You can also use an ES6 class to define a class component by omil.

<template name="ComponentName">
    <p>{this.state.title}</p>
</template>
<script>
    export default class {
        constructor(props) {
            super(props)
            this.state.title = "Eno Yao"
        }
    }
</script>
<style lang="scss">
    p {color: #58bc58;}
</style>

React Demo

A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API. Here's a concrete example.

<template name="ComponentName">
    <div><p>{this.state.title}</p></div>
</template>
<script>
    const HOC = (props) => {
        return (WraooedComponent) => {
            return class HOC extends WeElement {
                state = {
                    name: 'Eno Yao',
                    ...props
                }
                render() {
                    return (
                        <div>Hello World<WraooedComponent name={{ ...this.state }} /></div>
                    )
                }
            }
        }
    }
    export default HOC({
        age: 18
    })(class {
        constructor(props) {
            super(props)
            this.state = { title: 'Lemon' }
        }
        componentDidMount() { console.log(this) }
        handleChange() {}
    })
</script>
<style lang="scss">
    p { color: #58bc58; }
</style>

Cooperate With TypeScript

A static type system can help prevent many potential runtime errors, especially as applications grow. You can use Single File Components(SFC) cooperate with Higher Order Components(HOC) to get support with TypeScript

<template name="Eno">
    <div><p>{this.state.name}</p></div>
</template>
<script>
    // TypeScript Support
    import EnoType from './EnoType.tsx'
    export default EnoType(class {
        constructor(props) {
            super(props);
            this.state = { name: 'abc', age: 18}
        }
    })
</script>
<style lang="scss">
    p { color: #58bc58; }
</style>

Now, you can create EnoType.tsx in editor which provides TypeScript inference inside SFCs and many other great features.

// EnoType.ts
import React from 'react';
interface EnoTypeProps { }
interface EnoTypeState { name: string }
export default (Component: React.ComponentType) => {
    return class EnoType extends React.Component<EnoTypeProps, EnoTypeState> {
        constructor(props: EnoTypeProps) {
            super(props)
            this.state = { name: 'Eno Yao' }
        }
        render() { return <Component /> }
    }
}

React Demo

Typescript Demo

There are many cool features provided by omil:

  • Allows using other webpack loaders for each part of a Omi component, for example Sass for <style lang="scss"> and JSX/HTML for <template lang="html"> and ES5+ for <script type="text/babel">;
  • Allows custom blocks in a .omi or .eno file that can have custom loader chains applied to them Here Online Demo;
  • Treat static assets referenced in <style> and <template> as module dependencies and handle them with webpack loaders (Such as htm, to-string-loader);
  • Simulate scoped CSS for each component (Use Shadow DOM);
  • State-preserving hot-reloading during development.

In a nutshell, the combination of webpack and omil gives you a modern, flexible and extremely powerful front-end workflow for authoring Omi.js applications.

Cooperate With Sass

Automatically compiles sass/scss files to .css saving. You may also quickly compile sass/scss files in your project.

Code Snippets

trigger snippet
!omi/t-omi <template><script><style>
!react/t-react <template><script><style>
import import { * } from 'omi'
export default export default {}
modult.export" modult.export = {}
render render(){}
css css(){}
template <template></template>
templateLang <template lang></template>
script <script></script>
style <style></style>
styleLang <style lang></style>
scaffold/t <template><script><style>
... ...

NOTE: You still need to install corresponding packages for pre-processors (e.g. JSX, SASS, TypeScript) to get proper syntax highlighting for them.

Enabling JSX Highlighting

The <script> block uses the syntax highlighting currently active for you normal .js files. To support JSX highlighting inside Omi files, just set Babel javascript highlighting package, which supports JSX, as your default JS highlighting.

Note you may need to explicitly disable Sublime's default JavaScript package to make it work.

Contributors


Eno Yao

Aaron Xie

DK Lan

Yong

Li Ting

Xin

Lemon

Jing

Lin

Tian Fly

If you think it's useful, you can leave us a message and like it, Your support is our driving force😀

Thanks

License

Omi Snippets is released under the MIT

More Repositories

1

articles

🔖My Learning Notes and Memories - 分享我的学习片段和与你的回忆
Lua
3,171
star
2

piano

🎹Play the piano with the keyboard - 用键盘8个键演奏一首蒲公英的约定送给自己或月亮代表我的心送给她
JavaScript
1,130
star
3

CV

🙈Front End Engineer Curriculum Vitae - 面试宝典和简历生成器
HTML
1,043
star
4

node-tutorial

☺️Some of the node tutorial -《Node学习笔记》
JavaScript
541
star
5

vue-tutorial

🎃 Some of the vue-tutorial - 《Vue学习笔记》
494
star
6

vue-cli

📃基于 Vue3.0 Composition Api 快速构建实战项目
Vue
478
star
7

emoji

⭕〽️❗Omi Emoji
JavaScript
426
star
8

react-tutorial

🐅Some of the react tutorial - 《React学习笔记》
JavaScript
423
star
9

angular-tutorial

🐰Some of the angular tutorial - 《Angular学习笔记》
387
star
10

news

🐼Based on angular.js, weui and node.js rewrite news client - 新闻客户端
JavaScript
363
star
11

vue-awesome-mui

🏆Mui component for Vue.js(1.x ~ 2.x)
JavaScript
350
star
12

iPhone-X

🐳A simple and easy way to keep your custom views layout properly on iPhone X
CSS
340
star
13

socket.io

NodeJS《你画我猜》游戏
JavaScript
309
star
14

layout-demo

Various Layouts Of CSS
Lua
300
star
15

cms

News Management System Written In PHP - 从零开始用 PHP 实现内容管理系统后台
HTML
294
star
16

blog

Waving wild hands in the wind, writing brilliant poems, no matter how tired
HTML
277
star
17

webpack

📜Some of the node tutorial -《Webpack学习笔记》
JavaScript
276
star
18

littlefish

How far a life has to go, and how many years have passed before we can reach the end
CSS
259
star
19

compile-hero

🔰Visual Studio Code Extension For Compiling Language
TypeScript
257
star
20

wechat-jump-game

😊 Nodejs 微信《跳一跳》辅助
JavaScript
252
star
21

workerman

Workerman框架二次开发
PHP
249
star
22

openharmony-sheet

📊从零开始使用华为鸿蒙 OpenHarmony 开发游戏和表格渲染引擎
JavaScript
232
star
23

wechat-tnwz

Nodejs 微信《头脑王者》辅助
JavaScript
230
star
24

requirejs-demo

《RequreJS学习笔记》
JavaScript
198
star
25

browser-preview

🎢Preview html file in your default browser
TypeScript
195
star
26

virtual-dom

关于Vue,React,Preact和Omi等框架源码的解读
HTML
191
star
27

awesome

🚠Algorithm And Data Structure
JavaScript
189
star
28

omil

📝Webpack loader for Omi.js React.js and Rax.js components 基于 Omi.js,React.js 和 Rax.js 单文件组件的 Webpack 模块加载器
JavaScript
180
star
29

glup

Some of the gulp tutorial -《gulp笔记》
JavaScript
174
star
30

awesome-harmony

收录来源于网上鸿蒙系统开发的相关资料
JavaScript
168
star
31

search-online

🔍A simple extension for VSCode to search online easily using search engine.
TypeScript
164
star
32

python-tutorial

🏃 Some of the python tutorial - 《Python学习笔记》
JavaScript
157
star
33

regular

🔍The convenient paste of regular expression🔎
153
star
34

leetcode

leetcode
HTML
149
star
35

trip

Angular 仿携程的 demo
CSS
147
star
36

omi-electron

🚀Build cross platform desktop apps with Omi.js and Electron.js 基于Omi.js和Electron.js构建跨平台的桌面应用
HTML
146
star
37

egret

🐦Some of the egret tutorial -《白鹭引擎笔记》
JavaScript
146
star
38

less-demo

JavaScript
146
star
39

weixin-demo

JavaScript
143
star
40

swiper-iscroll-demo

JavaScript
141
star
41

see-you-again

😊 Because love is very heavy, but I don’t want to understand it, I’m afraid of being touched, I only walk in the opposite direction, with my back to the wet pupils, please let go, seek your own sky, if you lose, you’re tired, remember to turn around See You Again My Class~
141
star
42

cordova-demo

Objective-C
138
star
43

git-test

136
star
44

spy

A simple module that displays DOM attributes on mouseover inside a tooltip.
JavaScript
136
star
45

react-native

📱Test Directory Of React Native
JavaScript
135
star
46

create-angular-app

基于 Webpack 自定义 Angular 脚手架
TypeScript
135
star
47

react-redux

《Redux笔记》
JavaScript
131
star
48

vueno

Vue Conversion Plugin
JavaScript
124
star
49

create-react-app

基于Webpack自定义React脚手架
JavaScript
124
star
50

performance-decorator

🏇User behavior & Function execution tracking solution - 大型前端项目的用户行为跟踪,函数调用链分析,断点调试共享化和复用化实践
114
star
51

jest-tutorial

🎪Jest Architecture -《从零开始实现一个 Jest 单元测试框架》
JavaScript
100
star
52

omi-docs

📃Omil 文档
HTML
100
star
53

intersect

一道面试题的思考 - 6000万数据包和300万数据包在50M内存使用环境中求交集
JavaScript
97
star
54

media-tutorial

流处理,TCP和UDP,WebRTC和Blob
JavaScript
83
star
55

prototype

📖Prototype Document
82
star
56

vue-snippets

Visual Studio Code Syntax Highlighting For Vue3 And Vue2
JavaScript
67
star
57

sheet

📊OpenHarmony Sheet 表格渲染引擎
JavaScript
60
star
58

sweet

🍡Life needs a little sweet
51
star
59

html-snippets

Full HTML tags including HTML5 Snippets.
50
star
60

bullshit-generator

Greatly improve the production efficiency of nonsense.
TypeScript
49
star
61

Wscats

👨‍🚒 About me
48
star
62

command-runner

💻A VSCode extension that simply obtains the file path and executes the corresponding command
TypeScript
47
star
63

github-actions-tutorial

➿Github Action Tutorial - 《Github Action教程》
JavaScript
46
star
64

flappy

🐧OpenHarmony Flappy Bird
JavaScript
46
star
65

uni-app

Support commonly used code snippets in Hbuilder/HbuilderX.
Lua
44
star
66

yox-snippets

Visual Studio Code Syntax Highlighting For Yox
TypeScript
42
star
67

ACEM

TypeScript
42
star
68

java-snippets

Provide Java development 35000+ code snippets and detailed interface reminders, which greatly improves your development efficiency
HTML
42
star
69

dnd-tutorial

拖拽示例
TypeScript
42
star
70

dependency-injection

🌀Dependency injection to achieve inversion of control -《从零开始实现依赖注入框架》
TypeScript
42
star
71

chatgpt-demo

A demo repo based on OpenAI GPT-3.5 Turbo API
TypeScript
42
star
72

chrome-devtools-cli

Google Chrome Extension CLI
JavaScript
42
star
73

lerna-tutorial

💈Some of the lerna tutorial - 《Lerna学习笔记》
JavaScript
42
star
74

delete-node-modules

✂️ Simple extension for Visual Studio Code that allows you to quickly delete your project's node_modules directory
JavaScript
41
star
75

vscode-clipboard

一款 VSCode 插件,用于保留项目的复制和剪切内容,并可在面板的历史记录中重新选择粘贴。
TypeScript
41
star
76

vue-extension-pack

🚚Popular VS Code extensions for Vue.js development.
Vue
40
star
77

react-extension-pack

🚚Popular VS Code extensions for React.js development.
40
star
78

webpack-nx-build-coordination-plugin

Use to coordinate the compiling of the libs and the webpack linking.
TypeScript
40
star
79

monorepo-tutorial

💈Some of the lerna tutorial - 《Lerna学习笔记》
JavaScript
39
star
80

angular-extension-pack

🚚Popular VS Code extensions for Angular development.
39
star
81

assemblyscript-tutorial

Learning about webassembly
HTML
39
star
82

lazy-preload

Wraps the React.lazy API with preloaded functionality.
TypeScript
38
star
83

theia-extension

TypeScript
37
star
84

vscode-explore

Learning about vscode
TypeScript
37
star