-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7.0.6: Support more types for safeIntanceOf (#395)
* Fix #388 (2nd try) * add test case * 7.0.6: Support types in roosterjs-cross-window * auto generate TargetWIndow type * export TargetWindow
- Loading branch information
1 parent
4f6c9f1
commit 726d610
Showing
6 changed files
with
222 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 4 additions & 9 deletions
13
packages/roosterjs-cross-window/lib/typeUtils/safeInstanceOf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
packages/roosterjs-cross-window/lib/types/TargetWindow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/** | ||
* Define DOM types of window, used by safeInstanceOf() to check if a given object is of the specified type of its own window | ||
* | ||
* !!!Note: This file is generated from /tools/generateTargetWindow.js. Do NOT modify this file directly!!! | ||
*/ | ||
export default interface TargetWindow { | ||
Range: Range; | ||
Node: Node; | ||
Element: Element; | ||
SVGElement: SVGElement; | ||
SVGViewElement: SVGViewElement; | ||
SVGTitleElement: SVGTitleElement; | ||
SVGSymbolElement: SVGSymbolElement; | ||
SVGStyleElement: SVGStyleElement; | ||
SVGStopElement: SVGStopElement; | ||
SVGScriptElement: SVGScriptElement; | ||
SVGPatternElement: SVGPatternElement; | ||
SVGMetadataElement: SVGMetadataElement; | ||
SVGMaskElement: SVGMaskElement; | ||
SVGMarkerElement: SVGMarkerElement; | ||
SVGGraphicsElement: SVGGraphicsElement; | ||
SVGUseElement: SVGUseElement; | ||
SVGTextContentElement: SVGTextContentElement; | ||
SVGTextPositioningElement: SVGTextPositioningElement; | ||
SVGTextElement: SVGTextElement; | ||
SVGTSpanElement: SVGTSpanElement; | ||
SVGTextPathElement: SVGTextPathElement; | ||
SVGSwitchElement: SVGSwitchElement; | ||
SVGSVGElement: SVGSVGElement; | ||
SVGPathElement: SVGPathElement; | ||
SVGImageElement: SVGImageElement; | ||
SVGGeometryElement: SVGGeometryElement; | ||
SVGRectElement: SVGRectElement; | ||
SVGPolylineElement: SVGPolylineElement; | ||
SVGPolygonElement: SVGPolygonElement; | ||
SVGLineElement: SVGLineElement; | ||
SVGEllipseElement: SVGEllipseElement; | ||
SVGCircleElement: SVGCircleElement; | ||
SVGGElement: SVGGElement; | ||
SVGForeignObjectElement: SVGForeignObjectElement; | ||
SVGDefsElement: SVGDefsElement; | ||
SVGClipPathElement: SVGClipPathElement; | ||
SVGAElement: SVGAElement; | ||
SVGGradientElement: SVGGradientElement; | ||
SVGRadialGradientElement: SVGRadialGradientElement; | ||
SVGLinearGradientElement: SVGLinearGradientElement; | ||
SVGFilterElement: SVGFilterElement; | ||
SVGFETurbulenceElement: SVGFETurbulenceElement; | ||
SVGFETileElement: SVGFETileElement; | ||
SVGFESpotLightElement: SVGFESpotLightElement; | ||
SVGFESpecularLightingElement: SVGFESpecularLightingElement; | ||
SVGFEPointLightElement: SVGFEPointLightElement; | ||
SVGFEOffsetElement: SVGFEOffsetElement; | ||
SVGFEMorphologyElement: SVGFEMorphologyElement; | ||
SVGFEMergeNodeElement: SVGFEMergeNodeElement; | ||
SVGFEMergeElement: SVGFEMergeElement; | ||
SVGFEImageElement: SVGFEImageElement; | ||
SVGFEGaussianBlurElement: SVGFEGaussianBlurElement; | ||
SVGFEFloodElement: SVGFEFloodElement; | ||
SVGFEDropShadowElement: SVGFEDropShadowElement; | ||
SVGFEDistantLightElement: SVGFEDistantLightElement; | ||
SVGFEDisplacementMapElement: SVGFEDisplacementMapElement; | ||
SVGFEDiffuseLightingElement: SVGFEDiffuseLightingElement; | ||
SVGFEConvolveMatrixElement: SVGFEConvolveMatrixElement; | ||
SVGFECompositeElement: SVGFECompositeElement; | ||
SVGFEComponentTransferElement: SVGFEComponentTransferElement; | ||
SVGFEColorMatrixElement: SVGFEColorMatrixElement; | ||
SVGFEBlendElement: SVGFEBlendElement; | ||
SVGDescElement: SVGDescElement; | ||
SVGCursorElement: SVGCursorElement; | ||
SVGComponentTransferFunctionElement: SVGComponentTransferFunctionElement; | ||
SVGFEFuncRElement: SVGFEFuncRElement; | ||
SVGFEFuncGElement: SVGFEFuncGElement; | ||
SVGFEFuncBElement: SVGFEFuncBElement; | ||
SVGFEFuncAElement: SVGFEFuncAElement; | ||
SVGAnimationElement: SVGAnimationElement; | ||
SVGAnimateTransformElement: SVGAnimateTransformElement; | ||
SVGAnimateMotionElement: SVGAnimateMotionElement; | ||
SVGAnimateElement: SVGAnimateElement; | ||
HTMLElement: HTMLElement; | ||
HTMLUnknownElement: HTMLUnknownElement; | ||
HTMLUListElement: HTMLUListElement; | ||
HTMLTrackElement: HTMLTrackElement; | ||
HTMLTitleElement: HTMLTitleElement; | ||
HTMLTimeElement: HTMLTimeElement; | ||
HTMLTextAreaElement: HTMLTextAreaElement; | ||
HTMLTemplateElement: HTMLTemplateElement; | ||
HTMLTableSectionElement: HTMLTableSectionElement; | ||
HTMLTableRowElement: HTMLTableRowElement; | ||
HTMLTableElement: HTMLTableElement; | ||
HTMLTableColElement: HTMLTableColElement; | ||
HTMLTableCellElement: HTMLTableCellElement; | ||
HTMLTableHeaderCellElement: HTMLTableHeaderCellElement; | ||
HTMLTableDataCellElement: HTMLTableDataCellElement; | ||
HTMLTableCaptionElement: HTMLTableCaptionElement; | ||
HTMLStyleElement: HTMLStyleElement; | ||
HTMLSpanElement: HTMLSpanElement; | ||
HTMLSourceElement: HTMLSourceElement; | ||
HTMLSlotElement: HTMLSlotElement; | ||
HTMLSelectElement: HTMLSelectElement; | ||
HTMLScriptElement: HTMLScriptElement; | ||
HTMLQuoteElement: HTMLQuoteElement; | ||
HTMLProgressElement: HTMLProgressElement; | ||
HTMLPreElement: HTMLPreElement; | ||
HTMLPictureElement: HTMLPictureElement; | ||
HTMLParamElement: HTMLParamElement; | ||
HTMLParagraphElement: HTMLParagraphElement; | ||
HTMLOutputElement: HTMLOutputElement; | ||
HTMLOptionElement: HTMLOptionElement; | ||
HTMLOptGroupElement: HTMLOptGroupElement; | ||
HTMLObjectElement: HTMLObjectElement; | ||
HTMLOListElement: HTMLOListElement; | ||
HTMLModElement: HTMLModElement; | ||
HTMLMeterElement: HTMLMeterElement; | ||
HTMLMetaElement: HTMLMetaElement; | ||
HTMLMenuElement: HTMLMenuElement; | ||
HTMLMediaElement: HTMLMediaElement; | ||
HTMLVideoElement: HTMLVideoElement; | ||
HTMLAudioElement: HTMLAudioElement; | ||
HTMLMarqueeElement: HTMLMarqueeElement; | ||
HTMLMapElement: HTMLMapElement; | ||
HTMLLinkElement: HTMLLinkElement; | ||
HTMLLegendElement: HTMLLegendElement; | ||
HTMLLabelElement: HTMLLabelElement; | ||
HTMLLIElement: HTMLLIElement; | ||
HTMLInputElement: HTMLInputElement; | ||
HTMLImageElement: HTMLImageElement; | ||
HTMLIFrameElement: HTMLIFrameElement; | ||
HTMLHtmlElement: HTMLHtmlElement; | ||
HTMLHeadingElement: HTMLHeadingElement; | ||
HTMLHeadElement: HTMLHeadElement; | ||
HTMLHRElement: HTMLHRElement; | ||
HTMLFrameSetElement: HTMLFrameSetElement; | ||
HTMLFrameElement: HTMLFrameElement; | ||
HTMLFormElement: HTMLFormElement; | ||
HTMLFontElement: HTMLFontElement; | ||
HTMLFieldSetElement: HTMLFieldSetElement; | ||
HTMLEmbedElement: HTMLEmbedElement; | ||
HTMLDivElement: HTMLDivElement; | ||
HTMLDirectoryElement: HTMLDirectoryElement; | ||
HTMLDialogElement: HTMLDialogElement; | ||
HTMLDetailsElement: HTMLDetailsElement; | ||
HTMLDataListElement: HTMLDataListElement; | ||
HTMLDataElement: HTMLDataElement; | ||
HTMLDListElement: HTMLDListElement; | ||
HTMLCanvasElement: HTMLCanvasElement; | ||
HTMLButtonElement: HTMLButtonElement; | ||
HTMLBodyElement: HTMLBodyElement; | ||
HTMLBaseFontElement: HTMLBaseFontElement; | ||
HTMLBaseElement: HTMLBaseElement; | ||
HTMLBRElement: HTMLBRElement; | ||
HTMLAreaElement: HTMLAreaElement; | ||
HTMLAppletElement: HTMLAppletElement; | ||
HTMLAnchorElement: HTMLAnchorElement; | ||
DocumentType: DocumentType; | ||
DocumentFragment: DocumentFragment; | ||
ShadowRoot: ShadowRoot; | ||
Document: Document; | ||
XMLDocument: XMLDocument; | ||
HTMLDocument: HTMLDocument; | ||
ChildNode: ChildNode; | ||
CharacterData: CharacterData; | ||
Text: Text; | ||
CDATASection: CDATASection; | ||
ProcessingInstruction: ProcessingInstruction; | ||
Comment: Comment; | ||
Attr: Attr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const libDomFilePath = path.join(__dirname, '../node_modules/typescript/lib/lib.dom.d.ts'); | ||
const crossWindowPath = path.join(__dirname, '../packages/roosterjs-cross-window'); | ||
const targetPath = path.join(crossWindowPath, 'lib/types/TargetWindow.ts'); | ||
const packageJsonPath = path.join(crossWindowPath, 'package.json'); | ||
|
||
if (!fs.existsSync(libDomFilePath)) { | ||
console.error(`Cannot find source file: ${libDomFilePath}`); | ||
return 1; | ||
} | ||
|
||
const source = fs.readFileSync(libDomFilePath).toString(); | ||
const search = ['Node', 'Range']; | ||
|
||
let result = '/**\n'; | ||
result += | ||
' * Define DOM types of window, used by safeInstanceOf() to check if a given object is of the specified type of its own window\n'; | ||
result += ' *\n'; | ||
result += | ||
' * !!!Note: This file is generated from /tools/generateTargetWindow.js. Do NOT modify this file directly!!!\n'; | ||
result += ' */\n'; | ||
result += 'export default interface TargetWindow {\n'; | ||
|
||
while (search.length > 0) { | ||
const name = search.pop(); | ||
result += ` ${name}: ${name};\n`; | ||
const reg = new RegExp(`^interface (\\w+) extends\\s?${name}( \\{$|,.*$)`, 'gm'); | ||
let match; | ||
|
||
while ((match = reg.exec(source)) != null) { | ||
search.push(match[1]); | ||
} | ||
} | ||
|
||
result += '}\n'; | ||
|
||
try { | ||
fs.writeFileSync(targetPath, result); | ||
console.log( | ||
`\nSuccessfully generated target file ${targetPath}.\n\nRemember to change package version in ${packageJsonPath}.` | ||
); | ||
} catch (e) { | ||
console.error(e); | ||
return 1; | ||
} |