trek 2.5.0 → 2.7.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 +4 -4
- data/.node-version +1 -1
- data/AGENTS.md +18 -14
- data/CHANGELOG.md +88 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +135 -124
- data/Makefile +9 -1
- data/README.md +17 -21
- data/app/components/trek/dashboard/tile_component/tile_component.css +9 -0
- data/app/components/trek/dashboard/tile_component/tile_component.html.slim +4 -2
- data/app/components/trek/dashboard/tile_component.rb +12 -2
- data/app/components/trek/form/content_editor_component/content_editor_component.css +9 -8
- data/app/components/trek/form/content_editor_component/content_editor_component.html.slim +19 -93
- data/app/components/trek/form/content_editor_component/content_editor_component.js +94 -251
- data/app/components/trek/form/content_editor_component/extensions/block_view.js +40 -0
- data/app/components/trek/form/content_editor_component/extensions/image_block.js +28 -26
- data/app/components/trek/form/content_editor_component/extensions/prompts_block.js +15 -26
- data/app/components/trek/form/content_editor_component/extensions/table_of_contents.js +1 -3
- data/app/components/trek/form/content_editor_component.rb +15 -0
- data/app/components/trek/form/image_field_component/image_field_component.css +40 -1
- data/app/components/trek/form/image_field_component/image_field_component.html.slim +0 -9
- data/app/components/trek/form/image_field_component/image_field_component.js +1 -2
- data/app/components/trek/form/image_field_component.rb +36 -9
- data/app/components/trek/form/password_strength_component/password_strength_component.css +2 -0
- data/app/components/trek/form/sound_field_component/sound_field_component.js +1 -2
- data/app/components/trek/security_check_component/security_check_component.css +69 -0
- data/app/components/trek/security_check_component/security_check_component.html.slim +19 -0
- data/app/components/trek/security_check_component/security_check_component.js +15 -0
- data/app/components/trek/security_check_component.rb +19 -0
- data/app/content/trek/content/cleaner.rb +53 -0
- data/app/content/trek/content/document.rb +2 -2
- data/app/content/trek/content/list_item.rb +1 -1
- data/app/content/trek/content/paragraph.rb +7 -2
- data/app/content/trek/content/prompts_block.rb +1 -2
- data/app/content/trek/content.rb +6 -0
- data/app/controllers/concerns/trek/auditable.rb +5 -2
- data/app/controllers/concerns/trek/localization.rb +6 -2
- data/app/controllers/concerns/trek/reorderable.rb +24 -6
- data/app/controllers/trek/csp_reports_controller.rb +14 -1
- data/app/controllers/trek/panels/prompts_controller.rb +1 -1
- data/app/controllers/trek/resource_controller.rb +5 -5
- data/app/jobs/trek/purge_expired_sessions_job.rb +4 -3
- data/app/jobs/trek/purge_expired_sign_in_codes_job.rb +15 -0
- data/app/models/concerns/trek/contentable.rb +15 -1
- data/app/models/concerns/trek/users/sign_in_code.rb +70 -0
- data/app/models/concerns/trek/users/sign_in_lockout.rb +4 -2
- data/app/policies/trek/security_check_policy.rb +8 -0
- data/app/uploaders/image_uploader.rb +77 -15
- data/app/views/trek/panels/links/_form.html.slim +2 -4
- data/app/views/trek/panels/prompts/create.turbo_stream.slim +0 -1
- data/config/locales/trek.en.yml +97 -11
- data/config/locales/trek.fr.yml +97 -11
- data/docs/.vitepress/config.mjs +5 -1
- data/docs/background-jobs.md +74 -0
- data/docs/content-editor.md +219 -0
- data/docs/customize.md +2 -0
- data/docs/deploy.md +69 -6
- data/docs/getting-started.md +16 -18
- data/docs/index.md +2 -2
- data/docs/personal-data.md +61 -0
- data/docs/proxies.md +2 -2
- data/docs/reference/components.md +4 -4
- data/docs/reference/concerns/contentable.md +10 -4
- data/docs/reference/concerns/formattable.md +1 -1
- data/docs/reference/concerns/fragmentable.md +12 -6
- data/docs/reference/concerns/orderable.md +2 -2
- data/docs/reference/concerns/search-engine-optimizable.md +1 -1
- data/docs/reference/concerns/searchable.md +14 -1
- data/docs/reference/concerns/sectionable.md +7 -3
- data/docs/reference/concerns/versionable.md +1 -1
- data/docs/reference/controllers.md +33 -1
- data/docs/reference/environment-variables.md +3 -2
- data/docs/reference/formatters.md +4 -31
- data/docs/reference/forms.md +7 -4
- data/docs/reference/generators/admin-user.md +1 -1
- data/docs/reference/generators/audit-log.md +12 -13
- data/docs/reference/generators/install.md +23 -11
- data/docs/reference/generators/public-accounts.md +159 -0
- data/docs/reference/generators/scaffold.md +28 -9
- data/docs/reference/generators/security-headers.md +5 -4
- data/docs/reference/generators/taxonomies.md +1 -1
- data/docs/reference/icons.md +5 -3
- data/docs/reference/index.md +10 -7
- data/docs/reference/models/current.md +5 -3
- data/docs/reference/models/page-version.md +1 -1
- data/docs/reference/models/user.md +7 -8
- data/docs/reference/uploaders.md +25 -0
- data/docs/reference/validators.md +1 -1
- data/docs/security.md +30 -9
- data/docs/what-is-trek.md +4 -4
- data/lib/generators/trek/USAGE +1 -1
- data/lib/generators/trek/audit_log_generator.rb +62 -0
- data/lib/generators/trek/helpers.rb +17 -0
- data/lib/generators/trek/install/admin/routes_generator.rb +2 -1
- data/lib/generators/trek/install/admin/security_check_generator.rb +36 -0
- data/lib/generators/trek/install/admin/users_generator.rb +6 -1
- data/lib/generators/trek/install/audit_log_generator.rb +9 -45
- data/lib/generators/trek/install/ci_generator.rb +19 -0
- data/lib/generators/trek/install/good_job_generator.rb +161 -0
- data/lib/generators/trek/install/model_specs_generator.rb +3 -3
- data/lib/generators/trek/install/postcss_generator.rb +1 -2
- data/lib/generators/trek/install/ruby_generator.rb +1 -1
- data/lib/generators/trek/install/scalingo_generator.rb +7 -45
- data/lib/generators/trek/install/translations_generator.rb +1 -2
- data/lib/generators/trek/install_generator.rb +18 -2
- data/lib/generators/trek/public_accounts_generator.rb +294 -0
- data/lib/generators/trek/scaffold_generator.rb +22 -21
- data/lib/generators/trek/scalingo_generator.rb +67 -0
- data/lib/generators/trek/templates/.gitlab-ci.yml +10 -1
- data/lib/generators/trek/templates/AGENTS.md +2 -2
- data/lib/generators/trek/templates/Makefile +1 -0
- data/lib/generators/trek/templates/config/i18n-tasks.yml.erb +0 -8
- data/lib/generators/trek/templates/controllers/admin/password_renewals_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/admin/security_checks_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/admin/user_sessions_controller.rb +1 -1
- data/lib/generators/trek/templates/controllers/admin/users_controller.rb +0 -8
- data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +13 -4
- data/lib/generators/trek/templates/initializers/content_security_policy.rb +3 -2
- data/lib/generators/trek/templates/initializers/good_job.rb.tt +40 -0
- data/lib/generators/trek/templates/jobs/mail_delivery_job.rb +6 -0
- data/lib/generators/trek/templates/layouts/admin.html.slim +10 -0
- data/lib/generators/trek/templates/mailers/admin_mailer.rb +4 -2
- data/lib/generators/trek/templates/package.json.tt +1 -1
- data/lib/generators/trek/templates/policies/security_check.rb +4 -0
- data/lib/generators/trek/templates/public_accounts/api/authentication.rb.tt +76 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/accounts_controller.rb.tt +22 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/active_sessions_controller.rb.tt +21 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/base_controller.rb.tt +71 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/email_changes_controller.rb.tt +55 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/email_confirmations_controller.rb.tt +19 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/password_resets_controller.rb.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/passwords_controller.rb.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/registrations_controller.rb.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sessions_controller.rb.tt +57 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sign_in_codes_controller.rb.tt +20 -0
- data/lib/generators/trek/templates/public_accounts/jobs/sign_in_code_job.rb.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.en.yml.tt +215 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.fr.yml.tt +215 -0
- data/lib/generators/trek/templates/public_accounts/mailers/account_mailer.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/migrations/create_accounts.rb.tt +46 -0
- data/lib/generators/trek/templates/public_accounts/models/account/session.rb.tt +47 -0
- data/lib/generators/trek/templates/public_accounts/models/account/sign_in_code.rb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/models/account.rb.tt +87 -0
- data/lib/generators/trek/templates/public_accounts/spec/api/accounts_spec.rb.tt +90 -0
- data/lib/generators/trek/templates/public_accounts/spec/api/sign_ins_spec.rb.tt +188 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account/sign_in_code_spec.rb.tt +66 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account_spec.rb.tt +129 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/accounts_spec.rb.tt +126 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/authentication_spec.rb.tt +43 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/sign_ins_spec.rb.tt +237 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.html.slim.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.html.slim.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.html.slim.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.html.slim.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.text.erb.tt +14 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.html.slim.tt +24 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.text.erb.tt +14 -0
- data/lib/generators/trek/templates/public_accounts/web/authentication.rb.tt +97 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/accounts_controller.rb.tt +33 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/active_sessions_controller.rb.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/base_controller.rb.tt +52 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/email_changes_controller.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/email_confirmations_controller.rb.tt +19 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/password_resets_controller.rb.tt +41 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/passwords_controller.rb.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/registrations_controller.rb.tt +24 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sessions_controller.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sign_in_codes_controller.rb.tt +32 -0
- data/lib/generators/trek/templates/public_accounts/web/views/_flash.html.slim.tt +5 -0
- data/lib/generators/trek/templates/public_accounts/web/views/accounts/show.html.slim.tt +52 -0
- data/lib/generators/trek/templates/public_accounts/web/views/email_changes/edit.html.slim.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/web/views/email_changes/new.html.slim.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/edit.html.slim.tt +29 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/new.html.slim.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/views/passwords/edit.html.slim.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/web/views/registrations/new.html.slim.tt +30 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sessions/new.html.slim.tt +40 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sign_in_codes/new.html.slim.tt +17 -0
- data/lib/generators/trek/templates/spec/jobs/mail_delivery_job_spec.rb +11 -0
- data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +10 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +1 -1
- data/lib/generators/trek/templates/spec/requests/admin/good_job_spec.rb +34 -0
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +12 -1
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +16 -0
- data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +2 -2
- data/lib/generators/trek/templates/spec/requests/admin/security_checks_spec.rb +24 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_lockout_spec.rb +1 -1
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +33 -0
- data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +2 -2
- data/lib/generators/trek/templates/views/admin/pages/_form.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin/security_checks/show.html.slim +9 -0
- data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +6 -1
- data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +4 -1
- data/lib/generators/trek/templates/views/admin/users/index.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.text.erb +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.text.erb +1 -1
- data/lib/tasks/trek/attachments.rake +12 -0
- data/lib/tasks/trek/security.rake +10 -0
- data/lib/trek/csp_reports.rb +22 -4
- data/lib/trek/disposable_email_domains.rb +9 -20
- data/lib/trek/engine.rb +5 -0
- data/lib/trek/json_compatibility.rb +20 -0
- data/lib/trek/security_check.rb +241 -0
- data/lib/trek/stored_image_metadata.rb +88 -0
- data/lib/trek/typography_formatter.rb +35 -4
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +2 -1
- data/package.json +16 -13
- data/postcss.config.js +0 -3
- data/trek.gemspec +6 -7
- data/vitest.config.mjs +24 -0
- data/yarn.lock +1667 -1010
- metadata +122 -33
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
display: none;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
.floating-menu {
|
|
43
|
+
/* Above the editor's content: Floating UI positions it, with no z-index of its own */
|
|
44
|
+
z-index: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
.floating-menu .button {
|
|
43
48
|
padding: 0.7rem 1.2rem;
|
|
44
49
|
}
|
|
@@ -142,19 +147,15 @@
|
|
|
142
147
|
width: 2rem;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
/* app/assets/icons/trek/arrow-bar-left.svg and arrow-bar-right.svg, inlined: a host app builds this
|
|
151
|
+
file from its own directory, where a plugin loading Trek's icons wouldn't find them */
|
|
148
152
|
.content-image[data-size="larger"]::before {
|
|
149
|
-
content: svg-
|
|
153
|
+
content: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke-width='2' stroke='currentColor' fill='none' stroke-linecap='round' stroke-linejoin='round'%3E %3Cpath stroke='none' d='M0 0h24v24H0z' fill='none'/%3E %3Cline x1='4' y1='12' x2='14' y2='12'/%3E %3Cline x1='4' y1='12' x2='8' y2='16'/%3E %3Cline x1='4' y1='12' x2='8' y2='8'/%3E %3Cline x1='20' y1='4' x2='20' y2='20'/%3E %3C/svg%3E");
|
|
150
154
|
margin-right: 1rem;
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
@svg-load arrow-bar-right url("trek/arrow-bar-right.svg") {
|
|
154
|
-
}
|
|
155
|
-
|
|
156
157
|
.content-image[data-size="larger"]::after {
|
|
157
|
-
content: svg-
|
|
158
|
+
content: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke-width='2' stroke='currentColor' fill='none' stroke-linecap='round' stroke-linejoin='round'%3E %3Cpath stroke='none' d='M0 0h24v24H0z' fill='none'/%3E %3Cline x1='20' y1='12' x2='10' y2='12'/%3E %3Cline x1='20' y1='12' x2='16' y2='16'/%3E %3Cline x1='20' y1='12' x2='16' y2='8'/%3E %3Cline x1='4' y1='4' x2='4' y2='20'/%3E %3C/svg%3E");
|
|
158
159
|
margin-left: 1rem;
|
|
159
160
|
}
|
|
160
161
|
|
|
@@ -8,34 +8,22 @@ div(
|
|
|
8
8
|
button.bold(
|
|
9
9
|
class=class_for("button")
|
|
10
10
|
type="button"
|
|
11
|
-
data
|
|
11
|
+
data=command_data("toggleBold", active: "bold")
|
|
12
12
|
) = render Trek::IconComponent.new("trek/bold", title: t(".bold"))
|
|
13
13
|
|
|
14
14
|
button.italic(
|
|
15
15
|
class=class_for("button")
|
|
16
16
|
type="button"
|
|
17
|
-
data
|
|
17
|
+
data=command_data("toggleItalic", active: "italic")
|
|
18
18
|
) = render Trek::IconComponent.new("trek/italic", title: t(".italic"))
|
|
19
19
|
|
|
20
|
-
/ button.strike(
|
|
21
|
-
/ class=class_for("button")
|
|
22
|
-
/ type="button"
|
|
23
|
-
/ data-action=stimulus_action("toggleStrike")
|
|
24
|
-
/ ) strike
|
|
25
|
-
|
|
26
|
-
/ button.code(
|
|
27
|
-
/ class=class_for("button")
|
|
28
|
-
/ type="button"
|
|
29
|
-
/ data-action=stimulus_action("toggleCode")
|
|
30
|
-
/ ) code
|
|
31
|
-
|
|
32
20
|
/ The panel opening is handled by the hidden button's
|
|
33
21
|
openStackedPanelWhenLoaded action — a direct openPanel here would
|
|
34
22
|
pop the (possibly empty) primary panel alongside the stacked one.
|
|
35
23
|
button.link(
|
|
36
24
|
class=class_for("button")
|
|
37
25
|
type="button"
|
|
38
|
-
data
|
|
26
|
+
data={ action: stimulus_action("toggleLink"), **state_data("link") }
|
|
39
27
|
) = render Trek::IconComponent.new("trek/link", title: t(".link"))
|
|
40
28
|
|
|
41
29
|
= link_to "",
|
|
@@ -51,7 +39,7 @@ div(
|
|
|
51
39
|
button(
|
|
52
40
|
class=class_for("button")
|
|
53
41
|
type="button"
|
|
54
|
-
data
|
|
42
|
+
data=command_data("unsetAllMarks")
|
|
55
43
|
)
|
|
56
44
|
= render Trek::IconComponent.new(\
|
|
57
45
|
"trek/eraser",
|
|
@@ -61,7 +49,7 @@ div(
|
|
|
61
49
|
button(
|
|
62
50
|
class=class_for("button")
|
|
63
51
|
type="button"
|
|
64
|
-
data
|
|
52
|
+
data=command_data("setHardBreak")
|
|
65
53
|
)
|
|
66
54
|
= render Trek::IconComponent.new(\
|
|
67
55
|
"trek/return",
|
|
@@ -74,86 +62,36 @@ div(
|
|
|
74
62
|
button.paragraph(
|
|
75
63
|
class=class_for("button")
|
|
76
64
|
type="button"
|
|
77
|
-
data
|
|
65
|
+
data=command_data("setParagraph", active: "paragraph")
|
|
78
66
|
)
|
|
79
67
|
= render Trek::IconComponent.new(\
|
|
80
68
|
"trek/paragraph",
|
|
81
69
|
title: t(".paragraph"),
|
|
82
70
|
)
|
|
83
71
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
class=class_for("button")
|
|
93
|
-
type="button"
|
|
94
|
-
data-action=stimulus_action("toggleHeading")
|
|
95
|
-
data-level=2
|
|
96
|
-
title=t(".h2")
|
|
97
|
-
) h2
|
|
98
|
-
|
|
99
|
-
button.h3(
|
|
100
|
-
class=class_for("button")
|
|
101
|
-
type="button"
|
|
102
|
-
data-action=stimulus_action("toggleHeading")
|
|
103
|
-
data-level=3
|
|
104
|
-
title=t(".h3")
|
|
105
|
-
) h3
|
|
106
|
-
|
|
107
|
-
button.h4(
|
|
108
|
-
class=class_for("button")
|
|
109
|
-
type="button"
|
|
110
|
-
data-action=stimulus_action("toggleHeading")
|
|
111
|
-
data-level=4
|
|
112
|
-
title=t(".h4")
|
|
113
|
-
) h4
|
|
114
|
-
|
|
115
|
-
/ button.h5(
|
|
116
|
-
/ class=class_for("button")
|
|
117
|
-
/ type="button"
|
|
118
|
-
/ data-action=stimulus_action("toggleHeading")
|
|
119
|
-
/ data-level=5
|
|
120
|
-
/ title=t(".h5")
|
|
121
|
-
/ ) h5
|
|
122
|
-
|
|
123
|
-
/ button.h6(
|
|
124
|
-
/ class=class_for("button")
|
|
125
|
-
/ type="button"
|
|
126
|
-
/ data-action=stimulus_action("toggleHeading")
|
|
127
|
-
/ data-level=6
|
|
128
|
-
/ title=t(".h6")
|
|
129
|
-
/ ) h6
|
|
72
|
+
- [2, 3, 4].each do |level|
|
|
73
|
+
button(
|
|
74
|
+
class=class_for("button")
|
|
75
|
+
class="h#{level}"
|
|
76
|
+
type="button"
|
|
77
|
+
data=command_data("toggleHeading", active: "heading", level:)
|
|
78
|
+
title=t(".h#{level}")
|
|
79
|
+
) = "h#{level}"
|
|
130
80
|
|
|
131
81
|
button.bulletList(
|
|
132
82
|
class=class_for("button")
|
|
133
83
|
type="button"
|
|
134
|
-
data
|
|
84
|
+
data=command_data("toggleBulletList", active: "bulletList")
|
|
135
85
|
)
|
|
136
86
|
= render Trek::IconComponent.new( \
|
|
137
87
|
"trek/list-bullets",
|
|
138
88
|
title: t(".bullet_list"),
|
|
139
89
|
)
|
|
140
90
|
|
|
141
|
-
/ button.orderedList(
|
|
142
|
-
/ class=class_for("button")
|
|
143
|
-
/ type="button"
|
|
144
|
-
/ data-action=stimulus_action("toggleOrderedList")
|
|
145
|
-
/ ) ordered list
|
|
146
|
-
|
|
147
|
-
/ button.codeBlock(
|
|
148
|
-
/ class=class_for("button")
|
|
149
|
-
/ type="button"
|
|
150
|
-
/ data-action=stimulus_action("toggleCodeBlock")
|
|
151
|
-
/ ) code block
|
|
152
|
-
|
|
153
91
|
button.blockquote(
|
|
154
92
|
class=class_for("button")
|
|
155
93
|
type="button"
|
|
156
|
-
data
|
|
94
|
+
data=command_data("toggleBlockquote", active: "blockquote")
|
|
157
95
|
)
|
|
158
96
|
= render Trek::IconComponent.new( \
|
|
159
97
|
"trek/quotation",
|
|
@@ -163,37 +101,25 @@ div(
|
|
|
163
101
|
button(
|
|
164
102
|
class=class_for("button")
|
|
165
103
|
type="button"
|
|
166
|
-
data
|
|
104
|
+
data=command_data("setHorizontalRule")
|
|
167
105
|
)
|
|
168
106
|
= render Trek::IconComponent.new( \
|
|
169
107
|
"trek/hr",
|
|
170
108
|
title: t(".horizontal_rule"),
|
|
171
109
|
)
|
|
172
110
|
|
|
173
|
-
/ button(
|
|
174
|
-
/ class=class_for("button")
|
|
175
|
-
/ type="button"
|
|
176
|
-
/ data-action=stimulus_action("clearNodes")
|
|
177
|
-
/ ) clear nodes
|
|
178
|
-
|
|
179
111
|
button(
|
|
180
112
|
class=class_names_for("button", "button-end", map_args: true)
|
|
181
113
|
type="button"
|
|
182
|
-
data
|
|
114
|
+
data=command_data("undo")
|
|
183
115
|
) = render Trek::IconComponent.new("trek/undo", title: t(".undo"))
|
|
184
116
|
|
|
185
117
|
button(
|
|
186
118
|
class=class_for("button")
|
|
187
119
|
type="button"
|
|
188
|
-
data
|
|
120
|
+
data=command_data("redo")
|
|
189
121
|
) = render Trek::IconComponent.new("trek/redo", title: t(".redo"))
|
|
190
122
|
|
|
191
|
-
/ button(
|
|
192
|
-
/ class=class_for("button")
|
|
193
|
-
/ type="button"
|
|
194
|
-
/ data-action=stimulus_action("insertFrame")
|
|
195
|
-
/ ) frame
|
|
196
|
-
|
|
197
123
|
div(
|
|
198
124
|
class=class_for("content")
|
|
199
125
|
data=content_data_attributes
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import "./content_editor_component.css";
|
|
2
2
|
import { Editor } from "@tiptap/core";
|
|
3
3
|
import FloatingMenu from "@tiptap/extension-floating-menu";
|
|
4
|
-
import Link from "@tiptap/extension-link";
|
|
5
|
-
// import Placeholder from '@tiptap/extension-placeholder';
|
|
6
4
|
import StarterKit from "@tiptap/starter-kit";
|
|
7
5
|
import { Controller as BaseController } from "@hotwired/stimulus";
|
|
8
6
|
import { TableOfContents } from "./extensions/table_of_contents.js";
|
|
9
7
|
import PromptsBlock from "./extensions/prompts_block.js";
|
|
10
8
|
import ImageBlock from "./extensions/image_block.js";
|
|
11
9
|
|
|
10
|
+
// The content editor (Trek::Form::ContentEditorComponent): Tiptap, its toolbar, and the panels inserting
|
|
11
|
+
// links, images and calls to action. The document is kept in the form's field as JSON.
|
|
12
12
|
export class Controller extends BaseController {
|
|
13
13
|
static classes = ["active", "empty"];
|
|
14
14
|
static targets = [
|
|
15
15
|
"editorContent",
|
|
16
16
|
"editorJson",
|
|
17
17
|
"floatingMenu",
|
|
18
|
+
"stateButton",
|
|
18
19
|
"hiddenPromptsButton",
|
|
19
20
|
"hiddenImageButton",
|
|
20
21
|
"hiddenLinkButton",
|
|
@@ -34,43 +35,50 @@ export class Controller extends BaseController {
|
|
|
34
35
|
heading: {
|
|
35
36
|
levels: [2, 3, 4],
|
|
36
37
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
target: null,
|
|
38
|
+
link: {
|
|
39
|
+
openOnClick: false,
|
|
40
|
+
// Internal links are stored as GlobalIDs (resolved to URLs at
|
|
41
|
+
// render time): without this, setLink refuses the gid:// scheme
|
|
42
|
+
// and silently does nothing. A check rather than the `protocols`
|
|
43
|
+
// option, which registers the scheme with linkifyjs, and warns
|
|
44
|
+
// from the second editor on ("linkifyjs: already initialized").
|
|
45
|
+
isAllowedUri: (url, { defaultValidate }) =>
|
|
46
|
+
url.startsWith("gid://") || defaultValidate(url),
|
|
47
|
+
HTMLAttributes: {
|
|
48
|
+
"data-action": `${this.identifier}#selectLink`,
|
|
49
|
+
target: null,
|
|
50
|
+
},
|
|
51
51
|
},
|
|
52
|
+
// Not in Trek's editor before Tiptap 3: no underline (nor its
|
|
53
|
+
// Ctrl+U shortcut), and no empty paragraph added after a final
|
|
54
|
+
// block, which would change every saved document
|
|
55
|
+
underline: false,
|
|
56
|
+
trailingNode: false,
|
|
52
57
|
}),
|
|
53
58
|
TableOfContents,
|
|
54
59
|
this.hasFloatingMenuTarget
|
|
55
|
-
? FloatingMenu.configure({
|
|
56
|
-
element: this.floatingMenuTarget,
|
|
57
|
-
})
|
|
60
|
+
? FloatingMenu.configure({ element: this.floatingMenuTarget })
|
|
58
61
|
: null,
|
|
59
62
|
ImageBlock,
|
|
60
63
|
PromptsBlock,
|
|
61
|
-
],
|
|
64
|
+
].filter(Boolean),
|
|
62
65
|
content: this.contentJson,
|
|
63
66
|
autofocus: this.autofocusValue ? "end" : false,
|
|
67
|
+
onUpdate: () => this.updateContent(),
|
|
68
|
+
// Every change of the document or the selection: the buttons show the
|
|
69
|
+
// styles and the block where the cursor is
|
|
70
|
+
onTransaction: () => this.updateButtons(),
|
|
64
71
|
});
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
// Tiptap 3 moves the floating menu next to the editor when it shows it,
|
|
74
|
+
// and out of the page when it hides it, but leaves it where the template
|
|
75
|
+
// puts it until then: out of the page from the start, as Tiptap 2 did
|
|
76
|
+
if (this.hasFloatingMenuTarget) this.floatingMenuTarget.remove();
|
|
68
77
|
this.updateContent();
|
|
78
|
+
this.updateButtons();
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
disconnect() {
|
|
72
|
-
this.editor.off("update", () => this.updateContent());
|
|
73
|
-
this.editor.off("selectionUpdate", () => this.updateSelection());
|
|
74
82
|
this.editor.destroy();
|
|
75
83
|
this.editor = null;
|
|
76
84
|
}
|
|
@@ -79,264 +87,99 @@ export class Controller extends BaseController {
|
|
|
79
87
|
this.editor.chain().focus().run();
|
|
80
88
|
}
|
|
81
89
|
|
|
90
|
+
// A toolbar button's command, from its params (see the component's `command_data`)
|
|
91
|
+
run({ params: { command, level } }) {
|
|
92
|
+
this.editor
|
|
93
|
+
.chain()
|
|
94
|
+
.focus()
|
|
95
|
+
[command](level ? { level } : undefined)
|
|
96
|
+
.run();
|
|
97
|
+
}
|
|
98
|
+
|
|
82
99
|
updateContent() {
|
|
83
100
|
this.editorJsonTarget.value = JSON.stringify(this.editor.getJSON());
|
|
84
101
|
}
|
|
85
102
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
{ key: "h2", command: "heading", params: { level: 2 } },
|
|
96
|
-
{ key: "h3", command: "heading", params: { level: 3 } },
|
|
97
|
-
{ key: "h4", command: "heading", params: { level: 4 } },
|
|
98
|
-
{ key: "h5", command: "heading", params: { level: 5 } },
|
|
99
|
-
{ key: "h6", command: "heading", params: { level: 6 } },
|
|
100
|
-
{ key: "bulletList" },
|
|
101
|
-
{ key: "orderedList" },
|
|
102
|
-
{ key: "codeBlock" },
|
|
103
|
-
{ key: "blockquote" },
|
|
104
|
-
];
|
|
105
|
-
|
|
106
|
-
buttons.forEach((b) => {
|
|
107
|
-
const button = this.element.querySelector("button." + b.key);
|
|
108
|
-
|
|
109
|
-
if (!button) return;
|
|
110
|
-
|
|
111
|
-
const active = this.editor.isActive(b.command || b.key, b.params || {});
|
|
112
|
-
|
|
103
|
+
updateButtons() {
|
|
104
|
+
this.stateButtonTargets.forEach((button) => {
|
|
105
|
+
const level = Number(
|
|
106
|
+
button.getAttribute(`data-${this.identifier}-level-param`)
|
|
107
|
+
);
|
|
108
|
+
const active = this.editor.isActive(
|
|
109
|
+
button.dataset.stateName,
|
|
110
|
+
level ? { level } : {}
|
|
111
|
+
);
|
|
113
112
|
button.classList.toggle(this.activeClass, active);
|
|
114
113
|
});
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
this.editor.chain().focus().toggleBold().run();
|
|
119
|
-
e.target.classList.toggle(this.activeClass, this.editor.isActive("bold"));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
toggleItalic(e) {
|
|
123
|
-
this.editor.chain().focus().toggleItalic().run();
|
|
124
|
-
e.target.classList.toggle(this.activeClass, this.editor.isActive("italic"));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
toggleStrike(e) {
|
|
128
|
-
this.editor.chain().focus().toggleStrike().run();
|
|
129
|
-
e.target.classList.toggle(this.activeClass, this.editor.isActive("strike"));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
toggleCode(e) {
|
|
133
|
-
this.editor.chain().focus().toggleCode().run();
|
|
134
|
-
e.target.classList.toggle(this.activeClass, this.editor.isActive("code"));
|
|
135
|
-
}
|
|
116
|
+
// Links
|
|
136
117
|
|
|
137
118
|
selectLink() {
|
|
138
119
|
this.editor.commands.extendMarkRange("link");
|
|
139
120
|
}
|
|
140
121
|
|
|
141
|
-
toggleLink(
|
|
122
|
+
toggleLink() {
|
|
142
123
|
this.selectLink();
|
|
143
|
-
e.target.classList.toggle(this.activeClass, this.editor.isActive("link"));
|
|
144
|
-
|
|
145
|
-
const attributes = this.editor.getAttributes("link");
|
|
146
|
-
attributes.text = this.currentlySelectedText();
|
|
147
|
-
|
|
148
|
-
const url = this.hiddenLinkButtonTarget.dataset.basePath;
|
|
149
|
-
this.hiddenLinkButtonTarget.href = url + "&" + this.linkParams(attributes);
|
|
150
|
-
this.hiddenLinkButtonTarget.click();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
linkParams(attributes) {
|
|
154
|
-
const linkAttributes = Object.fromEntries(
|
|
155
|
-
Object.entries(attributes).map(([k, v]) => [`link[${k}]`, v])
|
|
156
|
-
);
|
|
157
|
-
return new URLSearchParams(linkAttributes).toString();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
currentlySelectedText() {
|
|
161
|
-
const state = this.editor.state;
|
|
162
|
-
const text = state.doc.textBetween(
|
|
163
|
-
state.selection.from,
|
|
164
|
-
state.selection.to
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
return text;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
linkInserterTargetConnected(t) {
|
|
171
|
-
const params = JSON.parse(t.dataset.params);
|
|
172
|
-
|
|
173
|
-
this.editor
|
|
174
|
-
.chain()
|
|
175
|
-
.focus()
|
|
176
|
-
.setLink({
|
|
177
|
-
href: params.href,
|
|
178
|
-
target: params.target,
|
|
179
|
-
title: params.title,
|
|
180
|
-
})
|
|
181
|
-
.run();
|
|
182
|
-
|
|
183
|
-
t.parentNode.removeChild(t);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
unsetAllMarks() {
|
|
187
|
-
this.editor.chain().focus().unsetAllMarks().run();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
clearNodes() {
|
|
191
|
-
this.editor.chain().focus().clearNodes().run();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
setParagraph(e) {
|
|
195
|
-
this.editor.chain().focus().setParagraph().run();
|
|
196
|
-
e.target.classList.toggle(
|
|
197
|
-
this.activeClass,
|
|
198
|
-
this.editor.isActive("paragraph")
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
toggleHeading(e) {
|
|
203
|
-
const level = parseInt(e.target.dataset.level, 10);
|
|
204
|
-
this.editor.chain().focus().toggleHeading({ level: level }).run();
|
|
205
|
-
e.target.classList.toggle(
|
|
206
|
-
this.activeClass,
|
|
207
|
-
this.editor.isActive("heading", { level: level })
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
toggleBulletList(e) {
|
|
212
|
-
this.editor.chain().focus().toggleBulletList().run();
|
|
213
|
-
e.target.classList.toggle(
|
|
214
|
-
this.activeClass,
|
|
215
|
-
this.editor.isActive("bulletList")
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
toggleOrderedList(e) {
|
|
220
|
-
this.editor.chain().focus().toggleOrderedList().run();
|
|
221
|
-
e.target.classList.toggle(
|
|
222
|
-
this.activeClass,
|
|
223
|
-
this.editor.isActive("orderedList")
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
124
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
);
|
|
125
|
+
const attributes = {
|
|
126
|
+
...this.editor.getAttributes("link"),
|
|
127
|
+
text: this.selectedText,
|
|
128
|
+
};
|
|
129
|
+
this.openPanel(this.hiddenLinkButtonTarget, toParams("link", attributes));
|
|
233
130
|
}
|
|
234
131
|
|
|
235
|
-
|
|
236
|
-
this.editor.
|
|
237
|
-
|
|
238
|
-
this.activeClass,
|
|
239
|
-
this.editor.isActive("blockquote")
|
|
240
|
-
);
|
|
132
|
+
get selectedText() {
|
|
133
|
+
const { doc, selection } = this.editor.state;
|
|
134
|
+
return doc.textBetween(selection.from, selection.to);
|
|
241
135
|
}
|
|
242
136
|
|
|
243
|
-
|
|
244
|
-
|
|
137
|
+
linkInserterTargetConnected(inserter) {
|
|
138
|
+
const { href, target, title } = JSON.parse(inserter.dataset.params);
|
|
139
|
+
this.editor.chain().focus().setLink({ href, target, title }).run();
|
|
140
|
+
inserter.remove();
|
|
245
141
|
}
|
|
246
142
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
143
|
+
// Blocks (calls to action, images): a block's button carries its
|
|
144
|
+
// attributes (see block_view.js), the floating menu's none
|
|
250
145
|
|
|
251
|
-
|
|
252
|
-
this.
|
|
146
|
+
togglePrompts(event) {
|
|
147
|
+
this.openPanel(this.hiddenPromptsButtonTarget, blockParams(event));
|
|
253
148
|
}
|
|
254
149
|
|
|
255
|
-
|
|
256
|
-
this.
|
|
150
|
+
toggleImage(event) {
|
|
151
|
+
this.openPanel(this.hiddenImageButtonTarget, blockParams(event));
|
|
257
152
|
}
|
|
258
153
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.
|
|
263
|
-
|
|
154
|
+
// The panel's response: a new block, at the cursor, or an edited one, in
|
|
155
|
+
// place of the block selected by clicking it
|
|
156
|
+
contentInserterTargetConnected(inserter) {
|
|
157
|
+
this.editor.commands.insertContent(inserter.innerHTML);
|
|
158
|
+
inserter.remove();
|
|
264
159
|
}
|
|
265
160
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const pos = this._editingImagePos;
|
|
272
|
-
this._editingImagePos = null;
|
|
273
|
-
|
|
274
|
-
const parser = new DOMParser();
|
|
275
|
-
const doc = parser.parseFromString(content, "text/html");
|
|
276
|
-
const imageBlock = doc.querySelector("image-block");
|
|
277
|
-
|
|
278
|
-
if (imageBlock) {
|
|
279
|
-
const attrs = {};
|
|
280
|
-
for (const attr of imageBlock.attributes) {
|
|
281
|
-
attrs[attr.name] = attr.value;
|
|
282
|
-
}
|
|
283
|
-
const tr = this.editor.state.tr;
|
|
284
|
-
const node = this.editor.state.doc.nodeAt(pos);
|
|
285
|
-
if (node && node.type.name === "imageBlock") {
|
|
286
|
-
tr.setNodeMarkup(pos, undefined, attrs);
|
|
287
|
-
this.editor.view.dispatch(tr);
|
|
288
|
-
} else {
|
|
289
|
-
this.editor.commands.insertContent(content);
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
this.editor.commands.insertContent(content);
|
|
293
|
-
}
|
|
294
|
-
} else {
|
|
295
|
-
this.editor.commands.insertContent(content);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
t.parentNode.removeChild(t);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
toggleImage(e) {
|
|
302
|
-
const button = e.target.closest("button");
|
|
303
|
-
const params = button.dataset.params;
|
|
304
|
-
|
|
305
|
-
// Check if clicking an existing image block in the editor
|
|
306
|
-
const imageBlockEl = button.closest("image-block");
|
|
307
|
-
if (imageBlockEl) {
|
|
308
|
-
const pos = this.editor.view.posAtDOM(imageBlockEl, 0);
|
|
309
|
-
const resolved = this.editor.state.doc.resolve(pos);
|
|
310
|
-
// Walk up to find the imageBlock node position
|
|
311
|
-
for (let d = resolved.depth; d >= 0; d--) {
|
|
312
|
-
if (resolved.node(d).type.name === "imageBlock") {
|
|
313
|
-
this._editingImagePos = d > 0 ? resolved.before(d) : pos;
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
// Fallback: the pos itself might point at the imageBlock
|
|
318
|
-
if (this._editingImagePos == null) {
|
|
319
|
-
const node = this.editor.state.doc.nodeAt(pos);
|
|
320
|
-
if (node && node.type.name === "imageBlock") {
|
|
321
|
-
this._editingImagePos = pos;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
} else {
|
|
325
|
-
this._editingImagePos = null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const url = this.hiddenImageButtonTarget.dataset.basePath;
|
|
329
|
-
this.hiddenImageButtonTarget.href = url + (params ? "&" + params : "");
|
|
330
|
-
this.hiddenImageButtonTarget.click();
|
|
161
|
+
// Opens a panel through its hidden link, with the given params
|
|
162
|
+
openPanel(link, params) {
|
|
163
|
+
const url = link.dataset.basePath;
|
|
164
|
+
link.href = params ? `${url}&${params}` : url;
|
|
165
|
+
link.click();
|
|
331
166
|
}
|
|
332
167
|
|
|
333
168
|
get contentJson() {
|
|
334
169
|
const { value } = this.editorJsonTarget;
|
|
335
|
-
|
|
336
|
-
if (value == "") {
|
|
337
|
-
return "";
|
|
338
|
-
} else {
|
|
339
|
-
return JSON.parse(value);
|
|
340
|
-
}
|
|
170
|
+
return value == "" ? "" : JSON.parse(value);
|
|
341
171
|
}
|
|
342
172
|
}
|
|
173
|
+
|
|
174
|
+
function toParams(scope, attributes) {
|
|
175
|
+
return new URLSearchParams(
|
|
176
|
+
Object.entries(attributes).map(([name, value]) => [
|
|
177
|
+
`${scope}[${name}]`,
|
|
178
|
+
value ?? "",
|
|
179
|
+
])
|
|
180
|
+
).toString();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function blockParams(event) {
|
|
184
|
+
return event.target.closest("button")?.dataset.params;
|
|
185
|
+
}
|