@papercraftgames/estragon 0.1.0-beta.30 → 0.1.0-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ class Argument extends RefCounted:
15
15
  var type_name: String
16
16
  var name: String
17
17
  var binding_path: Array = []
18
+ var binding_type := "bool"
18
19
 
19
20
  class Factory extends RefCounted:
20
21
  var name: String
@@ -60,6 +61,13 @@ func emit() -> MappedWriter:
60
61
  while _module.identifiers.has(metadata): metadata += "_"
61
62
  _writer.append("\nconst "+metadata+" = "+var_to_str({"reactive":_module.render_functions,"ordinary":_module.ordinary_functions}))
62
63
  _writer.append("\n")
64
+ var observable := {}
65
+ for part in _module.parts:
66
+ if part is Model.Bindable: observable[part.name] = part.type_name
67
+ if not observable.is_empty():
68
+ var contract := "_GOGO_BINDABLE_PROPERTIES_"+_file.name.sha256_text().substr(0,16)
69
+ while _module.identifiers.has(contract): contract += "_"
70
+ _writer.append("const "+contract+" = "+var_to_str(observable)+"\n")
63
71
  var exports := {}
64
72
  for binding in _module.presets:
65
73
  if binding.exported: exports[binding.name] = binding
@@ -128,7 +136,9 @@ func _collect(node: Model.Component, factory: Factory) -> void:
128
136
  if attribute.value is Model.GdExpression:
129
137
  _argument(attribute.value, attribute.type_name, factory)
130
138
  factory.arguments.back().spread = attribute.kind=="spread"
131
- if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
139
+ if attribute.kind=="binding":
140
+ factory.arguments.back().binding_path = attribute.binding_path
141
+ factory.arguments.back().binding_type = attribute.binding_type
132
142
  for part in node.text_body:
133
143
  if part is Model.GdExpression: _argument(part,"Variant",factory)
134
144
  for child in node.children:
@@ -221,16 +231,12 @@ func _description(node: Model.Component, indentation: String) -> String:
221
231
  _variable += 1
222
232
  var props := PackedStringArray()
223
233
  var events := PackedStringArray()
224
- var bindings := PackedStringArray()
225
234
  var key := "null"
226
235
  var keyed := "false"
227
236
  var expanded := node.attributes.any(func(item): return item.kind=="spread")
228
237
  var ordered := PackedStringArray()
229
238
  for attribute in node.attributes:
230
239
  var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
231
- if attribute.kind == "binding":
232
- bindings.append(_string("value")+": "+value)
233
- continue
234
240
  if attribute.kind == "key":
235
241
  key = value
236
242
  keyed = "true"
@@ -248,15 +254,16 @@ func _description(node: Model.Component, indentation: String) -> String:
248
254
  _line("var %s := %s.new(%s, {%s}, {%s}, [%s], %s, %s, %s)" % [variable,_element_class,native_type,", ".join(props),", ".join(events),", ".join(children),_string("%s:%d:%d" % [_file.name,node.span.start.line,node.span.start.column]),key,keyed],node.span,indentation)
249
255
  for attribute in node.attributes:
250
256
  if attribute.kind=="placement" and not expanded: _line(variable+".origins["+_string(attribute.name)+"] = "+_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column]),attribute.name_span,indentation)
257
+ if attribute.kind=="binding": _line(variable+".origins[\"value\"] = "+_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column]),attribute.name_span,indentation)
251
258
 
252
259
  if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
260
+ _line(variable+".resolve_bindings()",node.span,indentation)
253
261
  if not node.text_body.is_empty():
254
262
  var parts := PackedStringArray()
255
263
  for part in node.text_body:
256
264
  var value: String = _arguments[part].name if part is Model.GdExpression else literal(part)
257
265
  parts.append("[%s, %s]" % [value,_string("%s:%d:%d" % [_file.name,part.span.start.line,part.span.start.column])])
258
266
  _line(variable+".set_text_body(["+", ".join(parts)+"])",node.span,indentation)
259
- if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
260
267
  if node.preset!=null: _line(variable+" = preload("+_resource(Preset)+").apply("+_arguments[node.preset_expression].name+", "+variable+")",node.span,indentation)
261
268
  return variable
262
269
 
@@ -329,6 +336,7 @@ func _bindable(property: Model.Bindable) -> void:
329
336
 
330
337
  func _binding_argument(argument: Argument) -> void:
331
338
  var path := argument.binding_path.duplicate()
339
+ var root: String = path.pop_front()
332
340
  var field: String = path.pop_back()
333
341
  var owner := "_gogo_root"
334
342
  var source := "_gogo_source"
@@ -341,7 +349,17 @@ func _binding_argument(argument: Argument) -> void:
341
349
  for name in path:
342
350
  endpoint += "."+str(name)
343
351
  checks.append(endpoint+" != null")
344
- _writer.append("preload("+_resource(Binding)+").new(self, func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": bool): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+")",argument.expression.span)
352
+ _writer.append("preload("+_resource(Binding)+").new("+root+", func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": "+argument.binding_type+"): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+", (",argument.expression.span)
353
+ # Keep the original property read in authored scope: native semantic
354
+ # validation still rejects unknown members, and the getter runs once.
355
+ _parts(argument.expression.parts)
356
+ var original_checks: Array[String] = []
357
+ var original := root
358
+ original_checks.append(original+" != null")
359
+ for name in path:
360
+ original += "."+str(name)
361
+ original_checks.append(original+" != null")
362
+ _writer.append(") if "+" and ".join(original_checks)+" else null"+(", TYPE_STRING" if argument.binding_type=="String" else "")+")",argument.expression.span)
345
363
 
