decidim-core 0.23.6 → 0.24.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim-core might be problematic. Click here for more details.

Files changed (455) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/images/decidim/icons.svg +1 -1
  4. data/app/assets/javascripts/decidim/core/bundle.js +1 -1
  5. data/app/assets/javascripts/decidim/core/bundle.js.map +1 -1
  6. data/app/assets/javascripts/decidim/editor/history_override.js.es6 +117 -0
  7. data/app/assets/javascripts/decidim/editor/linebreak_module.js.es6 +83 -0
  8. data/app/assets/javascripts/decidim/editor/modified_backspace_offset1.js.es6 +98 -0
  9. data/app/assets/javascripts/decidim/editor/modified_backspace_offset_any.js.es6 +48 -0
  10. data/app/assets/javascripts/decidim/editor/modified_backspace_utils.js.es6 +31 -0
  11. data/app/assets/javascripts/decidim/editor/modified_enter.js.es6 +118 -0
  12. data/app/assets/javascripts/decidim/editor.js.es6 +15 -4
  13. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +25 -0
  14. data/app/assets/javascripts/decidim/geocoding/attach_input.js.es6 +41 -4
  15. data/app/assets/javascripts/decidim/input_character_counter.js.es6 +6 -1
  16. data/app/assets/javascripts/decidim/map/controller/markers.js.es6 +27 -9
  17. data/app/assets/javascripts/decidim/session_timeouter.js.es6 +78 -0
  18. data/app/assets/javascripts/decidim.js.es6 +1 -0
  19. data/app/assets/stylesheets/decidim/_variables.scss +9 -0
  20. data/app/assets/stylesheets/decidim/email.scss +14 -2
  21. data/app/assets/stylesheets/decidim/extras/_external-links.scss +0 -1
  22. data/app/assets/stylesheets/decidim/extras/_process_stats.scss +1 -1
  23. data/app/assets/stylesheets/decidim/extras/_results-per-page.scss +1 -0
  24. data/app/assets/stylesheets/decidim/modules/_author-avatar.scss +2 -2
  25. data/app/assets/stylesheets/decidim/modules/_buttons.scss +2 -2
  26. data/app/assets/stylesheets/decidim/modules/_cards.scss +18 -1
  27. data/app/assets/stylesheets/decidim/modules/_collapsible-list.scss +1 -1
  28. data/app/assets/stylesheets/decidim/modules/_comments.scss +5 -1
  29. data/app/assets/stylesheets/decidim/modules/_conference-speaker.scss +4 -3
  30. data/app/assets/stylesheets/decidim/modules/_data-picker.scss +7 -0
  31. data/app/assets/stylesheets/decidim/modules/_extra.scss +4 -0
  32. data/app/assets/stylesheets/decidim/modules/_forms.scss +4 -0
  33. data/app/assets/stylesheets/decidim/modules/_loading-spinner.scss +34 -0
  34. data/app/assets/stylesheets/decidim/modules/_modules.scss +1 -1
  35. data/app/assets/stylesheets/decidim/modules/_opinion-toggle.scss +1 -1
  36. data/app/assets/stylesheets/decidim/modules/_reveal.scss +6 -0
  37. data/app/assets/stylesheets/decidim/modules/_signup.scss +1 -0
  38. data/app/assets/stylesheets/decidim/modules/{_process-stats.scss → _space-stats.scss} +1 -1
  39. data/app/cells/decidim/activity/show.erb +1 -1
  40. data/app/cells/decidim/activity_cell.rb +11 -14
  41. data/app/cells/decidim/address/details.erb +5 -5
  42. data/app/cells/decidim/address_cell.rb +0 -21
  43. data/app/cells/decidim/announcement/show.erb +4 -4
  44. data/app/cells/decidim/announcement_cell.rb +22 -2
  45. data/app/cells/decidim/author/flag_user.erb +10 -0
  46. data/app/cells/decidim/author/profile_minicard.erb +1 -1
  47. data/app/cells/decidim/author_cell.rb +9 -1
  48. data/app/cells/decidim/card_m/top.erb +1 -1
  49. data/app/cells/decidim/card_m_cell.rb +1 -1
  50. data/app/cells/decidim/content_blocks/cta/show.erb +14 -0
  51. data/app/cells/decidim/content_blocks/cta_cell.rb +35 -0
  52. data/app/cells/decidim/content_blocks/cta_settings_form/show.erb +9 -0
  53. data/app/cells/decidim/content_blocks/cta_settings_form_cell.rb +13 -0
  54. data/app/cells/decidim/content_blocks/hero_cell.rb +14 -0
  55. data/app/cells/decidim/content_blocks/highlighted_elements/elements.erb +0 -0
  56. data/app/cells/decidim/content_blocks/highlighted_elements/heading.erb +0 -0
  57. data/app/cells/decidim/content_blocks/highlighted_elements/show.erb +4 -0
  58. data/app/cells/decidim/content_blocks/highlighted_elements_cell.rb +51 -0
  59. data/app/cells/decidim/content_blocks/highlighted_elements_settings_form/show.erb +3 -0
  60. data/app/cells/decidim/content_blocks/highlighted_elements_settings_form_cell.rb +28 -0
  61. data/app/cells/decidim/content_blocks/last_activity_cell.rb +11 -0
  62. data/app/cells/decidim/content_blocks/metrics_cell.rb +0 -6
  63. data/app/cells/decidim/content_blocks/stats_cell.rb +0 -6
  64. data/app/cells/decidim/date/show.erb +31 -0
  65. data/app/cells/decidim/date_cell.rb +50 -0
  66. data/app/cells/decidim/endorsement_buttons_cell.rb +3 -3
  67. data/app/cells/decidim/flag_modal/flag_user.erb +24 -0
  68. data/app/cells/decidim/flag_modal/show.erb +24 -0
  69. data/app/cells/decidim/flag_modal_cell.rb +25 -0
  70. data/app/cells/decidim/profile/inaccessible.erb +9 -0
  71. data/app/cells/decidim/profile_cell.rb +9 -1
  72. data/app/cells/decidim/profile_sidebar/show.erb +10 -1
  73. data/app/cells/decidim/profile_sidebar_cell.rb +1 -0
  74. data/app/cells/decidim/reported_content/show.erb +5 -0
  75. data/app/cells/decidim/reported_content_cell.rb +44 -0
  76. data/app/cells/decidim/scopes_picker/scope_picker_prompt.erb +3 -0
  77. data/app/cells/decidim/scopes_picker/scope_picker_values.erb +5 -0
  78. data/app/cells/decidim/scopes_picker/show.erb +14 -0
  79. data/app/cells/decidim/scopes_picker_cell.rb +93 -0
  80. data/app/cells/decidim/tos_page/announcement.erb +1 -1
  81. data/app/cells/decidim/tos_page/form.erb +15 -13
  82. data/app/cells/decidim/tos_page_cell.rb +10 -8
  83. data/app/cells/decidim/translation_bar_cell.rb +1 -1
  84. data/app/cells/decidim/user_conversation/conversation_header.erb +1 -1
  85. data/app/cells/decidim/user_conversations_cell.rb +1 -1
  86. data/app/commands/decidim/create_report.rb +11 -1
  87. data/app/commands/decidim/create_user_report.rb +67 -0
  88. data/app/commands/decidim/destroy_account.rb +0 -2
  89. data/app/commands/decidim/gallery_methods.rb +2 -2
  90. data/app/commands/decidim/multiple_attachments_methods.rb +14 -10
  91. data/app/commands/decidim/search.rb +5 -2
  92. data/app/commands/decidim/update_notifications_settings.rb +1 -0
  93. data/app/commands/decidim/update_user_group.rb +1 -0
  94. data/app/controllers/concerns/decidim/devise_controllers.rb +1 -1
  95. data/app/controllers/concerns/decidim/flaggable.rb +5 -1
  96. data/app/controllers/concerns/decidim/force_authentication.rb +11 -3
  97. data/app/controllers/concerns/decidim/locale_switcher.rb +5 -0
  98. data/app/controllers/concerns/decidim/needs_permission.rb +7 -1
  99. data/app/controllers/concerns/decidim/orderable.rb +3 -1
  100. data/app/controllers/concerns/decidim/user_blocked_checker.rb +26 -0
  101. data/app/controllers/decidim/application_controller.rb +22 -0
  102. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +3 -1
  103. data/app/controllers/decidim/devise/sessions_controller.rb +10 -6
  104. data/app/controllers/decidim/errors_controller.rb +1 -1
  105. data/app/controllers/decidim/locales_controller.rb +1 -1
  106. data/app/controllers/decidim/profiles_controller.rb +6 -0
  107. data/app/controllers/decidim/report_users_controller.rb +42 -0
  108. data/app/controllers/decidim/scopes_controller.rb +19 -10
  109. data/app/controllers/decidim/timeouts_controller.rb +28 -0
  110. data/app/controllers/decidim/user_activities_controller.rb +5 -0
  111. data/app/controllers/decidim/user_timeline_controller.rb +1 -0
  112. data/app/events/decidim/demoted_membership_event.rb +2 -2
  113. data/app/events/decidim/invited_to_group_event.rb +2 -2
  114. data/app/events/decidim/join_request_accepted_event.rb +2 -2
  115. data/app/events/decidim/join_request_created_event.rb +2 -2
  116. data/app/events/decidim/join_request_rejected_event.rb +2 -2
  117. data/app/events/decidim/promoted_to_admin_event.rb +2 -2
  118. data/app/events/decidim/removed_from_group_event.rb +2 -2
  119. data/app/forms/decidim/account_form.rb +2 -2
  120. data/app/forms/decidim/invite_user_form.rb +2 -2
  121. data/app/forms/decidim/messaging/conversation_form.rb +1 -1
  122. data/app/forms/decidim/messaging/message_form.rb +1 -1
  123. data/app/forms/decidim/notifications_settings_form.rb +20 -0
  124. data/app/forms/url_validator.rb +20 -0
  125. data/app/helpers/decidim/action_authorization_helper.rb +2 -0
  126. data/app/helpers/decidim/application_helper.rb +1 -3
  127. data/app/helpers/decidim/cells_helper.rb +6 -0
  128. data/app/helpers/decidim/filters_helper.rb +9 -0
  129. data/app/helpers/decidim/messaging/conversation_helper.rb +11 -1
  130. data/app/helpers/decidim/newsletters_helper.rb +7 -9
  131. data/app/helpers/decidim/scopes_helper.rb +1 -1
  132. data/app/jobs/decidim/block_user_job.rb +11 -0
  133. data/app/jobs/decidim/export_job.rb +2 -2
  134. data/app/jobs/decidim/find_and_update_descendants_job.rb +48 -0
  135. data/app/jobs/decidim/machine_translation_resource_job.rb +3 -0
  136. data/app/jobs/decidim/machine_translation_save_job.rb +29 -0
  137. data/app/jobs/decidim/update_search_indexes_job.rb +11 -0
  138. data/app/jobs/decidim/user_report_job.rb +11 -0
  139. data/app/mailers/decidim/block_user_mailer.rb +21 -0
  140. data/app/mailers/decidim/reported_mailer.rb +33 -3
  141. data/app/mailers/decidim/user_report_mailer.rb +21 -0
  142. data/app/models/decidim/area.rb +0 -1
  143. data/app/models/decidim/area_type.rb +1 -1
  144. data/app/models/decidim/attachment.rb +3 -2
  145. data/app/models/decidim/attachment_collection.rb +1 -1
  146. data/app/models/decidim/authorization.rb +4 -0
  147. data/app/models/decidim/category.rb +6 -1
  148. data/app/models/decidim/impersonation_log.rb +5 -7
  149. data/app/models/decidim/metric.rb +2 -2
  150. data/app/models/decidim/moderation.rb +12 -0
  151. data/app/models/decidim/organization.rb +5 -1
  152. data/app/models/decidim/scope.rb +5 -2
  153. data/app/models/decidim/scope_type.rb +1 -1
  154. data/app/models/decidim/share_token.rb +1 -1
  155. data/app/models/decidim/static_page.rb +11 -1
  156. data/app/models/decidim/static_page_topic.rb +4 -0
  157. data/app/models/decidim/user.rb +13 -8
  158. data/app/models/decidim/user_base_entity.rb +13 -13
  159. data/app/models/decidim/user_block.rb +10 -0
  160. data/app/models/decidim/user_group.rb +1 -4
  161. data/app/models/decidim/user_moderation.rb +22 -0
  162. data/app/models/decidim/user_report.rb +31 -0
  163. data/app/permissions/decidim/permissions.rb +1 -3
  164. data/app/permissions/decidim/report_user_permissions.rb +13 -0
  165. data/app/presenters/decidim/admin_log/impersonation_log_presenter.rb +39 -0
  166. data/app/presenters/decidim/admin_log/organization_presenter.rb +1 -2
  167. data/app/presenters/decidim/admin_log/user_moderation_presenter.rb +63 -0
  168. data/app/presenters/decidim/admin_log/user_presenter.rb +18 -9
  169. data/app/presenters/decidim/home_stats_presenter.rb +3 -3
  170. data/app/presenters/decidim/log/diff_presenter.rb +4 -3
  171. data/app/presenters/decidim/log/resource_presenter.rb +4 -4
  172. data/app/presenters/decidim/log/user_presenter.rb +1 -1
  173. data/app/presenters/decidim/menu_presenter.rb +12 -7
  174. data/app/presenters/decidim/nil_presenter.rb +0 -2
  175. data/app/presenters/decidim/user_presenter.rb +1 -1
  176. data/app/queries/decidim/metrics/blocked_users_metric_manage.rb +26 -0
  177. data/app/queries/decidim/metrics/followers_metric_manage.rb +3 -0
  178. data/app/queries/decidim/metrics/participants_metric_manage.rb +3 -0
  179. data/app/queries/decidim/metrics/reported_users_metric_manage.rb +26 -0
  180. data/app/queries/decidim/metrics/user_reports_metric_manage.rb +26 -0
  181. data/app/queries/decidim/user_groups/accepted_memberships.rb +1 -1
  182. data/app/queries/decidim/user_groups/admin_memberships.rb +1 -1
  183. data/app/queries/decidim/user_groups/member_memberships.rb +1 -1
  184. data/app/services/decidim/activity_search.rb +1 -3
  185. data/app/services/decidim/base_diff_renderer.rb +1 -1
  186. data/app/services/decidim/data_portability_exporter.rb +1 -0
  187. data/app/services/decidim/email_notification_generator.rb +2 -2
  188. data/app/services/decidim/events_manager.rb +1 -1
  189. data/app/services/decidim/open_data_exporter.rb +36 -7
  190. data/app/services/decidim/zip_stream/zip_stream_writer.rb +3 -3
  191. data/app/uploaders/decidim/application_uploader.rb +22 -2
  192. data/app/uploaders/decidim/attachment_uploader.rb +2 -4
  193. data/app/uploaders/decidim/downloader.rb +9 -0
  194. data/app/uploaders/decidim/image_uploader.rb +9 -21
  195. data/app/uploaders/decidim/open_data_uploader.rb +5 -0
  196. data/app/uploaders/decidim/record_image_uploader.rb +2 -2
  197. data/app/validators/etiquette_validator.rb +0 -7
  198. data/app/validators/uploader_content_type_validator.rb +4 -2
  199. data/app/views/decidim/application/_document.html.erb +1 -1
  200. data/app/views/decidim/block_user_mailer/notify.html.erb +7 -0
  201. data/app/views/decidim/devise/confirmations/new.html.erb +1 -1
  202. data/app/views/decidim/devise/registrations/edit.html.erb +1 -1
  203. data/app/views/decidim/devise/unlocks/new.html.erb +1 -1
  204. data/app/views/decidim/messaging/conversations/_conversation.html.erb +1 -1
  205. data/app/views/decidim/messaging/conversations/_messages.html.erb +1 -1
  206. data/app/views/decidim/messaging/conversations/_show.html.erb +4 -4
  207. data/app/views/decidim/notifications_settings/show.html.erb +11 -0
  208. data/app/views/decidim/pages/_standalone.html.erb +3 -1
  209. data/app/views/decidim/reported_mailer/report.html.erb +9 -17
  210. data/app/views/decidim/shared/_check_boxes_tree.html.erb +3 -3
  211. data/app/views/decidim/shared/_component_announcement.html.erb +2 -2
  212. data/app/views/decidim/shared/participatory_space_filters/_filters.html.erb +1 -1
  213. data/app/views/decidim/user_report_mailer/notify.html.erb +7 -0
  214. data/app/views/decidim/widgets/_data_picker.html.erb +1 -1
  215. data/app/views/layouts/decidim/_application.html.erb +1 -0
  216. data/app/views/layouts/decidim/_js_configuration.html.erb +1 -1
  217. data/app/views/layouts/decidim/_main_footer.html.erb +6 -4
  218. data/app/views/layouts/decidim/_timeout_modal.html.erb +21 -0
  219. data/config/initializers/active_support.rb +7 -0
  220. data/config/initializers/devise.rb +1 -1
  221. data/config/initializers/omniauth.rb +1 -1
  222. data/config/locales/ar.yml +1 -7
  223. data/config/locales/bg.yml +1 -13
  224. data/config/locales/ca.yml +46 -17
  225. data/config/locales/cs.yml +118 -53
  226. data/config/locales/de.yml +83 -18
  227. data/config/locales/el.yml +1 -14
  228. data/config/locales/en.yml +79 -14
  229. data/config/locales/eo.yml +0 -1
  230. data/config/locales/es-MX.yml +31 -14
  231. data/config/locales/es-PY.yml +31 -14
  232. data/config/locales/es.yml +34 -17
  233. data/config/locales/eu.yml +4 -10
  234. data/config/locales/fi-plain.yml +80 -16
  235. data/config/locales/fi.yml +85 -21
  236. data/config/locales/fr-CA.yml +79 -14
  237. data/config/locales/fr.yml +76 -11
  238. data/config/locales/gl.yml +1 -15
  239. data/config/locales/hu.yml +1 -12
  240. data/config/locales/id-ID.yml +1 -7
  241. data/config/locales/is-IS.yml +0 -9
  242. data/config/locales/it.yml +72 -19
  243. data/config/locales/ja.yml +1 -14
  244. data/config/locales/lv.yml +1 -12
  245. data/config/locales/nl.yml +38 -13
  246. data/config/locales/no.yml +7 -14
  247. data/config/locales/pl.yml +81 -14
  248. data/config/locales/pt-BR.yml +1 -7
  249. data/config/locales/pt.yml +1 -14
  250. data/config/locales/ro-RO.yml +15 -25
  251. data/config/locales/ru.yml +7 -12
  252. data/config/locales/sk.yml +2 -13
  253. data/config/locales/sr-CS.yml +0 -9
  254. data/config/locales/sv.yml +5 -27
  255. data/config/locales/tr-TR.yml +65 -14
  256. data/config/locales/uk.yml +7 -9
  257. data/config/locales/zh-CN.yml +1 -14
  258. data/config/routes.rb +9 -4
  259. data/db/migrate/20170713131206_add_admin_to_users.rb +1 -1
  260. data/db/migrate/20180206143340_fix_reference_for_all_resources.rb +2 -0
  261. data/db/migrate/20180314085339_rename_maximum_votes_per_proposal_to_threshold_per_proposal.rb +2 -2
  262. data/db/migrate/20200929171508_remove_show_statistics_from_organizations.rb +7 -0
  263. data/db/migrate/20201010124755_create_decidim_user_moderations.rb +12 -0
  264. data/db/migrate/20201010124756_create_decidim_user_reports.rb +16 -0
  265. data/db/migrate/20201010224433_add_suspension_fields_to_decidim_users.rb +8 -0
  266. data/db/migrate/20201011074641_create_decidim_user_suspensions.rb +14 -0
  267. data/db/migrate/20201011081626_add_current_suspension_id_to_decidim_users.rb +7 -0
  268. data/db/migrate/20201013071533_add_reported_content_to_moderations.rb +7 -0
  269. data/db/migrate/20201019074554_add_locale_to_moderation_reports.rb +7 -0
  270. data/db/migrate/20201127114444_encrypt_authorization_metadatas.rb +35 -0
  271. data/db/migrate/20201128130723_add_allow_public_access_to_static_pages.rb +17 -0
  272. data/db/migrate/20201218144706_update_table_block_user_functionality.rb +8 -0
  273. data/db/migrate/20201218145252_rename_decidim_user_fields_for_block_functionality.rb +9 -0
  274. data/db/migrate/20210208134328_add_email_on_moderations_to_users.rb +7 -0
  275. data/db/seeds.rb +14 -13
  276. data/lib/decidim/amendable.rb +3 -2
  277. data/{app/functions/decidim/core → lib/decidim/api/functions}/component_finder_base.rb +1 -1
  278. data/{app/functions/decidim/core → lib/decidim/api/functions}/component_list.rb +4 -4
  279. data/{app/functions/decidim/core → lib/decidim/api/functions}/component_list_base.rb +3 -1
  280. data/lib/decidim/api/functions/needs_api_default_order.rb +24 -0
  281. data/{app/functions/decidim/core → lib/decidim/api/functions}/needs_api_filter_and_order.rb +0 -0
  282. data/{app/functions/decidim/core → lib/decidim/api/functions}/participatory_space_finder_base.rb +2 -2
  283. data/{app/functions/decidim/core → lib/decidim/api/functions}/participatory_space_list_base.rb +3 -1
  284. data/{app/functions/decidim/core → lib/decidim/api/functions}/user_entity_finder.rb +1 -4
  285. data/{app/functions/decidim/core → lib/decidim/api/functions}/user_entity_list.rb +1 -3
  286. data/{app/types/decidim/core → lib/decidim/api/input_filters}/base_input_filter.rb +0 -0
  287. data/{app/types/decidim/core → lib/decidim/api/input_filters}/component_input_filter.rb +20 -22
  288. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_hastaggable_input_filter.rb +1 -1
  289. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_localized_input_filter.rb +3 -3
  290. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_publishable_input_filter.rb +6 -6
  291. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_timestamp_input_filter.rb +12 -12
  292. data/{app/types/decidim/core → lib/decidim/api/input_filters}/participatory_space_input_filter.rb +0 -1
  293. data/lib/decidim/api/input_filters/user_entity_input_filter.rb +89 -0
  294. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/base_input_sort.rb +3 -2
  295. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/component_input_sort.rb +10 -11
  296. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/has_endorsable_input_sort.rb +2 -4
  297. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/has_localized_input_sort.rb +3 -3
  298. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/has_publishable_input_sort.rb +1 -1
  299. data/lib/decidim/api/input_sorts/has_timestamp_input_sort.rb +12 -0
  300. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/participatory_space_input_sort.rb +1 -1
  301. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/user_entity_input_sort.rb +4 -4
  302. data/lib/decidim/api/{amendable_entity_interface.rb → interfaces/amendable_entity_interface.rb} +5 -5
  303. data/lib/decidim/api/interfaces/amendable_interface.rb +17 -0
  304. data/lib/decidim/api/{attachable_interface.rb → interfaces/attachable_interface.rb} +3 -3
  305. data/lib/decidim/api/interfaces/author_interface.rb +32 -0
  306. data/lib/decidim/api/interfaces/authorable_interface.rb +23 -0
  307. data/lib/decidim/api/{categorizable_interface.rb → interfaces/categorizable_interface.rb} +3 -3
  308. data/lib/decidim/api/interfaces/coauthorable_interface.rb +30 -0
  309. data/lib/decidim/api/interfaces/component_interface.rb +22 -0
  310. data/lib/decidim/api/interfaces/endorsable_interface.rb +19 -0
  311. data/lib/decidim/api/{fingerprint_interface.rb → interfaces/fingerprint_interface.rb} +3 -3
  312. data/lib/decidim/api/interfaces/participatory_space_interface.rb +48 -0
  313. data/lib/decidim/api/interfaces/participatory_space_resourceable_interface.rb +25 -0
  314. data/lib/decidim/api/{scopable_interface.rb → interfaces/scopable_interface.rb} +3 -3
  315. data/lib/decidim/api/interfaces/timestamps_interface.rb +15 -0
  316. data/lib/decidim/api/interfaces/traceable_interface.rb +14 -0
  317. data/lib/decidim/api/scalars/date_time_type.rb +17 -0
  318. data/lib/decidim/api/scalars/date_type.rb +17 -0
  319. data/lib/decidim/api/types/amendment_type.rb +19 -0
  320. data/lib/decidim/api/types/area_api_type.rb +16 -0
  321. data/lib/decidim/api/types/area_type_type.rb +13 -0
  322. data/lib/decidim/api/types/attachment_type.rb +13 -0
  323. data/lib/decidim/api/types/category_type.rb +14 -0
  324. data/{app/types/decidim/core → lib/decidim/api/types}/component_type.rb +2 -4
  325. data/lib/decidim/api/types/coordinates_type.rb +21 -0
  326. data/lib/decidim/api/types/decidim_type.rb +13 -0
  327. data/lib/decidim/api/types/fingerprint_type.rb +12 -0
  328. data/lib/decidim/api/types/hashtag_type.rb +13 -0
  329. data/lib/decidim/api/types/localized_string_type.rb +13 -0
  330. data/lib/decidim/api/types/metric_history_type.rb +18 -0
  331. data/lib/decidim/api/types/metric_type.rb +13 -0
  332. data/lib/decidim/api/types/organization_type.rb +17 -0
  333. data/lib/decidim/api/types/participatory_space_link_type.rb +22 -0
  334. data/lib/decidim/api/types/participatory_space_type.rb +10 -0
  335. data/lib/decidim/api/types/scope_api_type.rb +16 -0
  336. data/lib/decidim/api/types/session_type.rb +22 -0
  337. data/lib/decidim/api/types/statistic_type.rb +20 -0
  338. data/lib/decidim/api/types/trace_version_type.rb +21 -0
  339. data/lib/decidim/api/types/translated_field_type.rb +36 -0
  340. data/lib/decidim/api/types/user_group_type.rb +64 -0
  341. data/lib/decidim/api/types/user_type.rb +67 -0
  342. data/lib/decidim/attachment_attributes.rb +57 -0
  343. data/lib/decidim/attributes/clean_string.rb +37 -0
  344. data/lib/decidim/attributes.rb +1 -0
  345. data/lib/decidim/coauthorable.rb +3 -3
  346. data/lib/decidim/component_manifest.rb +17 -0
  347. data/lib/decidim/content_block_manifest.rb +1 -1
  348. data/lib/decidim/content_parsers/hashtag_parser.rb +3 -6
  349. data/lib/decidim/content_parsers/user_group_parser.rb +2 -5
  350. data/lib/decidim/content_parsers/user_parser.rb +2 -5
  351. data/lib/decidim/content_processor.rb +1 -1
  352. data/lib/decidim/content_renderers/hashtag_renderer.rb +3 -6
  353. data/lib/decidim/core/api.rb +71 -16
  354. data/lib/decidim/core/engine.rb +35 -6
  355. data/lib/decidim/core/test/factories.rb +53 -15
  356. data/lib/decidim/core/test/shared_examples/admin_resource_gallery_examples.rb +1 -1
  357. data/lib/decidim/core/test/shared_examples/amendable/amendment_accepted_event_examples.rb +1 -1
  358. data/lib/decidim/core/test/shared_examples/amendable/amendment_promoted_event_examples.rb +1 -1
  359. data/lib/decidim/core/test/shared_examples/amendable/amendment_rejected_event_examples.rb +1 -1
  360. data/lib/decidim/core/test/shared_examples/categorizable_interface_examples.rb +6 -14
  361. data/lib/decidim/core/test/shared_examples/comments_examples.rb +11 -9
  362. data/lib/decidim/core/test/shared_examples/component_type.rb +1 -1
  363. data/lib/decidim/core/test/shared_examples/controller_render_views.rb +28 -0
  364. data/lib/decidim/core/test/shared_examples/follows_examples.rb +1 -1
  365. data/lib/decidim/core/test/shared_examples/logo_email.rb +1 -1
  366. data/lib/decidim/core/test/shared_examples/map_examples.rb +1 -1
  367. data/lib/decidim/core/test/shared_examples/process_announcements_examples.rb +1 -1
  368. data/lib/decidim/core/test/shared_examples/reportable.rb +8 -0
  369. data/lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb +1 -1
  370. data/lib/decidim/core/test/shared_examples/searchable_participatory_space_examples.rb +2 -3
  371. data/lib/decidim/core/test/shared_examples/searchable_results_examples.rb +46 -0
  372. data/lib/decidim/core/test/shared_examples/static_pages_examples.rb +43 -0
  373. data/lib/decidim/core/test.rb +2 -0
  374. data/lib/decidim/core/version.rb +1 -1
  375. data/lib/decidim/core.rb +11 -3
  376. data/lib/decidim/diffy_extension.rb +2 -2
  377. data/lib/decidim/exporters/csv.rb +3 -2
  378. data/lib/decidim/exporters/export_data.rb +1 -1
  379. data/lib/decidim/faker/internet.rb +17 -0
  380. data/lib/decidim/faker/localized.rb +43 -20
  381. data/lib/decidim/file_validator_humanizer.rb +6 -4
  382. data/lib/decidim/form_builder.rb +33 -22
  383. data/lib/decidim/gamification/badge_scorer.rb +3 -2
  384. data/lib/decidim/gamification/base_event.rb +2 -2
  385. data/lib/decidim/geocodable.rb +2 -0
  386. data/lib/decidim/has_category.rb +1 -1
  387. data/lib/decidim/has_private_users.rb +1 -1
  388. data/lib/decidim/importers/import_manifest.rb +36 -0
  389. data/lib/decidim/map/autocomplete.rb +11 -1
  390. data/lib/decidim/metric_operation.rb +5 -6
  391. data/lib/decidim/participatory_space_resourceable.rb +1 -3
  392. data/lib/decidim/query_extensions.rb +90 -69
  393. data/lib/decidim/randomable.rb +6 -1
  394. data/lib/decidim/record_encryptor.rb +131 -0
  395. data/lib/decidim/reportable.rb +26 -0
  396. data/lib/decidim/resource_manifest.rb +3 -0
  397. data/lib/decidim/resourceable.rb +6 -6
  398. data/lib/decidim/scopable.rb +1 -1
  399. data/lib/decidim/search_resource_fields_mapper.rb +1 -1
  400. data/lib/decidim/searchable.rb +9 -0
  401. data/lib/decidim/settings_manifest.rb +2 -1
  402. data/lib/decidim/shareable_with_token.rb +0 -1
  403. data/lib/decidim/translatable_attributes.rb +2 -1
  404. data/lib/decidim/translatable_resource.rb +10 -0
  405. data/lib/decidim/user_reportable.rb +33 -0
  406. data/lib/decidim/view_model.rb +26 -0
  407. data/lib/premailer/adapter/decidim.rb +4 -4
  408. data/lib/tasks/decidim_data_portability_tasks.rake +4 -4
  409. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ko.js +18 -0
  410. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.vi.js +14 -0
  411. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.zh-CN.js +14 -0
  412. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.zh-TW.js +14 -0
  413. metadata +190 -95
  414. data/app/functions/decidim/core/participatory_space_finder.rb +0 -11
  415. data/app/functions/decidim/core/participatory_space_list.rb +0 -11
  416. data/app/helpers/decidim/cache_helper.rb +0 -14
  417. data/app/types/decidim/core/amendment_type.rb +0 -26
  418. data/app/types/decidim/core/area_api_type.rb +0 -16
  419. data/app/types/decidim/core/area_type_type.rb +0 -14
  420. data/app/types/decidim/core/attachment_type.rb +0 -14
  421. data/app/types/decidim/core/category_type.rb +0 -16
  422. data/app/types/decidim/core/coordinates_type.rb +0 -19
  423. data/app/types/decidim/core/date_time_type.rb +0 -12
  424. data/app/types/decidim/core/date_type.rb +0 -13
  425. data/app/types/decidim/core/decidim_type.rb +0 -19
  426. data/app/types/decidim/core/fingerprint_type.rb +0 -15
  427. data/app/types/decidim/core/has_timestamp_input_sort.rb +0 -12
  428. data/app/types/decidim/core/hashtag_type.rb +0 -13
  429. data/app/types/decidim/core/localized_string_type.rb +0 -14
  430. data/app/types/decidim/core/metric_history_type.rb +0 -17
  431. data/app/types/decidim/core/metric_type.rb +0 -14
  432. data/app/types/decidim/core/organization_type.rb +0 -20
  433. data/app/types/decidim/core/participatory_space_link_type.rb +0 -24
  434. data/app/types/decidim/core/participatory_space_type.rb +0 -12
  435. data/app/types/decidim/core/scope_api_type.rb +0 -16
  436. data/app/types/decidim/core/session_type.rb +0 -19
  437. data/app/types/decidim/core/statistic_type.rb +0 -22
  438. data/app/types/decidim/core/trace_version_type.rb +0 -29
  439. data/app/types/decidim/core/translated_field_type.rb +0 -45
  440. data/app/types/decidim/core/user_entity_input_filter.rb +0 -81
  441. data/app/types/decidim/core/user_group_type.rb +0 -51
  442. data/app/types/decidim/core/user_type.rb +0 -52
  443. data/app/views/decidim/shared/_announcement.html.erb +0 -1
  444. data/app/views/decidim/shared/_flag_modal.html.erb +0 -20
  445. data/db/migrate/20210302150803_invalidate_all_sessions_for_deleted_users.rb +0 -11
  446. data/lib/decidim/api/amendable_interface.rb +0 -18
  447. data/lib/decidim/api/author_interface.rb +0 -29
  448. data/lib/decidim/api/authorable_interface.rb +0 -22
  449. data/lib/decidim/api/coauthorable_interface.rb +0 -29
  450. data/lib/decidim/api/component_interface.rb +0 -20
  451. data/lib/decidim/api/endorsable_interface.rb +0 -22
  452. data/lib/decidim/api/participatory_space_interface.rb +0 -47
  453. data/lib/decidim/api/participatory_space_resourceable_interface.rb +0 -21
  454. data/lib/decidim/api/timestamps_interface.rb +0 -21
  455. data/lib/decidim/api/traceable_interface.rb +0 -14
