glib-web 8.2.0 → 8.2.2
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.
- checksums.yaml +4 -4
- data/app/controllers/glib/glib_direct_uploads_controller.rb +6 -2
- data/app/helpers/glib/format_helper.rb +8 -12
- data/app/helpers/glib/json_ui/abstract_builder.rb +44 -47
- data/app/helpers/glib/json_ui/action_builder/popovers.rb +1 -1
- data/app/helpers/glib/json_ui/hash_schema.rb +182 -0
- data/app/helpers/glib/json_ui/list_builders.rb +2 -2
- data/app/helpers/glib/json_ui/menu_builder.rb +8 -3
- data/app/helpers/glib/json_ui/view_builder/charts.rb +14 -2
- data/app/helpers/glib/json_ui/view_builder/fields.rb +66 -17
- data/app/helpers/glib/json_ui/view_builder/panels.rb +17 -11
- data/app/helpers/glib/json_ui/view_builder.rb +26 -6
- data/app/models/glib/markdown.rb +172 -0
- data/app/views/json_ui/garage/actions/sheet_content.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/_action_text_conversion.json.jbuilder +12 -0
- data/app/views/json_ui/garage/forms/action_text.json.jbuilder +23 -0
- data/app/views/json_ui/garage/forms/action_text_conversion.json.jbuilder +5 -0
- data/app/views/json_ui/garage/forms/action_text_mentions.json.jbuilder +4 -0
- data/app/views/json_ui/garage/forms/dialogs_form.json.jbuilder +10 -10
- data/app/views/json_ui/garage/forms/dirty_prompt.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/dynamic_group.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/rich_text.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/show_hide.json.jbuilder +1 -1
- data/app/views/json_ui/garage/test_page/charts.json.jbuilder +4 -2
- data/app/views/json_ui/garage/test_page/fields_actionText.json.jbuilder +104 -1
- data/app/views/json_ui/garage/test_page/fields_richText.json.jbuilder +45 -1
- data/app/views/json_ui/garage/test_page/form_dirty_fields.json.jbuilder +1 -1
- data/app/views/json_ui/garage/test_page/form_hidden_panels.json.jbuilder +3 -22
- data/app/views/json_ui/garage/views/charts.json.jbuilder +4 -2
- data/lib/glib/all_helpers.rb +1 -0
- metadata +22 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 213673ab92ffc514108c0906bef9059e54b942c97f4ca28b26c1258f80cbcecf
|
|
4
|
+
data.tar.gz: 4d430ba703fb6c7078b5f24a4f907c97ec9aab16e930372b7b28b480faf59fed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d331c3ac21065411e0affeb2c768b69a6d262fb1da23b25461a82a0eb0db518de8ca9fa47bff4f42266b8480cbe6f6a0db79a4e781b58bf3765344754ef47fd
|
|
7
|
+
data.tar.gz: 9f5f63fe7a91547f739667bf3825c9639aa6fe4fd02f4088f6aa203343b8fb6529bbe53609ab5b6eb1523baddc1916215ed31ca80af378db88dfa1f9af6c92f1
|
|
@@ -20,14 +20,18 @@ module Glib
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def create
|
|
23
|
-
|
|
23
|
+
# Unqualified, `ActiveStorage` resolves to Glib::ActiveStorage inside this module. Its Blob
|
|
24
|
+
# subclass would leak into Action Text sgids (rendering as glib/active_storage/blobs/_blob,
|
|
25
|
+
# which doesn't exist) and may connect to the dynamic-text database.
|
|
26
|
+
blob = ::ActiveStorage::Blob.new # generate blob key
|
|
24
27
|
if blob_args[:prefix].present?
|
|
25
28
|
blob.key = "#{blob_args[:prefix]}/#{blob.key}"
|
|
26
29
|
end
|
|
27
30
|
blob.assign_attributes(**blob_args.except(:tagging, :prefix))
|
|
28
31
|
blob.save!
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
# GlibS3Service is only loaded when an app configures it, so referencing the constant breaks Disk-backed apps.
|
|
34
|
+
if blob.service.respond_to?(:tagging=)
|
|
31
35
|
blob.service.tagging = blob_args[:tagging]
|
|
32
36
|
end
|
|
33
37
|
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
module Glib
|
|
2
2
|
module FormatHelper
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"<s>#{text}</s>"
|
|
8
|
-
end
|
|
3
|
+
# Kept for existing callers; same output as glib_markdown_to_html.
|
|
4
|
+
def glib_format_markdown(content)
|
|
5
|
+
Glib::Markdown.to_html(content)
|
|
6
|
+
end
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
8
|
+
def glib_markdown_to_html(markdown, **options)
|
|
9
|
+
Glib::Markdown.to_html(markdown, **options)
|
|
13
10
|
end
|
|
14
11
|
|
|
15
|
-
def
|
|
16
|
-
|
|
17
|
-
markdown.render(content).delete("\n")
|
|
12
|
+
def glib_html_to_markdown(html, **options)
|
|
13
|
+
Glib::Markdown.from_html(html, **options)
|
|
18
14
|
end
|
|
19
15
|
end
|
|
20
16
|
end
|
|
@@ -65,18 +65,31 @@ module Glib
|
|
|
65
65
|
# `h[k] ||= default` a no-op. Reject such values before wrapping them.
|
|
66
66
|
#
|
|
67
67
|
# Returns true when `value` was rejected and the caller should fall back to {}.
|
|
68
|
-
# Raises only in development/test: such pages rendered (as {}) before this check
|
|
69
|
-
# existed, so production reports instead of turning them into 500s.
|
|
70
68
|
def reject_non_hash(propName, value)
|
|
71
69
|
return false if value.respond_to?(:to_hash)
|
|
72
70
|
|
|
73
71
|
message = "Hash property: '#{propName}' must be a hash, got #{value.inspect}"
|
|
74
|
-
raise ArgumentError, message if
|
|
72
|
+
raise ArgumentError, message if raise_hash_errors?
|
|
75
73
|
|
|
76
74
|
GLog.warn("#{message}; emitting {} instead")
|
|
77
75
|
true
|
|
78
76
|
end
|
|
79
77
|
|
|
78
|
+
def report_hash_errors(messages)
|
|
79
|
+
return if messages.empty?
|
|
80
|
+
|
|
81
|
+
message = messages.join('; ')
|
|
82
|
+
raise ArgumentError, message if raise_hash_errors?
|
|
83
|
+
|
|
84
|
+
GLog.warn("#{message}; emitting the hash unchanged")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Only development/test raise: pages with these mistakes rendered before the
|
|
88
|
+
# checks existed, so production reports instead of turning them into 500s.
|
|
89
|
+
def raise_hash_errors?
|
|
90
|
+
Rails.env.development? || Rails.env.test?
|
|
91
|
+
end
|
|
92
|
+
|
|
80
93
|
def self.component_name
|
|
81
94
|
@component_name ||= self.name.sub('Glib::JsonUi::ActionBuilder::', '')
|
|
82
95
|
end
|
|
@@ -311,7 +324,33 @@ module Glib
|
|
|
311
324
|
end
|
|
312
325
|
end
|
|
313
326
|
|
|
314
|
-
|
|
327
|
+
# Shortcuts so `schema:` literals don't need the full HashSchema constant, which
|
|
328
|
+
# files opened as `class Glib::JsonUi::ViewBuilder` can't resolve unqualified.
|
|
329
|
+
def self.schema_enum(*values)
|
|
330
|
+
HashSchema.enum(*values)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def self.schema_array_of(type)
|
|
334
|
+
HashSchema.array_of(type)
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def self.schema_open(spec)
|
|
338
|
+
HashSchema.open(spec)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
# `schema:` is the typed form (see HashSchema). `required:`/`optional:`/`nested:`
|
|
342
|
+
# are the older untyped shorthand, kept so existing declarations work unchanged.
|
|
343
|
+
def self.hash(propName, schema: nil, required: nil, optional: nil, nested: nil)
|
|
344
|
+
if schema && (required || optional || nested)
|
|
345
|
+
raise ArgumentError, "Hash property: '#{propName}' takes either schema: or required:/optional:/nested:, not both"
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
node = if schema
|
|
349
|
+
HashSchema.compile(schema)
|
|
350
|
+
else
|
|
351
|
+
HashSchema.from_legacy(required: required || [], optional: optional || [], nested: nested || {})
|
|
352
|
+
end
|
|
353
|
+
|
|
315
354
|
define_method(propName) do |value|
|
|
316
355
|
return if value.nil?
|
|
317
356
|
|
|
@@ -321,49 +360,7 @@ module Glib
|
|
|
321
360
|
end
|
|
322
361
|
|
|
323
362
|
value = ActiveSupport::HashWithIndifferentAccess.new(value)
|
|
324
|
-
|
|
325
|
-
required = options[:required] || []
|
|
326
|
-
optional = options[:optional] || []
|
|
327
|
-
|
|
328
|
-
required.each do |req|
|
|
329
|
-
raise ArgumentError, "Hash property: '#{req}' is required" if value[req.to_s].nil?
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
if optional.present?
|
|
333
|
-
value.except(*required).each do |k, v|
|
|
334
|
-
raise ArgumentError, "Unknown hash property: '#{k}'" if !optional.include?(k.to_sym)
|
|
335
|
-
end
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
# Sub-hash validation, one level deep: each `nested` key names a
|
|
339
|
-
# sub-hash whose own required/optional lists are checked the same
|
|
340
|
-
# way the top level is checked, so a typo inside a composite hash
|
|
341
|
-
# (e.g. a field's `draw` options) fails loudly at render time
|
|
342
|
-
# instead of passing silently. A nested spec that declares any
|
|
343
|
-
# keys (required or optional) CLOSES its sub-hash: keys outside
|
|
344
|
-
# required+optional raise. No recursion: sub-hashes of sub-hashes
|
|
345
|
-
# are the app's own data.
|
|
346
|
-
(options[:nested] || {}).each do |key, sub_options|
|
|
347
|
-
sub_value = value[key]
|
|
348
|
-
next if sub_value.nil?
|
|
349
|
-
raise ArgumentError, "Hash property: '#{key}' must be a hash" if !sub_value.is_a?(Hash)
|
|
350
|
-
|
|
351
|
-
sub_value = ActiveSupport::HashWithIndifferentAccess.new(sub_value)
|
|
352
|
-
sub_required = sub_options[:required] || []
|
|
353
|
-
sub_optional = sub_options[:optional] || []
|
|
354
|
-
|
|
355
|
-
sub_required.each do |req|
|
|
356
|
-
raise ArgumentError, "Hash property: '#{key}.#{req}' is required" if sub_value[req.to_s].nil?
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
allowed = sub_required + sub_optional
|
|
360
|
-
if allowed.present?
|
|
361
|
-
sub_value.each_key do |k|
|
|
362
|
-
raise ArgumentError, "Unknown hash property: '#{key}.#{k}'" if !allowed.include?(k.to_sym)
|
|
363
|
-
end
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
|
|
363
|
+
report_hash_errors(HashSchema.errors(value, node, propName))
|
|
367
364
|
json.set! propName, value
|
|
368
365
|
end
|
|
369
366
|
end
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Typed, recursive validation for `hash` props (see JsonUiElement.hash).
|
|
2
|
+
#
|
|
3
|
+
# hash :draw, schema: {
|
|
4
|
+
# hint: :string,
|
|
5
|
+
# savedSignature: { value!: :string, fileUrl!: :string },
|
|
6
|
+
# saveOption: { name!: :string, value: :bool, tooltip: { text!: :string } }
|
|
7
|
+
# }
|
|
8
|
+
#
|
|
9
|
+
# Validate only as deep as the frontend reads keys. Below that (Chart.js
|
|
10
|
+
# options, app data) stop with `:hash` or `:any`, otherwise glib would have to
|
|
11
|
+
# mirror a third-party schema and every new option would need a glib release.
|
|
12
|
+
module Glib
|
|
13
|
+
module JsonUi
|
|
14
|
+
class HashSchema
|
|
15
|
+
Node = Struct.new(:keys, :open)
|
|
16
|
+
Enum = Struct.new(:values)
|
|
17
|
+
ArrayOf = Struct.new(:type)
|
|
18
|
+
|
|
19
|
+
SCALARS = {
|
|
20
|
+
any: ->(_v) { true },
|
|
21
|
+
string: ->(v) { v.is_a?(String) || v.is_a?(Symbol) },
|
|
22
|
+
int: ->(v) { v.is_a?(Integer) },
|
|
23
|
+
number: ->(v) { v.is_a?(Numeric) },
|
|
24
|
+
bool: ->(v) { v == true || v == false },
|
|
25
|
+
hash: ->(v) { v.respond_to?(:to_hash) },
|
|
26
|
+
array: ->(v) { v.is_a?(Array) }
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
DESCRIPTIONS = {
|
|
30
|
+
any: 'anything',
|
|
31
|
+
string: 'a string',
|
|
32
|
+
int: 'an integer',
|
|
33
|
+
number: 'a number',
|
|
34
|
+
bool: 'a boolean',
|
|
35
|
+
hash: 'a hash',
|
|
36
|
+
array: 'an array'
|
|
37
|
+
}.freeze
|
|
38
|
+
|
|
39
|
+
def self.enum(*values)
|
|
40
|
+
Enum.new(values.freeze)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.array_of(type)
|
|
44
|
+
ArrayOf.new(compile(type))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Types the listed keys but still accepts others, for hashes where the
|
|
48
|
+
# frontend reads more keys than glib has typed yet.
|
|
49
|
+
def self.open(spec)
|
|
50
|
+
raise ArgumentError, "HashSchema.open takes a hash, got #{spec.inspect}" if !spec.is_a?(Hash)
|
|
51
|
+
|
|
52
|
+
Node.new(compile(spec).keys, true)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Runs once per `hash` declaration, at class load, so a typo in the schema
|
|
56
|
+
# itself fails when the builder loads rather than when a page renders.
|
|
57
|
+
def self.compile(spec)
|
|
58
|
+
case spec
|
|
59
|
+
when Node, Enum, ArrayOf
|
|
60
|
+
spec
|
|
61
|
+
when Symbol
|
|
62
|
+
raise ArgumentError, "Invalid hash schema type: #{spec.inspect}" if !SCALARS.key?(spec)
|
|
63
|
+
|
|
64
|
+
spec
|
|
65
|
+
when Array
|
|
66
|
+
raise ArgumentError, 'A hash schema union needs at least one type' if spec.empty?
|
|
67
|
+
|
|
68
|
+
spec.map { |type| compile(type) }.freeze
|
|
69
|
+
when Hash
|
|
70
|
+
keys = spec.to_h do |key, type|
|
|
71
|
+
name = key.to_s
|
|
72
|
+
required = name.end_with?('!')
|
|
73
|
+
name = name.delete_suffix('!') if required
|
|
74
|
+
raise ArgumentError, "Invalid hash schema key: #{key.inspect}" if name.empty?
|
|
75
|
+
|
|
76
|
+
[name, [compile(type), required].freeze]
|
|
77
|
+
end
|
|
78
|
+
Node.new(keys.freeze, false)
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "Invalid hash schema type: #{spec.inspect}"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Translates the pre-schema options so both forms share one code path, while
|
|
85
|
+
# keeping their looser rules: the top level is open unless `optional` is
|
|
86
|
+
# given, and a nested spec is open unless it declares keys.
|
|
87
|
+
def self.from_legacy(required: [], optional: [], nested: {})
|
|
88
|
+
keys = legacy_keys(required, optional)
|
|
89
|
+
open = optional.empty?
|
|
90
|
+
nested.each do |key, sub|
|
|
91
|
+
# Legacy `nested` only described a key's sub-hash; it never allowed a key
|
|
92
|
+
# that a closed top level didn't already list.
|
|
93
|
+
next if !open && !keys.key?(key.to_s)
|
|
94
|
+
|
|
95
|
+
sub_required = sub[:required] || []
|
|
96
|
+
sub_optional = sub[:optional] || []
|
|
97
|
+
sub_node = Node.new(legacy_keys(sub_required, sub_optional).freeze, sub_required.empty? && sub_optional.empty?)
|
|
98
|
+
keys[key.to_s] = [sub_node, keys.dig(key.to_s, 1) || false].freeze
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
Node.new(keys.freeze, open)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.legacy_keys(required, optional)
|
|
105
|
+
keys = {}
|
|
106
|
+
optional.each { |key| keys[key.to_s] = [:any, false].freeze }
|
|
107
|
+
required.each { |key| keys[key.to_s] = [:any, true].freeze }
|
|
108
|
+
keys
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Returns error messages rather than raising, so the caller decides how
|
|
112
|
+
# each environment reports them.
|
|
113
|
+
def self.errors(value, type, path)
|
|
114
|
+
case type
|
|
115
|
+
when Symbol
|
|
116
|
+
SCALARS.fetch(type).call(value) ? [] : [mismatch(path, type, value)]
|
|
117
|
+
when Array
|
|
118
|
+
type.any? { |member| errors(value, member, path).empty? } ? [] : [mismatch(path, type, value)]
|
|
119
|
+
when Enum
|
|
120
|
+
enum_match?(type.values, value) ? [] : [mismatch(path, type, value)]
|
|
121
|
+
when ArrayOf
|
|
122
|
+
return [mismatch(path, type, value)] if !value.is_a?(Array)
|
|
123
|
+
|
|
124
|
+
value.each_with_index.flat_map { |item, i| errors(item, type.type, "#{path}[#{i}]") }
|
|
125
|
+
when Node
|
|
126
|
+
node_errors(value, type, path)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.node_errors(value, node, path)
|
|
131
|
+
return [mismatch(path, node, value)] if !value.respond_to?(:to_hash)
|
|
132
|
+
|
|
133
|
+
value = value.to_hash.stringify_keys if !value.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
|
134
|
+
messages = []
|
|
135
|
+
|
|
136
|
+
if !node.open
|
|
137
|
+
value.each_key do |key|
|
|
138
|
+
messages << "Unknown hash property: '#{path}.#{key}'" if !node.keys.key?(key.to_s)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
node.keys.each do |key, (type, required)|
|
|
143
|
+
sub_value = value[key]
|
|
144
|
+
if sub_value.nil?
|
|
145
|
+
messages << "Hash property: '#{path}.#{key}' is required" if required
|
|
146
|
+
next
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
messages.concat(errors(sub_value, type, "#{path}.#{key}"))
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
messages
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def self.enum_match?(allowed, value)
|
|
156
|
+
allowed.any? do |option|
|
|
157
|
+
option == value || (stringish?(option) && stringish?(value) && option.to_s == value.to_s)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def self.stringish?(value)
|
|
162
|
+
value.is_a?(String) || value.is_a?(Symbol)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def self.mismatch(path, type, value)
|
|
166
|
+
"Hash property: '#{path}' must be #{describe(type)}, got #{value.inspect}"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def self.describe(type)
|
|
170
|
+
case type
|
|
171
|
+
when Symbol then DESCRIPTIONS.fetch(type)
|
|
172
|
+
when Array then type.map { |member| describe(member) }.join(' or ')
|
|
173
|
+
when Enum then "one of #{type.values.map(&:inspect).join(', ')}"
|
|
174
|
+
when ArrayOf then "an array of items that are each #{describe(type.type)}"
|
|
175
|
+
when Node then 'a hash'
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
private_class_method :legacy_keys, :node_errors, :enum_match?, :stringish?, :mismatch, :describe
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
@@ -40,7 +40,7 @@ module Glib
|
|
|
40
40
|
action :onLongPress
|
|
41
41
|
icon :icon
|
|
42
42
|
# bool :avatar
|
|
43
|
-
hash :avatar,
|
|
43
|
+
hash :avatar, schema: { url: :string, initials: { text!: :string, color: :string }, backgroundColor: :string }
|
|
44
44
|
# action :onReorder
|
|
45
45
|
string :paramNameForFormData
|
|
46
46
|
string :paramNameForNewAbsoluteIndex
|
|
@@ -93,7 +93,7 @@ module Glib
|
|
|
93
93
|
string :subtitle
|
|
94
94
|
action :onClick
|
|
95
95
|
hash :dropData
|
|
96
|
-
hash :icon,
|
|
96
|
+
hash :icon, schema: { name!: :string, color: :string, size: [:number, :string] }
|
|
97
97
|
array :rows
|
|
98
98
|
end
|
|
99
99
|
end
|
|
@@ -8,14 +8,19 @@ module Glib
|
|
|
8
8
|
class MenuItem < JsonUiElement
|
|
9
9
|
include Builder::MouseEvents
|
|
10
10
|
|
|
11
|
-
hash :analytics,
|
|
12
|
-
hash :tooltip,
|
|
11
|
+
hash :analytics, schema: { featured: :any, disabled: :bool, group: :string, action: :string }
|
|
12
|
+
hash :tooltip, schema: { text!: :string, placement: :string, position: :string }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
class Button < MenuItem
|
|
16
16
|
badgeable
|
|
17
17
|
|
|
18
|
-
hash :avatar,
|
|
18
|
+
hash :avatar, schema: {
|
|
19
|
+
size: [:number, :string],
|
|
20
|
+
backgroundColor: :string,
|
|
21
|
+
url: :string,
|
|
22
|
+
initials: { text!: :string, color: :string }
|
|
23
|
+
}
|
|
19
24
|
string :text
|
|
20
25
|
icon :icon
|
|
21
26
|
action :onClick
|
|
@@ -73,8 +73,20 @@ class Glib::JsonUi::ViewBuilder
|
|
|
73
73
|
int :min
|
|
74
74
|
int :max
|
|
75
75
|
# https://www.chartjs.org/docs/latest/configuration/legend.html
|
|
76
|
-
hash :legend,
|
|
77
|
-
|
|
76
|
+
hash :legend, schema: {
|
|
77
|
+
position: [schema_enum(:top, :left, :bottom, :right, :chartArea), :hash],
|
|
78
|
+
align: schema_enum(:start, :center, :end),
|
|
79
|
+
display: :bool,
|
|
80
|
+
maxHeight: :number,
|
|
81
|
+
maxWidth: :number,
|
|
82
|
+
fullSize: :bool,
|
|
83
|
+
reverse: :bool,
|
|
84
|
+
labels: :hash,
|
|
85
|
+
rtl: :bool,
|
|
86
|
+
title: :hash,
|
|
87
|
+
override: :bool
|
|
88
|
+
}
|
|
89
|
+
hash :plugins, schema: { datalabels: [:hash, :bool], centerLabel: { labels: :array }, customTooltip: :bool }
|
|
78
90
|
end
|
|
79
91
|
end
|
|
80
92
|
|
|
@@ -575,7 +575,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
575
575
|
|
|
576
576
|
# Image to display instead of standard checkbox.
|
|
577
577
|
# @example image: { url: '/checkmark.png', template: 'image', width: 24, height: 24 }
|
|
578
|
-
hash :image,
|
|
578
|
+
hash :image, schema: { url!: :string, template!: :string, width: [:number, :string], height: [:number, :string] }
|
|
579
579
|
|
|
580
580
|
# Shows indeterminate state (partially checked).
|
|
581
581
|
# Useful for "select all" checkboxes when some but not all children are selected.
|
|
@@ -609,6 +609,11 @@ class Glib::JsonUi::ViewBuilder
|
|
|
609
609
|
|
|
610
610
|
# Rich text editor field with WYSIWYG editing.
|
|
611
611
|
#
|
|
612
|
+
# @deprecated Quill has an unfixed XSS advisory. Use `fields_actionText` for rich text, or
|
|
613
|
+
# `fields_textarea` where users write markdown themselves. See the glib-web-npm
|
|
614
|
+
# `doc/rich_text_migration.md` guide. For `produce:`/`accept: :markdown`, convert on the
|
|
615
|
+
# server with `Glib::Markdown.to_html` / `.from_html` (doc/common/cookbook/markdown_with_action_text.md).
|
|
616
|
+
#
|
|
612
617
|
# Provides a full-featured text editor with formatting options, image uploads,
|
|
613
618
|
# and @mention support. Can output HTML or Markdown.
|
|
614
619
|
#
|
|
@@ -645,7 +650,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
645
650
|
# directUploadUrl: rails_direct_uploads_path,
|
|
646
651
|
# accepts: 'image/png,image/jpeg'
|
|
647
652
|
# }
|
|
648
|
-
hash :imageUploader,
|
|
653
|
+
hash :imageUploader, schema: { name!: :string, accepts: [:string, :hash], directUploadUrl: :string, blobUrlGenerator: :string }
|
|
649
654
|
|
|
650
655
|
# Output format for the editor content.
|
|
651
656
|
enum :produce, options: [:html, :markdown]
|
|
@@ -663,6 +668,16 @@ class Glib::JsonUi::ViewBuilder
|
|
|
663
668
|
|
|
664
669
|
# Enables debug mode with additional logging.
|
|
665
670
|
bool :debug
|
|
671
|
+
|
|
672
|
+
# Override
|
|
673
|
+
def created
|
|
674
|
+
super
|
|
675
|
+
# Local only: every render of every richText field would otherwise flood remote logging.
|
|
676
|
+
GLog.local_warn(
|
|
677
|
+
'`fields_richText` is deprecated: use `fields_actionText`, or `fields_textarea` for ' \
|
|
678
|
+
'markdown input. See doc/rich_text_migration.md in glib-web-npm.'
|
|
679
|
+
)
|
|
680
|
+
end
|
|
666
681
|
end
|
|
667
682
|
|
|
668
683
|
# Trix editor field that submits the same HTML as Rails' Action Text form helper,
|
|
@@ -676,6 +691,10 @@ class Glib::JsonUi::ViewBuilder
|
|
|
676
691
|
# When `prop` refers to a `has_rich_text` attribute, the field is pre-filled with the
|
|
677
692
|
# attribute's `to_trix_html`.
|
|
678
693
|
#
|
|
694
|
+
# The field only speaks HTML. To edit Markdown, pre-fill with `Glib::Markdown.to_html` and
|
|
695
|
+
# convert the submitted value with `Glib::Markdown.from_html`
|
|
696
|
+
# (see doc/common/cookbook/markdown_with_action_text.md).
|
|
697
|
+
#
|
|
679
698
|
# @example Action Text attribute on a model form
|
|
680
699
|
# form.fields_actionText \
|
|
681
700
|
# prop: :body,
|
|
@@ -709,6 +728,28 @@ class Glib::JsonUi::ViewBuilder
|
|
|
709
728
|
# @example libraryUrl: media_picks_url(target: 'post_body')
|
|
710
729
|
string :libraryUrl
|
|
711
730
|
|
|
731
|
+
# People offered when the user types `@`. Each item is
|
|
732
|
+
# `{ sgid:, value:, text:, avatar:, group: }`; only `value` is required. An item with an
|
|
733
|
+
# `sgid` is inserted as an Action Text attachment that `has_rich_text` resolves to the
|
|
734
|
+
# record (its model must include `ActionText::Attachable`). When the sgid does not resolve
|
|
735
|
+
# (a plain column, a deleted record), the attachment renders its own `@value` text. An
|
|
736
|
+
# item without an `sgid` is inserted as plain `@value` text.
|
|
737
|
+
# @example mentionList: users.map { |u| { sgid: u.attachable_sgid, value: u.name } }
|
|
738
|
+
array :mentionList
|
|
739
|
+
|
|
740
|
+
# Endpoint searched as the user types after `@` (`GET <url>?term=...`), returning
|
|
741
|
+
# `{ items: [...] }` in the `mentionList` item shape. Replaces filtering `mentionList`.
|
|
742
|
+
# @example mentionUrl: mention_searches_url
|
|
743
|
+
string :mentionUrl
|
|
744
|
+
|
|
745
|
+
# Hides the formatting toolbar, e.g. for a chat input. Keyboard shortcuts (Ctrl/Cmd+B, …)
|
|
746
|
+
# and pasting or dropping files (when uploads are configured) still work.
|
|
747
|
+
bool :hideToolbar
|
|
748
|
+
|
|
749
|
+
# Enter submits the enclosing form and Shift+Enter inserts a line break. While a mention
|
|
750
|
+
# list is open, Enter picks from it instead.
|
|
751
|
+
bool :submitOnEnter
|
|
752
|
+
|
|
712
753
|
def created
|
|
713
754
|
super
|
|
714
755
|
file_upload_error_handler_on_create
|
|
@@ -729,7 +770,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
729
770
|
bool :multiple, cache: true
|
|
730
771
|
# bool :manualEntry
|
|
731
772
|
icon :leftIcon
|
|
732
|
-
hash :append,
|
|
773
|
+
hash :append, schema: { icon: :string }
|
|
733
774
|
|
|
734
775
|
panels_builder :accessory, :header, :footer
|
|
735
776
|
bool :clearable
|
|
@@ -837,8 +878,8 @@ class Glib::JsonUi::ViewBuilder
|
|
|
837
878
|
action :onClick
|
|
838
879
|
string :offIcon
|
|
839
880
|
string :onIcon
|
|
840
|
-
hash :image,
|
|
841
|
-
hash :icon,
|
|
881
|
+
hash :image, schema: { url!: :string, template!: :string, width: [:number, :string], height: [:number, :string], subtitle: :string }
|
|
882
|
+
hash :icon, schema: { name!: :string, template!: :string, color: :string, size: [:number, :string], subtitle: :string }
|
|
842
883
|
|
|
843
884
|
views :childViews
|
|
844
885
|
end
|
|
@@ -864,9 +905,15 @@ class Glib::JsonUi::ViewBuilder
|
|
|
864
905
|
bool :multiple, cache: true
|
|
865
906
|
# `url` is the current file's image; `emptyUrl` is shown whenever there is no file
|
|
866
907
|
# (none attached, or after the field is reset), otherwise a neutral box is shown.
|
|
867
|
-
hash :placeholderView,
|
|
868
|
-
|
|
869
|
-
|
|
908
|
+
hash :placeholderView, schema: {
|
|
909
|
+
type!: schema_enum(:image, :avatar),
|
|
910
|
+
width!: [:number, :string],
|
|
911
|
+
height!: [:number, :string],
|
|
912
|
+
url: :string,
|
|
913
|
+
emptyUrl: :string
|
|
914
|
+
}
|
|
915
|
+
hash :inputView, schema: { files: :array, variant: :string }
|
|
916
|
+
hash :clipboardView, schema: { icon: :string }
|
|
870
917
|
|
|
871
918
|
def multiProgressView(values)
|
|
872
919
|
# Consumers naturally write jbuilder hashes with symbol keys, but the
|
|
@@ -1031,7 +1078,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
1031
1078
|
# `name` is still accepted but unused: the typed name is submitted
|
|
1032
1079
|
# through the field's own param (single-param contract), and the
|
|
1033
1080
|
# server routes it to the name attribute.
|
|
1034
|
-
hash :typedName,
|
|
1081
|
+
hash :typedName, schema: { name: :string, value: :string, label: :string, placeholder: :string }
|
|
1035
1082
|
|
|
1036
1083
|
# Run instead of opening the dialog while the field is BLANK (a filled box
|
|
1037
1084
|
# always opens the dialog on what it holds). The app composes whatever the
|
|
@@ -1056,11 +1103,13 @@ class Glib::JsonUi::ViewBuilder
|
|
|
1056
1103
|
# id or the typed name. Distinct from `fileUrl` above: that is the box's OWN
|
|
1057
1104
|
# value on re-edit, pre-filled and, like any painted drawing, read-only on
|
|
1058
1105
|
# the canvas until cleared.
|
|
1059
|
-
hash :draw,
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1106
|
+
hash :draw, schema: {
|
|
1107
|
+
hint: :string,
|
|
1108
|
+
placeholder: :string,
|
|
1109
|
+
confirmedHint: :string,
|
|
1110
|
+
savedSignature: { value!: :string, fileUrl!: :string },
|
|
1111
|
+
saveOption: { name!: :string, label: :string, value: :bool, tooltip: { text!: :string } }
|
|
1112
|
+
}
|
|
1064
1113
|
|
|
1065
1114
|
# Override
|
|
1066
1115
|
# A stored signature is an attachment -- submit its signed id (mirrors
|
|
@@ -1128,7 +1177,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
1128
1177
|
enum :type, options: [:month]
|
|
1129
1178
|
bool :clearable
|
|
1130
1179
|
bool :buttonTemplate # TODO: Remove
|
|
1131
|
-
hash :template,
|
|
1180
|
+
hash :template, schema: schema_open(type!: :string)
|
|
1132
1181
|
string :time_zone
|
|
1133
1182
|
enum :format, options: DATE_FORMAT_OPTIONS
|
|
1134
1183
|
|
|
@@ -1148,7 +1197,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
1148
1197
|
enum :format, options: DATE_FORMAT_OPTIONS
|
|
1149
1198
|
|
|
1150
1199
|
bool :buttonTemplate # TODO: Remove
|
|
1151
|
-
hash :template,
|
|
1200
|
+
hash :template, schema: schema_open(type!: :string)
|
|
1152
1201
|
end
|
|
1153
1202
|
|
|
1154
1203
|
# Location/address field with Google Places autocomplete integration.
|
|
@@ -1190,7 +1239,7 @@ class Glib::JsonUi::ViewBuilder
|
|
|
1190
1239
|
# fields: ['formatted_address', 'geometry']
|
|
1191
1240
|
# }
|
|
1192
1241
|
# @see https://developers.google.com/maps/documentation/javascript/reference/places-widget#AutocompleteOptions
|
|
1193
|
-
hash :autocompleteOptions,
|
|
1242
|
+
hash :autocompleteOptions, schema: { bounds: :hash, componentRestrictions: :hash, fields: :array, strictBounds: :bool, types: :array }
|
|
1194
1243
|
end
|
|
1195
1244
|
|
|
1196
1245
|
# Stripe payment token field for secure card tokenization.
|