346
364
  func _render_call(node: Model.RenderCall) -> void:
347
365
  var cast: String = node.result_type
@@ -196,8 +196,8 @@ func _binding(node, groups: Array, layout, scope: int, root: bool):
196
196
  for group in groups:
197
197
  var seen := {}
198
198
  for attribute in group.attributes:
199
- if attribute.name in ["key","bind:value"]:
200
- _error("layout defaults cannot preset key or bind:value; author instance controls at the use site",attribute.name_span)
199
+ if attribute.name=="key" or attribute.name.begins_with("bind:"):
200
+ _error("layout defaults cannot preset key or removed bind:* syntax; author instance properties at the use site",attribute.name_span)
201
201
  return null
202
202
  if attribute.kind=="spread": continue
203
203
  if seen.has(attribute.name):
@@ -59,6 +59,7 @@ class Literal extends SyntaxNode:
59
59
  class Attribute extends RefCounted:
60
60
  var span: Span
61
61
  var binding_path: Array = []
62
+ var binding_type := "bool"
62
63
  var kind: String = "property"
63
64
  var name: String
64
65
  var name_span: Span
@@ -256,8 +256,8 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span, check
256
256
  qualified = name+"."+module.import_aliases.get(root_name,root_name)+type.trim_prefix(root_name)
257
257
  elif ClassDB.class_exists(type.get_slice(".",0)) or imported.globals.has(type.get_slice(".",0)): qualified = type
258
258
  else: qualified = name+"."+type
259
- properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT,"source_writable":true}
260
- if not part.signal_name.is_empty(): signals[part.signal_name] = {"name":part.signal_name}
259
+ properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT,"source_writable":true,"source_bindable":not part.signal_name.is_empty()}
260
+ if not part.signal_name.is_empty(): signals[part.signal_name] = {"name":part.signal_name,"args":[{"type":kind},{"type":kind}]}
261
261
  if check_constructor and required: return _fail("GGX construction requires a zero-argument initializer: "+name,span)
262
262
  return {"native":base.native,"script":base.script,"properties":properties,"signals":signals,"required_initializer":required,"gogo_path":path}
263
263
 
@@ -265,33 +265,12 @@ func _fail(message: String, span: Model.Span) -> Dictionary:
265
265
  file.fail(message, span.start.index, span.end.index)
266
266
  return {}
267
267
 
268
- # Source-only proof for a writable Gogo path. Native fields never gain an
269
- # observation contract merely because an unrelated signal shares their name.
270
- func bindable_path(module, names: Array) -> bool:
271
- if names.is_empty(): return false
272
- for part in module.parts:
273
- if not part is Model.Bindable or part.name!=names[0]: continue
274
- if names.size()==1: return part.type_name=="bool"
275
- var path: String = aliases.get(part.type_name,globals.get(part.type_name,""))
276
- if path.is_empty(): return false
277
- var authored := path.get_base_dir().get_base_dir().path_join(path.get_file().get_basename()+".gogo")
278
- if path.get_base_dir().get_file()!="generated" or not FileAccess.file_exists(authored): return false
279
- var source := Source.new(FileAccess.get_file_as_string(authored),authored)
280
- var parsed = Parser.new(source).parse()
281
- if parsed==null: return false
282
- Bindable.new(source).apply(parsed)
283
- if not source.diagnostics.is_empty(): return false
284
- var imported = get_script().new(source)
285
- imported.scan(parsed)
286
- return imported.bindable_path(parsed,names.slice(1))
287
- return false
288
-
289
268
  # Godot 4.0 reports TYPE_NIL even for typed GDScript signal arguments.
290
269
  # Recover only this lexical declaration contract; native reload remains the
291
270
  # semantic authority. Never instantiate a control to inspect its signals.
292
271
  func signal_contract(script: Script, event: Dictionary) -> Dictionary:
293
272
  var args: Array = event.get("args",[])
294
- if args.size()!=1 or args[0].type!=TYPE_NIL or not script is GDScript: return event
273
+ if args.is_empty() or not args.any(func(arg): return arg.type==TYPE_NIL) or not script is GDScript: return event
295
274
  var source := Source.new(script.source_code,script.resource_path)
296
275
  var lexer := Lexer.new(source)
297
276
  var tokens: Array = []
@@ -301,11 +280,21 @@ func signal_contract(script: Script, event: Dictionary) -> Dictionary:
301
280
  if token==null: return event
302
281
  cursor = token.span.end.index
303
282
  if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
304
- for index in range(tokens.size()-6):
283
+ for index in range(tokens.size()-3):
305
284
  if tokens[index].text!="signal" or tokens[index].span.start.column!=1 or tokens[index+1].text!=event.name: continue
306
- if tokens[index+2].text!="(" or tokens[index+3].kind!="identifier" or tokens[index+4].text!=":" or tokens[index+6].text!=")": return event
307
- var kind: int = {"bool":TYPE_BOOL,"int":TYPE_INT,"float":TYPE_FLOAT,"String":TYPE_STRING}.get(tokens[index+5].text,TYPE_NIL)
285
+ if tokens[index+2].text!="(": return event
286
+ var argument_cursor := index+3
308
287
  var result := event.duplicate(true)
309
- result.args[0].type = kind
310
- return result
311
- return event
288
+ for arg in range(args.size()):
289
+ if argument_cursor+3>=tokens.size() or tokens[argument_cursor].kind!="identifier" or tokens[argument_cursor+1].text!=":": return event
290
+ result.args[arg].type = {"bool":TYPE_BOOL,"int":TYPE_INT,"float":TYPE_FLOAT,"String":TYPE_STRING}.get(tokens[argument_cursor+2].text,TYPE_NIL)
291
+ argument_cursor += 3
292
+ if arg<args.size()-1:
293
+ if tokens[argument_cursor].text!=",": return event
294
+ argument_cursor += 1
295
+ if tokens[argument_cursor].text==")": return result
296
+ # Older native metadata can list inherited signals on the leaf Script.
297
+ # Recover the declaration from its real base rather than treating NIL as
298
+ # proof that a valid inherited Bool endpoint is unobservable.
299
+ var base = script.get_base_script()
300
+ return signal_contract(base,event) if base!=null else event
@@ -2,6 +2,7 @@
2
2
  extends RefCounted
3
3
  ## Static native Node property/signal contracts; no SceneTree or editor dependency.
4
4
  const Element = preload("../runtime/composition/element.gd")
5
+ const Binding = preload("../runtime/composition/binding.gd")
5
6
  const Model = preload("model.gd")
6
7
  const Source = preload("source.gd")
7
8
  const Resolver = preload("native/resolver.gd")
@@ -81,13 +82,13 @@ func _component(node: Model.Component) -> void:
81
82
  return
82
83
  seen[name] = true
83
84
  if attribute.kind=="boolean-shorthand":
84
- if name in ["key","bind:value"] or signals.has(name) or not properties.has(name) or properties[name].type!=TYPE_BOOL or not NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
85
+ if name=="key" or signals.has(name) or not properties.has(name) or properties[name].type!=TYPE_BOOL or not NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
85
86
  _error("Valueless attribute requires a writable native Bool property: "+name,attribute.name_span)
86
87
  return
87
88
  attribute.type_name = "bool"
88
89
  continue
89
90
  if name.begins_with("bind:"):
90
- _binding(attribute,node,properties,signals)
91
+ _error("Authored bind:* syntax was removed; use value={direct.observable.path}",attribute.name_span)
91
92
  if not file.diagnostics.is_empty(): return
92
93
  continue
93
94
  if name=="key":
@@ -123,6 +124,7 @@ func _component(node: Model.Component) -> void:
123
124
  else:
124
125
  _error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
125
126
  return
127
+ _implicit_binding(attribute,properties,signals,resolved.script)
126
128
  if not expanded and StackContract.registered(resolved.script) and attribute.value is Model.Literal:
127
129
  var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script),StackContract.grid_capable(resolved.script))
128
130
  if not message.is_empty():
@@ -365,38 +367,23 @@ func _native_type(property: Dictionary) -> String:
365
367
  # Names are stable Variant types, not an engine-version-specific type_string API.
366
368
  return {TYPE_BOOL:"bool", TYPE_INT:"int", TYPE_FLOAT:"float", TYPE_STRING:"String", TYPE_STRING_NAME:"StringName", TYPE_VECTOR2:"Vector2", TYPE_VECTOR2I:"Vector2i", TYPE_RECT2:"Rect2", TYPE_RECT2I:"Rect2i", TYPE_VECTOR3:"Vector3", TYPE_VECTOR3I:"Vector3i", TYPE_TRANSFORM2D:"Transform2D", TYPE_VECTOR4:"Vector4", TYPE_VECTOR4I:"Vector4i", TYPE_PLANE:"Plane", TYPE_QUATERNION:"Quaternion", TYPE_AABB:"AABB", TYPE_BASIS:"Basis", TYPE_TRANSFORM3D:"Transform3D", TYPE_PROJECTION:"Projection", TYPE_COLOR:"Color", TYPE_NODE_PATH:"NodePath", TYPE_RID:"RID", TYPE_CALLABLE:"Callable", TYPE_SIGNAL:"Signal", TYPE_DICTIONARY:"Dictionary", TYPE_ARRAY:"Array", TYPE_PACKED_BYTE_ARRAY:"PackedByteArray", TYPE_PACKED_INT32_ARRAY:"PackedInt32Array", TYPE_PACKED_INT64_ARRAY:"PackedInt64Array", TYPE_PACKED_FLOAT32_ARRAY:"PackedFloat32Array", TYPE_PACKED_FLOAT64_ARRAY:"PackedFloat64Array", TYPE_PACKED_STRING_ARRAY:"PackedStringArray", TYPE_PACKED_VECTOR2_ARRAY:"PackedVector2Array", TYPE_PACKED_VECTOR3_ARRAY:"PackedVector3Array", TYPE_PACKED_COLOR_ARRAY:"PackedColorArray"}.get(property.type, "")
367
369
 
368
- func _binding(attribute, node, properties: Dictionary, signals: Dictionary) -> void:
369
- if attribute.name!="bind:value":
370
- _error("Only bind:value is supported",attribute.name_span)
371
- return
372
- for peer in node.attributes:
373
- if peer.name in ["value","value_changed"]:
374
- _error("bind:value conflicts with value/value_changed",peer.name_span)
375
- return
376
- var event: Dictionary = signals.get("value_changed",{})
377
- var args: Array = event.get("args",[])
378
- if not properties.has("value") or properties.value.type!=TYPE_BOOL or int(properties.value.usage)&PROPERTY_USAGE_READ_ONLY or args.size()!=1 or args[0].type!=TYPE_BOOL:
379
- _error("bind:value requires writable bool value and value_changed(value: bool)",attribute.name_span)
380
- return
381
- if not attribute.value is Model.GdExpression:
382
- _error("bind:value requires an explicit self bindable lvalue path",attribute.value.span)
383
- return
370
+ func _implicit_binding(attribute, properties: Dictionary, signals: Dictionary, script) -> void:
371
+ if attribute.name!="value" or not attribute.value is Model.GdExpression: return
372
+ if not properties.has("value") or properties.value.type not in [TYPE_BOOL,TYPE_STRING] or int(properties.value.usage)&PROPERTY_USAGE_READ_ONLY: return
373
+ var kind: int = properties.value.type
374
+ if not properties.value.get("source_bindable",false) and not Binding.declared(script,"value",kind): return
375
+ var args: Array = signals.get("value_changed",{}).get("args",[])
376
+ if args.size()!=2 or args.any(func(arg): return arg.type!=kind): return
384
377
  var tokens := _expression_tokens(attribute.value)
385
- if tokens.size()<3 or tokens.size()%2!=1 or tokens[0].text!="self":
386
- _error("bind:value requires self.field or self.model.field",attribute.value.span)
387
- return
378
+ if tokens.size()<3 or tokens.size()%2!=1: return
388
379
  var names: Array = []
389
- for index in range(1,tokens.size()):
390
- if index%2==1 and tokens[index].text!="." or index%2==0 and tokens[index].kind!="identifier":
391
- _error("bind:value accepts only assignable identifier paths",tokens[index].span)
392
- return
380
+ for index in range(tokens.size()):
381
+ if index%2==1 and tokens[index].text!="." or index%2==0 and tokens[index].kind!="identifier": return
393
382
  if index%2==0: names.append(tokens[index].text)
394
- if not resolver.bindable_path(current_module,names):
395
- _error("bind:value path requires typed Gogo bindable fields ending in bool",attribute.value.span)
396
- return
397
383
  attribute.kind = "binding"
398
384
  attribute.type_name = "Variant"
399
385
  attribute.binding_path = names
386
+ attribute.binding_type = "String" if kind==TYPE_STRING else "bool"
400
387
 
401
388
  func _length(attribute, domain: String) -> void:
402
389
  var value = attribute.value
@@ -514,7 +514,6 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
514
514
  for name in members:
515
515
  if members[name].kind in [CodeEdit.KIND_MEMBER,CodeEdit.KIND_SIGNAL] and members[name].get("writable",true) and name not in ["owner","script"]: offered[name] = members[name]
516
516
  if _node_type(context.tag,_aliases): offered.key = {"kind":CodeEdit.KIND_MEMBER}
517
- if members.has("value") and (members.value.get("value_type") == TYPE_BOOL or members.value.get("type") == "bool") and members.has("value_changed") and members.value_changed.get("args",[]).size() == 1 and members.value_changed.args[0] in ["bool",TYPE_BOOL]: offered["bind:value"] = {"kind":CodeEdit.KIND_MEMBER}
518
517
  elif context.mode == "body": return []
519
518
  elif member_cursor >= 0 and left[member_cursor] == ".":
520
519
  var tokens := _chain_tokens(lexical,row,member_cursor)
@@ -2,6 +2,8 @@
2
2
  extends RefCounted
3
3
  ## Trusted installed resources, not guessed global classes or installation roots.
