refactor(DomSchema): improve readability by making the schema more explicit using interface names
This commit is contained in:
parent
c31535982c
commit
93deff6c33
@ -33,7 +33,7 @@ const OBJECT = 'object';
|
|||||||
* An `element` may inherit additional properties from `parentElement` If no `^parentElement` is
|
* An `element` may inherit additional properties from `parentElement` If no `^parentElement` is
|
||||||
* specified then `""` (blank) element is assumed.
|
* specified then `""` (blank) element is assumed.
|
||||||
*
|
*
|
||||||
* NOTE: The blank element inherits from root `*` element, the super element of all elements.
|
* NOTE: The blank element inherits from root `[Element]` element, the super element of all elements.
|
||||||
*
|
*
|
||||||
* NOTE an element prefix such as `:svg:` has no special meaning to the schema.
|
* NOTE an element prefix such as `:svg:` has no special meaning to the schema.
|
||||||
*
|
*
|
||||||
@ -72,10 +72,11 @@ const OBJECT = 'object';
|
|||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
|
|
||||||
const SCHEMA: string[] = ([
|
const SCHEMA: string[] = ([
|
||||||
'*|textContent,%classList,className,id,innerHTML,*beforecopy,*beforecut,*beforepaste,*copy,*cut,*paste,*search,*selectstart,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerHTML,#scrollLeft,#scrollTop',
|
'[Element]|textContent,%classList,className,id,innerHTML,*beforecopy,*beforecut,*beforepaste,*copy,*cut,*paste,*search,*selectstart,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerHTML,#scrollLeft,#scrollTop',
|
||||||
'abbr,address,article,aside,b,bdi,bdo,cite,code,dd,dfn,dt,em,figcaption,figure,footer,header,i,kbd,main,mark,nav,noscript,rb,rp,rt,rtc,ruby,s,samp,section,small,strong,sub,sup,u,var,wbr^*|accessKey,contentEditable,dir,!draggable,!hidden,innerText,lang,*abort,*beforecopy,*beforecut,*beforepaste,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*copy,*cuechange,*cut,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*message,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*mozfullscreenchange,*mozfullscreenerror,*mozpointerlockchange,*mozpointerlockerror,*paste,*pause,*play,*playing,*progress,*ratechange,*reset,*resize,*scroll,*search,*seeked,*seeking,*select,*selectstart,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,*webglcontextcreationerror,*webglcontextlost,*webglcontextrestored,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerText,!spellcheck,%style,#tabIndex,title,!translate',
|
'[HTMLElement]^[Element]|accessKey,contentEditable,dir,!draggable,!hidden,innerText,lang,*abort,*beforecopy,*beforecut,*beforepaste,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*copy,*cuechange,*cut,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*message,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*mozfullscreenchange,*mozfullscreenerror,*mozpointerlockchange,*mozpointerlockerror,*paste,*pause,*play,*playing,*progress,*ratechange,*reset,*resize,*scroll,*search,*seeked,*seeking,*select,*selectstart,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,*webglcontextcreationerror,*webglcontextlost,*webglcontextrestored,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerText,!spellcheck,%style,#tabIndex,title,!translate',
|
||||||
'media^abbr|!autoplay,!controls,%crossOrigin,#currentTime,!defaultMuted,#defaultPlaybackRate,!disableRemotePlayback,!loop,!muted,*encrypted,#playbackRate,preload,src,%srcObject,#volume',
|
'abbr,address,article,aside,b,bdi,bdo,cite,code,dd,dfn,dt,em,figcaption,figure,footer,header,i,kbd,main,mark,nav,noscript,rb,rp,rt,rtc,ruby,s,samp,section,small,strong,sub,sup,u,var,wbr^[HTMLElement]|accessKey,contentEditable,dir,!draggable,!hidden,innerText,lang,*abort,*beforecopy,*beforecut,*beforepaste,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*copy,*cuechange,*cut,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*message,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*mozfullscreenchange,*mozfullscreenerror,*mozpointerlockchange,*mozpointerlockerror,*paste,*pause,*play,*playing,*progress,*ratechange,*reset,*resize,*scroll,*search,*seeked,*seeking,*select,*selectstart,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,*webglcontextcreationerror,*webglcontextlost,*webglcontextrestored,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerText,!spellcheck,%style,#tabIndex,title,!translate',
|
||||||
':svg:^abbr|*abort,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*cuechange,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*pause,*play,*playing,*progress,*ratechange,*reset,*resize,*scroll,*seeked,*seeking,*select,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,%style,#tabIndex',
|
'media^[HTMLElement]|!autoplay,!controls,%crossOrigin,#currentTime,!defaultMuted,#defaultPlaybackRate,!disableRemotePlayback,!loop,!muted,*encrypted,#playbackRate,preload,src,%srcObject,#volume',
|
||||||
|
':svg:^[HTMLElement]|*abort,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*cuechange,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*pause,*play,*playing,*progress,*ratechange,*reset,*resize,*scroll,*seeked,*seeking,*select,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,%style,#tabIndex',
|
||||||
':svg:graphics^:svg:|',
|
':svg:graphics^:svg:|',
|
||||||
':svg:animation^:svg:|*begin,*end,*repeat',
|
':svg:animation^:svg:|*begin,*end,*repeat',
|
||||||
':svg:geometry^:svg:|',
|
':svg:geometry^:svg:|',
|
||||||
@ -83,75 +84,74 @@ const SCHEMA: string[] = ([
|
|||||||
':svg:gradient^:svg:|',
|
':svg:gradient^:svg:|',
|
||||||
':svg:textContent^:svg:graphics|',
|
':svg:textContent^:svg:graphics|',
|
||||||
':svg:textPositioning^:svg:textContent|',
|
':svg:textPositioning^:svg:textContent|',
|
||||||
'abbr^*|accessKey,contentEditable,dir,!draggable,!hidden,innerText,lang,*abort,*beforecopy,*beforecut,*beforepaste,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*copy,*cuechange,*cut,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*message,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*mozfullscreenchange,*mozfullscreenerror,*mozpointerlockchange,*mozpointerlockerror,*paste,*pause,*play,*playing,*progress,*ratechange,*reset,*resize,*scroll,*search,*seeked,*seeking,*select,*selectstart,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,*webglcontextcreationerror,*webglcontextlost,*webglcontextrestored,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerText,!spellcheck,%style,#tabIndex,title,!translate',
|
'a^[HTMLElement]|charset,coords,download,hash,host,hostname,href,hreflang,name,password,pathname,ping,port,protocol,referrerPolicy,rel,rev,search,shape,target,text,type,username',
|
||||||
'a^abbr|charset,coords,download,hash,host,hostname,href,hreflang,name,password,pathname,ping,port,protocol,referrerPolicy,rel,rev,search,shape,target,text,type,username',
|
'area^[HTMLElement]|alt,coords,hash,host,hostname,href,!noHref,password,pathname,ping,port,protocol,referrerPolicy,search,shape,target,username',
|
||||||
'area^abbr|alt,coords,hash,host,hostname,href,!noHref,password,pathname,ping,port,protocol,referrerPolicy,search,shape,target,username',
|
|
||||||
'audio^media|',
|
'audio^media|',
|
||||||
'br^abbr|clear',
|
'br^[HTMLElement]|clear',
|
||||||
'base^abbr|href,target',
|
'base^[HTMLElement]|href,target',
|
||||||
'body^abbr|aLink,background,bgColor,link,*beforeunload,*blur,*error,*focus,*hashchange,*languagechange,*load,*message,*offline,*online,*pagehide,*pageshow,*popstate,*rejectionhandled,*resize,*scroll,*storage,*unhandledrejection,*unload,text,vLink',
|
'body^[HTMLElement]|aLink,background,bgColor,link,*beforeunload,*blur,*error,*focus,*hashchange,*languagechange,*load,*message,*offline,*online,*pagehide,*pageshow,*popstate,*rejectionhandled,*resize,*scroll,*storage,*unhandledrejection,*unload,text,vLink',
|
||||||
'button^abbr|!autofocus,!disabled,formAction,formEnctype,formMethod,!formNoValidate,formTarget,name,type,value',
|
'button^[HTMLElement]|!autofocus,!disabled,formAction,formEnctype,formMethod,!formNoValidate,formTarget,name,type,value',
|
||||||
'canvas^abbr|#height,#width',
|
'canvas^[HTMLElement]|#height,#width',
|
||||||
'content^abbr|select',
|
'content^[HTMLElement]|select',
|
||||||
'dl^abbr|!compact',
|
'dl^[HTMLElement]|!compact',
|
||||||
'datalist^abbr|',
|
'datalist^[HTMLElement]|',
|
||||||
'details^abbr|!open',
|
'details^[HTMLElement]|!open',
|
||||||
'dialog^abbr|!open,returnValue',
|
'dialog^[HTMLElement]|!open,returnValue',
|
||||||
'dir^abbr|!compact',
|
'dir^[HTMLElement]|!compact',
|
||||||
'div^abbr|align',
|
'div^[HTMLElement]|align',
|
||||||
'embed^abbr|align,height,name,src,type,width',
|
'embed^[HTMLElement]|align,height,name,src,type,width',
|
||||||
'fieldset^abbr|!disabled,name',
|
'fieldset^[HTMLElement]|!disabled,name',
|
||||||
'font^abbr|color,face,size',
|
'font^[HTMLElement]|color,face,size',
|
||||||
'form^abbr|acceptCharset,action,autocomplete,encoding,enctype,method,name,!noValidate,target',
|
'form^[HTMLElement]|acceptCharset,action,autocomplete,encoding,enctype,method,name,!noValidate,target',
|
||||||
'frame^abbr|frameBorder,longDesc,marginHeight,marginWidth,name,!noResize,scrolling,src',
|
'frame^[HTMLElement]|frameBorder,longDesc,marginHeight,marginWidth,name,!noResize,scrolling,src',
|
||||||
'frameset^abbr|cols,*beforeunload,*blur,*error,*focus,*hashchange,*languagechange,*load,*message,*offline,*online,*pagehide,*pageshow,*popstate,*rejectionhandled,*resize,*scroll,*storage,*unhandledrejection,*unload,rows',
|
'frameset^[HTMLElement]|cols,*beforeunload,*blur,*error,*focus,*hashchange,*languagechange,*load,*message,*offline,*online,*pagehide,*pageshow,*popstate,*rejectionhandled,*resize,*scroll,*storage,*unhandledrejection,*unload,rows',
|
||||||
'hr^abbr|align,color,!noShade,size,width',
|
'hr^[HTMLElement]|align,color,!noShade,size,width',
|
||||||
'head^abbr|',
|
'head^[HTMLElement]|',
|
||||||
'h1,h2,h3,h4,h5,h6^abbr|align',
|
'h1,h2,h3,h4,h5,h6^[HTMLElement]|align',
|
||||||
'html^abbr|version',
|
'html^[HTMLElement]|version',
|
||||||
'iframe^abbr|align,!allowFullscreen,frameBorder,height,longDesc,marginHeight,marginWidth,name,referrerPolicy,%sandbox,scrolling,src,srcdoc,width',
|
'iframe^[HTMLElement]|align,!allowFullscreen,frameBorder,height,longDesc,marginHeight,marginWidth,name,referrerPolicy,%sandbox,scrolling,src,srcdoc,width',
|
||||||
'img^abbr|align,alt,border,%crossOrigin,#height,#hspace,!isMap,longDesc,lowsrc,name,referrerPolicy,sizes,src,srcset,useMap,#vspace,#width',
|
'img^[HTMLElement]|align,alt,border,%crossOrigin,#height,#hspace,!isMap,longDesc,lowsrc,name,referrerPolicy,sizes,src,srcset,useMap,#vspace,#width',
|
||||||
'input^abbr|accept,align,alt,autocapitalize,autocomplete,!autofocus,!checked,!defaultChecked,defaultValue,dirName,!disabled,%files,formAction,formEnctype,formMethod,!formNoValidate,formTarget,#height,!incremental,!indeterminate,max,#maxLength,min,#minLength,!multiple,name,pattern,placeholder,!readOnly,!required,selectionDirection,#selectionEnd,#selectionStart,#size,src,step,type,useMap,value,%valueAsDate,#valueAsNumber,#width',
|
'input^[HTMLElement]|accept,align,alt,autocapitalize,autocomplete,!autofocus,!checked,!defaultChecked,defaultValue,dirName,!disabled,%files,formAction,formEnctype,formMethod,!formNoValidate,formTarget,#height,!incremental,!indeterminate,max,#maxLength,min,#minLength,!multiple,name,pattern,placeholder,!readOnly,!required,selectionDirection,#selectionEnd,#selectionStart,#size,src,step,type,useMap,value,%valueAsDate,#valueAsNumber,#width',
|
||||||
'keygen^abbr|!autofocus,challenge,!disabled,keytype,name',
|
'keygen^[HTMLElement]|!autofocus,challenge,!disabled,keytype,name',
|
||||||
'li^abbr|type,#value',
|
'li^[HTMLElement]|type,#value',
|
||||||
'label^abbr|htmlFor',
|
'label^[HTMLElement]|htmlFor',
|
||||||
'legend^abbr|align',
|
'legend^[HTMLElement]|align',
|
||||||
'link^abbr|as,charset,%crossOrigin,!disabled,href,hreflang,integrity,media,rel,%relList,rev,%sizes,target,type',
|
'link^[HTMLElement]|as,charset,%crossOrigin,!disabled,href,hreflang,integrity,media,rel,%relList,rev,%sizes,target,type',
|
||||||
'map^abbr|name',
|
'map^[HTMLElement]|name',
|
||||||
'marquee^abbr|behavior,bgColor,direction,height,#hspace,#loop,#scrollAmount,#scrollDelay,!trueSpeed,#vspace,width',
|
'marquee^[HTMLElement]|behavior,bgColor,direction,height,#hspace,#loop,#scrollAmount,#scrollDelay,!trueSpeed,#vspace,width',
|
||||||
'menu^abbr|!compact',
|
'menu^[HTMLElement]|!compact',
|
||||||
'meta^abbr|content,httpEquiv,name,scheme',
|
'meta^[HTMLElement]|content,httpEquiv,name,scheme',
|
||||||
'meter^abbr|#high,#low,#max,#min,#optimum,#value',
|
'meter^[HTMLElement]|#high,#low,#max,#min,#optimum,#value',
|
||||||
'ins,del^abbr|cite,dateTime',
|
'ins,del^[HTMLElement]|cite,dateTime',
|
||||||
'ol^abbr|!compact,!reversed,#start,type',
|
'ol^[HTMLElement]|!compact,!reversed,#start,type',
|
||||||
'object^abbr|align,archive,border,code,codeBase,codeType,data,!declare,height,#hspace,name,standby,type,useMap,#vspace,width',
|
'object^[HTMLElement]|align,archive,border,code,codeBase,codeType,data,!declare,height,#hspace,name,standby,type,useMap,#vspace,width',
|
||||||
'optgroup^abbr|!disabled,label',
|
'optgroup^[HTMLElement]|!disabled,label',
|
||||||
'option^abbr|!defaultSelected,!disabled,label,!selected,text,value',
|
'option^[HTMLElement]|!defaultSelected,!disabled,label,!selected,text,value',
|
||||||
'output^abbr|defaultValue,%htmlFor,name,value',
|
'output^[HTMLElement]|defaultValue,%htmlFor,name,value',
|
||||||
'p^abbr|align',
|
'p^[HTMLElement]|align',
|
||||||
'param^abbr|name,type,value,valueType',
|
'param^[HTMLElement]|name,type,value,valueType',
|
||||||
'picture^abbr|',
|
'picture^[HTMLElement]|',
|
||||||
'pre^abbr|#width',
|
'pre^[HTMLElement]|#width',
|
||||||
'progress^abbr|#max,#value',
|
'progress^[HTMLElement]|#max,#value',
|
||||||
'q,blockquote,cite^abbr|',
|
'q,blockquote,cite^[HTMLElement]|',
|
||||||
'script^abbr|!async,charset,%crossOrigin,!defer,event,htmlFor,integrity,src,text,type',
|
'script^[HTMLElement]|!async,charset,%crossOrigin,!defer,event,htmlFor,integrity,src,text,type',
|
||||||
'select^abbr|!autofocus,!disabled,#length,!multiple,name,!required,#selectedIndex,#size,value',
|
'select^[HTMLElement]|!autofocus,!disabled,#length,!multiple,name,!required,#selectedIndex,#size,value',
|
||||||
'shadow^abbr|',
|
'shadow^[HTMLElement]|',
|
||||||
'source^abbr|media,sizes,src,srcset,type',
|
'source^[HTMLElement]|media,sizes,src,srcset,type',
|
||||||
'span^abbr|',
|
'span^[HTMLElement]|',
|
||||||
'style^abbr|!disabled,media,type',
|
'style^[HTMLElement]|!disabled,media,type',
|
||||||
'caption^abbr|align',
|
'caption^[HTMLElement]|align',
|
||||||
'th,td^abbr|abbr,align,axis,bgColor,ch,chOff,#colSpan,headers,height,!noWrap,#rowSpan,scope,vAlign,width',
|
'th,td^[HTMLElement]|abbr,align,axis,bgColor,ch,chOff,#colSpan,headers,height,!noWrap,#rowSpan,scope,vAlign,width',
|
||||||
'col,colgroup^abbr|align,ch,chOff,#span,vAlign,width',
|
'col,colgroup^[HTMLElement]|align,ch,chOff,#span,vAlign,width',
|
||||||
'table^abbr|align,bgColor,border,%caption,cellPadding,cellSpacing,frame,rules,summary,%tFoot,%tHead,width',
|
'table^[HTMLElement]|align,bgColor,border,%caption,cellPadding,cellSpacing,frame,rules,summary,%tFoot,%tHead,width',
|
||||||
'tr^abbr|align,bgColor,ch,chOff,vAlign',
|
'tr^[HTMLElement]|align,bgColor,ch,chOff,vAlign',
|
||||||
'tfoot,thead,tbody^abbr|align,ch,chOff,vAlign',
|
'tfoot,thead,tbody^[HTMLElement]|align,ch,chOff,vAlign',
|
||||||
'template^abbr|',
|
'template^[HTMLElement]|',
|
||||||
'textarea^abbr|autocapitalize,!autofocus,#cols,defaultValue,dirName,!disabled,#maxLength,#minLength,name,placeholder,!readOnly,!required,#rows,selectionDirection,#selectionEnd,#selectionStart,value,wrap',
|
'textarea^[HTMLElement]|autocapitalize,!autofocus,#cols,defaultValue,dirName,!disabled,#maxLength,#minLength,name,placeholder,!readOnly,!required,#rows,selectionDirection,#selectionEnd,#selectionStart,value,wrap',
|
||||||
'title^abbr|text',
|
'title^[HTMLElement]|text',
|
||||||
'track^abbr|!default,kind,label,src,srclang',
|
'track^[HTMLElement]|!default,kind,label,src,srclang',
|
||||||
'ul^abbr|!compact,type',
|
'ul^[HTMLElement]|!compact,type',
|
||||||
'unknown^abbr|',
|
'unknown^[HTMLElement]|',
|
||||||
'video^media|#height,poster,#width',
|
'video^media|#height,poster,#width',
|
||||||
':svg:a^:svg:graphics|',
|
':svg:a^:svg:graphics|',
|
||||||
':svg:animate^:svg:animation|',
|
':svg:animate^:svg:animation|',
|
||||||
@ -235,12 +235,12 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
SCHEMA.forEach(encodedType => {
|
SCHEMA.forEach(encodedType => {
|
||||||
|
let type: {[property: string]: string} = {};
|
||||||
const [strType, strProperties] = encodedType.split('|');
|
const [strType, strProperties] = encodedType.split('|');
|
||||||
const properties = strProperties.split(',');
|
const properties = strProperties.split(',');
|
||||||
const [typeNames, superName] = strType.split('^');
|
const [typeNames, superName] = strType.split('^');
|
||||||
const type: {[property: string]: string} = {};
|
|
||||||
typeNames.split(',').forEach(tag => this._schema[tag.toLowerCase()] = type);
|
typeNames.split(',').forEach(tag => this._schema[tag.toLowerCase()] = type);
|
||||||
const superType = this._schema[superName];
|
const superType = superName && this._schema[superName.toLowerCase()];
|
||||||
if (superType) {
|
if (superType) {
|
||||||
Object.keys(superType).forEach((prop: string) => { type[prop] = superType[prop]; });
|
Object.keys(superType).forEach((prop: string) => { type[prop] = superType[prop]; });
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should detect different kinds of types', () => {
|
it('should detect different kinds of types', () => {
|
||||||
// inheritance: video => media => HTMLElement
|
// inheritance: video => media => [HTMLElement] => [Element]
|
||||||
expect(registry.hasProperty('video', 'className', [])).toBeTruthy(); // from *
|
expect(registry.hasProperty('video', 'className', [])).toBeTruthy(); // from [Element]
|
||||||
expect(registry.hasProperty('video', 'id', [])).toBeTruthy(); // string
|
expect(registry.hasProperty('video', 'id', [])).toBeTruthy(); // string
|
||||||
expect(registry.hasProperty('video', 'scrollLeft', [])).toBeTruthy(); // number
|
expect(registry.hasProperty('video', 'scrollLeft', [])).toBeTruthy(); // number
|
||||||
expect(registry.hasProperty('video', 'height', [])).toBeTruthy(); // number
|
expect(registry.hasProperty('video', 'height', [])).toBeTruthy(); // number
|
||||||
|
@ -7,9 +7,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const SVG_PREFIX = ':svg:';
|
const SVG_PREFIX = ':svg:';
|
||||||
const HTMLELEMENT_NAMES =
|
|
||||||
'abbr,address,article,aside,b,bdi,bdo,cite,code,dd,dfn,dt,em,figcaption,figure,footer,header,i,kbd,main,mark,nav,noscript,rb,rp,rt,rtc,ruby,s,samp,section,small,strong,sub,sup,u,var,wbr';
|
// Element | Node interfaces
|
||||||
const HTMLELEMENT_NAME = 'abbr';
|
// see https://developer.mozilla.org/en-US/docs/Web/API/Element
|
||||||
|
// see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
||||||
|
const ELEMENT_IF = '[Element]';
|
||||||
|
// HTMLElement interface
|
||||||
|
// see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
||||||
|
const HTMLELEMENT_IF = '[HTMLElement]';
|
||||||
|
|
||||||
|
const HTMLELEMENT_TAGS =
|
||||||
|
'abbr,address,article,aside,b,bdi,bdo,cite,code,dd,dfn,dt,em,figcaption,figure,footer,header,i,kbd,main,mark,nav,noscript,rb,rp,rt,rtc,ruby,s,samp,section,small,strong,sub,sup,u,var,wbr';
|
||||||
|
|
||||||
const _G: any = global;
|
const _G: any = global;
|
||||||
const document: any = typeof _G['document'] == 'object' ? _G['document'] : null;
|
const document: any = typeof _G['document'] == 'object' ? _G['document'] : null;
|
||||||
@ -36,13 +44,14 @@ export function extractSchema(): Map<string, string[]> {
|
|||||||
let visited: {[name: string]: boolean} = {};
|
let visited: {[name: string]: boolean} = {};
|
||||||
|
|
||||||
// HTML top level
|
// HTML top level
|
||||||
extractProperties(Node, element, visited, descMap, '*', '');
|
extractProperties(Node, element, visited, descMap, ELEMENT_IF, '');
|
||||||
extractProperties(Element, element, visited, descMap, '*', '');
|
extractProperties(Element, element, visited, descMap, ELEMENT_IF, '');
|
||||||
extractProperties(HTMLElement, element, visited, descMap, HTMLELEMENT_NAMES, '*');
|
extractProperties(HTMLElement, element, visited, descMap, HTMLELEMENT_IF, ELEMENT_IF);
|
||||||
extractProperties(HTMLMediaElement, element, visited, descMap, 'media', HTMLELEMENT_NAME);
|
extractProperties(HTMLElement, element, visited, descMap, HTMLELEMENT_TAGS, HTMLELEMENT_IF);
|
||||||
|
extractProperties(HTMLMediaElement, element, visited, descMap, 'media', HTMLELEMENT_IF);
|
||||||
|
|
||||||
// SVG top level
|
// SVG top level
|
||||||
extractProperties(SVGElement, svgText, visited, descMap, SVG_PREFIX, HTMLELEMENT_NAME);
|
extractProperties(SVGElement, svgText, visited, descMap, SVG_PREFIX, HTMLELEMENT_IF);
|
||||||
extractProperties(
|
extractProperties(
|
||||||
SVGGraphicsElement, svgText, visited, descMap, SVG_PREFIX + 'graphics', SVG_PREFIX);
|
SVGGraphicsElement, svgText, visited, descMap, SVG_PREFIX + 'graphics', SVG_PREFIX);
|
||||||
extractProperties(
|
extractProperties(
|
||||||
@ -81,23 +90,21 @@ function extractRecursiveProperties(
|
|||||||
|
|
||||||
let superName: string;
|
let superName: string;
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case '*':
|
case ELEMENT_IF:
|
||||||
|
// ELEMENT_IF is the top most interface (Element | Node)
|
||||||
superName = '';
|
superName = '';
|
||||||
break;
|
break;
|
||||||
case HTMLELEMENT_NAME:
|
case HTMLELEMENT_IF:
|
||||||
superName = '*';
|
superName = ELEMENT_IF;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
superName =
|
superName =
|
||||||
extractRecursiveProperties(visited, descMap, type.prototype.__proto__.constructor);
|
extractRecursiveProperties(visited, descMap, type.prototype.__proto__.constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the ancestor is an HTMLElement, use one of the multiple implememtation
|
|
||||||
superName = superName.split(',')[0];
|
|
||||||
|
|
||||||
let instance: HTMLElement = null;
|
let instance: HTMLElement = null;
|
||||||
name.split(',').forEach(tagName => {
|
name.split(',').forEach(tagName => {
|
||||||
instance = isSVG(type) ?
|
instance = type['name'].startsWith('SVG') ?
|
||||||
document.createElementNS('http://www.w3.org/2000/svg', tagName.replace(SVG_PREFIX, '')) :
|
document.createElementNS('http://www.w3.org/2000/svg', tagName.replace(SVG_PREFIX, '')) :
|
||||||
document.createElement(tagName);
|
document.createElement(tagName);
|
||||||
|
|
||||||
@ -105,6 +112,7 @@ function extractRecursiveProperties(
|
|||||||
|
|
||||||
switch (tagName) {
|
switch (tagName) {
|
||||||
case 'cite':
|
case 'cite':
|
||||||
|
// <cite> interface is `HTMLQuoteElement`
|
||||||
htmlType = HTMLElement;
|
htmlType = HTMLElement;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -160,9 +168,9 @@ function extractName(type: Function): string {
|
|||||||
// see https://www.w3.org/TR/html5/index.html
|
// see https://www.w3.org/TR/html5/index.html
|
||||||
// TODO(vicb): generate this map from all the element types
|
// TODO(vicb): generate this map from all the element types
|
||||||
case 'Element':
|
case 'Element':
|
||||||
return '*';
|
return ELEMENT_IF;
|
||||||
case 'HTMLElement':
|
case 'HTMLElement':
|
||||||
return HTMLELEMENT_NAME;
|
return HTMLELEMENT_IF;
|
||||||
case 'HTMLImageElement':
|
case 'HTMLImageElement':
|
||||||
return 'img';
|
return 'img';
|
||||||
case 'HTMLAnchorElement':
|
case 'HTMLAnchorElement':
|
||||||
@ -217,10 +225,6 @@ function extractName(type: Function): string {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSVG(type: Function): boolean {
|
|
||||||
return type['name'].startsWith('SVG');
|
|
||||||
}
|
|
||||||
|
|
||||||
const _TYPE_MNEMONICS: {[type: string]: string} = {
|
const _TYPE_MNEMONICS: {[type: string]: string} = {
|
||||||
'string': '',
|
'string': '',
|
||||||
'number': '#',
|
'number': '#',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user