Skip to content

Commit 87ca914

Browse files
committed
Remove WebViewGlobals
#146 (comment)
1 parent 601a9a8 commit 87ca914

File tree

1 file changed

+0
-70
lines changed

1 file changed

+0
-70
lines changed

ios/Sources/GutenbergKit/Sources/EditorConfiguration.swift

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public struct EditorConfiguration {
2626
public let namespaceExcludedPaths: [String]
2727
/// Authorization header
2828
public let authHeader: String
29-
/// Global variables to be made available to the editor
30-
public let webViewGlobals: [WebViewGlobal]
3129
/// Raw block editor settings from the WordPress REST API
3230
public let editorSettings: EditorSettings
3331
/// Locale used for translations
@@ -52,7 +50,6 @@ public struct EditorConfiguration {
5250
siteApiNamespace: [String],
5351
namespaceExcludedPaths: [String],
5452
authHeader: String,
55-
webViewGlobals: [WebViewGlobal],
5653
editorSettings: EditorSettings,
5754
locale: String,
5855
editorAssetsEndpoint: URL? = nil,
@@ -70,7 +67,6 @@ public struct EditorConfiguration {
7067
self.siteApiNamespace = siteApiNamespace
7168
self.namespaceExcludedPaths = namespaceExcludedPaths
7269
self.authHeader = authHeader
73-
self.webViewGlobals = webViewGlobals
7470
self.editorSettings = editorSettings
7571
self.locale = locale
7672
self.editorAssetsEndpoint = editorAssetsEndpoint
@@ -91,7 +87,6 @@ public struct EditorConfiguration {
9187
siteApiNamespace: siteApiNamespace,
9288
namespaceExcludedPaths: namespaceExcludedPaths,
9389
authHeader: authHeader,
94-
webViewGlobals: webViewGlobals,
9590
editorSettings: editorSettings,
9691
locale: locale,
9792
editorAssetsEndpoint: editorAssetsEndpoint
@@ -128,7 +123,6 @@ public struct EditorConfigurationBuilder {
128123
private var siteApiNamespace: [String]
129124
private var namespaceExcludedPaths: [String]
130125
private var authHeader: String
131-
private var webViewGlobals: [WebViewGlobal]
132126
private var editorSettings: EditorSettings
133127
private var locale: String
134128
private var editorAssetsEndpoint: URL?
@@ -146,7 +140,6 @@ public struct EditorConfigurationBuilder {
146140
siteApiNamespace: [String] = [],
147141
namespaceExcludedPaths: [String] = [],
148142
authHeader: String = "",
149-
webViewGlobals: [WebViewGlobal] = [],
150143
editorSettings: EditorSettings = [:],
151144
locale: String = "en",
152145
editorAssetsEndpoint: URL? = nil
@@ -163,7 +156,6 @@ public struct EditorConfigurationBuilder {
163156
self.siteApiNamespace = siteApiNamespace
164157
self.namespaceExcludedPaths = namespaceExcludedPaths
165158
self.authHeader = authHeader
166-
self.webViewGlobals = webViewGlobals
167159
self.editorSettings = editorSettings
168160
self.locale = locale
169161
self.editorAssetsEndpoint = editorAssetsEndpoint
@@ -241,12 +233,6 @@ public struct EditorConfigurationBuilder {
241233
return copy
242234
}
243235

244-
public func setWebViewGlobals(_ webViewGlobals: [WebViewGlobal]) -> EditorConfigurationBuilder {
245-
var copy = self
246-
copy.webViewGlobals = webViewGlobals
247-
return copy
248-
}
249-
250236
public func setEditorSettings(_ editorSettings: EditorSettings) -> EditorConfigurationBuilder {
251237
var copy = self
252238
copy.editorSettings = editorSettings
@@ -279,69 +265,13 @@ public struct EditorConfigurationBuilder {
279265
siteApiNamespace: siteApiNamespace,
280266
namespaceExcludedPaths: namespaceExcludedPaths,
281267
authHeader: authHeader,
282-
webViewGlobals: webViewGlobals,
283268
editorSettings: editorSettings,
284269
locale: locale,
285270
editorAssetsEndpoint: editorAssetsEndpoint
286271
)
287272
}
288273
}
289274

290-
public struct WebViewGlobal: Equatable {
291-
let name: String
292-
let value: WebViewGlobalValue
293-
294-
public init(name: String, value: WebViewGlobalValue) throws {
295-
// Validate name is a valid JavaScript identifier
296-
guard Self.isValidJavaScriptIdentifier(name) else {
297-
throw WebViewGlobalError.invalidIdentifier(name)
298-
}
299-
self.name = name
300-
self.value = value
301-
}
302-
303-
private static func isValidJavaScriptIdentifier(_ name: String) -> Bool {
304-
// Add validation logic for JavaScript identifiers
305-
return name.range(of: "^[a-zA-Z_$][a-zA-Z0-9_$]*$", options: .regularExpression) != nil
306-
}
307-
}
308-
309-
public enum WebViewGlobalError: Error {
310-
case invalidIdentifier(String)
311-
}
312-
313-
public enum WebViewGlobalValue: Equatable {
314-
case string(String)
315-
case number(Double)
316-
case boolean(Bool)
317-
case object([String: WebViewGlobalValue])
318-
case array([WebViewGlobalValue])
319-
case null
320-
321-
func toJavaScript() -> String {
322-
switch self {
323-
case .string(let str):
324-
return "\"\(str.escaped)\""
325-
case .number(let num):
326-
return "\(num)"
327-
case .boolean(let bool):
328-
return "\(bool)"
329-
case .object(let dict):
330-
let sortedKeys = dict.keys.sorted()
331-
var pairs: [String] = []
332-
for key in sortedKeys {
333-
let value = dict[key]!
334-
pairs.append("\"\(key.escaped)\": \(value.toJavaScript())")
335-
}
336-
return "{\(pairs.joined(separator: ","))}"
337-
case .array(let array):
338-
return "[\(array.map { $0.toJavaScript() }.joined(separator: ","))]"
339-
case .null:
340-
return "null"
341-
}
342-
}
343-
}
344-
345275
public typealias EditorSettings = [String: Encodable]
346276

347277
// String escaping extension

0 commit comments

Comments
 (0)