4
4
  const ITEMS := [
5
+ {"alias":"Input","canonical":"EstragonInput","script":preload("../runtime/node/input.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
6
+ {"alias":"Checkbox","canonical":"EstragonCheckbox","script":preload("../runtime/node/checkbox.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
5
7
  {"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.gd"),"dimension":2,"origin":"native layout"},
6
8
  {"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
7
9
  {"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.30"
6
+ version="0.1.0-beta.32"
7
7
  script="plugin.gd"
@@ -10,12 +10,17 @@ var read: Callable
10
10
  var write: Callable
11
11
  var value: Variant
12
12
  var valid := false
13
+ var observable := false
14
+ var kind := TYPE_BOOL
13
15
  var node: WeakRef
14
16
  var computation: WeakRef
15
17
  var connected := false
16
18
  var writing := false
17
- func _init(owner: Object, reader: Callable, property: StringName, writer: Callable, identity: String) -> void:
18
- if owner==null: return
19
+ func _init(owner: Variant, reader: Callable, property: StringName, writer: Callable, identity: String, snapshot_value: Variant, value_type: int = TYPE_BOOL) -> void:
20
+ kind = value_type
21
+ value = snapshot_value
22
+ valid = kind in [TYPE_BOOL,TYPE_STRING] and typeof(value)==kind
23
+ if not owner is Object or not is_instance_valid(owner): return
19
24
  route = identity
20
25
  root = weakref(owner)
21
26
  read = reader
@@ -24,14 +29,25 @@ func _init(owner: Object, reader: Callable, property: StringName, writer: Callab
24
29
  var endpoint = current()
25
30
  if endpoint == null: return
26
31
  source = weakref(endpoint)
27
- value = endpoint.get(field)
28
- valid = typeof(value)==TYPE_BOOL and endpoint.has_signal(str(field)+"_changed")
32
+ if not valid: return
33
+ observable = declared(endpoint.get_script(),str(field),kind)
34
+ if observable:
35
+ valid = endpoint.has_signal(str(field)+"_changed")
36
+ static func declared(script, property: String, value_type: int = TYPE_BOOL) -> bool:
37
+ var type_name: String = {TYPE_BOOL:"bool",TYPE_STRING:"String"}.get(value_type,"")
38
+ if type_name.is_empty(): return false
39
+ while script is Script:
40
+ for name in script.get_script_constant_map():
41
+ var contract = script.get_script_constant_map()[name]
42
+ if str(name).begins_with("_GOGO_BINDABLE_PROPERTIES_") and contract is Dictionary and contract.get(property,"")==type_name: return true
43
+ script = script.get_base_script()
44
+ return false
29
45
  func current():
30
46
  var owner = root.get_ref() if root!=null else null
31
47
  var endpoint = read.call(owner) if is_instance_valid(owner) else null
32
- return endpoint if is_instance_valid(endpoint) else null
48
+ return endpoint if endpoint is Object and is_instance_valid(endpoint) else null
33
49
  func same(other) -> bool:
34
- return other!=null and valid and other.valid and source.get_ref()==other.source.get_ref() and root.get_ref()==other.root.get_ref() and field==other.field and route==other.route
50
+ return other!=null and valid and other.valid and kind==other.kind and source.get_ref()==other.source.get_ref() and root.get_ref()==other.root.get_ref() and field==other.field and route==other.route
35
51
  func attach(target: Node, scope) -> void:
36
52
  node = weakref(target)
37
53
  computation = weakref(scope)
@@ -49,7 +65,8 @@ func _target_exit() -> void:
49
65
  disconnect_edit()
50
66
  var scope = computation.get_ref() if computation!=null else null
51
67
  if scope!=null and scope.active and not scope.disposed: scope.schedule()
52
- func edit(next: bool) -> void:
68
+ func edit(_previous: Variant, next: Variant) -> void:
69
+ if typeof(next)!=kind: return
53
70
  var scope = computation.get_ref() if computation!=null else null
54
71
  var target = node.get_ref() if node!=null else null
55
72
  var endpoint = source.get_ref() if source!=null else null
@@ -61,11 +78,15 @@ func edit(next: bool) -> void:
61
78
  # Reentrant model callbacks can restore the old value; commit must still
62
79
  # restore a control whose local user value diverged from its snapshot.
63
80
  scope.schedule()
81
+ func project(target: Node, next: Variant) -> void:
82
+ writing = true
83
+ target.set("value",next)
84
+ writing = false
64
85
 
65
86
  # A desired linkage is reusable data; each native mount owns its mutable edit
66
87
  # connection. Copy without evaluating getters outside the render read scope.
67
88
  func snapshot():
68
- var result = get_script().new(null,Callable(),&"",Callable(),"")
89
+ var result = get_script().new(null,Callable(),&"",Callable(),"",null)
69
90
  result.root = root
70
91
  result.source = source
71
92
  result.field = field
@@ -74,4 +95,6 @@ func snapshot():
74
95
  result.write = write
75
96
  result.value = value
76
97
  result.valid = valid
98
+ result.observable = observable
99
+ result.kind = kind
77
100
  return result
@@ -248,8 +248,11 @@ func _valid(desired: Element, previous: Mounted) -> bool:
248
248
  elif desired.type is Script:
249
249
  if not desired.type.can_instantiate() or not ClassDB.is_parent_class(desired.type.get_instance_base_type(),"Node"): return false
250
250
  else: return false
251
- for binding in desired.bindings.values():
252
- if not binding is Binding or not binding.valid: return false
251
+ for key in desired.bindings:
252
+ var binding = desired.bindings[key]
253
+ if not binding is Binding or not binding.valid:
254
+ validation_error = desired.location(str(key))+": invalid observable "+("String" if binding is Binding and binding.kind==TYPE_STRING else "Bool")+" binding endpoint; previous tree retained"
255
+ return false
253
256
  for event in desired.handlers:
254
257
  var handler = desired.handlers[event]
255
258
  if not handler is Callable or not handler.is_valid(): return _invalid_attribute(desired,event,"signal requires a valid native Callable")
@@ -360,7 +363,7 @@ func _apply(desired: Element, record: Mounted) -> void:
360
363
  var binding = record.bindings.get(key,desired.bindings[key])
361
364
  record.bindings[key] = binding
362
365
  if not is_same(node.get(key),desired.bindings[key].value):
363
- node.set(key,desired.bindings[key].value)
366
+ binding.project(node,desired.bindings[key].value)
364
367
  writes += 1
365
368
  if Profile.is_enabled(): Profile.add("property_writes")
366
369
  binding.attach(node,self)
@@ -402,7 +405,7 @@ func _apply(desired: Element, record: Mounted) -> void:
402
405
  if Profile.is_enabled(): Profile.add("property_writes")
403
406
  for key in desired.properties:
404
407
  if scroll and key=="scroll_offset": continue
405
- if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
408
+ if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]) or key=="value" and Binding.declared(node.get_script(),"value",typeof(desired.properties[key])) and not is_same(node.get(key),desired.properties[key]):
406
409
  if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
407
410
  writes += 1
408
411
  if Profile.is_enabled(): Profile.add("property_writes")
@@ -699,13 +702,13 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
699
702
  var expected: String = str(properties[key].get("class_name",""))
700
703
  if ClassDB.class_exists(expected) and not value.is_class(expected): return _invalid_attribute(desired,str(key),"incompatible native Object class "+expected)
701
704
  for key in desired.bindings:
702
- if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,"value_changed" if desired.handlers.has("value_changed") else str(key),"invalid or conflicting controlled binding")
705
+ if key!="value" or desired.properties.has(key) or not properties.has(key) or properties[key].type not in [TYPE_BOOL,TYPE_STRING] or desired.bindings[key].kind!=properties[key].type or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,str(key),"invalid or conflicting controlled binding")
703
706
  var args: Array = signals.get("value_changed",{}).get("args",[])
704
707
 
705
708
  # 4.0 lacks signal argument type metadata. Compiler source proof and
706
709
  # native typed callback still apply; optional introspection cannot
707
710
  # reject a valid input on that engine.
708
- if args.size()!=1 or args[0].type not in [TYPE_NIL,TYPE_BOOL]: return false
711
+ if args.size()!=2 or args.any(func(arg): return arg.type!=TYPE_NIL and arg.type!=properties[key].type): return false
709
712
  for key in desired.handlers:
710
713
  if not signals.has(key): return _invalid_attribute(desired,str(key),"unknown native signal")
711
714
  var message := _handler_error(desired.handlers[key],signals[key].get("args",[]).size())
@@ -1,6 +1,7 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  const Profile = preload("profile.tres")
4
+ const Binding = preload("binding.gd")
4
5
  ## Desired values only. No native Node is allocated during description creation.
5
6
  # Internal normalized weak reference, only populated by child normalization.
6
7
  var borrowed: WeakRef
@@ -8,6 +9,13 @@ var type: Variant
8
9
  var properties: Dictionary
9
10
  var placement: Dictionary = {}
10
11
  var bindings: Dictionary = {}
12
+ func resolve_bindings() -> void:
13
+ var value = properties.get("value")
14
+ if not value is Binding: return
15
+ if value.observable or not value.valid and value.value==null:
16
+ bindings.value = value
17
+ properties.erase("value")
18
+ else: properties.value = value.value
11
19
  var handlers: Dictionary
12
20
  var children: Array
13
21
  var key: Variant
@@ -0,0 +1,33 @@
1
+ @tool
2
+ class_name EstragonCheckbox
3
+ extends "toggle.gd"
4
+ ## Square/checkmark and label on the shared observable Bool/focus/input path.
5
+ func _init() -> void:
6
+ super._init()
7
+ background_color = "transparent"
8
+ func _square_size() -> float:
9
+ return maxf(16.0,float(font_size))
10
+ func _measure_native() -> Vector2:
11
+ var label := _measure_label() if not text.is_empty() else Vector2.ZERO
12
+ return Vector2(_square_size()+(8.0+label.x if not text.is_empty() else 0.0),maxf(_square_size(),label.y))
13
+ func get_label_origin() -> Vector2:
14
+ var content := get_content_rect()
15
+ return content.position+Vector2(_square_size()+8.0,maxf(0.0,(content.size.y-_measure_label().y)*0.5))
16
+ func get_background_color() -> Color:
17
+ # Checkbox is distinct from Toggle's checked full-surface fill/underline.
18
+ if disabled: return _visual_style.colors.disabled_background_color
19
+ if _held and _hovered or _keyboard_held: return _visual_style.colors.pressed_background_color
20
+ return _visual_style.colors.hover_background_color if _hovered else _visual_style.colors.background_color
21
+ func _draw() -> void:
22
+ var content := get_content_rect()
23
+ if content.size.x<=0 or content.size.y<=0: return
24
+ var side := minf(_square_size(),minf(content.size.x,content.size.y))
25
+ var square := Rect2(content.position+Vector2(0,maxf(0,(content.size.y-side)*0.5)),Vector2(side,side))
26
+ var tint := Color(1,1,1,0.5) if disabled else Color.WHITE
27
+ draw_rect(square,_visual_style.colors.disabled_background_color if disabled else _visual_style.colors.checked_background_color if value else Color("#252525"))
28
+ draw_rect(square,Color("#c5d4df")*tint,false,1.5)
29
+ if value and side>=8:
30
+ draw_polyline(PackedVector2Array([square.position+Vector2(side*0.2,side*0.52),square.position+Vector2(side*0.43,side*0.76),square.position+Vector2(side*0.82,side*0.25)]),tint,2.0,true)
31
+ _draw_label(get_label_origin(),tint)
32
+ if has_focus() and layout_size.x>4 and layout_size.y>4:
33
+ draw_rect(Rect2(Vector2(2,2),layout_size-Vector2(4,4)),Color("#9cdcff"),false,2)
@@ -0,0 +1 @@
1
+ uid://bhx8qo8oamg8g
@@ -0,0 +1,161 @@
1
+ @tool
2
+ class_name EstragonInput
3
+ extends "component_2d.gd"
4
+ ## Node2D layout/skin with one private native single-line editing endpoint.
5
+ signal value_changed(previous: String, value: String)
6
+ signal submitted(value: String)
7
+ signal cancelled
8
+ signal focus_entered
9
+ signal focus_exited
10
+ const Editor = preload("internal/input_control.gd")
11
+ const Focus = preload("internal/focus.tres")
12
+ const State = preload("../composition/state.tres")
13
+ const _GOGO_BINDABLE_PROPERTIES_NATIVE := {"value":"String"}
14
+ @export var value: String = "":
15
+ set(next):
16
+ if value==next: return
17
+ var previous := value
18
+ value = next
19
+ _project_value()
20
+ value_changed.emit(previous,next)
21
+ get:
22
+ State.observe(self,&"value_changed")
23
+ return value
24
+ @export var placeholder: String = "":
25
+ set(next):
26
+ if placeholder==next: return
27
+ placeholder = next
28
+ _sync_editor()
29
+ @export var disabled := false:
30
+ set(next):
31
+ if disabled==next: return
32
+ disabled = next
33
+ _sync_editor()
34
+ queue_redraw()
35
+ @export var read_only := false:
36
+ set(next):
37
+ if read_only==next: return
38
+ read_only = next
39
+ _sync_editor()
40
+ @export var invalid := false:
41
+ set(next):
42
+ if invalid==next: return
43
+ invalid = next
44
+ queue_redraw()
45
+ @export_enum("None", "Click", "All") var focus_mode: int = Control.FOCUS_ALL:
46
+ set(next):
47
+ if next<Control.FOCUS_NONE or next>Control.FOCUS_ALL: return
48
+ focus_mode = next
49
+ _sync_editor()
50
+ @export var font: Font = ThemeDB.fallback_font:
51
+ set(next):
52
+ if next==null or next==font: return
53
+ _disconnect_font()
54
+ font = next
55
+ _connect_font()
56
+ _style_changed()
57
+ @export var font_size: int = 20:
58
+ set(next):
59
+ if next<=0 or font_size==next: return
60
+ font_size = next
61
+ _style_changed()
62
+ @export var color := Color.WHITE:
63
+ set(next):
64
+ if color==next: return
65
+ color = next
66
+ _sync_theme()
67
+ @export var focus_color := Color("#9cdcff"):
68
+ set(next):
69
+ focus_color = next
70
+ queue_redraw()
71
+ @export var invalid_color := Color("#f17b83"):
72
+ set(next):
73
+ invalid_color = next
74
+ queue_redraw()
75
+ var _editor: LineEdit
76
+ var _editor_skin := StyleBoxEmpty.new()
77
+ func _init() -> void:
78
+ background_color = Color("#252d38")
79
+ padding = 8.0
80
+ func _measure_native() -> Vector2:
81
+ # A stable single-line viewport, not a text-dependent expanding field.
82
+ return Vector2(200,font.get_height(font_size))
83
+ func _enter_tree() -> void:
84
+ _connect_font()
85
+ super._enter_tree()
86
+ if Engine.is_editor_hint(): return
87
+ _editor = Editor.new()
88
+ _editor.name = "_EstragonInput"
89
+ _editor.text = value
90
+ add_child(_editor,false,Node.INTERNAL_MODE_BACK)
91
+ _editor.text_changed.connect(_edited)
92
+ _editor.text_submitted.connect(_submitted)
93
+ layout_applied.connect(_sync_editor)
94
+ _sync_theme()
95
+ _sync_editor()
96
+ func _exit_tree() -> void:
97
+ if is_instance_valid(_editor):
98
+ layout_applied.disconnect(_sync_editor)
99
+ remove_child(_editor)
100
+ _editor.free()
101
+ _editor = null
102
+ _disconnect_font()
103
+ super._exit_tree()
104
+ func _composition_is_private(child: Node) -> bool:
105
+ return child==_editor or super._composition_is_private(child)
106
+ func _connect_font() -> void:
107
+ if is_inside_tree() and not font.changed.is_connected(_style_changed): font.changed.connect(_style_changed)
108
+ func _disconnect_font() -> void:
109
+ if font!=null and font.changed.is_connected(_style_changed): font.changed.disconnect(_style_changed)
110
+ func _style_changed() -> void:
111
+ _changed()
112
+ _sync_theme()
113
+ func _sync_theme() -> void:
114
+ if not is_instance_valid(_editor): return
115
+ # Native text/caret/selection draw in the real content rect; the host
116
+ # supplies the local surface, border and focus/invalid outline.
117
+ for state in ["normal","read_only","focus"]: _editor.add_theme_stylebox_override(state,_editor_skin)
118
+ _editor.add_theme_constant_override("minimum_character_width",0)
119
+ _editor.add_theme_font_override("font",font)
120
+ _editor.add_theme_font_size_override("font_size",font_size)
121
+ for key in ["font_color","font_uneditable_color","caret_color"]: _editor.add_theme_color_override(key,color)
122
+ _editor.add_theme_color_override("font_placeholder_color",Color(color,0.5))
123
+ _sync_editor()
124
+ func _sync_editor(_size: Vector2 = Vector2.ZERO) -> void:
125
+ if not is_instance_valid(_editor): return
126
+ var content := get_content_rect()
127
+ _editor.visible = content.size.x>0 and content.size.y>=font.get_height(font_size)
128
+ _editor_skin.content_margin_left = content.position.x
129
+ _editor_skin.content_margin_top = content.position.y
130
+ _editor_skin.content_margin_right = maxf(0,layout_size.x-content.end.x)
131
+ _editor_skin.content_margin_bottom = maxf(0,layout_size.y-content.end.y)
132
+ _editor.position = Vector2.ZERO
133
+ _editor.size = layout_size
134
+ _editor.placeholder_text = placeholder
135
+ _editor.editable = not disabled and not read_only
136
+ _editor.selecting_enabled = not disabled
137
+ _editor.shortcut_keys_enabled = not disabled
138
+ _editor.context_menu_enabled = not disabled
139
+ _editor.focus_mode = Control.FOCUS_NONE if disabled else focus_mode
140
+ _editor.modulate = Color(1,1,1,0.5) if disabled else Color.WHITE
141
+ if not Focus.eligible(_editor): _editor.release_focus()
142
+ func _project_value() -> void:
143
+ if not is_instance_valid(_editor) or _editor.text==value: return
144
+ var caret := _editor.caret_column
145
+ var selected := _editor.has_selection()
146
+ var start := _editor.get_selection_from_column() if selected else 0
147
+ var end := _editor.get_selection_to_column() if selected else 0
148
+ _editor.text = value
149
+ _editor.caret_column = mini(caret,value.length())
150
+ if selected: _editor.select(mini(start,value.length()),mini(end,value.length()))
151
+ func _edited(next: String) -> void: value = next
152
+ func _submitted(next: String) -> void: submitted.emit(next)
153
+ func grab_focus() -> void:
154
+ if is_instance_valid(_editor) and Focus.eligible(_editor): _editor.grab_focus()
155
+ func release_focus() -> void:
156
+ if is_instance_valid(_editor): _editor.release_focus()
157
+ func has_focus() -> bool: return is_instance_valid(_editor) and _editor.has_focus()
158
+ func get_focus_control() -> Control: return _editor
159
+ func _draw() -> void:
160
+ if (has_focus() or invalid) and layout_size.x>4 and layout_size.y>4:
161
+ draw_rect(Rect2(Vector2(2,2),layout_size-Vector2(4,4)),invalid_color if invalid else focus_color,false,2)
@@ -0,0 +1 @@
1
+ uid://dmgpinqaglofu
@@ -0,0 +1,25 @@
1
+ @tool
2
+ extends LineEdit
3
+ ## Native editing, selection and platform text input in the host's actual rect.
4
+ const Focus = preload("focus.tres")
5
+ func _estragon_focus_host(): return get_parent()
6
+ func _ready() -> void:
7
+ clip_contents = true
8
+ expand_to_text_length = false
9
+ focus_entered.connect(_entered)
10
+ focus_exited.connect(_exited)
11
+ func _entered() -> void:
12
+ var host = _estragon_focus_host()
13
+ if not Focus.eligible(self): release_focus(); return
14
+ host.queue_redraw()
15
+ host.focus_entered.emit()
16
+ func _exited() -> void:
17
+ var host = _estragon_focus_host()
18
+ host.queue_redraw()
19
+ host.focus_exited.emit()
20
+ func _gui_input(event: InputEvent) -> void:
21
+ if event is InputEventKey and event.is_action("ui_cancel") and event.pressed and not event.echo:
22
+ accept_event()
23
+ var host = _estragon_focus_host()
24
+ host.release_focus()
25
+ host.cancelled.emit()
@@ -0,0 +1 @@
1
+ uid://dfb5e8colfuh7
@@ -2,7 +2,9 @@
2
2
  class_name EstragonToggle
3
3
  extends "button.gd"
4
4
  ## Controlled boolean input. Completed native pointer/keyboard activation edits.
5
- signal value_changed(value: bool)
5
+ signal value_changed(previous: bool, value: bool)
6
+ const _GOGO_BINDABLE_PROPERTIES_NATIVE := {"value":"bool"}
7
+ const State = preload("../composition/state.tres")
6
8
  const ESTRAGON_TOGGLE_STYLE := true
7
9
  var checked_background_color: Variant = Color("#227a60"):
8
10
  set(next):
@@ -16,15 +18,19 @@ func _get_property_list() -> Array[Dictionary]:
16
18
  @export var value: bool = false:
17
19
  set(next):
18
20
  if value == next: return
21
+ var previous := value
19
22
  value = next
20
23
  _queue_style_redraw()
24
+ value_changed.emit(previous,next)
25
+ get:
26
+ State.observe(self,&"value_changed")
27
+ return value
21
28
  func _init() -> void:
22
29
  super._init()
23
30
  pressed.connect(_activate)
24
31
  func _activate() -> void:
25
32
  if disabled: return
26
33
  value = not value
27
- value_changed.emit(value)
28
34
  func get_background_color() -> Color:
29
35
  if disabled: return super.get_background_color()
30
36
  return _visual_style.colors.checked_background_color if value else super.get_background_color()
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.30"
32
+ "version": "0.1.0-beta.32"
33
33
  }