Add Link view, update JavaScriptKit to 0.8.0 (#276)
* Add Link View * Add Publish support * Remove #if checks * Upgrade swift snapshot * Try swiftwasm-action@main * Remove Publish support from this repo * Remove TokamakPublish target
This commit is contained in:
parent
a5da04989e
commit
348408eba1
|
@ -1 +1 @@
|
|||
wasm-5.3-SNAPSHOT-2020-09-25-a
|
||||
wasm-5.3-SNAPSHOT-2020-10-29-c
|
||||
|
|
|
@ -39,7 +39,7 @@ let package = Package(
|
|||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
.package(
|
||||
url: "https://github.com/swiftwasm/JavaScriptKit.git",
|
||||
.upToNextMinor(from: "0.7.2")
|
||||
.upToNextMinor(from: "0.8.0")
|
||||
),
|
||||
.package(url: "https://github.com/MaxDesiatov/Runtime.git", from: "2.1.2"),
|
||||
.package(url: "https://github.com/MaxDesiatov/OpenCombine.git", from: "0.0.1"),
|
||||
|
@ -69,7 +69,16 @@ let package = Package(
|
|||
),
|
||||
.target(
|
||||
name: "TokamakDOM",
|
||||
dependencies: ["CombineShim", "JavaScriptKit", "TokamakCore", "TokamakStaticHTML"]
|
||||
dependencies: [
|
||||
"CombineShim",
|
||||
"TokamakCore",
|
||||
"TokamakStaticHTML",
|
||||
.product(
|
||||
name: "JavaScriptKit",
|
||||
package: "JavaScriptKit",
|
||||
condition: .when(platforms: [.wasi])
|
||||
)
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "TokamakShim",
|
||||
|
@ -77,7 +86,14 @@ let package = Package(
|
|||
),
|
||||
.target(
|
||||
name: "TokamakDemo",
|
||||
dependencies: ["JavaScriptKit", "TokamakShim"]
|
||||
dependencies: [
|
||||
"TokamakShim",
|
||||
.product(
|
||||
name: "JavaScriptKit",
|
||||
package: "JavaScriptKit",
|
||||
condition: .when(platforms: [.wasi])
|
||||
)
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "TokamakStaticDemo",
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2018-2020 Tokamak contributors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Created by Carson Katri on 9/9/20.
|
||||
//
|
||||
|
||||
import struct Foundation.URL
|
||||
|
||||
public struct Link<Label>: View where Label: View {
|
||||
let destination: URL
|
||||
let label: Label
|
||||
|
||||
public init(destination: URL, @ViewBuilder label: () -> Label) {
|
||||
(self.destination, self.label) = (destination, label())
|
||||
}
|
||||
|
||||
public var body: Never {
|
||||
neverBody("Link")
|
||||
}
|
||||
}
|
||||
|
||||
extension Link where Label == Text {
|
||||
public init<S: StringProtocol>(_ titleKey: S, destination: URL) {
|
||||
self.init(destination: destination) { Text(titleKey) }
|
||||
}
|
||||
}
|
||||
|
||||
public struct _LinkProxy<Label> where Label: View {
|
||||
public let subject: Link<Label>
|
||||
|
||||
public init(_ subject: Link<Label>) { self.subject = subject }
|
||||
|
||||
public var label: Label { subject.label }
|
||||
public var destination: URL {
|
||||
subject.destination
|
||||
}
|
||||
}
|
|
@ -69,6 +69,7 @@ public typealias Spacer = TokamakCore.Spacer
|
|||
public typealias Text = TokamakCore.Text
|
||||
public typealias VStack = TokamakCore.VStack
|
||||
public typealias ZStack = TokamakCore.ZStack
|
||||
public typealias Link = TokamakCore.Link
|
||||
|
||||
// MARK: Special Views
|
||||
|
||||
|
@ -87,6 +88,8 @@ public typealias SceneStorage = TokamakCore.SceneStorage
|
|||
|
||||
// MARK: Misc
|
||||
|
||||
public typealias ViewBuilder = TokamakCore.ViewBuilder
|
||||
|
||||
// FIXME: I would put this inside TokamakCore, but for
|
||||
// some reason it doesn't get exported with the typealias
|
||||
extension Text {
|
||||
|
|
|
@ -97,7 +97,7 @@ extension _PaddingLayout: DOMViewModifier {
|
|||
}
|
||||
}
|
||||
return ["style": padding
|
||||
.map { "padding-\($0.0): \($0.1);" }
|
||||
.map { "padding-\($0.0): \($0.1)px;" }
|
||||
.joined(separator: " ")]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,10 @@ public let tokamakStyles = """
|
|||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
._tokamak-link {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme:dark) {
|
||||
._tokamak-text-redacted::after {
|
||||
background-color: rgb(100, 100, 100);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2018-2020 Tokamak contributors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Created by Carson Katri on 9/9/20.
|
||||
//
|
||||
|
||||
import TokamakCore
|
||||
|
||||
extension Link: ViewDeferredToRenderer {
|
||||
public var deferredBody: AnyView {
|
||||
let proxy = _LinkProxy(self)
|
||||
return AnyView(HTML("a", ["href": proxy.destination.absoluteString, "class": "_tokamak-link"]) {
|
||||
proxy.label
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue