Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ DerivedData/
.history
.cursor

.reference
.reference

*.artifactbundle
*.zip
48 changes: 1 addition & 47 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ let package = Package(
// The Markdown support for Shaft
.library(name: "ShaftMarkdown", targets: ["ShaftMarkdown"]),

// The Web backend and renderer for Shaft
// .library(name: "ShaftWeb", targets: ["ShaftWeb"]),

// Companion tool for downloading Skia binaries. Will be removed in the
// future when BuilderPlugin is more mature.
.plugin(name: "CSkiaSetupPlugin", targets: ["CSkiaSetupPlugin"]),

// (experimental) Tool to build application bundles
.plugin(name: "BuilderPlugin", targets: ["BuilderPlugin"]),
],
Expand Down Expand Up @@ -82,10 +75,6 @@ let package = Package(
url: "https://github.com/ShaftUI/SwiftReload.git",
branch: "main"
),
// .package(
// url: "https://github.com/swiftwasm/JavaScriptKit",
// from: "0.36.0"
// ),
.package(
url: "https://github.com/swiftlang/swift-markdown.git",
branch: "main"
Expand Down Expand Up @@ -122,16 +111,6 @@ let package = Package(
]
),

// .executableTarget(
// name: "WebDemo",
// dependencies: [
// "SwiftMath",
// "Shaft",
// "ShaftWeb",
// .product(name: "JavaScriptEventLoop", package: "JavaScriptKit"),
// ]
// ),

.target(
name: "CSkia",
dependencies: [
Expand Down Expand Up @@ -223,14 +202,7 @@ let package = Package(
),

.target(
name: "Fetch",
// dependencies: [
// .product(
// name: "JavaScriptKit",
// package: "JavaScriptKit",
// condition: .when(platforms: [.wasi])
// )
// ]
name: "Fetch"
),

.target(
Expand All @@ -255,15 +227,6 @@ let package = Package(
name: "ShaftSDL3",
condition: .when(platforms: [.linux, .windows, .macOS])
),
// .target(
// name: "ShaftWeb",
// condition: .when(platforms: [.wasi])
// ),
// .product(
// name: "JavaScriptEventLoop",
// package: "JavaScriptKit",
// condition: .when(platforms: [.wasi])
// ),
],
swiftSettings: [
.interoperabilityMode(.Cxx, .when(platforms: [.linux, .windows, .macOS]))
Expand Down Expand Up @@ -291,15 +254,6 @@ let package = Package(
swiftSettings: [.interoperabilityMode(.Cxx)]
),

// .target(
// name: "ShaftWeb",
// dependencies: [
// "SwiftMath",
// "Shaft",
// "JavaScriptKit",
// ]
// ),

.target(
name: "ShaftCodeHighlight",
dependencies: [
Expand Down
19 changes: 12 additions & 7 deletions Sources/Fetch/Fetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#elseif os(wasi)
import JavaScriptKit
// #elseif canImport(JavaScriptKit)
// import JavaScriptKit
#endif

/// Fetches data from a URL.
public func fetch(_ url: URL) async throws -> Data {
#if os(wasi)
let jsFetch = JSObject.global.fetch.function!
let response = try await JSPromise(jsFetch(url.absoluteString).object!)!.jsValue
let buffer = try await JSPromise(response.arrayBuffer().object!)!.jsValue
return Data()
#if canImport(JavaScriptKit)
// let jsFetch = JSObject.global.fetch.function!
// let response = try await JSPromise(jsFetch(url.absoluteString).object!)!.jsValue
// let buffer = try await JSPromise(response.arrayBuffer().object!)!.jsValue
// return Data()
throw NSError(
domain: "Fetch",
code: 0,
userInfo: [NSLocalizedDescriptionKey: "Fetch is not supported on JavaScriptKit"]
)
#else
return try await URLSession.shared.data(from: url).0
#endif
Expand Down
3 changes: 3 additions & 0 deletions Sources/Shaft/Core/Backend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public protocol NativeView: AnyObject {
/// and begin receiving these events.
var onTextComposed: TextComposedCallback? { get set }

/// A callback that is invoked when the text input connection is closed.
var onTextInputClosed: VoidCallback? { get set }

/// Getting/Setting the title of the view if possible.
var title: String { get set }

Expand Down
28 changes: 14 additions & 14 deletions Sources/Shaft/Core/KeyboardKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3807,74 +3807,74 @@ extension LogicalKeyboardKey {
/// Mask for the 32-bit value portion of the key code.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let valueMask = 0x000_ffff_ffff
private static let valueMask: UInt64 = 0x000_ffff_ffff

/// Mask for the plane prefix portion of the key code.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let planeMask = 0x0ff_0000_0000
private static let planeMask: UInt64 = 0x0ff_0000_0000

/// The plane value for keys which have a Unicode representation.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let unicodePlane = 0x000_0000_0000
private static let unicodePlane: UInt64 = 0x000_0000_0000

/// The plane value for keys defined by Chromium and does not have a Unicode
/// representation.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let unprintablePlane = 0x001_0000_0000
private static let unprintablePlane: UInt64 = 0x001_0000_0000

/// The plane value for keys defined by Flutter.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let flutterPlane = 0x002_0000_0000
private static let flutterPlane: UInt64 = 0x002_0000_0000

/// The platform plane with the lowest mask value, beyond which the keys are
/// considered autogenerated.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let startOfPlatformPlanes = 0x011_0000_0000
private static let startOfPlatformPlanes: UInt64 = 0x011_0000_0000

/// The plane value for the private keys defined by the Android embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let androidPlane = 0x011_0000_0000
private static let androidPlane: UInt64 = 0x011_0000_0000

/// The plane value for the private keys defined by the Fuchsia embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let fuchsiaPlane = 0x012_0000_0000
private static let fuchsiaPlane: UInt64 = 0x012_0000_0000

/// The plane value for the private keys defined by the iOS embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let iosPlane = 0x013_0000_0000
private static let iosPlane: UInt64 = 0x013_0000_0000

/// The plane value for the private keys defined by the macOS embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let macosPlane = 0x014_0000_0000
private static let macosPlane: UInt64 = 0x014_0000_0000

/// The plane value for the private keys defined by the Gtk embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let gtkPlane = 0x015_0000_0000
private static let gtkPlane: UInt64 = 0x015_0000_0000

/// The plane value for the private keys defined by the Windows embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let windowsPlane = 0x016_0000_0000
private static let windowsPlane: UInt64 = 0x016_0000_0000

/// The plane value for the private keys defined by the Web embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let webPlane = 0x017_0000_0000
private static let webPlane: UInt64 = 0x017_0000_0000

/// The plane value for the private keys defined by the GLFW embedding.
///
/// This is used by platform-specific code to generate Flutter key codes.
private static let glfwPlane = 0x018_0000_0000
private static let glfwPlane: UInt64 = 0x018_0000_0000

/// A predefined map of key labels for non-printable keys
private static let _keyLabels: [UInt64: String] = [
Expand Down
9 changes: 9 additions & 0 deletions Sources/Shaft/Services/TextInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class TextInput {
self.view = view
view.onTextEditing = handleTextEditing
view.onTextComposed = handleTextComposed
view.onTextInputClosed = handleTextInputClosed
}

public weak var view: NativeView!
Expand All @@ -34,6 +35,11 @@ public class TextInput {
currentConnection?.client?.onTextComposed(text: text)
}

private func handleTextInputClosed() {
currentConnection?.client?.onTextInputClosed()
currentConnection = nil
}

fileprivate func setComposingRect(_ rect: Rect) {
view.setComposingRect(rect)
}
Expand Down Expand Up @@ -75,6 +81,9 @@ public protocol TextInputClient: AnyObject {

/// Called when the text has been composed and committed.
func onTextComposed(text: String)

/// Called when the text input connection is closed.
func onTextInputClosed()
}

/// An interface for interacting with a text input control.
Expand Down
9 changes: 8 additions & 1 deletion Sources/Shaft/Widgets/Text/EditableText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,13 @@ public final class EditableTextState: State<EditableText>, TextSelectionDelegate
// no-op
}

public func onTextInputClosed() {
if hasInputConnection {
textInputConnection = nil
widget.focusNode.unfocus()
}
}

/// Sends the current composing rect to the embedder's text input plugin.
///
/// In cases where the composing rect hasn't been updated in the embedder due
Expand Down Expand Up @@ -1752,7 +1759,7 @@ public final class EditableTextState: State<EditableText>, TextSelectionDelegate
}

private var textInputConnection: TextInputConnection?
private var hasInputConnection: Bool { textInputConnection != nil }
private var hasInputConnection: Bool { textInputConnection?.isActive ?? false }

private func openOrCloseInputConnectionIfNeeded() {
if hasFocus && widget.focusNode.consumeKeyboardToken() {
Expand Down
5 changes: 5 additions & 0 deletions Sources/ShaftSDL3/SDLView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public class SDLView: NativeView {

if SDL_StopTextInput(sdlWindow) {
backend?.textEditingView = nil
onTextInputClosed?()
} else {
mark("SDL_StopTextInput failed")
}
Expand Down Expand Up @@ -246,6 +247,10 @@ public class SDLView: NativeView {
/// events are received.
public var onTextComposed: TextComposedCallback?

/// It's the backend's responsibility to call this method when the text input
/// connection is closed.
public var onTextInputClosed: VoidCallback?

fileprivate func handleEventSync(_ event: inout SDL_Event) -> Bool {
switch SDL_EventType(event.type.cast()) {
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
Expand Down
73 changes: 0 additions & 73 deletions Sources/ShaftWeb/Paragraph.swift

This file was deleted.

Loading
Loading