@@ -0,0 +1,117 @@
1
+ // import Parchment from 'parchment';
2
+ // import Quill from '../core/quill';
3
+ // import Module from '../core/module';
4
+
5
+ ((exports) => {
6
+ const Quill = exports.Quill;
7
+ const History = Quill.import("modules/history");
8
+
9
+ /**
10
+ * Linebreak module brokes quill's default history class.
11
+ * So here we are moving innerHTML to undo and redo stack
12
+ * instead of deltas.
13
+ */
14
+ class HistoryOverride extends History {
15
+ constructor(quill, options) {
16
+ super(quill, options);
17
+ this.lastRecorded = 0;
18
+ this.ignoreChange = false;
19
+ this.init = false;
20
+ this.quill.emitter.on("editor-ready", () => {
21
+ this.clear();
22
+ const $input = $(this.quill.container).siblings('input[type="hidden"]');
23
+ this.stack.undo.push({content: $input.val() || "", index: this.quill.getLength() - 2 });
24
+ this.lastLength = this.quill.getLength();
25
+ })
26
+ /* eslint-disable max-params */
27
+ this.quill.on(Quill.events.EDITOR_CHANGE, (eventName, delta, oldDelta, source) => {
28
+ if (!delta) {
29
+ return;
30
+ }
31
+ if (!this.init && eventName === "selection-change") {
32
+ this.stack.undo[0].index = delta.index;
33
+ }
34
+ if (eventName !== Quill.events.TEXT_CHANGE || this.ignoreChange) {
35
+ return;
36
+ }
37
+
38
+ if (!this.options.userOnly || source === Quill.sources.USER) {
39
+ this.record(delta, oldDelta);
40
+ }
41
+ });
42
+ this.quill.keyboard.addBinding({ key: "Z", shortKey: true }, this.undo.bind(this));
43
+ this.quill.keyboard.addBinding({ key: "Z", shortKey: true, shiftKey: true }, this.redo.bind(this));
44
+ if (/Win/i.test(navigator.platform)) {
45
+ this.quill.keyboard.addBinding({ key: "Y", shortKey: true }, this.redo.bind(this));
46
+ }
47
+ }
48
+ /* eslint-enable max-params */
49
+
50
+ change(source, dest) {
51
+ if (this.stack[source].length === 0) {
52
+ return;
53
+ }
54
+ let obj = this.updateStacks(source, dest);
55
+ if (!obj.content) {
56
+ return;
57
+ }
58
+ if (!obj.index) {
59
+ obj.index = 0
60
+ }
61
+ this.lastRecorded = 0;
62
+ this.ignoreChange = true;
63
+ this.quill.setContents(this.quill.clipboard.convert(obj.content));
64
+ this.ignoreChange = false;
65
+ let index = obj.index;
66
+ this.quill.setSelection(index);
67
+ }
68
+
69
+ updateStacks(source, dest) {
70
+ if (source === "undo") {
71
+ if (this.stack.undo.length === 1) {
72
+ return this.stack.undo[0]
73
+ }
74
+ this.stack[dest].push(this.stack.undo.pop())
75
+ return this.stack.undo[this.stack.undo.length - 1]
76
+ }
77
+ let content = this.stack.redo.pop();
78
+ this.stack.undo.push(content)
79
+ return content
80
+ }
81
+
82
+ record(changeDelta) {
83
+ if (changeDelta.ops.length === 0) {
84
+ return
85
+ } else if (!this.init) {
86
+ this.init = true;
87
+ }
88
+ this.stack.redo = [];
89
+ let timestamp = Date.now();
90
+ // Should not return after length check, because after linebreak a keypress replaces invisible characters with
91
+ // visible characters.
92
+ // For example: <br><br></p> -> [press X] -> <br>X</p>.
93
+ if (Math.abs(this.lastLength === this.quill.getLength()) || this.lastRecorded + this.options.delay > timestamp) {
94
+ if (this.stack.undo.length > 1) {
95
+ this.stack.undo.pop();
96
+ }
97
+ } else {
98
+ this.lastLength = this.quill.getLength();
99
+ if (this.lastRecorded + this.options.delay <= timestamp) {
100
+ this.lastRecorded = timestamp;
101
+ }
102
+ }
103
+ this.stack.undo.push({content: this.quill.container.firstChild.innerHTML, index: this.quill.getSelection()})
104
+ }
105
+
106
+ transform() {
107
+ return;
108
+ }
109
+ }
110
+ History.DEFAULTS = {
111
+ delay: 1000,
112
+ maxStack: 100,
113
+ userOnly: true
114
+ };
115
+
116
+ exports.Decidim.Editor.HistoryOverride = HistoryOverride
117
+ })(window)
@@ -0,0 +1,83 @@
1
+ // = require decidim/editor/modified_enter
2
+ // = require decidim/editor/modified_backspace_utils
3
+ // = require decidim/editor/modified_backspace_offset_any
4
+ // = require decidim/editor/modified_backspace_offset1
5
+ // = require decidim/editor/history_override
6
+
7
+ // It all started with these snippets of code: https://github.com/quilljs/quill/issues/252
8
+ ((exports) => {
9
+ const Quill = exports.Quill;
10
+ const Delta = Quill.import("delta");
11
+ const Break = Quill.import("blots/break");
12
+ const Embed = Quill.import("blots/embed");
13
+ const { HistoryOverride } = exports.Decidim.Editor
14
+ Quill.register({"modules/history": HistoryOverride}, true)
15
+ let icons = Quill.import("ui/icons");
16
+ icons.linebreak = "⏎";
17
+
18
+ class SmartBreak extends Break {
19
+ length() {
20
+ return 1;
21
+ }
22
+
23
+ value() {
24
+ return "\n";
25
+ }
26
+
27
+ insertInto(parent, ref) {
28
+ // Embed.prototype.insertInto.call(this, parent, ref);
29
+ Reflect.apply(Embed.prototype.insertInto, this, [parent, ref]);
30
+ }
31
+ }
32
+ Quill.register(SmartBreak);
33
+
34
+ const lineBreakButtonHandler = (quill) => {
35
+ let range = quill.selection.getRange()[0];
36
+ let currentLeaf = quill.getLeaf(range.index)[0];
37
+ let nextLeaf = quill.getLeaf(range.index + 1)[0];
38
+ const previousChar = quill.getText(range.index - 1, 1);
39
+
40
+ // Insert a second break if:
41
+ // At the end of the editor, OR next leaf has a different parent (<p>)
42
+ if (nextLeaf === null || (currentLeaf.parent !== nextLeaf.parent)) {
43
+ quill.insertEmbed(range.index, "break", true, "user");
44
+ quill.insertEmbed(range.index, "break", true, "user");
45
+ } else if (previousChar === "\n") {
46
+ const delta = new Delta().retain(range.index).insert("\n");
47
+ quill.updateContents(delta, Quill.sources.USER);
48
+ } else {
49
+ quill.insertEmbed(range.index, "break", true, "user");
50
+ }
51
+
52
+ // Now that we've inserted a line break, move the cursor forward
53
+ quill.setSelection(range.index + 1, Quill.sources.SILENT);
54
+ };
55
+
56
+ Quill.register("modules/linebreak", (quill) => {
57
+ const { addEnterBindings } = exports.Decidim.Editor;
58
+ const { backspaceBindingsRangeAny } = exports.Decidim.Editor;
59
+ const { backspaceBindings } = exports.Decidim.Editor;
60
+
61
+ quill.getModule("toolbar").addHandler("linebreak", () => {
62
+ lineBreakButtonHandler(quill);
63
+ });
64
+
65
+ quill.emitter.on("editor-ready", () => {
66
+ const length = quill.getLength();
67
+ const text = quill.getText(length - 2, 2);
68
+
69
+ // Remove extraneous new lines
70
+ if (text === "\n\n") {
71
+ quill.deleteText(quill.getLength() - 2, 2);
72
+ }
73
+ });
74
+
75
+ addEnterBindings(quill);
76
+ backspaceBindingsRangeAny(quill);
77
+ backspaceBindings(quill);
78
+
79
+ return;
80
+ });
81
+
82
+ exports.Decidim.Editor.lineBreakButtonHandler = lineBreakButtonHandler;
83
+ })(window);
@@ -0,0 +1,98 @@
1
+ ((exports) => {
2
+ const Quill = exports.Quill;
3
+ const Delta = Quill.import("delta");
4
+ const { attributeDiff } = exports.Decidim.Editor;
5
+
6
+ const previousChar = (quill, range) => {
7
+ return quill.getText(range.index - 1, 1);
8
+ }
9
+
10
+ const beforePreviousChar = (quill, range) => {
11
+ return quill.getText(range.index - 2, 1);
12
+ }
13
+
14
+ const nextChar = (quill, range) => {
15
+ return quill.getText(range.index, 1);
16
+ }
17
+
18
+ const handleListSelection = (quill, range) => {
19
+ const lastCharacterOfPreviousLine = quill.getText(range.index - 3, 1);
20
+ if (nextChar(quill, range) === "\n" || lastCharacterOfPreviousLine !== "\n") {
21
+ quill.setSelection(range.index - 1, Quill.sources.SILENT);
22
+ } else {
23
+ quill.setSelection(range.index - 3, Quill.sources.SILENT);
24
+ }
25
+ }
26
+
27
+ const moveSelectionToPreviousLine = (quill, range) => {
28
+ const lastCharacterOfPreviousLine = quill.getText(range.index - 3, 1);
29
+ if (nextChar(quill, range) === "\n" || lastCharacterOfPreviousLine !== "\n") {
30
+ quill.setSelection(range.index - 1, Quill.sources.SILENT);
31
+ } else {
32
+ quill.setSelection(range.index - 3, Quill.sources.SILENT);
33
+ }
34
+ }
35
+
36
+ const backspaceBindings = (quill) => {
37
+ quill.keyboard.addBinding({ key: 8, offset: 1, collapsed: true }, (range, context) => {
38
+ let length = 1
39
+ if (/[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix)) {
40
+ length = 2;
41
+ }
42
+
43
+ if (range.index === 0 || quill.getLength() <= 1) {
44
+ return;
45
+ }
46
+ let formats = {};
47
+ const [line] = quill.getLine(range.index);
48
+ let delta = new Delta().retain(range.index - length).delete(length);
49
+ if (context.offset === 1 && previousChar(quill, range) === "\n") {
50
+ const [prev] = quill.getLine(range.index - 2);
51
+ if (prev && prev.statics.blotName === "list-item") {
52
+ formats = handleListSelection(quill, range);
53
+ if (prev !== null && prev.length() > 1) {
54
+ let curFormats = line.formats();
55
+ let prevFormats = quill.getFormat(range.index - 2, 1);
56
+ formats = attributeDiff(curFormats, prevFormats) || {};
57
+ length += 1;
58
+ }
59
+ delta = new Delta().retain(range.index - 2).delete(2);
60
+ moveSelectionToPreviousLine(quill, range);
61
+ } else {
62
+ delta = new Delta().retain(range.index - 1).delete(1);
63
+ if (range.index < 2) {
64
+ delta = new Delta().delete(1).retain(range.index + line.length() - 1);
65
+ } else if (previousChar(quill, range) === "\n" && beforePreviousChar(quill, range) === "\n") {
66
+ delta = new Delta().retain(range.index - 2).delete(2);
67
+ }
68
+ }
69
+ } else {
70
+ const [prev] = quill.getLine(range.index - 1);
71
+ if (prev) {
72
+ const isPrevLineEmpty =
73
+ prev.statics.blotName === "block" && prev.length() <= 1;
74
+ if (!isPrevLineEmpty) {
75
+ const curFormats = line.formats();
76
+ const prevFormats = quill.getFormat(range.index - 1, 1);
77
+ formats = attributeDiff(curFormats, prevFormats) || {};
78
+ if (Object.keys(formats).length > 0) {
79
+ // line.length() - 1 targets \n in line, another -1 for newline being deleted
80
+ const formatDelta = new Delta().retain(range.index + line.length() - 2).retain(1, formats);
81
+ delta = delta.compose(formatDelta);
82
+ }
83
+ }
84
+ }
85
+ }
86
+ quill.updateContents(delta, Quill.sources.USER);
87
+ if (Object.keys(formats).length > 0) {
88
+ quill.formatLine(range.index - length, length, formats, Quill.sources.USER);
89
+ }
90
+ quill.focus();
91
+ });
92
+
93
+ // Put this backspace binding to second
94
+ quill.keyboard.bindings[8].splice(1, 0, quill.keyboard.bindings[8].pop());
95
+ }
96
+
97
+ exports.Decidim.Editor.backspaceBindings = backspaceBindings;
98
+ })(window)
@@ -0,0 +1,48 @@
1
+ ((exports) => {
2
+ const Quill = exports.Quill;
3
+ const { attributeDiff } = exports.Decidim.Editor
4
+
5
+ const backspaceBindingsRangeAny = (quill) => {
6
+ quill.keyboard.addBinding({ key: 8, altKey: null, ctrlKey: null, metaKey: null, shiftKey: null, collapsed: true }, (range, context) => {
7
+ let length = 1;
8
+ if (range.index === 0 || quill.getLength() <= 1) {
9
+ return;
10
+ }
11
+ let [line] = quill.getLine(range.index);
12
+ let formats = {};
13
+ if (context.offset === 0) {
14
+ let [prev] = quill.getLine(range.index - 1);
15
+ if (prev !== null && prev.length() > 1) {
16
+ let curFormats = line.formats();
17
+ let prevFormats = quill.getFormat(range.index - 1, 1);
18
+ formats = attributeDiff(curFormats, prevFormats) || {};
19
+ const previousLineLength = quill.getLine(range.index - 1)[1];
20
+ const previousChar = quill.getText(range.index - 1, 1)
21
+ const beforePreviousChar = quill.getText(range.index - 2, 1);
22
+ if (previousLineLength && previousLineLength === 1 && beforePreviousChar === "\n") {
23
+ if (prevFormats && prevFormats.list) {
24
+ quill.setSelection(range.index - 2, Quill.sources.SILENT);
25
+ } else if (previousChar === "\n" && beforePreviousChar === "\n") {
26
+ length += 1;
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ if (/[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix)) {
33
+ length += 1;
34
+ }
35
+ quill.deleteText(range.index - length, length, Quill.sources.USER);
36
+
37
+ if (Object.keys(formats).length > 0) {
38
+ quill.formatLine(range.index - length, length, formats, Quill.sources.USER);
39
+ }
40
+ quill.focus();
41
+ })
42
+
43
+ // Put this backspace binding to second (after backspce_offset1 it's going to be third)
44
+ quill.keyboard.bindings[8].splice(1, 0, quill.keyboard.bindings[8].pop());
45
+ }
46
+
47
+ exports.Decidim.Editor.backspaceBindingsRangeAny = backspaceBindingsRangeAny;
48
+ })(window)
@@ -0,0 +1,31 @@
1
+ // ORGINAL: https://github.com/quilljs/delta/blob/ddda3bf088cda3ec03d5dbcc1179679d147f3a02/src/AttributeMap.ts
2
+
3
+ ((exports) => {
4
+ const attributeDiff = (attributes1, attributes2) => {
5
+ let alpha = attributes1;
6
+ let beta = attributes2;
7
+ if (typeof alpha !== "object") {
8
+ alpha = {};
9
+ }
10
+ if (typeof beta !== "object") {
11
+ beta = {};
12
+ }
13
+ const attributes = Object.keys(alpha).concat(Object.keys(beta)).reduce((attrs, key) => {
14
+ // ORGINAL: import isEqual from 'lodash.isequal'; if (!isEqual(a[key], b[key]))
15
+ if ((alpha[key] !== beta[key])) {
16
+ attrs[key] = null;
17
+ if (beta[key]) {
18
+ attrs[key] = beta[key]
19
+ }
20
+ }
21
+ return attrs;
22
+ }, {});
23
+
24
+ if (Object.keys(attributes).length > 0) {
25
+ return attributes;
26
+ }
27
+ return null;
28
+ }
29
+
30
+ exports.Decidim.Editor.attributeDiff = attributeDiff
31
+ })(window)
@@ -0,0 +1,118 @@
1
+
2
+ ((exports) => {
3
+ const Quill = exports.Quill;
4
+ const Parchment = Quill.import("parchment")
5
+ const Delta = Quill.import("delta");
6
+
7
+ const getLineFormats = (context) => {
8
+ return Object.keys(context.format).reduce(
9
+ (formats, format) => {
10
+ // See Parchment registry.ts => (1 << 3) | ((1 << 2) - 1) = 8 | 3 = 11
11
+ const blockScope = 11;
12
+ if (
13
+ Parchment.query(format, blockScope) &&
14
+ !Array.isArray(context.format[format])
15
+ ) {
16
+ formats[format] = context.format[format];
17
+ }
18
+ return formats;
19
+ },
20
+ {},
21
+ );
22
+ }
23
+
24
+ const continueFormats = (quill, context, lineFormats) => {
25
+ Object.keys(context.format).forEach((name) => {
26
+ if (typeof lineFormats[name] !== "undefined" && lineFormats[name] !== null) {
27
+ return;
28
+ }
29
+ if (Array.isArray(context.format[name])) {
30
+ return;
31
+ }
32
+ if (name === "link") {
33
+ return;
34
+ }
35
+ quill.format(name, context.format[name], Quill.sources.USER);
36
+ });
37
+ }
38
+
39
+ const lineBreakHandler = (quill, range, context) => {
40
+ const currentLeaf = quill.getLeaf(range.index)[0];
41
+ const nextLeaf = quill.getLeaf(range.index + 1)[0];
42
+ const previousChar = quill.getText(range.index - 1, 1);
43
+
44
+ quill.insertEmbed(range.index, "break", true, "user");
45
+ quill.formatText(range.index + 1, "bold", true)
46
+ if (nextLeaf === null || (currentLeaf.parent !== nextLeaf.parent)) {
47
+ quill.insertEmbed(range.index, "break", true, "user");
48
+ } else if (context.offset === 1 && previousChar === "\n") {
49
+ const delta = new Delta().retain(range.index).insert("\n");
50
+ quill.updateContents(delta, Quill.sources.USER);
51
+ }
52
+
53
+ quill.format(name, context.format[name], Quill.sources.USER);
54
+ quill.setSelection(range.index + 1, Quill.sources.SILENT);
55
+
56
+ const lineFormats = getLineFormats(context);
57
+ continueFormats(quill, context, lineFormats);
58
+ };
59
+
60
+ const addEnterBindings = (quill) => {
61
+ quill.clipboard.addMatcher("BR", () => {
62
+ let newDelta = new Delta();
63
+ newDelta.insert({"break": ""});
64
+ return newDelta;
65
+ });
66
+
67
+ quill.keyboard.addBinding({
68
+ key: 13,
69
+ shiftKey: true
70
+ }, (range, context) => {
71
+ lineBreakHandler(quill, range, context);
72
+ });
73
+
74
+ // HAX: make our SHIFT+ENTER binding the second (first is added below) in order to override Quill defaults
75
+ quill.keyboard.bindings[13].unshift(quill.keyboard.bindings[13].pop());
76
+
77
+ quill.keyboard.addBinding({ key: 13, shiftKey: false }, (range, context) => {
78
+ const lineFormats = getLineFormats(context);
79
+ const previousChar = quill.getText(range.index - 1, 1);
80
+ const nextChar = quill.getText(range.index, 1);
81
+ const delta = new Delta().retain(range.index).insert("\n", lineFormats);
82
+ // const length = context.prefix.length;
83
+ if (previousChar === "" || previousChar === "\n") {
84
+ if (lineFormats.list && nextChar === "\n") {
85
+ if (quill.getLength() - range.index > 2) {
86
+ const endFormatDelta = new Delta().retain(range.index - 1).delete(1);
87
+ quill.updateContents(endFormatDelta, Quill.sources.USER);
88
+ } else {
89
+ // Delete empty list item and end the list
90
+ const endFormatDelta = new Delta().retain(range.index - 1).delete(1).retain(range.index).insert("\n");
91
+ quill.updateContents(endFormatDelta, Quill.sources.USER);
92
+ quill.setSelection(range.index + 1, Quill.sources.SILENT);
93
+ }
94
+ } else {
95
+ quill.updateContents(delta, Quill.sources.USER);
96
+ if (context.offset === 1 && previousChar === "\n") {
97
+ quill.setSelection(range.index + 1, Quill.sources.SILENT);
98
+ } else {
99
+ quill.setSelection(range.index + 2, Quill.sources.SILENT);
100
+ }
101
+ }
102
+ } else {
103
+ quill.updateContents(delta, Quill.sources.USER);
104
+ quill.setSelection(range.index + 1, Quill.sources.SILENT);
105
+ }
106
+ quill.focus();
107
+
108
+ continueFormats(quill, context, lineFormats);
109
+ });
110
+
111
+ // Replace the default enter handling because we have modified the break element
112
+ quill.keyboard.bindings[13].unshift(quill.keyboard.bindings[13].pop());
113
+ return;
114
+ }
115
+
116
+ exports.Decidim.Editor = exports.Decidim.Editor || {};
117
+ exports.Decidim.Editor.addEnterBindings = addEnterBindings;
118
+ })(window)
@@ -1,15 +1,16 @@
1
1
  // = require quill.min
2
+ // = require decidim/editor/linebreak_module
2
3
  // = require_self
3
4
 
4
5
  ((exports) => {
5
- const quillFormats = ["bold", "italic", "link", "underline", "header", "list", "video", "image", "alt"];
6
+ const quillFormats = ["bold", "italic", "link", "underline", "header", "list", "video", "image", "alt", "break"];
6
7
 
7
8
  const createQuillEditor = (container) => {
8
9
  const toolbar = $(container).data("toolbar");
9
10
  const disabled = $(container).data("disabled");
10
11
 
11
12
  let quillToolbar = [
12
- ["bold", "italic", "underline"],
13
+ ["bold", "italic", "underline", "linebreak"],
13
14
  [{ list: "ordered" }, { list: "bullet" }],
14
15
  ["link", "clean"]
15
16
  ];
@@ -32,7 +33,13 @@
32
33
 
33
34
  const quill = new Quill(container, {
34
35
  modules: {
35
- toolbar: quillToolbar
36
+ linebreak: {},
37
+ toolbar: {
38
+ container: quillToolbar,
39
+ handlers: {
40
+ "linebreak": exports.Decidim.Editor.lineBreakButtonHandler
41
+ }
42
+ }
36
43
  },
37
44
  formats: quillFormats,
38
45
  theme: "snow"
@@ -52,12 +59,16 @@
52
59
  });
53
60
  container.dispatchEvent(event);
54
61
 
55
- if (text === "\n") {
62
+ if (text === "\n" || text === "\n\n") {
56
63
  $input.val("");
57
64
  } else {
58
65
  $input.val(quill.root.innerHTML);
59
66
  }
60
67
  });
68
+ // After editor is ready, linebreak_module deletes two extraneous new lines
69
+ quill.emitter.emit("editor-ready");
70
+
71
+ return quill;
61
72
  };
62
73
 
63
74
  const quillEditor = () => {
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable no-div-regex, no-useless-escape, no-param-reassign, id-length */
2
+ /* eslint max-lines: ["error", {"max": 350, "skipBlankLines": true}] */
2
3
 
3
4
  /**
4
5
  * A plain Javascript component that handles the form filter.
@@ -47,7 +48,12 @@
47
48
  mountComponent() {
48
49
  if (this.$form.length > 0 && !this.mounted) {
49
50
  this.mounted = true;
51
+ let queue = 0;
50
52
 
53
+ let contentContainer = $(this.$form.closest(".filters").parent().find(".skip").attr("href"));
54
+ if (contentContainer.length === 0) {
55
+ contentContainer = this.$form.data("remoteFill");
56
+ }
51
57
  this.$form.on("change", "input:not([data-disable-dynamic-change]), select:not([data-disable-dynamic-change])", this._onFormChange);
52
58
 
53
59
  this.currentFormRequest = null;
@@ -56,6 +62,25 @@
56
62
  this.currentFormRequest.abort();
57
63
  }
58
64
  this.currentFormRequest = e.originalEvent.detail[0];
65
+ queue += 1;
66
+ if (queue > 0 && contentContainer.length > 0 && !contentContainer.hasClass("spinner-container")) {
67
+ contentContainer.addClass("spinner-container");
68
+ }
69
+ });
70
+
71
+ this.$form.on("ajax:success", () => {
72
+ queue -= 1;
73
+ if (queue <= 0 && contentContainer.length > 0) {
74
+ contentContainer.removeClass("spinner-container");
75
+ }
76
+ });
77
+
78
+ this.$form.on("ajax:error", () => {
79
+ queue -= 1;
80
+ if (queue <= 0 && contentContainer.length > 0) {
81
+ contentContainer.removeClass("spinner-container");
82
+ }
83
+ this.$form.find(".spinner-container").addClass("hide");
59
84
  });
60
85
 
61
86
  exports.theCheckBoxesTree.setContainerForm(this.$form);
@@ -83,22 +83,59 @@
83
83
  latitudeName: getCoordinateInputName("latitude", $input, attachOptions),
84
84
  longitudeName: getCoordinateInputName("longitude", $input, attachOptions)
85
85
  }, options);
86
+ let geocoded = false;
86
87
 
87
- $input.on("geocoder-suggest-coordinates.decidim", (_ev, coordinates) => {
88
+ const createCoordinateFields = () => {
88
89
  let $latitude = $(`#${config.latitudeId}`);
89
- let $longitude = $(`#${config.longitudeId}`);
90
90
  if ($latitude.length < 1) {
91
91
  $latitude = $(`<input type="hidden" name="${config.latitudeName}" id="${config.latitudeId}" />`);
92
92
  $input.after($latitude);
93
93
  }
94
+
95
+ let $longitude = $(`#${config.longitudeId}`);
94
96
  if ($longitude.length < 1) {
95
97
  $longitude = $(`<input type="hidden" name="${config.longitudeName}" id="${config.longitudeId}" />`);
96
98
  $input.after($longitude);
97
99
  }
100
+ }
101
+ const clearCoordinateFields = () => {
102
+ if (geocoded) {
103
+ return;
104
+ }
105
+
106
+ $(`#${config.latitudeId}`).val("").removeAttr("value");
107
+ $(`#${config.longitudeId}`).val("").removeAttr("value");
108
+ };
109
+ const setCoordinates = (coordinates) => {
110
+ createCoordinateFields();
98
111
 
99
- $latitude.val(coordinates[0]).attr("value", coordinates[0]);
100
- $longitude.val(coordinates[1]).attr("value", coordinates[1]);
112
+ $(`#${config.latitudeId}`).val(coordinates[0]).attr("value", coordinates[0]);
113
+ $(`#${config.longitudeId}`).val(coordinates[1]).attr("value", coordinates[1]);
114
+ }
115
+
116
+ // When the user changes the value of the coordinate field without selecting
117
+ // any of the geocoding autocomplete results, clear the current latitude and
118
+ // longitude values to let the backend do the geocoding. Once a geocoding
119
+ // autocomplete value has been selected, assume the user just wants to
120
+ // refine the address formatting without changing the location point value.
121
+ // If they want, they can still modify the point in the next step of the
122
+ // proposal creation/editing.
123
+ $input.on("change.decidim", () => {
124
+ clearCoordinateFields();
101
125
  });
126
+
127
+ // When we receive the geocoding event on the field, update the coordinate
128
+ // values.
129
+ $input.on("geocoder-suggest-coordinates.decidim", (_ev, coordinates) => {
130
+ setCoordinates(coordinates);
131
+ geocoded = true;
132
+ });
133
+
134
+ // Set the initial values if the field defines the coordinates
135
+ const coordinates = `${$input.data("coordinates")}`.split(",").map(parseFloat);
136
+ if (Array.isArray(coordinates) && coordinates.length === 2) {
137
+ setCoordinates(coordinates);
138
+ }
102
139
  };
103
140
 
104
141
  exports.Decidim = exports.Decidim || {};
@@ -98,8 +98,13 @@
98
98
  }
99
99
  }
100
100
 
101
+ const createCharacterCounter = ($input) => {
102
+ $input.data("remaining-characters-counter", new InputCharacterCounter($input));
103
+ }
104
+
101
105
  exports.Decidim = exports.Decidim || {};
102
106
  exports.Decidim.InputCharacterCounter = InputCharacterCounter;
107
+ exports.Decidim.createCharacterCounter = createCharacterCounter;
103
108
 
104
109
  exports.$(() => {
105
110
  exports.$("input[type='text'], textarea, .editor>input[type='hidden']").each((_i, elem) => {
@@ -109,7 +114,7 @@
109
114
  return;
110
115
  }
111
116
 
112
- $input.data("remaining-characters-counter", new InputCharacterCounter($input));
117
+ createCharacterCounter($input);
113
118
  });
114
119
  });
115
120
  })(window);