一些小需求
void1005 / temp Goto Github PK
View Code? Open in Web Editor NEW一些小需求
一些小需求
增加include
和exclude
属性, 主要是用于包含或排除掉某些指定的元素标签
以下是排除/包含的定义:
- 包含: 可以右键点击出现菜单栏
- 排除: 该元素点击不会出现右键菜单, 但会出现系统的右键菜单
但是需要写一个解析器来区分如下场景的优先级:
...总之就是尽可能的兼容所有的css选择器, 先兼容下面的, 然后后期再继续支持更多的选择器
.box p
div.box
div>h1
后续要兼容的
.box.block
注意: 两个类样式直接没有空格.a+.b
这+号我忘了是干嘛的了至于到底是排除还是包含, 取决于选择器的优先级
interface ConfigType {
include?: string[] | RegExp // 包含的元素
exclude?: string[] | RegExp // 排除的元素
}
<body>
<div id="app">
<h1>包含h1</h1>
<div class="box">
<h1>排除h1</h1>
<p><span>包含span</span></p>
</div>
<div class="box">
<h1>排除h1</h1>
<p><span>包含span</span></p>
</div>
<ul>
<li><span>排除span</span></li>
<li><span>排除span</span></li>
<li><span>排除span</span></li>
<li><span>排除span</span></li>
</ul>
</div>
<script>
new RightMenu({
el: '#app', // 右键菜单是直接绑定在 div#app 上面的
include: [
'.box span', // 但是.box下的span标签包含
'div>h1' // 包含div下的h1
],
exclude: [
'span', // 排除掉所有的span标签
'div.box>h1' // 但是排除掉.box下的h1
]
}, [
{ type: 'li', text: '哈哈哈' }
])
</script>
</body>
因为考虑到某些用户的数据可能是后端传递的
此时用户要想使用的话, 还得遍历所有树节点, 把title改成text, 把items改成children, 咱们才能识别并渲染
考虑到大部分的初级前端, 并不会遍历树结构, 也是为了提升组件的属性自由度, 打算增加defaultProps
属性
defaultProps
属性与theme
同级, 为对象类型, 并且只支持下面5个key的替换
type
text
disabled
callback
children
interface ConfigType {
defaultProps?: {
type?: string, // 可以不传, 不传的话使用默认key, 就是'type'
text?: string, // 可以不传, 不传的话使用默认key, 就是'text'
disabled?: string, // 可以不传, 不传的话使用默认key, 就是'disabled'
children?: string, // 可以不传, 不传的话使用默认key, 就是'children'
callback?: string // 可以不传, 不传的话使用默认key, 就是'callback'
}
}
new RightMenu({
theme: 'mac',
defaultProps: {
type: 'flag',
text: 'title',
disabled: 'isDisabled',
children: 'items',
callback: 'function'
}
}, [
{
flag: 'li',
title: '复制(C)',
function: () => alert('点击了复制')
},
{
flag: 'li',
title: '粘贴(V)',
isDisabled: true,
function: () => alert('点击了复制')
},
{
flag: 'ul',
title: '发送到',
items: [
{
flag: 'li',
title: '发送到桌面',
},
{
flag: 'li',
title: '发送到邮件',
},
]
},
])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.