1 |
|
2 |
|
3 | import { makeMap } from 'shared/util'
|
4 |
|
5 |
|
6 |
|
7 | export const isReservedAttr = makeMap('style,class')
|
8 |
|
9 |
|
10 | const acceptValue = makeMap('input,textarea,option,select,progress')
|
11 | export const mustUseProp = (tag: string, type: ?string, attr: string): boolean => {
|
12 | return (
|
13 | (attr === 'value' && acceptValue(tag)) && type !== 'button' ||
|
14 | (attr === 'selected' && tag === 'option') ||
|
15 | (attr === 'checked' && tag === 'input') ||
|
16 | (attr === 'muted' && tag === 'video')
|
17 | )
|
18 | }
|
19 |
|
20 | export const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
|
21 |
|
22 | const isValidContentEditableValue = makeMap('events,caret,typing,plaintext-only')
|
23 |
|
24 | export const convertEnumeratedValue = (key: string, value: any) => {
|
25 | return isFalsyAttrValue(value) || value === 'false'
|
26 | ? 'false'
|
27 |
|
28 | : key === 'contenteditable' && isValidContentEditableValue(value)
|
29 | ? value
|
30 | : 'true'
|
31 | }
|
32 |
|
33 | export const isBooleanAttr = makeMap(
|
34 | 'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
|
35 | 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
|
36 | 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
|
37 | 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
|
38 | 'required,reversed,scoped,seamless,selected,sortable,translate,' +
|
39 | 'truespeed,typemustmatch,visible'
|
40 | )
|
41 |
|
42 | export const xlinkNS = 'http://www.w3.org/1999/xlink'
|
43 |
|
44 | export const isXlink = (name: string): boolean => {
|
45 | return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'
|
46 | }
|
47 |
|
48 | export const getXlinkProp = (name: string): string => {
|
49 | return isXlink(name) ? name.slice(6, name.length) : ''
|
50 | }
|
51 |
|
52 | export const isFalsyAttrValue = (val: any): boolean => {
|
53 | return val == null || val === false
|
54 | }
|