reactiveadmin 0.2.0
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 +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/app/assets/reactive_admin/bridge.js +89 -0
- data/app/controllers/reactive_admin/api_controller.rb +30 -0
- data/app/controllers/reactive_admin/client_errors_controller.rb +38 -0
- data/app/controllers/reactive_admin/manifest_controller.rb +10 -0
- data/app/controllers/reactive_admin/mcp_controller.rb +48 -0
- data/app/controllers/reactive_admin/openapi_controller.rb +13 -0
- data/app/controllers/reactive_admin/session_controller.rb +11 -0
- data/app/views/layouts/reactive_admin/embed.html.erb +30 -0
- data/lib/generators/reactiveadmin/install/install_generator.rb +341 -0
- data/lib/generators/reactiveadmin/install/templates/menu.rb.tt +25 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin.rb.tt +53 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin_annotated.rb.tt +110 -0
- data/lib/reactive_admin/aa/v3/controller.rb +76 -0
- data/lib/reactive_admin/aa/v3/forms.rb +29 -0
- data/lib/reactive_admin/aa/v3/inputs/filters/typeahead_input.rb +51 -0
- data/lib/reactive_admin/aa/v3/inputs/typeahead_input.rb +8 -0
- data/lib/reactive_admin/aa/v3/install.rb +36 -0
- data/lib/reactive_admin/aa/v3/menu.rb +67 -0
- data/lib/reactive_admin/aa/v3/presenters.rb +102 -0
- data/lib/reactive_admin/aa/v3/registry.rb +78 -0
- data/lib/reactive_admin/aa/v3/views.rb +63 -0
- data/lib/reactive_admin/aa/v3.rb +23 -0
- data/lib/reactive_admin/aa/v4.rb +59 -0
- data/lib/reactive_admin/aa.rb +46 -0
- data/lib/reactive_admin/action_items.rb +39 -0
- data/lib/reactive_admin/action_links.rb +197 -0
- data/lib/reactive_admin/action_safety.rb +19 -0
- data/lib/reactive_admin/actions.rb +95 -0
- data/lib/reactive_admin/api_errors.rb +116 -0
- data/lib/reactive_admin/api_fallback.rb +15 -0
- data/lib/reactive_admin/api_guards.rb +445 -0
- data/lib/reactive_admin/audit.rb +72 -0
- data/lib/reactive_admin/auth/guard.rb +68 -0
- data/lib/reactive_admin/auth/token_requests.rb +15 -0
- data/lib/reactive_admin/auth.rb +135 -0
- data/lib/reactive_admin/authorizer.rb +47 -0
- data/lib/reactive_admin/background_requests.rb +33 -0
- data/lib/reactive_admin/batch_actions.rb +57 -0
- data/lib/reactive_admin/choices.rb +289 -0
- data/lib/reactive_admin/client_error.rb +70 -0
- data/lib/reactive_admin/composite_keys.rb +12 -0
- data/lib/reactive_admin/configuration.rb +221 -0
- data/lib/reactive_admin/controller_extension.rb +229 -0
- data/lib/reactive_admin/csv_injection.rb +26 -0
- data/lib/reactive_admin/date_bound.rb +31 -0
- data/lib/reactive_admin/degradation.rb +72 -0
- data/lib/reactive_admin/diagnostics.rb +16 -0
- data/lib/reactive_admin/doctor.rb +466 -0
- data/lib/reactive_admin/dry_run.rb +147 -0
- data/lib/reactive_admin/dry_run_flag.rb +18 -0
- data/lib/reactive_admin/embed.rb +73 -0
- data/lib/reactive_admin/engine.rb +47 -0
- data/lib/reactive_admin/error_keys.rb +23 -0
- data/lib/reactive_admin/exposure.rb +86 -0
- data/lib/reactive_admin/filters.rb +165 -0
- data/lib/reactive_admin/fixtures/scrubber.rb +1075 -0
- data/lib/reactive_admin/fixtures.rb +161 -0
- data/lib/reactive_admin/form_content.rb +78 -0
- data/lib/reactive_admin/form_field.rb +279 -0
- data/lib/reactive_admin/form_has_many.rb +116 -0
- data/lib/reactive_admin/form_lock.rb +71 -0
- data/lib/reactive_admin/form_payload.rb +57 -0
- data/lib/reactive_admin/form_recorder.rb +192 -0
- data/lib/reactive_admin/form_schema.rb +160 -0
- data/lib/reactive_admin/frame.rb +97 -0
- data/lib/reactive_admin/html_nodes.rb +390 -0
- data/lib/reactive_admin/html_policy.rb +338 -0
- data/lib/reactive_admin/html_rich.rb +186 -0
- data/lib/reactive_admin/implicit_defaults.rb +102 -0
- data/lib/reactive_admin/index_options.rb +41 -0
- data/lib/reactive_admin/index_payload.rb +259 -0
- data/lib/reactive_admin/index_recorder.rb +115 -0
- data/lib/reactive_admin/index_views.rb +85 -0
- data/lib/reactive_admin/inline_style.rb +125 -0
- data/lib/reactive_admin/labels_payload.rb +34 -0
- data/lib/reactive_admin/ladder.rb +268 -0
- data/lib/reactive_admin/layout_classes.rb +167 -0
- data/lib/reactive_admin/legacy_inventory.rb +547 -0
- data/lib/reactive_admin/location.rb +22 -0
- data/lib/reactive_admin/lookup_audit.rb +30 -0
- data/lib/reactive_admin/lookup_payload.rb +41 -0
- data/lib/reactive_admin/manifest.rb +36 -0
- data/lib/reactive_admin/masked_json.rb +62 -0
- data/lib/reactive_admin/masking.rb +100 -0
- data/lib/reactive_admin/mcp/access.rb +111 -0
- data/lib/reactive_admin/mcp/api.rb +123 -0
- data/lib/reactive_admin/mcp/count_tool.rb +22 -0
- data/lib/reactive_admin/mcp/layout.rb +175 -0
- data/lib/reactive_admin/mcp/output.rb +46 -0
- data/lib/reactive_admin/mcp/prompts.rb +111 -0
- data/lib/reactive_admin/mcp/server.rb +134 -0
- data/lib/reactive_admin/mcp/shapes.rb +164 -0
- data/lib/reactive_admin/mcp/tools.rb +386 -0
- data/lib/reactive_admin/mcp.rb +53 -0
- data/lib/reactive_admin/media_nodes.rb +34 -0
- data/lib/reactive_admin/menu.rb +90 -0
- data/lib/reactive_admin/menu_overlay.rb +291 -0
- data/lib/reactive_admin/node_registry.rb +47 -0
- data/lib/reactive_admin/open_api/builder.rb +156 -0
- data/lib/reactive_admin/open_api/context.rb +46 -0
- data/lib/reactive_admin/open_api/core.rb +51 -0
- data/lib/reactive_admin/open_api/operation_ids.rb +18 -0
- data/lib/reactive_admin/open_api/page_doc.rb +75 -0
- data/lib/reactive_admin/open_api/parts.rb +86 -0
- data/lib/reactive_admin/open_api/resource_doc.rb +423 -0
- data/lib/reactive_admin/open_api/security.rb +55 -0
- data/lib/reactive_admin/open_api/write_schema.rb +104 -0
- data/lib/reactive_admin/open_api.rb +41 -0
- data/lib/reactive_admin/option_source.rb +36 -0
- data/lib/reactive_admin/option_sources.rb +14 -0
- data/lib/reactive_admin/options_payload.rb +61 -0
- data/lib/reactive_admin/page_controller_extension.rb +112 -0
- data/lib/reactive_admin/page_forms.rb +181 -0
- data/lib/reactive_admin/page_payload.rb +120 -0
- data/lib/reactive_admin/param_normalizer.rb +89 -0
- data/lib/reactive_admin/paths.rb +63 -0
- data/lib/reactive_admin/permissions.rb +31 -0
- data/lib/reactive_admin/provenance.rb +57 -0
- data/lib/reactive_admin/query_guard.rb +108 -0
- data/lib/reactive_admin/ransack_guard.rb +107 -0
- data/lib/reactive_admin/rate_limit.rb +59 -0
- data/lib/reactive_admin/reactive_dsl.rb +99 -0
- data/lib/reactive_admin/readiness.rb +189 -0
- data/lib/reactive_admin/registry.rb +69 -0
- data/lib/reactive_admin/resource_meta.rb +120 -0
- data/lib/reactive_admin/resource_summary.rb +41 -0
- data/lib/reactive_admin/routes.rb +60 -0
- data/lib/reactive_admin/row_errors.rb +29 -0
- data/lib/reactive_admin/rspec.rb +116 -0
- data/lib/reactive_admin/scrubbed_error.rb +22 -0
- data/lib/reactive_admin/search.rb +79 -0
- data/lib/reactive_admin/server_timing.rb +31 -0
- data/lib/reactive_admin/show_payload.rb +88 -0
- data/lib/reactive_admin/sidebars.rb +34 -0
- data/lib/reactive_admin/site.rb +55 -0
- data/lib/reactive_admin/style_report.rb +129 -0
- data/lib/reactive_admin/style_sources.rb +83 -0
- data/lib/reactive_admin/template_actions.rb +126 -0
- data/lib/reactive_admin/template_content.rb +49 -0
- data/lib/reactive_admin/template_form.rb +442 -0
- data/lib/reactive_admin/test_support.rb +31 -0
- data/lib/reactive_admin/typeahead.rb +33 -0
- data/lib/reactive_admin/ui/assets.rb +91 -0
- data/lib/reactive_admin/ui/client_build.rb +47 -0
- data/lib/reactive_admin/ui/helper.rb +24 -0
- data/lib/reactive_admin/ui/packaged_client.rb +67 -0
- data/lib/reactive_admin/ui/shell.rb +81 -0
- data/lib/reactive_admin/ui/switch.rb +38 -0
- data/lib/reactive_admin/ui.rb +43 -0
- data/lib/reactive_admin/value_payload.rb +147 -0
- data/lib/reactive_admin/value_token.rb +36 -0
- data/lib/reactive_admin/values.rb +43 -0
- data/lib/reactive_admin/version.rb +3 -0
- data/lib/reactive_admin/write_audit.rb +60 -0
- data/lib/reactive_admin/write_guards.rb +142 -0
- data/lib/reactive_admin.rb +153 -0
- data/lib/reactiveadmin.rb +1 -0
- data/lib/tasks/reactiveadmin.rake +36 -0
- data/lib/tasks/reactiveadmin_client.rake +11 -0
- data/lib/tasks/reactiveadmin_legacy.rake +7 -0
- data/lib/tasks/reactiveadmin_styles.rake +6 -0
- data/openapi/core.yaml +1643 -0
- data/vendor/client/assets/ActionPage-XUYorI8E.js +1 -0
- data/vendor/client/assets/ActionView-BsZFcsgp.js +1 -0
- data/vendor/client/assets/CommandPalette-C59HT1ip.js +1 -0
- data/vendor/client/assets/DatePicker-DuaK0iMg.js +1 -0
- data/vendor/client/assets/DateRangeCalendar-B2BDsG-X.js +1 -0
- data/vendor/client/assets/DegradedNotice-DiH5n2DO.js +1 -0
- data/vendor/client/assets/FormDialog-pmYl8Eov.js +1 -0
- data/vendor/client/assets/FormSkeleton-DuSBZO3C.js +1 -0
- data/vendor/client/assets/FrameView-2X8cFvUt.css +1 -0
- data/vendor/client/assets/FrameView-zmUeDO8d.js +1 -0
- data/vendor/client/assets/GroupOverview-DI5T3k5K.js +1 -0
- data/vendor/client/assets/InlineForm-CMEIMgeh.js +1 -0
- data/vendor/client/assets/JsonDiff-o7JWr7CH.js +3 -0
- data/vendor/client/assets/JsonEditor-D4VXdlEx.js +1 -0
- data/vendor/client/assets/JsonView-BrJLDmSN.js +1 -0
- data/vendor/client/assets/MobileMenu-GAeFOeEb.js +1 -0
- data/vendor/client/assets/Node-SQl61V4K.js +2 -0
- data/vendor/client/assets/PageView-C-laNEPZ.js +1 -0
- data/vendor/client/assets/ResourceForm-BPjsoCY6.js +1 -0
- data/vendor/client/assets/ResourceIndex-COezAw5t.js +3 -0
- data/vendor/client/assets/ResourceOrPage-CRZGCY84.js +1 -0
- data/vendor/client/assets/ResourceShow-DweRXn18.js +1 -0
- data/vendor/client/assets/Segmented-BE9TCbph.js +1 -0
- data/vendor/client/assets/Sidebars-CsB9rFqX.js +1 -0
- data/vendor/client/assets/breadcrumb-DSA3Tlyd.js +1 -0
- data/vendor/client/assets/button-CvZ4_DFC.js +1 -0
- data/vendor/client/assets/calendar-BoyMpJIf.js +1 -0
- data/vendor/client/assets/check-C5A3J16N.js +1 -0
- data/vendor/client/assets/command-CMuk0oAt.js +1 -0
- data/vendor/client/assets/dist-CqEI82S_.js +1 -0
- data/vendor/client/assets/dist-IW4yX942.js +1 -0
- data/vendor/client/assets/editor-yqRLzgsJ.js +2 -0
- data/vendor/client/assets/external-link-C2aR4slL.js +1 -0
- data/vendor/client/assets/frames-C9gPCc3N.js +1 -0
- data/vendor/client/assets/humanize-DtU_Kpr4.js +1 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- data/vendor/client/assets/index-B51aUaAY.js +43 -0
- data/vendor/client/assets/index-Cs9rCoWM.css +2 -0
- data/vendor/client/assets/input-DByFmQPa.js +1 -0
- data/vendor/client/assets/json-De3PN-R6.css +1 -0
- data/vendor/client/assets/json-oTp7Q-d-.js +5 -0
- data/vendor/client/assets/media-D4a_En8R.js +1 -0
- data/vendor/client/assets/plus-CfJ9vo8X.js +1 -0
- data/vendor/client/assets/popover-CDtI9R8Q.js +1 -0
- data/vendor/client/assets/purify-G7QKJyJq.js +1 -0
- data/vendor/client/assets/query-CCsZN2fa.js +1 -0
- data/vendor/client/assets/recent-BrzLwL0D.js +1 -0
- data/vendor/client/assets/rich-BQc_q5T7.js +1 -0
- data/vendor/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- data/vendor/client/assets/select-C43qDA3k.js +1 -0
- data/vendor/client/assets/sheet-BPl2n-4n.js +1 -0
- data/vendor/client/assets/textarea-BnOphXry.js +1 -0
- data/vendor/client/assets/uiMode-z0ZbRV49.js +1 -0
- data/vendor/client/assets/uiToggle-DwnRQTH1.js +1 -0
- data/vendor/client/assets/useRecordForm-X_DExEP2.js +1 -0
- data/vendor/client/assets/useRecordVisit-BRtfMi-q.js +1 -0
- data/vendor/client/assets/utils-DwBGbDkG.js +1 -0
- data/vendor/client/assets/vendor-calendar-nTZiq9oY.js +1 -0
- data/vendor/client/assets/vendor-datefns-BoC6MCnl.js +1 -0
- data/vendor/client/assets/vendor-forms-D0h8hG_S.js +55 -0
- data/vendor/client/assets/vendor-purify-BXoPR7WT.js +3 -0
- data/vendor/client/assets/vendor-query-DZ6APRNI.js +1 -0
- data/vendor/client/assets/vendor-react-C1iE8mnY.js +9 -0
- data/vendor/client/assets/vendor-router-CI6Vh4k_.js +1 -0
- data/vendor/client/assets/vendor-table-DuQ835by.js +4 -0
- data/vendor/client/index.html +24 -0
- data/vendor/client/manifest.json +867 -0
- data/vendor/client/reactiveadmin-client.json +4 -0
- metadata +350 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Walks AA-rendered HTML into typed nodes; anything unrecognised becomes sanitized html.
|
|
3
|
+
class HtmlNodes
|
|
4
|
+
include HtmlRich
|
|
5
|
+
|
|
6
|
+
VARIANTS = {
|
|
7
|
+
success: %w[yes ok success completed],
|
|
8
|
+
warning: %w[warning pending hold],
|
|
9
|
+
danger: %w[error no failed danger],
|
|
10
|
+
info: %w[info]
|
|
11
|
+
}.freeze
|
|
12
|
+
BOX_TAGS = %w[div span p section].freeze
|
|
13
|
+
SAFE_SCHEMES = %w[http https mailto tel].freeze
|
|
14
|
+
TOOLBAR_TAGS = %w[div section].freeze
|
|
15
|
+
PASSTHROUGH_TAGS = %w[div span section].freeze
|
|
16
|
+
STRUCTURAL_CLASSES = %w[panel attributes_table tabs columns status_tag empty].freeze
|
|
17
|
+
|
|
18
|
+
# `frame_src` is the classic URL the html came from: forms that PageForms did not record
|
|
19
|
+
# (see its marker nodes) are kept as interactive frame nodes that submit relative to it.
|
|
20
|
+
# `resource` only labels diagnostics about layout classes the walker can't translate.
|
|
21
|
+
def self.nodes(html, host: nil, links: nil, frame_src: nil, resource: nil) = new(host, links, frame_src:, resource:).nodes(html)
|
|
22
|
+
|
|
23
|
+
def self.convert(html, host: nil, links: nil, frame_src: nil, resource: nil) = new(host, links, frame_src:, resource:).convert(html)
|
|
24
|
+
|
|
25
|
+
# Content of a show or page view. A view that runs its own JS can't be walked, so it is embedded whole.
|
|
26
|
+
def self.layout(html, src:, host: nil, links: nil, title: nil, resource: nil)
|
|
27
|
+
if Ladder.script?(html)
|
|
28
|
+
Degradation.record(kind: :layout_iframe, where: Degradation.where, reason: "Content runs its own JS; embedded as iframe")
|
|
29
|
+
return [{type: "iframe", src: Ladder.embed_url(src), title:}.compact]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
nodes(html, host:, links:, frame_src: src, resource:)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Forms stay, scripts and handlers go, and nothing submits off-site.
|
|
36
|
+
def self.interactive(html, host: nil, where: nil) = HtmlPolicy.interactive(html, host:, where:)
|
|
37
|
+
|
|
38
|
+
def self.sanitize(html, host: nil, where: nil) = HtmlPolicy.display(html, host:, where:)
|
|
39
|
+
|
|
40
|
+
# `links` maps controls that act (button_to, data-method) to Actions, given the record in view.
|
|
41
|
+
def initialize(host = nil, links = nil, frame_src: nil, resource: nil)
|
|
42
|
+
@host = host
|
|
43
|
+
@links = links || ActionLinks.new(host:)
|
|
44
|
+
@frame_src = frame_src
|
|
45
|
+
@resource = resource&.to_s
|
|
46
|
+
@path = []
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def nodes(html)
|
|
50
|
+
fragment = HtmlPolicy.parse(html, where: @path.join("/")) or return [{type: "text", text: HtmlPolicy::TOO_COMPLEX}]
|
|
51
|
+
merge_toolbars(siblings(fragment.children))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def convert(html)
|
|
55
|
+
list = nodes(html)
|
|
56
|
+
if list.size == 1
|
|
57
|
+
list.first
|
|
58
|
+
else
|
|
59
|
+
(list.empty? ? {type: "empty"} : {type: "group", children: list})
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def node(el)
|
|
66
|
+
return text(el.text) if el.text? || el.cdata?
|
|
67
|
+
return unless el.element?
|
|
68
|
+
|
|
69
|
+
if el.name == "br"
|
|
70
|
+
nil
|
|
71
|
+
elsif el.name == "span" && el["class"].to_s.split.include?("status_tag")
|
|
72
|
+
status(el)
|
|
73
|
+
elsif el.name == "span" && el.classes.include?("empty")
|
|
74
|
+
{type: "empty"}
|
|
75
|
+
elsif el.name == "span" && el.classes.include?(Masking::CLASS_NAME)
|
|
76
|
+
Masking::NODE
|
|
77
|
+
elsif NodeRegistry.marker?(el)
|
|
78
|
+
NodeRegistry.from_html(el)
|
|
79
|
+
elsif action?(el)
|
|
80
|
+
action_node(el)
|
|
81
|
+
elsif HtmlPolicy::MEDIA.key?(el.name)
|
|
82
|
+
media(el)
|
|
83
|
+
elsif el.name == "time" && (typed = time(el))
|
|
84
|
+
typed
|
|
85
|
+
elsif %w[pre code].include?(el.name) && (typed = code(el))
|
|
86
|
+
typed
|
|
87
|
+
elsif @frame_src && el.name == "form" && Provenance.trusted?(el)
|
|
88
|
+
frame(el)
|
|
89
|
+
elsif el.name == "a"
|
|
90
|
+
link(el)
|
|
91
|
+
elsif el.name == "div" && el.classes.include?("attributes_table")
|
|
92
|
+
attributes_table(el)
|
|
93
|
+
elsif el.name == "div" && el.classes.include?("panel")
|
|
94
|
+
panel(el)
|
|
95
|
+
elsif el.name == "div" && el.classes.include?("tabs")
|
|
96
|
+
tabs(el)
|
|
97
|
+
elsif el.name == "div" && el.classes.include?("columns")
|
|
98
|
+
columns(el)
|
|
99
|
+
elsif el.name == "table"
|
|
100
|
+
table(el)
|
|
101
|
+
elsif rich?(el)
|
|
102
|
+
rich(el)
|
|
103
|
+
elsif (bar = toolbar(el))
|
|
104
|
+
bar
|
|
105
|
+
elsif BOX_TAGS.include?(el.name) && (el.element_children.any? || layout_hints(el).any?)
|
|
106
|
+
box(el)
|
|
107
|
+
elsif BOX_TAGS.include?(el.name)
|
|
108
|
+
text(el.text)&.merge(classes(el).text_style)
|
|
109
|
+
else
|
|
110
|
+
html(el)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Only controls the DSL's own helpers stamped act; the same markup in a stored value is a link or text.
|
|
115
|
+
def action?(el) = ActionLinks.control?(el) && Provenance.trusted?(el)
|
|
116
|
+
|
|
117
|
+
# No node when the control isn't offered to this channel (a browser-only POST, for a token).
|
|
118
|
+
def action_node(el) = (action = @links.action(el, placement: "inline")) && {type: "action", action:}
|
|
119
|
+
|
|
120
|
+
# The frame follows data-method links itself, so a form's stored text can't keep them.
|
|
121
|
+
def frame(el)
|
|
122
|
+
el.css("a[data-method], a[data-remote]").reject { Provenance.trusted?(it) }.each { |link| %w[data-method data-remote].each { link.remove_attribute(it) } }
|
|
123
|
+
{type: "frame", html: self.class.interactive(el.to_html, host: @host, where: @path.join("/")), src: @frame_src}
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# External images and documents never load on their own: they become links.
|
|
127
|
+
def media(el)
|
|
128
|
+
typed = MediaNodes.for(el, host: @host)
|
|
129
|
+
return typed if typed
|
|
130
|
+
|
|
131
|
+
src = el["src"].to_s.strip
|
|
132
|
+
return {type: "iframe", src: Ladder.embed_url(src), title: el["title"].presence}.compact if el.name == "iframe" && embeddable?(src)
|
|
133
|
+
|
|
134
|
+
decision = HtmlPolicy.media(el, host: @host)
|
|
135
|
+
return html(el) if decision == :keep
|
|
136
|
+
return if decision == :drop
|
|
137
|
+
|
|
138
|
+
HtmlPolicy.degrade(:external_media_blocked, "Replaced an external image or document with a link", where: @path.join("/"))
|
|
139
|
+
{type: "link", label: decision.first, href: decision.last, external: true}
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def time(el)
|
|
143
|
+
value = el["datetime"].to_s.strip
|
|
144
|
+
value.match?(/\A\d{4}-\d{2}-\d{2}\z/) ? {type: "date", value: Date.iso8601(value).iso8601} : {type: "datetime", value: Time.iso8601(value).iso8601}
|
|
145
|
+
rescue ArgumentError
|
|
146
|
+
nil
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Code (typically a JSON dump) with nothing but text inside; anything marked up stays html.
|
|
150
|
+
def code(el)
|
|
151
|
+
only = el.element_children.one? && el.element_children.first.name == "code" && el.children.none? { it.text? && it.text.strip.present? }
|
|
152
|
+
source = (el.name == "pre" && only) ? el.element_children.first : el
|
|
153
|
+
return unless source.element_children.empty?
|
|
154
|
+
|
|
155
|
+
text = source.text.delete_prefix("\n").rstrip
|
|
156
|
+
return {type: "empty"} if text.blank?
|
|
157
|
+
|
|
158
|
+
json = parse_json(text)
|
|
159
|
+
return Values.for(json, nil, source: ValuePayload::Source.new(inline: @frame_src.present?)) if json
|
|
160
|
+
|
|
161
|
+
language = [source, el].filter_map { it["class"].to_s[/\blang(?:uage)?-(\S+)/, 1] }.first
|
|
162
|
+
{type: "code", text:, language:}.compact
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def parse_json(text)
|
|
166
|
+
JSON.parse(text) if text.lstrip.start_with?("{", "[")
|
|
167
|
+
rescue JSON::ParserError
|
|
168
|
+
nil
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def text(string)
|
|
172
|
+
string = string.strip
|
|
173
|
+
{type: "text", text: string} unless string.empty?
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def status(el)
|
|
177
|
+
classes = el.classes
|
|
178
|
+
variant = VARIANTS.find { |_, names| (names & classes).any? }&.first || :neutral
|
|
179
|
+
{type: "status", label: el.text.strip, variant: variant.to_s}
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def link(el)
|
|
183
|
+
label = el.text.strip
|
|
184
|
+
return text(label) if ActionLinks.verb(el["data-method"]) != "get"
|
|
185
|
+
|
|
186
|
+
uri = begin
|
|
187
|
+
URI.parse(el["href"].to_s)
|
|
188
|
+
rescue
|
|
189
|
+
nil
|
|
190
|
+
end
|
|
191
|
+
return text(label) if uri.nil? || (uri.scheme && !SAFE_SCHEMES.include?(uri.scheme))
|
|
192
|
+
|
|
193
|
+
external = external?(uri)
|
|
194
|
+
node = {type: "link", label:, href: external ? @links.absolute(uri) : uri.to_s, external:}
|
|
195
|
+
ref = ref_for(uri)
|
|
196
|
+
node = node.merge(ref:) if ref
|
|
197
|
+
view = view_for(uri)
|
|
198
|
+
view ? node.merge(view:) : node
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# A link to a custom view (a custom GET action or a register_page) says how the client shows it.
|
|
202
|
+
def view_for(uri)
|
|
203
|
+
return if external?(uri) || uri.path.blank?
|
|
204
|
+
|
|
205
|
+
route = Rails.application.routes.recognize_path(uri.path)
|
|
206
|
+
href = [uri.path, uri.query].compact.join("?")
|
|
207
|
+
action = route[:action].dup.force_encoding(Encoding::UTF_8)
|
|
208
|
+
if (config = Registry.for_controller_path(route[:controller]))
|
|
209
|
+
Ladder.view(config, action, href:) if Exposure.allowed?(config)
|
|
210
|
+
elsif (page = Registry.page_for_controller_path(route[:controller]))
|
|
211
|
+
return unless Exposure.allowed?(page)
|
|
212
|
+
|
|
213
|
+
(action == "index") ? Ladder.page_view(page, href:) : Ladder.view(page, action, href:)
|
|
214
|
+
end
|
|
215
|
+
rescue ActionController::RoutingError
|
|
216
|
+
nil
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# An iframe in markup may only frame a page of a registered, exposed resource or page: a same-origin
|
|
220
|
+
# path elsewhere (an upload, a blob) runs with the admin's session and the frame's `allow-same-origin`.
|
|
221
|
+
def embeddable?(src)
|
|
222
|
+
return false unless HtmlPolicy.same_origin?(src, @host) && !HtmlPolicy.trusted_url?(src)
|
|
223
|
+
|
|
224
|
+
path = URI.parse(src).path.to_s
|
|
225
|
+
return false unless path.start_with?("/admin/") && !path.match?(%r{/\.\.?(/|\z)|%2[ef]}i)
|
|
226
|
+
|
|
227
|
+
route = Rails.application.routes.recognize_path(path)
|
|
228
|
+
config = Registry.for_controller_path(route[:controller]) || Registry.page_for_controller_path(route[:controller])
|
|
229
|
+
config.present? && Exposure.allowed?(config)
|
|
230
|
+
rescue ActionController::RoutingError, URI::InvalidURIError
|
|
231
|
+
false
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def external?(uri) = @links.external?(uri)
|
|
235
|
+
|
|
236
|
+
def ref_for(uri)
|
|
237
|
+
return if external?(uri) || uri.path.blank?
|
|
238
|
+
|
|
239
|
+
route = Rails.application.routes.recognize_path(uri.path)
|
|
240
|
+
return unless route[:action] == "show" && route[:id]
|
|
241
|
+
|
|
242
|
+
config = Registry.for_controller_path(route[:controller]) or return
|
|
243
|
+
return unless Exposure.allowed?(config)
|
|
244
|
+
|
|
245
|
+
ref = {resource: Registry.route_key(config), id: route[:id].to_s}
|
|
246
|
+
Paths.nested?(config) ? ref.merge(path: uri.path, api_path: Paths.api(uri.path)) : ref
|
|
247
|
+
rescue ActionController::RoutingError
|
|
248
|
+
nil
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def attributes_table(el)
|
|
252
|
+
title = el.parent&.classes&.include?("panel_contents") ? panel_title(el.parent.parent) : nil
|
|
253
|
+
rows = el.css("tr").map do |tr|
|
|
254
|
+
{label: tr.at_css("th")&.text.to_s.strip, value: cell_nodes(tr.at_css("td"))}
|
|
255
|
+
end
|
|
256
|
+
{type: "attributes_table", title:, rows:}
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def cell_nodes(td)
|
|
260
|
+
list = td ? nodes(td.inner_html) : []
|
|
261
|
+
list.empty? ? [{type: "empty"}] : list
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def panel(el)
|
|
265
|
+
contents = child(el, "panel_contents")
|
|
266
|
+
node = {type: "panel", title: panel_title(el), children: nodes((contents || el).inner_html)}
|
|
267
|
+
(actions = header_actions(el)).present? ? node.merge(header_actions: actions) : node
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def panel_title(panel)
|
|
271
|
+
heading = panel&.element_children&.find { it.name == "h3" } or return
|
|
272
|
+
heading.children.reject { it.element? && it.classes.include?("header_action") }.sum("") { it.text }.strip
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# `header_action` renders a div inside the h3 per call. Anything but actions and links is dropped, with a note.
|
|
276
|
+
def header_actions(panel)
|
|
277
|
+
slots = panel.element_children.find { it.name == "h3" }&.element_children.to_a.select { it.classes.include?("header_action") }
|
|
278
|
+
slots.to_a.flat_map do |slot|
|
|
279
|
+
toolbar_items(slot, [slot]) || begin
|
|
280
|
+
HtmlPolicy.degrade(:panel_header_action, "Panel header action holds more than actions and links; not shown", where: @path.join("/"))
|
|
281
|
+
[]
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def child(el, class_name) = el.element_children.find { it.classes.include?(class_name) }
|
|
287
|
+
|
|
288
|
+
def tabs(el)
|
|
289
|
+
titles = child(el, "nav-tabs")&.element_children.to_a.map { it.text.strip }
|
|
290
|
+
contents = child(el, "tab-content")&.element_children.to_a
|
|
291
|
+
tabs = titles.zip(contents).map { |title, content| {type: "tab", title:, children: nodes(content&.inner_html)} }
|
|
292
|
+
{type: "tabs", children: tabs}
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def columns(el)
|
|
296
|
+
columns = el.element_children.select { it.classes.include?("column") }
|
|
297
|
+
{type: "columns", children: columns.map { {type: "column", children: nodes(it.inner_html)} }}
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def table(el)
|
|
301
|
+
headers = el.css("thead th").map { it.text.strip }
|
|
302
|
+
cells = headers.empty? ? "th, td" : "td"
|
|
303
|
+
rows = el.css("tbody tr").map { |tr| tr.css(cells).map { convert(it.inner_html) } }
|
|
304
|
+
{type: "table", headers:, rows:}
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def box(el)
|
|
308
|
+
result = classes(el)
|
|
309
|
+
{type: "box", tag: el.name, **result.hints, **result.text_style, children: nodes(el.inner_html)}
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# A container holding only actions and links, however deeply wrapped. A width or a column
|
|
313
|
+
# direction means it is laying out other content, so it stays a box.
|
|
314
|
+
def toolbar(el)
|
|
315
|
+
return unless TOOLBAR_TAGS.include?(el.name) && (STRUCTURAL_CLASSES & el.classes).empty?
|
|
316
|
+
|
|
317
|
+
wrappers = [el]
|
|
318
|
+
items = toolbar_items(el, wrappers)
|
|
319
|
+
return if items.blank?
|
|
320
|
+
|
|
321
|
+
results = wrappers.map { classes(it) }
|
|
322
|
+
return if results.any? { it.width || it.span || it.max_width || it.grow || it.layout&.dig(:direction) == "column" }
|
|
323
|
+
|
|
324
|
+
{type: "toolbar", align: results.filter_map(&:toolbar_align).first || "start", spacing: results.filter_map(&:spacing).first, children: items}.compact
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def toolbar_items(el, wrappers)
|
|
328
|
+
el.children.flat_map do |child|
|
|
329
|
+
next [] if child.comment? || (child.text? && child.text.strip.empty?) || child.name == "br"
|
|
330
|
+
|
|
331
|
+
toolbar_item(child, wrappers) || (return nil)
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def toolbar_item(el, wrappers)
|
|
336
|
+
if NodeRegistry.marker?(el)
|
|
337
|
+
nil
|
|
338
|
+
elsif action?(el)
|
|
339
|
+
[action_node(el)].compact
|
|
340
|
+
elsif el.name == "a"
|
|
341
|
+
# An icon-only link with an unsafe href has no label to fall back on, so `link` gives nothing.
|
|
342
|
+
node = link(el)
|
|
343
|
+
[node] if node&.dig(:type) == "link"
|
|
344
|
+
elsif PASSTHROUGH_TAGS.include?(el.name) && (STRUCTURAL_CLASSES & el.classes).empty?
|
|
345
|
+
wrappers << el
|
|
346
|
+
toolbar_items(el, wrappers)
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def merge_toolbars(list)
|
|
351
|
+
list.each_with_object([]) do |node, merged|
|
|
352
|
+
last = merged.last
|
|
353
|
+
if node[:type] == "toolbar" && last&.dig(:type) == "toolbar" && last[:align] == node[:align]
|
|
354
|
+
merged[-1] = last.merge(children: last[:children] + node[:children])
|
|
355
|
+
else
|
|
356
|
+
merged << node
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
def layout_hints(el) = classes(el).hints
|
|
362
|
+
|
|
363
|
+
# Classes and styles are never passed on; the ones with no translation are reported for `doctor`,
|
|
364
|
+
# not to the user: the content renders, only some spacing is lost.
|
|
365
|
+
def classes(el)
|
|
366
|
+
result = LayoutClasses.parse(el["class"], style: el["style"])
|
|
367
|
+
result.unknown.each { diagnose(:unknown_layout_class, class: it) }
|
|
368
|
+
diagnose(:inline_style_ignored, style: InlineStyle.redact(el["style"]), ignored: InlineStyle.redact(result.unknown_styles.join("; "))) if result.unknown_styles.any?
|
|
369
|
+
result
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
def diagnose(kind, **details)
|
|
373
|
+
source = StyleSources.locate(details[:class] || details[:style], resource: @resource)
|
|
374
|
+
ReactiveAdmin.diagnostics.record(kind, resource: @resource, path: @path.join("/"), **details, **{source:}.compact)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def at(step)
|
|
378
|
+
@path.push(step)
|
|
379
|
+
yield
|
|
380
|
+
ensure
|
|
381
|
+
@path.pop
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def html(el)
|
|
385
|
+
diagnose(:html_unmapped_tag, tag: el.name)
|
|
386
|
+
Degradation.tally(kind: :html_fallback, where: Degradation.where(*@path), reason: "%d elements shown as sanitized html")
|
|
387
|
+
{type: "html", html: self.class.sanitize(el.to_html, host: @host, where: @path.join("/"))}
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
end
|