@@ -26,8 +26,6 @@ public struct EditorConfiguration {
26
26
public let namespaceExcludedPaths : [ String ]
27
27
/// Authorization header
28
28
public let authHeader : String
29
- /// Global variables to be made available to the editor
30
- public let webViewGlobals : [ WebViewGlobal ]
31
29
/// Raw block editor settings from the WordPress REST API
32
30
public let editorSettings : EditorSettings
33
31
/// Locale used for translations
@@ -52,7 +50,6 @@ public struct EditorConfiguration {
52
50
siteApiNamespace: [ String ] ,
53
51
namespaceExcludedPaths: [ String ] ,
54
52
authHeader: String ,
55
- webViewGlobals: [ WebViewGlobal ] ,
56
53
editorSettings: EditorSettings ,
57
54
locale: String ,
58
55
editorAssetsEndpoint: URL ? = nil ,
@@ -70,7 +67,6 @@ public struct EditorConfiguration {
70
67
self . siteApiNamespace = siteApiNamespace
71
68
self . namespaceExcludedPaths = namespaceExcludedPaths
72
69
self . authHeader = authHeader
73
- self . webViewGlobals = webViewGlobals
74
70
self . editorSettings = editorSettings
75
71
self . locale = locale
76
72
self . editorAssetsEndpoint = editorAssetsEndpoint
@@ -91,7 +87,6 @@ public struct EditorConfiguration {
91
87
siteApiNamespace: siteApiNamespace,
92
88
namespaceExcludedPaths: namespaceExcludedPaths,
93
89
authHeader: authHeader,
94
- webViewGlobals: webViewGlobals,
95
90
editorSettings: editorSettings,
96
91
locale: locale,
97
92
editorAssetsEndpoint: editorAssetsEndpoint
@@ -128,7 +123,6 @@ public struct EditorConfigurationBuilder {
128
123
private var siteApiNamespace : [ String ]
129
124
private var namespaceExcludedPaths : [ String ]
130
125
private var authHeader : String
131
- private var webViewGlobals : [ WebViewGlobal ]
132
126
private var editorSettings : EditorSettings
133
127
private var locale : String
134
128
private var editorAssetsEndpoint : URL ?
@@ -146,7 +140,6 @@ public struct EditorConfigurationBuilder {
146
140
siteApiNamespace: [ String ] = [ ] ,
147
141
namespaceExcludedPaths: [ String ] = [ ] ,
148
142
authHeader: String = " " ,
149
- webViewGlobals: [ WebViewGlobal ] = [ ] ,
150
143
editorSettings: EditorSettings = [ : ] ,
151
144
locale: String = " en " ,
152
145
editorAssetsEndpoint: URL ? = nil
@@ -163,7 +156,6 @@ public struct EditorConfigurationBuilder {
163
156
self . siteApiNamespace = siteApiNamespace
164
157
self . namespaceExcludedPaths = namespaceExcludedPaths
165
158
self . authHeader = authHeader
166
- self . webViewGlobals = webViewGlobals
167
159
self . editorSettings = editorSettings
168
160
self . locale = locale
169
161
self . editorAssetsEndpoint = editorAssetsEndpoint
@@ -241,12 +233,6 @@ public struct EditorConfigurationBuilder {
241
233
return copy
242
234
}
243
235
244
- public func setWebViewGlobals( _ webViewGlobals: [ WebViewGlobal ] ) -> EditorConfigurationBuilder {
245
- var copy = self
246
- copy. webViewGlobals = webViewGlobals
247
- return copy
248
- }
249
-
250
236
public func setEditorSettings( _ editorSettings: EditorSettings ) -> EditorConfigurationBuilder {
251
237
var copy = self
252
238
copy. editorSettings = editorSettings
@@ -279,69 +265,13 @@ public struct EditorConfigurationBuilder {
279
265
siteApiNamespace: siteApiNamespace,
280
266
namespaceExcludedPaths: namespaceExcludedPaths,
281
267
authHeader: authHeader,
282
- webViewGlobals: webViewGlobals,
283
268
editorSettings: editorSettings,
284
269
locale: locale,
285
270
editorAssetsEndpoint: editorAssetsEndpoint
286
271
)
287
272
}
288
273
}
289
274
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
-
345
275
public typealias EditorSettings = [ String : Encodable ]
346
276
347
277
// String escaping extension
0 commit comments