forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FSharpPocketViewTags.fs
114 lines (109 loc) · 3.73 KB
/
FSharpPocketViewTags.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Interactive.FSharp
open System
open Microsoft.AspNetCore.Html
open Microsoft.DotNet.Interactive.Formatting
type FSharpPocketViewTags(p: PocketView) as this =
override __.ToString() = p.ToString()
abstract member innerHTML: [<ParamArray>] content: obj[] -> FSharpPocketViewTags
abstract member Item: string * obj -> FSharpPocketViewTags with get
default __.innerHTML content =
p.SetContent(content)
this
default __.Item
with get (attribute: string, value: obj) =
p.HtmlAttributes.[attribute] <- value
this
interface IHtmlContent with
member __.WriteTo(writer, encoder) = p.WriteTo(writer, encoder)
// This class exists because F# can't open static classes like it can modules. All items on the `FSharpPocketViewTags`
// module below are essentially fields that are initialized at runtime start, which means that there is only one
// instance of the `div` item. Since calling the indexer to set attributes or the `innerHTML()` method to set the
// content mutates the inner value, we need a way to get around that. The fix is for this class to exist at the root
// level, but as soon as a mutating method is called, a clone is made. The base type is kept the same to simplify the
// public API surface area.
type internal FSharpPocketViewTagsRoot(p: PocketView) =
inherit FSharpPocketViewTags(p)
let wrapped () = FSharpPocketViewTags(PocketView(tagName=p.Name, nested=p))
override __.ToString() = p.ToString()
override __.innerHTML content = wrapped().innerHTML(content)
override __.Item
with get (attribute: string, value: obj) = wrapped().[attribute, value]
module FSharpPocketViewTags =
let private f name = FSharpPocketViewTagsRoot(PocketView(tagName=name)) :> FSharpPocketViewTags
let a = f "a"
let area = f "area"
let aside = f "aside"
let b = f "b"
let body = f "body"
let br = f "br"
let button = f "button"
let caption = f "caption"
let center = f "center"
let code = f "code"
let colgroup = f "colgroup"
let dd = f "dd"
let details = f "details"
let div = f "div"
let dl = f "dl"
let dt = f "dt"
let em = f "em"
let figure = f "figure"
let font = f "font"
let form = f "form"
let h1 = f "h1"
let h2 = f "h2"
let h3 = f "h3"
let h4 = f "h4"
let h5 = f "h5"
let h6 = f "h6"
let head = f "head"
let header = f "header"
let hgroup = f "hgroup"
let hr = f "hr"
let html = f "html"
let i = f "i"
let iframe = f "iframe"
let img = f "img"
let input = f "input"
let label = f "label"
let li = f "li"
let link = f "link"
let main = f "main"
let menu = f "menu"
let menuitem = f "menuitem"
let meta = f "meta"
let meter = f "meter"
let nav = f "nav"
let ol = f "ol"
let optgroup = f "optgroup"
let option = f "option"
let p = f "p"
let pre = f "pre"
let progress = f "progress"
let q = f "q"
let script = f "script"
let section = f "section"
let select = f "select"
let small = f "small"
let source = f "source"
let span = f "span"
let strike = f "strike"
let style = f "style"
let strong = f "strong"
let sub = f "sub"
let sup = f "sup"
let svg = f "svg"
let table = f "table"
let tbody = f "tbody"
let td = f "td"
let textarea = f "textarea"
let tfoot = f "tfoot"
let th = f "th"
let thead = f "thead"
let title = f "title"
let tr = f "tr"
let u = f "u"
let ul = f "ul"
let video = f "video"