From 8a427262ab5afd887f2c3f0b7cd44b04795a3fe6 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sat, 17 Aug 2024 19:41:16 -0400 Subject: [PATCH 1/3] Add basic Table elements. Part of https://github.com/jverkoey/slipstream/issues/25. --- .../Documentation.docc/W3C/W3CViews.md | 8 +++++ .../W3C/Elements/TabularData/Table.swift | 29 +++++++++++++++++++ .../W3C/Elements/TabularData/TableBody.swift | 18 ++++++++++++ .../W3C/Elements/TabularData/TableCell.swift | 16 ++++++++++ .../Elements/TabularData/TableHeader.swift | 18 ++++++++++++ .../W3C/Elements/TabularData/TableRow.swift | 16 ++++++++++ .../W3C/TabularData/TableBodyTests.swift | 19 ++++++++++++ .../W3C/TabularData/TableCellTests.swift | 19 ++++++++++++ .../W3C/TabularData/TableHeaderTests.swift | 19 ++++++++++++ .../W3C/TabularData/TableRowTests.swift | 19 ++++++++++++ .../W3C/TabularData/TableTests.swift | 19 ++++++++++++ 11 files changed, 200 insertions(+) create mode 100644 Sources/Slipstream/W3C/Elements/TabularData/Table.swift create mode 100644 Sources/Slipstream/W3C/Elements/TabularData/TableBody.swift create mode 100644 Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift create mode 100644 Sources/Slipstream/W3C/Elements/TabularData/TableHeader.swift create mode 100644 Sources/Slipstream/W3C/Elements/TabularData/TableRow.swift create mode 100644 Tests/SlipstreamTests/W3C/TabularData/TableBodyTests.swift create mode 100644 Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift create mode 100644 Tests/SlipstreamTests/W3C/TabularData/TableHeaderTests.swift create mode 100644 Tests/SlipstreamTests/W3C/TabularData/TableRowTests.swift create mode 100644 Tests/SlipstreamTests/W3C/TabularData/TableTests.swift diff --git a/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md b/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md index c315815..8dacf68 100644 --- a/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md +++ b/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md @@ -60,6 +60,14 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh - ``Image`` - ``RawHTML`` +### Tabular data + +- ``Table`` +- ``TableHeader`` +- ``TableBody`` +- ``TableRow`` +- ``TableCell`` + ### Forms - ``Form`` diff --git a/Sources/Slipstream/W3C/Elements/TabularData/Table.swift b/Sources/Slipstream/W3C/Elements/TabularData/Table.swift new file mode 100644 index 0000000..3d1c1eb --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TabularData/Table.swift @@ -0,0 +1,29 @@ +/// A view that represents data with more than one dimension, in +/// the form of a table. +/// +/// ```swift +/// struct MySiteContent: View { +/// var body: some View { +/// Body { +/// Table { +/// DOMString("Hello, world!") +/// } +/// } +/// } +/// } +/// ``` +/// +/// - SeeAlso: W3C [table](https://html.spec.whatwg.org/multipage/tables.html#the-table-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct Table: W3CElement where Content: View { + @_documentation(visibility: private) + public let tagName: String = "table" + + @_documentation(visibility: private) + @ViewBuilder public let content: () -> Content + + /// Creates a table. + public init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } +} diff --git a/Sources/Slipstream/W3C/Elements/TabularData/TableBody.swift b/Sources/Slipstream/W3C/Elements/TabularData/TableBody.swift new file mode 100644 index 0000000..d8dbb3c --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TabularData/TableBody.swift @@ -0,0 +1,18 @@ +/// A view that represents a block of rows that consist of a body of +/// data for the parent table view, if the ``TableBody`` has a +/// parent and it is a table. +/// +/// - SeeAlso: W3C [tbody](https://html.spec.whatwg.org/multipage/tables.html#the-tbody-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct TableBody: W3CElement where Content: View { + @_documentation(visibility: private) + public let tagName: String = "tbody" + + @_documentation(visibility: private) + @ViewBuilder public let content: () -> Content + + /// Creates a table body. + public init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } +} diff --git a/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift b/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift new file mode 100644 index 0000000..7880c06 --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TabularData/TableCell.swift @@ -0,0 +1,16 @@ +/// A view that represents a data cell in a table. +/// +/// - SeeAlso: W3C [td](https://html.spec.whatwg.org/multipage/tables.html#the-td-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct TableCell: W3CElement where Content: View { + @_documentation(visibility: private) + public let tagName: String = "td" + + @_documentation(visibility: private) + @ViewBuilder public let content: () -> Content + + /// Creates a table cell. + public init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } +} diff --git a/Sources/Slipstream/W3C/Elements/TabularData/TableHeader.swift b/Sources/Slipstream/W3C/Elements/TabularData/TableHeader.swift new file mode 100644 index 0000000..724166d --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TabularData/TableHeader.swift @@ -0,0 +1,18 @@ +/// A view that represents the block of rows that consist of the column +/// labels (headers) and any ancillary non-header cells for the parent +/// table element, if the view has a parent and it is a table. +/// +/// - SeeAlso: W3C [thead](https://html.spec.whatwg.org/multipage/tables.html#the-thead-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct TableHeader: W3CElement where Content: View { + @_documentation(visibility: private) + public let tagName: String = "thead" + + @_documentation(visibility: private) + @ViewBuilder public let content: () -> Content + + /// Creates a table header. + public init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } +} diff --git a/Sources/Slipstream/W3C/Elements/TabularData/TableRow.swift b/Sources/Slipstream/W3C/Elements/TabularData/TableRow.swift new file mode 100644 index 0000000..aa96c66 --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TabularData/TableRow.swift @@ -0,0 +1,16 @@ +/// A view that represents a row of cells in a table. +/// +/// - SeeAlso: W3C [tr](https://html.spec.whatwg.org/multipage/tables.html#the-tr-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct TableRow: W3CElement where Content: View { + @_documentation(visibility: private) + public let tagName: String = "tr" + + @_documentation(visibility: private) + @ViewBuilder public let content: () -> Content + + /// Creates a table row. + public init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } +} diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableBodyTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableBodyTests.swift new file mode 100644 index 0000000..3ce0c92 --- /dev/null +++ b/Tests/SlipstreamTests/W3C/TabularData/TableBodyTests.swift @@ -0,0 +1,19 @@ +import Testing + +import Slipstream + +struct TableBodyTests { + @Test func emptyBlock() throws { + try #expect(renderHTML(TableBody {}) == "") + } + + @Test func withText() throws { + try #expect(renderHTML(TableBody { + DOMString("Hello, world!") + }) == """ + + Hello, world! + +""") + } +} diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift new file mode 100644 index 0000000..0ca85b0 --- /dev/null +++ b/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift @@ -0,0 +1,19 @@ +import Testing + +import Slipstream + +struct TableCellTests { + @Test func emptyBlock() throws { + try #expect(renderHTML(TableCell {}) == "") + } + + @Test func withText() throws { + try #expect(renderHTML(TableCell { + DOMString("Hello, world!") + }) == """ + + Hello, world! + +""") + } +} diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableHeaderTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableHeaderTests.swift new file mode 100644 index 0000000..adcf365 --- /dev/null +++ b/Tests/SlipstreamTests/W3C/TabularData/TableHeaderTests.swift @@ -0,0 +1,19 @@ +import Testing + +import Slipstream + +struct TableHeaderTests { + @Test func emptyBlock() throws { + try #expect(renderHTML(TableHeader {}) == "") + } + + @Test func withText() throws { + try #expect(renderHTML(TableHeader { + DOMString("Hello, world!") + }) == """ + + Hello, world! + +""") + } +} diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableRowTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableRowTests.swift new file mode 100644 index 0000000..b044dd1 --- /dev/null +++ b/Tests/SlipstreamTests/W3C/TabularData/TableRowTests.swift @@ -0,0 +1,19 @@ +import Testing + +import Slipstream + +struct TableRowTests { + @Test func emptyBlock() throws { + try #expect(renderHTML(TableRow {}) == "") + } + + @Test func withText() throws { + try #expect(renderHTML(TableRow { + DOMString("Hello, world!") + }) == """ + + Hello, world! + +""") + } +} diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableTests.swift new file mode 100644 index 0000000..be4f8a6 --- /dev/null +++ b/Tests/SlipstreamTests/W3C/TabularData/TableTests.swift @@ -0,0 +1,19 @@ +import Testing + +import Slipstream + +struct TableTests { + @Test func emptyBlock() throws { + try #expect(renderHTML(Table {}) == "
") + } + + @Test func withText() throws { + try #expect(renderHTML(Table { + DOMString("Hello, world!") + }) == """ + + Hello, world! +
+""") + } +} From e6d7a91e6374de5edc04ffc44345981af90a71d2 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sat, 17 Aug 2024 19:46:42 -0400 Subject: [PATCH 2/3] Add table header cell + web guidance. --- .../Guides/SlipstreamForWebDevelopers.md | 12 ++++++------ .../Documentation.docc/W3C/W3CViews.md | 1 + .../Elements/TabularData/TableHeaderCell.swift | 16 ++++++++++++++++ .../W3C/TabularData/TableCellTests.swift | 4 +--- .../W3C/TabularData/TableHeaderCellTests.swift | 17 +++++++++++++++++ 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 Sources/Slipstream/W3C/Elements/TabularData/TableHeaderCell.swift create mode 100644 Tests/SlipstreamTests/W3C/TabularData/TableHeaderCellTests.swift diff --git a/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForWebDevelopers.md b/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForWebDevelopers.md index f25fbc0..c362ebc 100644 --- a/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForWebDevelopers.md +++ b/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForWebDevelopers.md @@ -153,16 +153,16 @@ provided below is an organized table of W3C HTML tags and their equivalent Slips W3C tag | Slipstream view :--------|:---------------- -[``](https://html.spec.whatwg.org/multipage/sections.html#the-table-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) +[`
`](https://html.spec.whatwg.org/multipage/sections.html#the-table-element) | ``Table`` [``](https://html.spec.whatwg.org/multipage/sections.html#the-colgroup-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) [``](https://html.spec.whatwg.org/multipage/sections.html#the-col-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) -[``](https://html.spec.whatwg.org/multipage/sections.html#the-tbody-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) -[``](https://html.spec.whatwg.org/multipage/sections.html#the-thead-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) +[``](https://html.spec.whatwg.org/multipage/sections.html#the-tbody-element) | ``TableBody`` +[``](https://html.spec.whatwg.org/multipage/sections.html#the-thead-element) | ``TableHeader`` [``](https://html.spec.whatwg.org/multipage/sections.html#the-tfoot-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) -[``](https://html.spec.whatwg.org/multipage/sections.html#the-tr-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) -[``](https://html.spec.whatwg.org/multipage/sections.html#the-tr-element) | ``TableRow`` +[` + """) } } diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableHeaderCellTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableHeaderCellTests.swift new file mode 100644 index 0000000..ff8792a --- /dev/null +++ b/Tests/SlipstreamTests/W3C/TabularData/TableHeaderCellTests.swift @@ -0,0 +1,17 @@ +import Testing + +import Slipstream + +struct TableHeaderCellTests { + @Test func emptyBlock() throws { + try #expect(renderHTML(TableHeaderCell {}) == "") + } + + @Test func withText() throws { + try #expect(renderHTML(TableHeaderCell { + DOMString("Hello, world!") + }) == """ + +""") + } +} From 7cd12ada5f4a844ee7b8edb19852a4ad36230d0f Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sat, 17 Aug 2024 19:47:14 -0400 Subject: [PATCH 3/3] Update beta. --- .github/workflows/package-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package-test.yml b/.github/workflows/package-test.yml index 1b653db..fb17b3e 100644 --- a/.github/workflows/package-test.yml +++ b/.github/workflows/package-test.yml @@ -11,7 +11,7 @@ jobs: runs-on: macos-latest steps: - name: Select Xcode - run: sudo xcode-select -s "/Applications/Xcode_16_beta_4.app" + run: sudo xcode-select -s "/Applications/Xcode_16_beta_5.app" - name: Get swift version run: swift --version - uses: actions/checkout@v4
`](https://html.spec.whatwg.org/multipage/sections.html#the-caption-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) [`
`](https://html.spec.whatwg.org/multipage/sections.html#the-td-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) -[``](https://html.spec.whatwg.org/multipage/sections.html#the-th-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25) +[`
`](https://html.spec.whatwg.org/multipage/sections.html#the-td-element) | ``TableCell`` +[``](https://html.spec.whatwg.org/multipage/sections.html#the-th-element) | ``TableHeaderCell`` ### Forms diff --git a/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md b/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md index 8dacf68..babdc0a 100644 --- a/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md +++ b/Sources/Slipstream/Documentation.docc/W3C/W3CViews.md @@ -64,6 +64,7 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh - ``Table`` - ``TableHeader`` +- ``TableHeaderCell`` - ``TableBody`` - ``TableRow`` - ``TableCell`` diff --git a/Sources/Slipstream/W3C/Elements/TabularData/TableHeaderCell.swift b/Sources/Slipstream/W3C/Elements/TabularData/TableHeaderCell.swift new file mode 100644 index 0000000..0da8f86 --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TabularData/TableHeaderCell.swift @@ -0,0 +1,16 @@ +/// A view that represents a header cell in a table. +/// +/// - SeeAlso: W3C [th](https://html.spec.whatwg.org/multipage/tables.html#the-th-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct TableHeaderCell: W3CElement where Content: View { + @_documentation(visibility: private) + public let tagName: String = "th" + + @_documentation(visibility: private) + @ViewBuilder public let content: () -> Content + + /// Creates a table header cell. + public init(@ViewBuilder content: @escaping () -> Content) { + self.content = content + } +} diff --git a/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift b/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift index 0ca85b0..2f31069 100644 --- a/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift +++ b/Tests/SlipstreamTests/W3C/TabularData/TableCellTests.swift @@ -11,9 +11,7 @@ struct TableCellTests { try #expect(renderHTML(TableCell { DOMString("Hello, world!") }) == """ - - Hello, world! -Hello, world!Hello, world!