pageflow 15.2.0 → 15.5.0

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

Potentially problematic release.


This version of pageflow might be problematic. Click here for more details.

Files changed (214) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +89 -83
  3. data/README.md +2 -3
  4. data/admins/pageflow/accounts.rb +1 -98
  5. data/admins/pageflow/entry.rb +21 -1
  6. data/admins/pageflow/entry_templates.rb +140 -0
  7. data/admins/pageflow/membership.rb +12 -0
  8. data/admins/pageflow/user.rb +5 -5
  9. data/app/assets/javascripts/pageflow/admin/accounts.js +1 -1
  10. data/app/assets/javascripts/pageflow/admin/entries.js +65 -0
  11. data/app/assets/javascripts/pageflow/admin/users.js +1 -1
  12. data/app/assets/javascripts/pageflow/asset_urls.js.erb +1 -0
  13. data/app/assets/javascripts/pageflow/base.js +0 -12
  14. data/app/assets/javascripts/pageflow/components.js +2 -6
  15. data/app/assets/javascripts/pageflow/dist/ui.js +178 -55
  16. data/app/assets/javascripts/pageflow/editor/vendor.js +1 -0
  17. data/app/assets/javascripts/pageflow/vendor.js +12 -10
  18. data/app/assets/stylesheets/pageflow/base.scss +0 -7
  19. data/app/assets/stylesheets/pageflow/editor/base.scss +5 -2
  20. data/app/assets/stylesheets/pageflow/editor/composables.scss +5 -1
  21. data/app/assets/stylesheets/pageflow/editor/drop_down_button.scss +1 -1
  22. data/app/assets/stylesheets/pageflow/editor/emulation_mode_button.scss +44 -55
  23. data/app/assets/stylesheets/pageflow/editor/help.scss +2 -2
  24. data/app/assets/stylesheets/pageflow/editor/select_button.scss +1 -1
  25. data/app/assets/stylesheets/pageflow/editor/sidebar_footer.scss +1 -1
  26. data/app/assets/stylesheets/pageflow/entries.scss +1 -1
  27. data/app/assets/stylesheets/pageflow/loading_spinner.scss +4 -1
  28. data/app/assets/stylesheets/pageflow/navigation_mobile.scss +4 -4
  29. data/app/assets/stylesheets/pageflow/themes/default/anchors.scss +1 -1
  30. data/app/assets/stylesheets/pageflow/themes/default/logo/variant/watermark.scss +1 -1
  31. data/app/assets/stylesheets/pageflow/themes/default/page.scss +7 -0
  32. data/app/assets/stylesheets/pageflow/themes/default/page/anchors.scss +1 -1
  33. data/app/assets/stylesheets/pageflow/themes/default/player_controls/classic/control_bar.scss +1 -1
  34. data/app/assets/stylesheets/pageflow/themes/default/player_controls/classic/info_box.scss +1 -1
  35. data/app/assets/stylesheets/pageflow/themes/default/player_controls/shared/menu_bar.scss +2 -2
  36. data/app/assets/stylesheets/pageflow/themes/default/player_controls/slim/control_bar.scss +2 -2
  37. data/app/assets/stylesheets/pageflow/themes/default/player_controls/slim/info_box.scss +1 -1
  38. data/app/assets/stylesheets/pageflow/themes/default/player_controls/slim/quality_menu.scss +2 -2
  39. data/app/assets/stylesheets/pageflow/themes/default/player_controls/waveform/wave.scss +1 -1
  40. data/app/assets/stylesheets/pageflow/ui/forms.scss +9 -2
  41. data/app/assets/stylesheets/pageflow/ui/input/extended_select_input.scss +2 -2
  42. data/app/assets/stylesheets/pageflow/ui/tooltip.scss +17 -3
  43. data/app/helpers/pageflow/admin/entries_helper.rb +16 -0
  44. data/app/helpers/pageflow/structured_data_helper.rb +0 -2
  45. data/app/models/pageflow/account.rb +21 -1
  46. data/app/models/pageflow/account_role_query.rb +1 -1
  47. data/app/models/pageflow/chapter.rb +3 -9
  48. data/app/models/pageflow/entry.rb +9 -2
  49. data/app/models/pageflow/entry_duplicate.rb +1 -0
  50. data/app/models/pageflow/entry_template.rb +16 -2
  51. data/app/models/pageflow/managed_user_query.rb +1 -1
  52. data/app/models/pageflow/page.rb +1 -4
  53. data/app/models/pageflow/revision.rb +0 -4
  54. data/app/models/pageflow/storyline.rb +2 -9
  55. data/app/policies/pageflow/account_policy.rb +10 -0
  56. data/app/policies/pageflow/entry_template_policy.rb +5 -1
  57. data/app/policies/pageflow/folder_policy.rb +2 -2
  58. data/app/policies/pageflow/membership_policy.rb +2 -2
  59. data/app/policies/pageflow/theming_policy.rb +2 -2
  60. data/app/policies/pageflow/user_policy.rb +1 -1
  61. data/app/views/admin/accounts/_entry_template_details.html.arb +7 -5
  62. data/app/views/admin/accounts/_form.html.erb +3 -49
  63. data/app/views/admin/entries/_attributes_table.html.arb +5 -0
  64. data/app/views/admin/entries/_not_allowed_to_see_entry_types.json.jbuilder +2 -0
  65. data/app/views/admin/entries/entry_types.json.jbuilder +4 -0
  66. data/app/views/admin/entry_templates/_form.html.erb +58 -0
  67. data/app/views/admin/users/_not_allowed_to_see_user_quota.html.erb +3 -0
  68. data/app/views/components/pageflow/admin/entry_templates_tab.rb +48 -0
  69. data/app/views/pageflow/admin/initial_passwords/edit.html.erb +2 -1
  70. data/app/views/pageflow/admin/users/_quota_exhausted.html.erb +1 -1
  71. data/app/views/pageflow/themes/_theme.json.jbuilder +1 -1
  72. data/app/views/pageflow/video_files/_video_file.json.jbuilder +8 -1
  73. data/config/initializers/admin_resource_tabs.rb +5 -0
  74. data/config/initializers/help_entries.rb +1 -5
  75. data/config/initializers/revision_components.rb +5 -0
  76. data/config/locales/de.yml +88 -155
  77. data/config/locales/en.yml +79 -143
  78. data/db/migrate/20200515112500_add_constraints_to_entry_templates.rb +21 -0
  79. data/db/migrate/20200807135200_rename_pageflow_entry_template_entry_type_to_entry_type_name.rb +7 -0
  80. data/entry_types/paged/app/assets/javascripts/pageflow_paged/components.js +7 -0
  81. data/entry_types/paged/app/assets/javascripts/pageflow_paged/dist/editor.js +1528 -1349
  82. data/entry_types/paged/app/assets/javascripts/pageflow_paged/dist/frontend.js +9258 -0
  83. data/{app/assets/javascripts/pageflow → entry_types/paged/app/assets/javascripts/pageflow_paged}/dist/react-client.js +1 -1
  84. data/{app/assets/javascripts/pageflow → entry_types/paged/app/assets/javascripts/pageflow_paged}/dist/react-server.js +3 -3
  85. data/entry_types/paged/app/assets/javascripts/pageflow_paged/frontend.js +6 -0
  86. data/entry_types/paged/app/assets/javascripts/pageflow_paged/server_rendering.js +9 -0
  87. data/entry_types/paged/app/assets/javascripts/pageflow_paged/vendor.js +9 -0
  88. data/entry_types/paged/app/assets/javascripts/pageflow_paged/videojs.js +6 -0
  89. data/entry_types/paged/app/controllers/pageflow_paged/application_controller.rb +2 -2
  90. data/{app/helpers/pageflow → entry_types/paged/app/helpers/pageflow_paged}/page_background_asset_helper.rb +4 -3
  91. data/{app/helpers/pageflow → entry_types/paged/app/helpers/pageflow_paged}/react_server_side_rendering_helper.rb +23 -2
  92. data/entry_types/paged/app/views/layouts/pageflow_paged/_loading_spinner_inline_script.html.erb +1 -0
  93. data/entry_types/paged/app/views/layouts/pageflow_paged/application.html.erb +3 -3
  94. data/entry_types/paged/app/views/pageflow_paged/editor/entries/_head.html.erb +4 -2
  95. data/entry_types/paged/app/views/pageflow_paged/entries/_entry.html.erb +1 -1
  96. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/page_background_asset/_element.html.erb +0 -0
  97. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/react/_widget.html.erb +0 -0
  98. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/react/page.html.erb +0 -0
  99. data/entry_types/paged/config/initializers/features.rb +1 -1
  100. data/entry_types/paged/config/initializers/help_entries.rb +17 -0
  101. data/entry_types/paged/config/locales/new/help.de.yml +162 -0
  102. data/entry_types/paged/config/locales/new/help.en.yml +153 -0
  103. data/entry_types/paged/lib/pageflow_paged/engine.rb +13 -0
  104. data/entry_types/paged/lib/pageflow_paged/plugin.rb +5 -1
  105. data/entry_types/paged/lib/pageflow_paged/react.rb +12 -0
  106. data/{lib/pageflow → entry_types/paged/lib/pageflow_paged}/react/page_type.rb +2 -2
  107. data/{lib/pageflow → entry_types/paged/lib/pageflow_paged}/react/widget_type.rb +2 -2
  108. data/entry_types/paged/lib/tasks/pageflow_paged_tasks.rake +7 -0
  109. data/entry_types/paged/vendor/assets/javascripts/development/pageflow_paged/vendor/react-server.js +20613 -0
  110. data/entry_types/paged/vendor/assets/javascripts/development/pageflow_paged/vendor/react.js +21495 -0
  111. data/{vendor/assets/javascripts → entry_types/paged/vendor/assets/javascripts/pageflow_paged/vendor}/dash.all.min.js +0 -0
  112. data/{vendor/assets/javascripts → entry_types/paged/vendor/assets/javascripts/pageflow_paged/vendor}/videojs-dash.js +0 -0
  113. data/{vendor/assets/javascripts → entry_types/paged/vendor/assets/javascripts/pageflow_paged/vendor}/videojs.js +0 -0
  114. data/entry_types/paged/vendor/assets/javascripts/production/pageflow_paged/vendor/react-server.js +24 -0
  115. data/entry_types/paged/vendor/assets/javascripts/production/pageflow_paged/vendor/react.js +24 -0
  116. data/entry_types/scrolled/app/assets/javascripts/pageflow_scrolled/legacy.js +0 -0
  117. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb +2 -2
  118. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/content_elements_controller.rb +14 -4
  119. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb +2 -2
  120. data/entry_types/scrolled/app/controllers/pageflow_scrolled/entries_controller.rb +10 -0
  121. data/entry_types/scrolled/app/helpers/pageflow_scrolled/editor/seed_html_helper.rb +7 -0
  122. data/entry_types/scrolled/app/helpers/pageflow_scrolled/entry_json_seed_helper.rb +2 -0
  123. data/entry_types/scrolled/app/helpers/pageflow_scrolled/favicon_helper.rb +21 -0
  124. data/entry_types/scrolled/app/helpers/pageflow_scrolled/react_server_side_rendering_helper.rb +40 -0
  125. data/entry_types/scrolled/app/helpers/pageflow_scrolled/themes_helper.rb +36 -0
  126. data/entry_types/scrolled/app/models/pageflow_scrolled/chapter.rb +3 -9
  127. data/entry_types/scrolled/app/models/pageflow_scrolled/content_element.rb +37 -2
  128. data/entry_types/scrolled/app/models/pageflow_scrolled/section.rb +3 -9
  129. data/entry_types/scrolled/app/models/pageflow_scrolled/storyline.rb +1 -9
  130. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/content_elements/batch.json.jbuilder +2 -0
  131. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/entries/_head.html.erb +1 -7
  132. data/entry_types/scrolled/app/views/pageflow_scrolled/entries/_global_notices.html.erb +10 -0
  133. data/entry_types/scrolled/app/views/pageflow_scrolled/entries/show.html.erb +28 -11
  134. data/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder +3 -0
  135. data/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_theme.json.jbuilder +8 -0
  136. data/entry_types/scrolled/app/views/pageflow_scrolled/favicons/_entry.html.erb +10 -0
  137. data/entry_types/scrolled/config/initializers/help_entries.rb +16 -0
  138. data/entry_types/scrolled/config/locales/de.yml +669 -0
  139. data/entry_types/scrolled/config/locales/en.yml +488 -0
  140. data/entry_types/scrolled/config/routes.rb +1 -0
  141. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/install_generator.rb +76 -6
  142. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/android-chrome-192x192.png +0 -0
  143. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/android-chrome-512x512.png +0 -0
  144. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/apple-touch-icon.png +0 -0
  145. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/browserconfig.xml +9 -0
  146. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/favicon-16x16.png +0 -0
  147. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/favicon-32x32.png +0 -0
  148. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/favicon.ico +0 -0
  149. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/mstile-150x150.png +0 -0
  150. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/safari-pinned-tab.svg +46 -0
  151. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/favicons/site.webmanifest +19 -0
  152. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/logoDesktop.svg +56 -0
  153. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/logoMobile.svg +22 -0
  154. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/unmute.mp3 +0 -0
  155. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/themes_plugin.rb.tt +26 -0
  156. data/entry_types/scrolled/lib/pageflow_scrolled/engine.rb +4 -0
  157. data/entry_types/scrolled/lib/pageflow_scrolled/plugin.rb +3 -1
  158. data/entry_types/scrolled/lib/pageflow_scrolled/seeds.rb +90 -30
  159. data/entry_types/scrolled/lib/tasks/pageflow_scrolled/create_bundle_symlinks_for_yarn.rake +32 -0
  160. data/entry_types/scrolled/lib/tasks/pageflow_scrolled/dummy.rake +8 -0
  161. data/entry_types/scrolled/lib/tasks/pageflow_scrolled/storybook.rake +173 -0
  162. data/entry_types/scrolled/package/contentElements-editor.js +541 -0
  163. data/entry_types/scrolled/package/contentElements-frontend.css +1 -0
  164. data/entry_types/scrolled/package/contentElements-frontend.js +1169 -0
  165. data/entry_types/scrolled/package/editor.js +2930 -371
  166. data/entry_types/scrolled/package/frontend-server.js +228 -0
  167. data/entry_types/scrolled/package/frontend/EditableText-7093fd0e.js +1071 -0
  168. data/entry_types/scrolled/package/frontend/Viewer-e49e7807.js +387 -0
  169. data/entry_types/scrolled/package/frontend/Wavesurfer-0adf5667.js +375 -0
  170. data/entry_types/scrolled/package/frontend/components-6a6793ca.js +2534 -0
  171. data/entry_types/scrolled/package/frontend/getPrototypeOf-63c7c8e8.js +86 -0
  172. data/entry_types/scrolled/package/frontend/i18n-4dc6c377.js +1092 -0
  173. data/entry_types/scrolled/package/frontend/index.css +9 -0
  174. data/entry_types/scrolled/package/frontend/index.js +5686 -0
  175. data/entry_types/scrolled/package/frontend/useBrowserFeature-91a4c29d.js +33 -0
  176. data/entry_types/scrolled/package/package.json +30 -9
  177. data/entry_types/scrolled/spec/fixtures/audio.m4a +0 -0
  178. data/entry_types/scrolled/spec/fixtures/video.mp4 +0 -0
  179. data/lib/generators/pageflow/initializer/templates/pageflow.rb +14 -9
  180. data/lib/pageflow/ability_mixin.rb +14 -2
  181. data/lib/pageflow/configuration.rb +6 -5
  182. data/lib/pageflow/entry_export_import/revision_serialization.rb +15 -13
  183. data/lib/pageflow/entry_export_import/revision_serialization/import.rb +18 -26
  184. data/lib/pageflow/entry_type_configuration.rb +2 -0
  185. data/lib/pageflow/global_config_api.rb +5 -4
  186. data/lib/pageflow/nested_revision_component.rb +49 -0
  187. data/lib/pageflow/react.rb +4 -2
  188. data/lib/pageflow/revision_component.rb +6 -2
  189. data/lib/pageflow/themes.rb +4 -0
  190. data/lib/pageflow/user_mixin.rb +2 -1
  191. data/lib/pageflow/version.rb +1 -1
  192. data/{packages/pageflow → package}/config/jest/index.js +8 -2
  193. data/{packages/pageflow → package}/config/jest/transformers/jst.js +0 -0
  194. data/{packages/pageflow → package}/config/jest/transformers/upwardBabel.js +0 -0
  195. data/{packages/pageflow → package}/config/webpack.js +7 -0
  196. data/{packages/pageflow → package}/editor.js +482 -1130
  197. data/package/frontend.js +2553 -0
  198. data/{packages/pageflow → package}/package.json +3 -0
  199. data/{packages/pageflow → package}/testHelpers.js +114 -13
  200. data/{packages/pageflow → package}/ui.js +178 -55
  201. data/spec/factories/accounts.rb +3 -1
  202. data/spec/factories/entry_templates.rb +1 -0
  203. data/spec/factories/published_entries.rb +6 -1
  204. data/spec/factories/test_revision_components.rb +4 -0
  205. metadata +96 -37
  206. data/app/assets/javascripts/pageflow/dist/editor.js +0 -11890
  207. data/app/assets/javascripts/pageflow/dist/frontend.js +0 -5800
  208. data/app/assets/javascripts/pageflow/videojs.js +0 -6
  209. data/config/initializers/entry_types.rb +0 -4
  210. data/entry_types/scrolled/config/locales/new/de.yml +0 -269
  211. data/entry_types/scrolled/config/locales/new/en.yml +0 -264
  212. data/entry_types/scrolled/lib/tasks/pageflow_scrolled_tasks.rake +0 -96
  213. data/entry_types/scrolled/package/frontend.js +0 -2879
  214. data/packages/pageflow/config/jest/transformers/cssModules.js +0 -1
@@ -0,0 +1,2534 @@
1
+ import React, { useMemo, useState, useCallback, useContext, useRef, useEffect, createContext, useLayoutEffect, memo } from 'react';
2
+ import { _ as _slicedToArray, r as useEntryStateDispatch, a as _defineProperty, b as _objectWithoutProperties, u as useI18n, w as updateContentElementConfiguration, k as _objectSpread2, p as _toConsumableArray } from './i18n-4dc6c377.js';
3
+ import classNames from 'classnames';
4
+ import 'use-context-selector';
5
+ import 'reselect';
6
+ import 'i18n-js';
7
+ import 'slugify';
8
+ import { C as ContentElementEditorCommandEmitterContext, d as usePostMessageListener, m as MotifAreaVisibilityProvider, n as ForcePaddingContext, o as ContentElementConfigurationUpdateContext, p as ContentElementEditorStateContext, f as api, i as useContentElementEditorState, q as LayoutWithoutInlineEditing, r as renderElement, s as renderLeaf, h as useContentElementEditorCommandSubscription, T as Text$1, P as PhonePlatformContext } from './EditableText-7093fd0e.js';
9
+ import './getPrototypeOf-63c7c8e8.js';
10
+ import BackboneEvents from 'backbone-events-standalone';
11
+ import { DndProvider, useDrop, useDrag } from 'react-dnd';
12
+ import { HTML5Backend } from 'react-dnd-html5-backend';
13
+ import { Range, Editor, Transforms, Text, Node, Path, createEditor } from 'slate';
14
+ import { useSlate, ReactEditor, withReact, Slate, Editable } from 'slate-react';
15
+ import debounce from 'debounce';
16
+
17
+ var Context = React.createContext({});
18
+ function EditorStateProvider(props) {
19
+ var _useState = useState(null),
20
+ _useState2 = _slicedToArray(_useState, 2),
21
+ selection = _useState2[0],
22
+ setSelectionState = _useState2[1];
23
+
24
+ var setSelection = useCallback(function (selection) {
25
+ if (window.parent !== window) {
26
+ window.parent.postMessage({
27
+ type: 'SELECTED',
28
+ payload: selection || {}
29
+ }, window.location.origin);
30
+ }
31
+
32
+ setSelectionState(selection);
33
+ }, []);
34
+ var value = useMemo(function () {
35
+ return {
36
+ selection: selection,
37
+ setSelection: setSelection
38
+ };
39
+ }, [setSelection, selection]);
40
+ return (
41
+ /*#__PURE__*/
42
+ React.createElement(Context.Provider, {
43
+ value: value
44
+ }, props.children)
45
+ );
46
+ }
47
+ function useEditorSelection(options) {
48
+ var _useContext = useContext(Context),
49
+ selection = _useContext.selection,
50
+ setSelection = _useContext.setSelection;
51
+
52
+ var resetSelection = useCallback(function () {
53
+ setSelection(null);
54
+ }, [setSelection]);
55
+ var select = useCallback(function (selection) {
56
+ setSelection(selection || options);
57
+ }, [setSelection, options]);
58
+ return useMemo(function () {
59
+ return setSelection ? {
60
+ isSelected: selection && options && selection.id === options.id && selection.type === options.type,
61
+ select: select,
62
+ resetSelection: resetSelection
63
+ } : {};
64
+ }, [options, selection, setSelection, select, resetSelection]);
65
+ }
66
+
67
+ function useContentElementEditorCommandEmitter() {
68
+ return useMemo(function () {
69
+ return Object.assign({}, BackboneEvents);
70
+ }, []);
71
+ }
72
+ function ContentElementEditorCommandSubscriptionProvider(_ref) {
73
+ var emitter = _ref.emitter,
74
+ children = _ref.children;
75
+ return (
76
+ /*#__PURE__*/
77
+ React.createElement(ContentElementEditorCommandEmitterContext.Provider, {
78
+ value: emitter
79
+ }, children)
80
+ );
81
+ }
82
+
83
+ // the editor phone preview. Each ContentElementDecorator renders a
84
+ // `data-scrollpoint` attribute with a unique value on its wrapper
85
+ // div. Before toggling the phone preview mode, the `EntryPreviewView`
86
+ // sends a `SAVE_SCROLL_POINT` message. `getCurrentScrollPoint` looks
87
+ // through all DOM elements with `data-scrollpoint` attributes and
88
+ // stores the unique id of the element with the smallest non-negative
89
+ // y coordinate in the viewport (i.e. the first content element inside
90
+ // the viewport). `ScrollPointMessageHandler` responds with a
91
+ // `SAVED_SCROLL_POINT` message which makes `EntryPreviewView` toggle
92
+ // the preview mode. Once the preview has been resized,
93
+ // `EntryPreviewView` sends a `RESTORE_SCROLL_POINT`
94
+ // message. `restoreScrollPoint` looks up the new position of the
95
+ // element with the saved scroll point and scrolls it into view.
96
+ //
97
+ // When a content element is selected, we want to keep that element
98
+ // in the viewport instead. The `SelectionRect` therefore renders a
99
+ // `data-scrollpoint=selection` attribute. If an element with such an
100
+ // attribute is present, `getCurrentScrollPoint` prefers it over all
101
+ // other scroll points. Since text block elements render a selection
102
+ // rect around the current paragraph, scroll position is also
103
+ // preserved correctly inside long text blocks.
104
+
105
+ function ScrollPointMessageHandler() {
106
+ var scrollPoint = useRef();
107
+ var receiveMessage = useCallback(function (data) {
108
+ if (data.type === 'SAVE_SCROLL_POINT') {
109
+ scrollPoint.current = getCurrentScrollPoint();
110
+ window.parent.postMessage({
111
+ type: 'SAVED_SCROLL_POINT'
112
+ }, window.location.origin);
113
+ } else if (data.type === 'RESTORE_SCROLL_POINT') {
114
+ if (scrollPoint.current) {
115
+ restoreScrollPoint(scrollPoint.current);
116
+ }
117
+ }
118
+ }, []);
119
+ usePostMessageListener(receiveMessage);
120
+ return null;
121
+ }
122
+
123
+ function getCurrentScrollPoint() {
124
+ var scrollPointElement = getSelectionScrollPointElement() || getScrollPointElementWithMinimumTopPositionInViewport();
125
+ return scrollPointElement === null || scrollPointElement === void 0 ? void 0 : scrollPointElement.getAttribute('data-scrollpoint');
126
+ }
127
+
128
+ function getSelectionScrollPointElement() {
129
+ return document.querySelector('[data-scrollpoint=selection]');
130
+ }
131
+
132
+ function getScrollPointElementWithMinimumTopPositionInViewport() {
133
+ var minTop = Infinity;
134
+ var scrollPointElement;
135
+ var scrollPoints = document.querySelectorAll('[data-scrollpoint]');
136
+
137
+ for (var i = 0; i < scrollPoints.length; i++) {
138
+ var rect = scrollPoints[i].getBoundingClientRect();
139
+
140
+ if (rect.top > 0 && rect.top < minTop) {
141
+ minTop = rect.top;
142
+ scrollPointElement = scrollPoints[i];
143
+ }
144
+ }
145
+
146
+ return scrollPointElement;
147
+ }
148
+
149
+ function restoreScrollPoint(name) {
150
+ var element = document.querySelector("[data-scrollpoint=\"".concat(name, "\"]"));
151
+
152
+ if (element) {
153
+ window.scrollTo({
154
+ top: element.getBoundingClientRect().top + window.scrollY - 100,
155
+ behavior: 'smooth'
156
+ });
157
+ }
158
+ }
159
+
160
+ function EntryDecorator(props) {
161
+ var contentElementEditorCommandEmitter = useContentElementEditorCommandEmitter();
162
+ return (
163
+ /*#__PURE__*/
164
+ React.createElement(EditorStateProvider, null,
165
+ /*#__PURE__*/
166
+ React.createElement(MessageHandler, {
167
+ contentElementEditorCommandEmitter: contentElementEditorCommandEmitter
168
+ }),
169
+ /*#__PURE__*/
170
+ React.createElement(ScrollPointMessageHandler, null),
171
+ /*#__PURE__*/
172
+ React.createElement(ContentElementEditorCommandSubscriptionProvider, {
173
+ emitter: contentElementEditorCommandEmitter
174
+ },
175
+ /*#__PURE__*/
176
+ React.createElement(DndProvider, {
177
+ backend: HTML5Backend
178
+ }, props.children)))
179
+ );
180
+ }
181
+
182
+ function MessageHandler(_ref) {
183
+ var contentElementEditorCommandEmitter = _ref.contentElementEditorCommandEmitter;
184
+
185
+ var _useEditorSelection = useEditorSelection(),
186
+ select = _useEditorSelection.select;
187
+
188
+ var dispatch = useEntryStateDispatch();
189
+ var receiveMessage = useCallback(function (data) {
190
+ if (data.type === 'ACTION') {
191
+ dispatch(data.payload);
192
+ } else if (data.type === 'SELECT') {
193
+ select(data.payload);
194
+ } else if (data.type === 'CONTENT_ELEMENT_EDITOR_COMMAND') {
195
+ contentElementEditorCommandEmitter.trigger("command:".concat(data.payload.contentElementId), data.payload.command);
196
+ }
197
+ }, [dispatch, select, contentElementEditorCommandEmitter]);
198
+ usePostMessageListener(receiveMessage);
199
+ useEffect(function () {
200
+ if (window.parent !== window) {
201
+ window.parent.postMessage({
202
+ type: 'READY'
203
+ }, window.location.origin);
204
+ }
205
+ }, []);
206
+ return null;
207
+ }
208
+
209
+ var styles = {"wrapper":"SectionDecorator-module_wrapper__3sTk3","selected":"SectionDecorator-module_selected__1gcmF","transitionSelected":"SectionDecorator-module_transitionSelected__Wklk6","controls":"SectionDecorator-module_controls__LVEJG","editToolbar":"SectionDecorator-module_editToolbar__18Kjq","toolbar":"SectionDecorator-module_toolbar__2Va1D","transitionToolbar-before":"SectionDecorator-module_transitionToolbar-before__KipOO SectionDecorator-module_toolbar__2Va1D","transitionToolbar-after":"SectionDecorator-module_transitionToolbar-after__2_DVO SectionDecorator-module_toolbar__2Va1D"};
210
+
211
+ var styles$1 = {"wrapper":"ContentElementDecorator-module_wrapper__NQgFN"};
212
+
213
+ var styles$2 = {"Toolbar":"Toolbar-module_Toolbar__1INSj","button":"Toolbar-module_button__de5BW","activeButton":"Toolbar-module_activeButton__2sOLP","collapsible":"Toolbar-module_collapsible__3sivb"};
214
+
215
+ function Toolbar(_ref) {
216
+ var buttons = _ref.buttons,
217
+ onButtonClick = _ref.onButtonClick,
218
+ iconSize = _ref.iconSize,
219
+ collapsible = _ref.collapsible;
220
+ return (
221
+ /*#__PURE__*/
222
+ React.createElement("div", {
223
+ className: classNames(styles$2.Toolbar, _defineProperty({}, styles$2.collapsible, collapsible)),
224
+ contentEditable: false
225
+ }, buttons.map(function (button) {
226
+ var Icon = button.icon;
227
+ return (
228
+ /*#__PURE__*/
229
+ React.createElement("button", {
230
+ key: button.name,
231
+ title: button.text,
232
+ className: classNames(styles$2.button, _defineProperty({}, styles$2.activeButton, button.active)),
233
+ onMouseDown: function onMouseDown(event) {
234
+ event.preventDefault();
235
+ event.stopPropagation();
236
+ onButtonClick(button.name);
237
+ }
238
+ },
239
+ /*#__PURE__*/
240
+ React.createElement(Icon, {
241
+ width: iconSize,
242
+ height: iconSize
243
+ }))
244
+ );
245
+ }))
246
+ );
247
+ }
248
+ Toolbar.defaultProps = {
249
+ iconSize: 15
250
+ };
251
+
252
+ function _extends() {
253
+ _extends = Object.assign || function (target) {
254
+ for (var i = 1; i < arguments.length; i++) {
255
+ var source = arguments[i];
256
+
257
+ for (var key in source) {
258
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
259
+ target[key] = source[key];
260
+ }
261
+ }
262
+ }
263
+
264
+ return target;
265
+ };
266
+
267
+ return _extends.apply(this, arguments);
268
+ }
269
+ var transitionIcon = (function (_ref) {
270
+ var _ref$styles = _ref.styles,
271
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
272
+ props = _objectWithoutProperties(_ref, ["styles"]);
273
+
274
+ return React.createElement("svg", _extends({
275
+ "aria-hidden": "true",
276
+ "data-prefix": "fas",
277
+ "data-icon": "random",
278
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-random"] || "fa-random") + " " + (styles["fa-w-16"] || "fa-w-16"),
279
+ xmlns: "http://www.w3.org/2000/svg",
280
+ viewBox: "0 0 512 512"
281
+ }, props), React.createElement("path", {
282
+ fill: "currentColor",
283
+ d: "M504.971 359.029c9.373 9.373 9.373 24.569 0 33.941l-80 79.984c-15.01 15.01-40.971 4.49-40.971-16.971V416h-58.785a12.004 12.004 0 01-8.773-3.812l-70.556-75.596 53.333-57.143L352 336h32v-39.981c0-21.438 25.943-31.998 40.971-16.971l80 79.981zM12 176h84l52.781 56.551 53.333-57.143-70.556-75.596A11.999 11.999 0 00122.785 96H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12zm372 0v39.984c0 21.46 25.961 31.98 40.971 16.971l80-79.984c9.373-9.373 9.373-24.569 0-33.941l-80-79.981C409.943 24.021 384 34.582 384 56.019V96h-58.785a12.004 12.004 0 00-8.773 3.812L96 336H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12h110.785c3.326 0 6.503-1.381 8.773-3.812L352 176h32z"
284
+ }));
285
+ });
286
+
287
+ function SectionDecorator(props) {
288
+ var _useI18n = useI18n({
289
+ locale: 'ui'
290
+ }),
291
+ t = _useI18n.t;
292
+
293
+ var _useEditorSelection = useEditorSelection({
294
+ id: props.id,
295
+ type: 'sectionSettings'
296
+ }),
297
+ isSelected = _useEditorSelection.isSelected,
298
+ select = _useEditorSelection.select,
299
+ resetSelection = _useEditorSelection.resetSelection;
300
+
301
+ var transitionSelection = useEditorSelection({
302
+ id: props.id,
303
+ type: 'sectionTransition'
304
+ });
305
+ var nextTransitionSelection = useEditorSelection({
306
+ id: props.nextSection && props.nextSection.id,
307
+ type: 'sectionTransition'
308
+ });
309
+ var lastContentElement = props.contentElements[props.contentElements.length - 1];
310
+
311
+ var _useEditorSelection2 = useEditorSelection({
312
+ id: lastContentElement && lastContentElement.id,
313
+ type: 'contentElement'
314
+ }),
315
+ isLastContentElementSelected = _useEditorSelection2.isSelected;
316
+
317
+ function selectIfOutsideContentItem(event) {
318
+ if (!event.target.closest(".".concat(styles$1.wrapper))) {
319
+ isSelected ? resetSelection() : select();
320
+ }
321
+ }
322
+
323
+ return (
324
+ /*#__PURE__*/
325
+ React.createElement("div", {
326
+ "aria-label": t('pageflow_scrolled.inline_editing.select_section'),
327
+ className: className(isSelected, transitionSelection),
328
+ onMouseDown: selectIfOutsideContentItem
329
+ },
330
+ /*#__PURE__*/
331
+ React.createElement("div", {
332
+ className: styles.controls
333
+ }, renderEditTransitionButton({
334
+ id: props.previousSection && props.id,
335
+ selection: transitionSelection,
336
+ position: 'before'
337
+ }), renderEditTransitionButton({
338
+ id: props.nextSection && props.nextSection.id,
339
+ selection: nextTransitionSelection,
340
+ position: 'after'
341
+ })),
342
+ /*#__PURE__*/
343
+ React.createElement(MotifAreaVisibilityProvider, {
344
+ visible: isSelected
345
+ },
346
+ /*#__PURE__*/
347
+ React.createElement(ForcePaddingContext.Provider, {
348
+ value: isLastContentElementSelected || isSelected
349
+ }, props.children)))
350
+ );
351
+ }
352
+
353
+ function className(isSectionSelected, transitionSelection) {
354
+ var _classNames;
355
+
356
+ return classNames(styles.wrapper, (_classNames = {}, _defineProperty(_classNames, styles.selected, isSectionSelected), _defineProperty(_classNames, styles.transitionSelected, transitionSelection.isSelected), _classNames));
357
+ }
358
+
359
+ function renderEditTransitionButton(_ref) {
360
+ var id = _ref.id,
361
+ position = _ref.position,
362
+ selection = _ref.selection;
363
+
364
+ if (!id) {
365
+ return null;
366
+ }
367
+
368
+ return (
369
+ /*#__PURE__*/
370
+ React.createElement("div", {
371
+ className: styles["transitionToolbar-".concat(position)]
372
+ },
373
+ /*#__PURE__*/
374
+ React.createElement(EditTransitionButton, {
375
+ id: id,
376
+ selection: selection,
377
+ position: position
378
+ }))
379
+ );
380
+ }
381
+
382
+ function EditTransitionButton(_ref2) {
383
+ var id = _ref2.id,
384
+ position = _ref2.position,
385
+ selection = _ref2.selection;
386
+
387
+ var _useI18n2 = useI18n({
388
+ locale: 'ui'
389
+ }),
390
+ t = _useI18n2.t;
391
+
392
+ return (
393
+ /*#__PURE__*/
394
+ React.createElement(EditSectionButton, {
395
+ id: id,
396
+ selection: selection,
397
+ text: t("pageflow_scrolled.inline_editing.edit_section_transition_".concat(position)),
398
+ icon: transitionIcon
399
+ })
400
+ );
401
+ }
402
+
403
+ function EditSectionButton(_ref3) {
404
+ var id = _ref3.id,
405
+ selection = _ref3.selection,
406
+ icon = _ref3.icon,
407
+ text = _ref3.text;
408
+ return (
409
+ /*#__PURE__*/
410
+ React.createElement(Toolbar, {
411
+ buttons: [{
412
+ name: 'button',
413
+ active: selection.isSelected,
414
+ icon: icon,
415
+ text: text
416
+ }],
417
+ iconSize: 20,
418
+ onButtonClick: function onButtonClick() {
419
+ return selection.select();
420
+ }
421
+ })
422
+ );
423
+ }
424
+
425
+ var styles$3 = {"selectionWidth":"1px","selectionPadding":"-6px","selectionPadding2":"-0.5em","main":"SelectionRect-module_main__3AOhG","draggable":"SelectionRect-module_draggable__3Qp53","full":"SelectionRect-module_full__3tsQF","selected":"SelectionRect-module_selected__1PhM6","toolbar":"SelectionRect-module_toolbar__3nPrd","insert":"SelectionRect-module_insert__w0Tl0","insertHovered":"SelectionRect-module_insertHovered__VTsDD","start":"SelectionRect-module_start__3_nAf","insert-before":"SelectionRect-module_insert-before__2Tyq5 SelectionRect-module_insert__w0Tl0","end":"SelectionRect-module_end__3qOoK","insert-after":"SelectionRect-module_insert-after__3FJ4R SelectionRect-module_insert__w0Tl0","insertButton":"SelectionRect-module_insertButton__1g-ZG","dragHandle":"SelectionRect-module_dragHandle__2vVhP"};
426
+
427
+ function _extends$1() {
428
+ _extends$1 = Object.assign || function (target) {
429
+ for (var i = 1; i < arguments.length; i++) {
430
+ var source = arguments[i];
431
+
432
+ for (var key in source) {
433
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
434
+ target[key] = source[key];
435
+ }
436
+ }
437
+ }
438
+
439
+ return target;
440
+ };
441
+
442
+ return _extends$1.apply(this, arguments);
443
+ }
444
+ var PlusIcon = (function (_ref) {
445
+ var _ref$styles = _ref.styles,
446
+ props = _objectWithoutProperties(_ref, ["styles"]);
447
+
448
+ return React.createElement("svg", _extends$1({
449
+ xmlns: "http://www.w3.org/2000/svg",
450
+ viewBox: "0 0 512 512"
451
+ }, props), React.createElement("path", {
452
+ d: "M256 0C114.844 0 0 114.839 0 256s114.844 256 256 256 256-114.839 256-256S397.156 0 256 0zm133.594 272.699H272.699v116.895c0 9.225-7.48 16.699-16.699 16.699-9.219 0-16.699-7.475-16.699-16.699V272.699H122.406c-9.219 0-16.699-7.475-16.699-16.699 0-9.225 7.48-16.699 16.699-16.699h116.895V122.406c0-9.225 7.48-16.699 16.699-16.699 9.219 0 16.699 7.475 16.699 16.699v116.895h116.895c9.219 0 16.699 7.475 16.699 16.699.001 9.225-7.48 16.699-16.699 16.699z"
453
+ }));
454
+ });
455
+
456
+ function _extends$2() {
457
+ _extends$2 = Object.assign || function (target) {
458
+ for (var i = 1; i < arguments.length; i++) {
459
+ var source = arguments[i];
460
+
461
+ for (var key in source) {
462
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
463
+ target[key] = source[key];
464
+ }
465
+ }
466
+ }
467
+
468
+ return target;
469
+ };
470
+
471
+ return _extends$2.apply(this, arguments);
472
+ }
473
+ var MoveIcon = (function (_ref) {
474
+ var _ref$styles = _ref.styles,
475
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
476
+ props = _objectWithoutProperties(_ref, ["styles"]);
477
+
478
+ return React.createElement("svg", _extends$2({
479
+ "aria-hidden": "true",
480
+ "data-prefix": "fas",
481
+ "data-icon": "arrows-alt",
482
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-arrows-alt"] || "fa-arrows-alt") + " " + (styles["fa-w-16"] || "fa-w-16"),
483
+ xmlns: "http://www.w3.org/2000/svg",
484
+ viewBox: "0 0 512 512"
485
+ }, props), React.createElement("path", {
486
+ fill: "currentColor",
487
+ d: "M352.201 425.775l-79.196 79.196c-9.373 9.373-24.568 9.373-33.941 0l-79.196-79.196c-15.119-15.119-4.411-40.971 16.971-40.97h51.162L228 284H127.196v51.162c0 21.382-25.851 32.09-40.971 16.971L7.029 272.937c-9.373-9.373-9.373-24.569 0-33.941L86.225 159.8c15.119-15.119 40.971-4.411 40.971 16.971V228H228V127.196h-51.23c-21.382 0-32.09-25.851-16.971-40.971l79.196-79.196c9.373-9.373 24.568-9.373 33.941 0l79.196 79.196c15.119 15.119 4.411 40.971-16.971 40.971h-51.162V228h100.804v-51.162c0-21.382 25.851-32.09 40.97-16.971l79.196 79.196c9.373 9.373 9.373 24.569 0 33.941L425.773 352.2c-15.119 15.119-40.971 4.411-40.97-16.971V284H284v100.804h51.23c21.382 0 32.09 25.851 16.971 40.971z"
488
+ }));
489
+ });
490
+
491
+ function SelectionRect(props) {
492
+ var _classNames;
493
+
494
+ return (
495
+ /*#__PURE__*/
496
+ React.createElement("div", {
497
+ className: classNames(styles$3.main, (_classNames = {}, _defineProperty(_classNames, styles$3.full, props.full), _defineProperty(_classNames, styles$3.selected, props.selected), _defineProperty(_classNames, styles$3.draggable, props.drag), _defineProperty(_classNames, styles$3.start, props.selected && props.start), _defineProperty(_classNames, styles$3.end, props.selected && props.end), _classNames)),
498
+ "aria-label": props.ariaLabel,
499
+ "data-scrollpoint": props.scrollPoint ? 'selection' : undefined,
500
+ onClick: props.onClick
501
+ }, renderDragHandle(props), renderToolbar(props),
502
+ /*#__PURE__*/
503
+ React.createElement(InsertButton, Object.assign({}, props, {
504
+ at: "before"
505
+ })), props.children,
506
+ /*#__PURE__*/
507
+ React.createElement(InsertButton, Object.assign({}, props, {
508
+ at: "after"
509
+ })))
510
+ );
511
+ }
512
+
513
+ function InsertButton(props) {
514
+ var _useState = useState(false),
515
+ _useState2 = _slicedToArray(_useState, 2),
516
+ insertHovered = _useState2[0],
517
+ setInsertHovered = _useState2[1];
518
+
519
+ return (
520
+ /*#__PURE__*/
521
+ React.createElement("div", {
522
+ className: classNames(styles$3["insert-".concat(props.at)], _defineProperty({}, styles$3.insertHovered, insertHovered)),
523
+ contentEditable: false
524
+ },
525
+ /*#__PURE__*/
526
+ React.createElement("button", {
527
+ className: styles$3.insertButton,
528
+ title: props.insertButtonTitles && props.insertButtonTitles[props.at],
529
+ onClick: function onClick() {
530
+ return props.onInsertButtonClick(props.at);
531
+ },
532
+ onMouseEnter: function onMouseEnter() {
533
+ return setInsertHovered(true);
534
+ },
535
+ onMouseLeave: function onMouseLeave() {
536
+ return setInsertHovered(false);
537
+ }
538
+ },
539
+ /*#__PURE__*/
540
+ React.createElement(PlusIcon, {
541
+ width: 15,
542
+ height: 15,
543
+ fill: "currentColor"
544
+ })))
545
+ );
546
+ }
547
+
548
+ function renderDragHandle(_ref) {
549
+ var drag = _ref.drag,
550
+ dragHandleTitle = _ref.dragHandleTitle;
551
+
552
+ if (!drag) {
553
+ return null;
554
+ }
555
+
556
+ return (
557
+ /*#__PURE__*/
558
+ React.createElement("div", {
559
+ ref: drag,
560
+ className: styles$3.dragHandle,
561
+ title: dragHandleTitle
562
+ },
563
+ /*#__PURE__*/
564
+ React.createElement(MoveIcon, null))
565
+ );
566
+ }
567
+
568
+ function renderToolbar(_ref2) {
569
+ var toolbarButtons = _ref2.toolbarButtons,
570
+ onToolbarButtonClick = _ref2.onToolbarButtonClick,
571
+ start = _ref2.start;
572
+
573
+ if (toolbarButtons && start) {
574
+ return (
575
+ /*#__PURE__*/
576
+ React.createElement("div", {
577
+ className: styles$3.toolbar
578
+ },
579
+ /*#__PURE__*/
580
+ React.createElement(Toolbar, {
581
+ buttons: toolbarButtons,
582
+ collapsible: true,
583
+ onButtonClick: onToolbarButtonClick
584
+ }))
585
+ );
586
+ }
587
+ }
588
+
589
+ SelectionRect.defaultProps = {
590
+ start: true,
591
+ end: true
592
+ };
593
+
594
+ var styles$4 = {"target":"DropTargets-module_target__Z2N2d","isOver":"DropTargets-module_isOver__3ksFy","before":"DropTargets-module_before__cAXo1 DropTargets-module_target__Z2N2d","after":"DropTargets-module_after__2Q8QU DropTargets-module_target__Z2N2d"};
595
+
596
+ function DropTargets(_ref) {
597
+ var accept = _ref.accept,
598
+ _canDrop = _ref.canDrop,
599
+ onDrop = _ref.onDrop;
600
+
601
+ var _useDrop = useDrop({
602
+ accept: accept,
603
+ canDrop: function canDrop(item) {
604
+ return _canDrop({
605
+ at: 'before',
606
+ id: item.id
607
+ });
608
+ },
609
+ collect: function collect(monitor) {
610
+ return {
611
+ canDropBefore: monitor.canDrop(),
612
+ isBefore: monitor.isOver() && monitor.canDrop()
613
+ };
614
+ },
615
+ drop: function drop(item) {
616
+ return onDrop({
617
+ at: 'before',
618
+ id: item.id
619
+ });
620
+ }
621
+ }),
622
+ _useDrop2 = _slicedToArray(_useDrop, 2),
623
+ _useDrop2$ = _useDrop2[0],
624
+ canDropBefore = _useDrop2$.canDropBefore,
625
+ isBefore = _useDrop2$.isBefore,
626
+ dropBefore = _useDrop2[1];
627
+
628
+ var _useDrop3 = useDrop({
629
+ accept: accept,
630
+ canDrop: function canDrop(item) {
631
+ return _canDrop({
632
+ at: 'after',
633
+ id: item.id
634
+ });
635
+ },
636
+ collect: function collect(monitor) {
637
+ return {
638
+ canDropAfter: monitor.canDrop(),
639
+ isAfter: monitor.isOver() && monitor.canDrop()
640
+ };
641
+ },
642
+ drop: function drop(item) {
643
+ return onDrop({
644
+ at: 'after',
645
+ id: item.id
646
+ });
647
+ }
648
+ }),
649
+ _useDrop4 = _slicedToArray(_useDrop3, 2),
650
+ _useDrop4$ = _useDrop4[0],
651
+ canDropAfter = _useDrop4$.canDropAfter,
652
+ isAfter = _useDrop4$.isAfter,
653
+ dropAfter = _useDrop4[1];
654
+
655
+ return (
656
+ /*#__PURE__*/
657
+ React.createElement(React.Fragment, null, canDropBefore &&
658
+ /*#__PURE__*/
659
+ React.createElement("div", {
660
+ ref: dropBefore,
661
+ "data-testid": "drop-before",
662
+ className: classNames(styles$4.before, _defineProperty({}, styles$4.isOver, isBefore))
663
+ }), canDropAfter &&
664
+ /*#__PURE__*/
665
+ React.createElement("div", {
666
+ ref: dropAfter,
667
+ "data-testid": "drop-after",
668
+ title: "bar",
669
+ className: classNames(styles$4.after, _defineProperty({}, styles$4.isOver, isAfter))
670
+ }))
671
+ );
672
+ }
673
+
674
+ function postInsertContentElementMessage(_ref) {
675
+ var id = _ref.id,
676
+ at = _ref.at,
677
+ splitPoint = _ref.splitPoint;
678
+ window.parent.postMessage({
679
+ type: 'INSERT_CONTENT_ELEMENT',
680
+ payload: {
681
+ id: id,
682
+ at: at,
683
+ splitPoint: splitPoint
684
+ }
685
+ }, window.location.origin);
686
+ }
687
+ function postMoveContentElementMessage(_ref2) {
688
+ var id = _ref2.id,
689
+ to = _ref2.to;
690
+ window.parent.postMessage({
691
+ type: 'MOVE_CONTENT_ELEMENT',
692
+ payload: {
693
+ id: id,
694
+ to: to
695
+ }
696
+ }, window.location.origin);
697
+ }
698
+ function postUpdateContentElementMessage(_ref3) {
699
+ var id = _ref3.id,
700
+ configuration = _ref3.configuration;
701
+ window.parent.postMessage({
702
+ type: 'UPDATE_CONTENT_ELEMENT',
703
+ payload: {
704
+ id: id,
705
+ configuration: configuration
706
+ }
707
+ }, window.location.origin);
708
+ }
709
+ function postUpdateTransientContentElementStateMessage(_ref4) {
710
+ var id = _ref4.id,
711
+ state = _ref4.state;
712
+ window.parent.postMessage({
713
+ type: 'UPDATE_TRANSIENT_CONTENT_ELEMENT_STATE',
714
+ payload: {
715
+ id: id,
716
+ state: state
717
+ }
718
+ }, window.location.origin);
719
+ }
720
+
721
+ function ContentElementConfigurationUpdateProvider(_ref) {
722
+ var id = _ref.id,
723
+ permaId = _ref.permaId,
724
+ children = _ref.children;
725
+ var dispatch = useEntryStateDispatch();
726
+ var update = useCallback(function (configuration) {
727
+ postUpdateContentElementMessage({
728
+ id: id,
729
+ configuration: configuration
730
+ });
731
+ updateContentElementConfiguration({
732
+ dispatch: dispatch,
733
+ permaId: permaId,
734
+ configuration: configuration
735
+ });
736
+ }, [dispatch, permaId, id]);
737
+ return (
738
+ /*#__PURE__*/
739
+ React.createElement(ContentElementConfigurationUpdateContext.Provider, {
740
+ value: update
741
+ }, children)
742
+ );
743
+ }
744
+
745
+ function ContentElementEditorStateProvider(_ref) {
746
+ var id = _ref.id,
747
+ children = _ref.children;
748
+
749
+ var _useEditorSelection = useEditorSelection({
750
+ id: id,
751
+ type: 'contentElement'
752
+ }),
753
+ isSelected = _useEditorSelection.isSelected,
754
+ select = _useEditorSelection.select;
755
+
756
+ var previousTransientState = useRef({});
757
+ var setTransientState = useCallback(function (state) {
758
+ if (!shallowEqual(state, previousTransientState.current)) {
759
+ postUpdateTransientContentElementStateMessage({
760
+ id: id,
761
+ state: state
762
+ });
763
+ previousTransientState.current = state;
764
+ }
765
+ }, [id]);
766
+ var value = useMemo(function () {
767
+ return {
768
+ isEditable: true,
769
+ select: select,
770
+ isSelected: isSelected,
771
+ setTransientState: setTransientState
772
+ };
773
+ }, [select, isSelected, setTransientState]);
774
+ return (
775
+ /*#__PURE__*/
776
+ React.createElement(ContentElementEditorStateContext.Provider, {
777
+ value: value
778
+ }, children)
779
+ );
780
+ }
781
+
782
+ function shallowEqual(obj1, obj2) {
783
+ return Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every(function (key) {
784
+ return Object.prototype.hasOwnProperty.call(obj2, key) && obj1[key] === obj2[key];
785
+ });
786
+ }
787
+
788
+ function ContentElementDecorator(props) {
789
+ return (
790
+ /*#__PURE__*/
791
+ React.createElement("div", {
792
+ className: styles$1.wrapper,
793
+ "data-scrollpoint": props.id
794
+ },
795
+ /*#__PURE__*/
796
+ React.createElement(ContentElementEditorStateProvider, {
797
+ id: props.id
798
+ },
799
+ /*#__PURE__*/
800
+ React.createElement(OptionalSelectionRect, props,
801
+ /*#__PURE__*/
802
+ React.createElement(ContentElementConfigurationUpdateProvider, {
803
+ id: props.id,
804
+ permaId: props.permaId
805
+ }, props.children))))
806
+ );
807
+ }
808
+
809
+ function OptionalSelectionRect(props) {
810
+ var _ref = api.contentElementTypes.getOptions(props.type) || {},
811
+ customSelectionRect = _ref.customSelectionRect;
812
+
813
+ if (customSelectionRect) {
814
+ return props.children;
815
+ } else {
816
+ return (
817
+ /*#__PURE__*/
818
+ React.createElement(DefaultSelectionRect, props, props.children)
819
+ );
820
+ }
821
+ }
822
+
823
+ function DefaultSelectionRect(props) {
824
+ var _useContentElementEdi = useContentElementEditorState(),
825
+ isSelected = _useContentElementEdi.isSelected,
826
+ select = _useContentElementEdi.select;
827
+
828
+ var _useI18n = useI18n({
829
+ locale: 'ui'
830
+ }),
831
+ t = _useI18n.t;
832
+
833
+ var _useDrag = useDrag({
834
+ item: {
835
+ type: 'contentElement',
836
+ id: props.id
837
+ }
838
+ }),
839
+ _useDrag2 = _slicedToArray(_useDrag, 3),
840
+ drag = _useDrag2[1],
841
+ preview = _useDrag2[2];
842
+
843
+ return (
844
+ /*#__PURE__*/
845
+ React.createElement(SelectionRect, {
846
+ selected: isSelected,
847
+ scrollPoint: isSelected,
848
+ drag: drag,
849
+ dragHandleTitle: t('pageflow_scrolled.inline_editing.drag_content_element'),
850
+ full: props.position === 'full',
851
+ ariaLabel: t('pageflow_scrolled.inline_editing.select_content_element'),
852
+ insertButtonTitles: t('pageflow_scrolled.inline_editing.insert_content_element'),
853
+ onClick: function onClick() {
854
+ return select();
855
+ },
856
+ onInsertButtonClick: function onInsertButtonClick(at) {
857
+ return postInsertContentElementMessage({
858
+ id: props.id,
859
+ at: at
860
+ });
861
+ }
862
+ },
863
+ /*#__PURE__*/
864
+ React.createElement("div", {
865
+ ref: preview
866
+ }, props.children),
867
+ /*#__PURE__*/
868
+ React.createElement(DropTargets, {
869
+ accept: "contentElement",
870
+ canDrop: function canDrop(_ref2) {
871
+ var id = _ref2.id;
872
+ return id !== props.id;
873
+ },
874
+ onDrop: function onDrop(_ref3) {
875
+ var id = _ref3.id,
876
+ at = _ref3.at;
877
+ return postMoveContentElementMessage({
878
+ id: id,
879
+ to: {
880
+ id: props.id,
881
+ at: at
882
+ }
883
+ });
884
+ }
885
+ }))
886
+ );
887
+ }
888
+
889
+ var styles$5 = {"container":"ContentElementInsertButton-module_container__3dvUS","hovered":"ContentElementInsertButton-module_hovered__3Pggi","button":"ContentElementInsertButton-module_button__2-eE2"};
890
+
891
+ function ContentElementInsertButton(_ref) {
892
+ var onClick = _ref.onClick;
893
+
894
+ var _useState = useState(),
895
+ _useState2 = _slicedToArray(_useState, 2),
896
+ hovered = _useState2[0],
897
+ setHovered = _useState2[1];
898
+
899
+ var _useI18n = useI18n({
900
+ locale: 'ui'
901
+ }),
902
+ t = _useI18n.t;
903
+
904
+ return (
905
+ /*#__PURE__*/
906
+ React.createElement("div", {
907
+ className: classNames(styles$5.container, _defineProperty({}, styles$5.hovered, hovered))
908
+ },
909
+ /*#__PURE__*/
910
+ React.createElement("button", {
911
+ className: styles$5.button,
912
+ title: t('pageflow_scrolled.inline_editing.add_content_element'),
913
+ onClick: onClick,
914
+ onMouseDown: function onMouseDown(event) {
915
+ return event.stopPropagation();
916
+ },
917
+ onMouseEnter: function onMouseEnter() {
918
+ return setHovered(true);
919
+ },
920
+ onMouseLeave: function onMouseLeave() {
921
+ return setHovered(false);
922
+ }
923
+ },
924
+ /*#__PURE__*/
925
+ React.createElement(PlusIcon, {
926
+ width: 15,
927
+ height: 15,
928
+ fill: "currentColor"
929
+ })))
930
+ );
931
+ }
932
+
933
+ function LayoutWithPlaceholder(props) {
934
+ var _useEditorSelection = useEditorSelection({
935
+ id: props.sectionId,
936
+ type: 'section'
937
+ }),
938
+ isSelected = _useEditorSelection.isSelected;
939
+
940
+ var _useEditorSelection2 = useEditorSelection({
941
+ id: props.sectionId,
942
+ type: 'sectionSettings'
943
+ }),
944
+ settingsSelected = _useEditorSelection2.isSelected;
945
+
946
+ var placeholder = isSelected || settingsSelected ?
947
+ /*#__PURE__*/
948
+ React.createElement(ContentElementInsertButton, {
949
+ onClick: function onClick() {
950
+ return postInsertContentElementMessage({
951
+ at: 'endOfSection',
952
+ id: props.sectionId
953
+ });
954
+ }
955
+ }) : null;
956
+ return (
957
+ /*#__PURE__*/
958
+ React.createElement(LayoutWithoutInlineEditing, Object.assign({}, props, {
959
+ placeholder: placeholder
960
+ }))
961
+ );
962
+ }
963
+
964
+ function useCachedValue(value) {
965
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
966
+ defaultValue = _ref.defaultValue,
967
+ onReset = _ref.onReset,
968
+ onDebouncedChange = _ref.onDebouncedChange,
969
+ _ref$delay = _ref.delay,
970
+ delay = _ref$delay === void 0 ? 2000 : _ref$delay;
971
+
972
+ var _useState = useState(value || defaultValue),
973
+ _useState2 = _slicedToArray(_useState, 2),
974
+ cachedValue = _useState2[0],
975
+ setCachedValue = _useState2[1];
976
+
977
+ var previousValue = useRef(value);
978
+ useEffect(function () {
979
+ if (previousValue.current !== value && value !== cachedValue) {
980
+ onReset && onReset(value);
981
+ setCachedValue(value);
982
+ }
983
+ }, [onReset, value, cachedValue]);
984
+ useEffect(function () {
985
+ previousValue.current = value;
986
+ });
987
+ var debouncedHandler = useDebouncedCallback(onDebouncedChange, delay);
988
+ var setValue = useCallback(function (value) {
989
+ setCachedValue(function (previousValue) {
990
+ if (previousValue !== value) {
991
+ debouncedHandler(value);
992
+ }
993
+
994
+ return value;
995
+ });
996
+ }, [debouncedHandler]);
997
+ return [cachedValue, setValue];
998
+ } // Debounce callback even if the callback function changes across renders.
999
+
1000
+ function useDebouncedCallback(callback, delay) {
1001
+ var mostRecentCallback = useRef(null);
1002
+ var debouncedHandler = useRef(null);
1003
+ useEffect(function () {
1004
+ mostRecentCallback.current = callback;
1005
+ }, [callback]);
1006
+ useEffect(function () {
1007
+ debouncedHandler.current = debounce(function (value) {
1008
+ if (mostRecentCallback.current) {
1009
+ mostRecentCallback.current(value);
1010
+ }
1011
+ }, delay);
1012
+ return function () {
1013
+ debouncedHandler.current.flush();
1014
+ };
1015
+ }, [delay]);
1016
+ return useCallback(function () {
1017
+ return debouncedHandler.current.apply(debouncedHandler, arguments);
1018
+ }, []);
1019
+ }
1020
+
1021
+ var styles$6 = {"placeholder":"TextPlaceholder-module_placeholder__sgVwx"};
1022
+
1023
+ function TextPlaceholder(_ref) {
1024
+ var text = _ref.text,
1025
+ visible = _ref.visible;
1026
+
1027
+ if (!text || !visible) {
1028
+ return null;
1029
+ }
1030
+
1031
+ return (
1032
+ /*#__PURE__*/
1033
+ React.createElement("div", {
1034
+ className: styles$6.placeholder
1035
+ },
1036
+ /*#__PURE__*/
1037
+ React.createElement("div", null, text))
1038
+ );
1039
+ }
1040
+
1041
+ function withCustomInsertBreak(editor) {
1042
+ var insertBreak = editor.insertBreak;
1043
+
1044
+ editor.insertBreak = function () {
1045
+ var selection = editor.selection;
1046
+
1047
+ if (selection && Range.isCollapsed(selection)) {
1048
+ var match = Editor.above(editor, {
1049
+ match: function match(n) {
1050
+ return Editor.isBlock(editor, n);
1051
+ }
1052
+ });
1053
+
1054
+ if (match) {
1055
+ var _match = _slicedToArray(match, 2),
1056
+ block = _match[0],
1057
+ path = _match[1];
1058
+
1059
+ if (Editor.isEnd(editor, selection.anchor, path) && block.type === 'heading') {
1060
+ Transforms.insertNodes(editor, {
1061
+ type: 'paragraph',
1062
+ children: [{
1063
+ text: ''
1064
+ }]
1065
+ });
1066
+ return;
1067
+ }
1068
+ }
1069
+ }
1070
+
1071
+ insertBreak();
1072
+ };
1073
+
1074
+ return editor;
1075
+ }
1076
+
1077
+ var styles$7 = {"container":"index-module_container__3dD9z","hoveringToolbar":"index-module_hoveringToolbar__31Xpd","selection":"index-module_selection__3dUiD","linkTooltip":"index-module_linkTooltip__36m1K"};
1078
+
1079
+ function _extends$3() {
1080
+ _extends$3 = Object.assign || function (target) {
1081
+ for (var i = 1; i < arguments.length; i++) {
1082
+ var source = arguments[i];
1083
+
1084
+ for (var key in source) {
1085
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1086
+ target[key] = source[key];
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ return target;
1092
+ };
1093
+
1094
+ return _extends$3.apply(this, arguments);
1095
+ }
1096
+ var ExternalLinkIcon = (function (_ref) {
1097
+ var _ref$styles = _ref.styles,
1098
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1099
+ props = _objectWithoutProperties(_ref, ["styles"]);
1100
+
1101
+ return React.createElement("svg", _extends$3({
1102
+ "aria-hidden": "true",
1103
+ "data-prefix": "fas",
1104
+ "data-icon": "external-link-alt",
1105
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-external-link-alt"] || "fa-external-link-alt") + " " + (styles["fa-w-16"] || "fa-w-16"),
1106
+ xmlns: "http://www.w3.org/2000/svg",
1107
+ viewBox: "0 0 512 512"
1108
+ }, props), React.createElement("path", {
1109
+ fill: "currentColor",
1110
+ d: "M432 320h-32a16 16 0 00-16 16v112H64V128h144a16 16 0 0016-16V80a16 16 0 00-16-16H48a48 48 0 00-48 48v352a48 48 0 0048 48h352a48 48 0 0048-48V336a16 16 0 00-16-16zM488 0H360c-21.37 0-32.05 25.91-17 41l35.73 35.73L135 320.37a24 24 0 000 34L157.67 377a24 24 0 0034 0l243.61-243.68L471 169c15 15 41 4.5 41-17V24a24 24 0 00-24-24z"
1111
+ }));
1112
+ });
1113
+
1114
+ var DisabledContext = createContext();
1115
+ var StateContext = createContext();
1116
+ var UpdateContext = createContext();
1117
+ function LinkTooltipProvider(_ref) {
1118
+ var disabled = _ref.disabled,
1119
+ children = _ref.children;
1120
+
1121
+ var _useState = useState(),
1122
+ _useState2 = _slicedToArray(_useState, 2),
1123
+ state = _useState2[0],
1124
+ setState = _useState2[1];
1125
+
1126
+ var outerRef = useRef();
1127
+ var update = useMemo(function () {
1128
+ var timeout;
1129
+ return {
1130
+ activate: function activate(href, linkRef) {
1131
+ clearTimeout(timeout);
1132
+ timeout = null;
1133
+ var outerRect = outerRef.current.getBoundingClientRect();
1134
+ var linkRect = linkRef.current.getBoundingClientRect();
1135
+ setState({
1136
+ href: href,
1137
+ top: linkRect.bottom - outerRect.top + 10,
1138
+ left: linkRect.left - outerRect.left
1139
+ });
1140
+ },
1141
+ keep: function keep() {
1142
+ clearTimeout(timeout);
1143
+ timeout = null;
1144
+ },
1145
+ deactivate: function deactivate() {
1146
+ if (!timeout) {
1147
+ timeout = setTimeout(function () {
1148
+ timeout = null;
1149
+ setState(null);
1150
+ }, 200);
1151
+ }
1152
+ }
1153
+ };
1154
+ }, []);
1155
+ return (
1156
+ /*#__PURE__*/
1157
+ React.createElement(DisabledContext.Provider, {
1158
+ value: disabled
1159
+ },
1160
+ /*#__PURE__*/
1161
+ React.createElement(StateContext.Provider, {
1162
+ value: state
1163
+ },
1164
+ /*#__PURE__*/
1165
+ React.createElement(UpdateContext.Provider, {
1166
+ value: update
1167
+ },
1168
+ /*#__PURE__*/
1169
+ React.createElement("div", {
1170
+ ref: outerRef
1171
+ },
1172
+ /*#__PURE__*/
1173
+ React.createElement(LinkTooltip, null), children))))
1174
+ );
1175
+ }
1176
+ function LinkPreview(_ref2) {
1177
+ var href = _ref2.href,
1178
+ children = _ref2.children;
1179
+
1180
+ var _useContext = useContext(UpdateContext),
1181
+ activate = _useContext.activate,
1182
+ deactivate = _useContext.deactivate;
1183
+
1184
+ var ref = useRef();
1185
+ return (
1186
+ /*#__PURE__*/
1187
+ React.createElement("span", {
1188
+ ref: ref,
1189
+ onMouseEnter: function onMouseEnter() {
1190
+ return activate(href, ref);
1191
+ },
1192
+ onMouseLeave: deactivate,
1193
+ onMouseDown: deactivate
1194
+ }, children)
1195
+ );
1196
+ }
1197
+ function LinkTooltip() {
1198
+ var disabled = useContext(DisabledContext);
1199
+ var state = useContext(StateContext);
1200
+
1201
+ var _useContext2 = useContext(UpdateContext),
1202
+ keep = _useContext2.keep,
1203
+ deactivate = _useContext2.deactivate;
1204
+
1205
+ var editor = useSlate();
1206
+
1207
+ if (disabled || !state || editor.selection && !Range.isCollapsed(editor.selection)) {
1208
+ return null;
1209
+ }
1210
+
1211
+ return (
1212
+ /*#__PURE__*/
1213
+ React.createElement("div", {
1214
+ className: classNames(styles$7.linkTooltip, styles$7.hoveringToolbar),
1215
+ onMouseEnter: keep,
1216
+ onMouseLeave: deactivate,
1217
+ style: {
1218
+ top: state.top,
1219
+ left: state.left,
1220
+ opacity: 1
1221
+ }
1222
+ },
1223
+ /*#__PURE__*/
1224
+ React.createElement("a", {
1225
+ href: state.href,
1226
+ target: "_blank",
1227
+ rel: "noopener noreferrer"
1228
+ }, state.href,
1229
+ /*#__PURE__*/
1230
+ React.createElement(ExternalLinkIcon, {
1231
+ width: 10,
1232
+ height: 10
1233
+ })))
1234
+ );
1235
+ }
1236
+
1237
+ function withLinks(editor) {
1238
+ var isInline = editor.isInline;
1239
+
1240
+ editor.isInline = function (element) {
1241
+ return element.type === 'link' ? true : isInline(element);
1242
+ };
1243
+
1244
+ return editor;
1245
+ }
1246
+ function renderElementWithLinkPreview(options) {
1247
+ if (options.element.type === 'link') {
1248
+ return (
1249
+ /*#__PURE__*/
1250
+ React.createElement(LinkPreview, {
1251
+ href: options.element.href
1252
+ }, renderElement(options))
1253
+ );
1254
+ } else {
1255
+ return renderElement(options);
1256
+ }
1257
+ }
1258
+ function renderLeafWithLinkSelection(options) {
1259
+ if (options.leaf.linkSelection) {
1260
+ return (
1261
+ /*#__PURE__*/
1262
+ React.createElement("span", Object.assign({}, options.attributes, {
1263
+ style: {
1264
+ backgroundColor: '#aaa'
1265
+ }
1266
+ }), renderLeaf(options))
1267
+ );
1268
+ }
1269
+
1270
+ return renderLeaf(options);
1271
+ }
1272
+ function decorateLinkSelection(_ref, linkSelection) {
1273
+ var _ref2 = _slicedToArray(_ref, 2),
1274
+ node = _ref2[0],
1275
+ path = _ref2[1];
1276
+
1277
+ if (linkSelection && Text.isText(node)) {
1278
+ var nodeRange = {
1279
+ anchor: {
1280
+ path: path,
1281
+ offset: 0
1282
+ },
1283
+ focus: {
1284
+ path: path,
1285
+ offset: node.text.length
1286
+ }
1287
+ };
1288
+ var intersection = Range.intersection(nodeRange, linkSelection);
1289
+
1290
+ if (intersection) {
1291
+ return [_objectSpread2(_objectSpread2({}, intersection), {}, {
1292
+ linkSelection: true
1293
+ })];
1294
+ }
1295
+ }
1296
+
1297
+ return [];
1298
+ }
1299
+
1300
+ // element is currently being dragged over the element. `react-dnd`
1301
+ // causes "Update on unmounted component warning" when dropping an
1302
+ // element removes a drop target [1]. As a workaround, couple
1303
+ // rendering of drop targets to asynchronously updated state. That way
1304
+ // the drop target is only removed after element has been dropped.
1305
+ //
1306
+ // [1] https://github.com/react-dnd/react-dnd/issues/1573
1307
+
1308
+ function useDropTargetsActive() {
1309
+ var _useState = useState(false),
1310
+ _useState2 = _slicedToArray(_useState, 2),
1311
+ dropTargetsActive = _useState2[0],
1312
+ setDropTargetsActive = _useState2[1];
1313
+
1314
+ var _useDrop = useDrop({
1315
+ accept: 'contentElement',
1316
+ collect: function collect(monitor) {
1317
+ return {
1318
+ canDrop: monitor.canDrop() && monitor.isOver()
1319
+ };
1320
+ }
1321
+ }),
1322
+ _useDrop2 = _slicedToArray(_useDrop, 2),
1323
+ canDrop = _useDrop2[0].canDrop,
1324
+ drop = _useDrop2[1];
1325
+
1326
+ useEffect(function () {
1327
+ if (canDrop) {
1328
+ setDropTargetsActive(true);
1329
+ } else {
1330
+ var timeout = setTimeout(function () {
1331
+ setDropTargetsActive(false);
1332
+ }, 10);
1333
+ return function () {
1334
+ clearTimeout(timeout);
1335
+ };
1336
+ }
1337
+ }, [canDrop]);
1338
+ return [dropTargetsActive, drop];
1339
+ }
1340
+
1341
+ function _extends$4() {
1342
+ _extends$4 = Object.assign || function (target) {
1343
+ for (var i = 1; i < arguments.length; i++) {
1344
+ var source = arguments[i];
1345
+
1346
+ for (var key in source) {
1347
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1348
+ target[key] = source[key];
1349
+ }
1350
+ }
1351
+ }
1352
+
1353
+ return target;
1354
+ };
1355
+
1356
+ return _extends$4.apply(this, arguments);
1357
+ }
1358
+ var CancelIcon = (function (_ref) {
1359
+ var _ref$styles = _ref.styles,
1360
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1361
+ props = _objectWithoutProperties(_ref, ["styles"]);
1362
+
1363
+ return React.createElement("svg", _extends$4({
1364
+ "aria-hidden": "true",
1365
+ "data-prefix": "fas",
1366
+ "data-icon": "times",
1367
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-times"] || "fa-times") + " " + (styles["fa-w-11"] || "fa-w-11"),
1368
+ xmlns: "http://www.w3.org/2000/svg",
1369
+ viewBox: "0 0 352 512"
1370
+ }, props), React.createElement("path", {
1371
+ fill: "currentColor",
1372
+ d: "M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
1373
+ }));
1374
+ });
1375
+
1376
+ function LinkInput(_ref) {
1377
+ var onSubmit = _ref.onSubmit,
1378
+ onCancel = _ref.onCancel;
1379
+
1380
+ var _useI18n = useI18n({
1381
+ locale: 'ui'
1382
+ }),
1383
+ t = _useI18n.t;
1384
+
1385
+ var _useState = useState(''),
1386
+ _useState2 = _slicedToArray(_useState, 2),
1387
+ href = _useState2[0],
1388
+ setHref = _useState2[1];
1389
+
1390
+ var ref = useRef(); // With useEffect the deselect in HoveringToolbar/handleButtonClick breaks focusing.
1391
+
1392
+ useLayoutEffect(function () {
1393
+ ref.current.focus();
1394
+ }, []);
1395
+
1396
+ function handleKey(event) {
1397
+ if (event.key === 'Enter') {
1398
+ event.preventDefault();
1399
+ ref.current.blur();
1400
+ } else if (event.key === 'Escape') {
1401
+ event.preventDefault();
1402
+ onCancel();
1403
+ }
1404
+ }
1405
+
1406
+ function submit() {
1407
+ if (href) {
1408
+ onSubmit(href);
1409
+ } else {
1410
+ onCancel();
1411
+ }
1412
+ }
1413
+
1414
+ return (
1415
+ /*#__PURE__*/
1416
+ React.createElement("div", {
1417
+ className: styles$7.linkTooltip
1418
+ },
1419
+ /*#__PURE__*/
1420
+ React.createElement("input", {
1421
+ ref: ref,
1422
+ type: "text",
1423
+ value: href,
1424
+ placeholder: t('pageflow_scrolled.inline_editing.url_placeholder'),
1425
+ onBlur: submit,
1426
+ onChange: function onChange(e) {
1427
+ return setHref(e.target.value);
1428
+ },
1429
+ onKeyDown: handleKey
1430
+ }),
1431
+ /*#__PURE__*/
1432
+ React.createElement("button", {
1433
+ onMouseDown: function onMouseDown(e) {
1434
+ return e.preventDefault();
1435
+ },
1436
+ onClick: onCancel,
1437
+ title: t('pageflow_scrolled.inline_editing.cancel')
1438
+ },
1439
+ /*#__PURE__*/
1440
+ React.createElement(CancelIcon, {
1441
+ width: 10,
1442
+ height: 10
1443
+ })))
1444
+ );
1445
+ }
1446
+
1447
+ function _extends$5() {
1448
+ _extends$5 = Object.assign || function (target) {
1449
+ for (var i = 1; i < arguments.length; i++) {
1450
+ var source = arguments[i];
1451
+
1452
+ for (var key in source) {
1453
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1454
+ target[key] = source[key];
1455
+ }
1456
+ }
1457
+ }
1458
+
1459
+ return target;
1460
+ };
1461
+
1462
+ return _extends$5.apply(this, arguments);
1463
+ }
1464
+ var BoldIcon = (function (_ref) {
1465
+ var _ref$styles = _ref.styles,
1466
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1467
+ props = _objectWithoutProperties(_ref, ["styles"]);
1468
+
1469
+ return React.createElement("svg", _extends$5({
1470
+ "aria-hidden": "true",
1471
+ "data-prefix": "fas",
1472
+ "data-icon": "bold",
1473
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-bold"] || "fa-bold") + " " + (styles["fa-w-12"] || "fa-w-12"),
1474
+ xmlns: "http://www.w3.org/2000/svg",
1475
+ viewBox: "0 0 384 512"
1476
+ }, props), React.createElement("path", {
1477
+ fill: "currentColor",
1478
+ d: "M333.49 238a122 122 0 0027-65.21C367.87 96.49 308 32 233.42 32H34a16 16 0 00-16 16v48a16 16 0 0016 16h31.87v288H34a16 16 0 00-16 16v48a16 16 0 0016 16h209.32c70.8 0 134.14-51.75 141-122.4 4.74-48.45-16.39-92.06-50.83-119.6zM145.66 112h87.76a48 48 0 010 96h-87.76zm87.76 288h-87.76V288h87.76a56 56 0 010 112z"
1479
+ }));
1480
+ });
1481
+
1482
+ function _extends$6() {
1483
+ _extends$6 = Object.assign || function (target) {
1484
+ for (var i = 1; i < arguments.length; i++) {
1485
+ var source = arguments[i];
1486
+
1487
+ for (var key in source) {
1488
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1489
+ target[key] = source[key];
1490
+ }
1491
+ }
1492
+ }
1493
+
1494
+ return target;
1495
+ };
1496
+
1497
+ return _extends$6.apply(this, arguments);
1498
+ }
1499
+ var UnderlineIcon = (function (_ref) {
1500
+ var _ref$styles = _ref.styles,
1501
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1502
+ props = _objectWithoutProperties(_ref, ["styles"]);
1503
+
1504
+ return React.createElement("svg", _extends$6({
1505
+ "aria-hidden": "true",
1506
+ "data-prefix": "fas",
1507
+ "data-icon": "underline",
1508
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-underline"] || "fa-underline") + " " + (styles["fa-w-14"] || "fa-w-14"),
1509
+ xmlns: "http://www.w3.org/2000/svg",
1510
+ viewBox: "0 0 448 512"
1511
+ }, props), React.createElement("path", {
1512
+ fill: "currentColor",
1513
+ d: "M32 64h32v160c0 88.22 71.78 160 160 160s160-71.78 160-160V64h32a16 16 0 0016-16V16a16 16 0 00-16-16H272a16 16 0 00-16 16v32a16 16 0 0016 16h32v160a80 80 0 01-160 0V64h32a16 16 0 0016-16V16a16 16 0 00-16-16H32a16 16 0 00-16 16v32a16 16 0 0016 16zm400 384H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16z"
1514
+ }));
1515
+ });
1516
+
1517
+ function _extends$7() {
1518
+ _extends$7 = Object.assign || function (target) {
1519
+ for (var i = 1; i < arguments.length; i++) {
1520
+ var source = arguments[i];
1521
+
1522
+ for (var key in source) {
1523
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1524
+ target[key] = source[key];
1525
+ }
1526
+ }
1527
+ }
1528
+
1529
+ return target;
1530
+ };
1531
+
1532
+ return _extends$7.apply(this, arguments);
1533
+ }
1534
+ var ItalicIcon = (function (_ref) {
1535
+ var _ref$styles = _ref.styles,
1536
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1537
+ props = _objectWithoutProperties(_ref, ["styles"]);
1538
+
1539
+ return React.createElement("svg", _extends$7({
1540
+ "aria-hidden": "true",
1541
+ "data-prefix": "fas",
1542
+ "data-icon": "italic",
1543
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-italic"] || "fa-italic") + " " + (styles["fa-w-10"] || "fa-w-10"),
1544
+ xmlns: "http://www.w3.org/2000/svg",
1545
+ viewBox: "0 0 320 512"
1546
+ }, props), React.createElement("path", {
1547
+ fill: "currentColor",
1548
+ d: "M320 48v32a16 16 0 01-16 16h-62.76l-80 320H208a16 16 0 0116 16v32a16 16 0 01-16 16H16a16 16 0 01-16-16v-32a16 16 0 0116-16h62.76l80-320H112a16 16 0 01-16-16V48a16 16 0 0116-16h192a16 16 0 0116 16z"
1549
+ }));
1550
+ });
1551
+
1552
+ function _extends$8() {
1553
+ _extends$8 = Object.assign || function (target) {
1554
+ for (var i = 1; i < arguments.length; i++) {
1555
+ var source = arguments[i];
1556
+
1557
+ for (var key in source) {
1558
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1559
+ target[key] = source[key];
1560
+ }
1561
+ }
1562
+ }
1563
+
1564
+ return target;
1565
+ };
1566
+
1567
+ return _extends$8.apply(this, arguments);
1568
+ }
1569
+ var StrikethroughIcon = (function (_ref) {
1570
+ var _ref$styles = _ref.styles,
1571
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1572
+ props = _objectWithoutProperties(_ref, ["styles"]);
1573
+
1574
+ return React.createElement("svg", _extends$8({
1575
+ "aria-hidden": "true",
1576
+ "data-prefix": "fas",
1577
+ "data-icon": "strikethrough",
1578
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-strikethrough"] || "fa-strikethrough") + " " + (styles["fa-w-16"] || "fa-w-16"),
1579
+ xmlns: "http://www.w3.org/2000/svg",
1580
+ viewBox: "0 0 512 512"
1581
+ }, props), React.createElement("path", {
1582
+ fill: "currentColor",
1583
+ d: "M496 224H293.9l-87.17-26.83A43.55 43.55 0 01219.55 112h66.79A49.89 49.89 0 01331 139.58a16 16 0 0021.46 7.15l42.94-21.47a16 16 0 007.16-21.46l-.53-1A128 128 0 00287.51 32h-68a123.68 123.68 0 00-123 135.64c2 20.89 10.1 39.83 21.78 56.36H16a16 16 0 00-16 16v32a16 16 0 0016 16h480a16 16 0 0016-16v-32a16 16 0 00-16-16zm-180.24 96A43 43 0 01336 356.45 43.59 43.59 0 01292.45 400h-66.79A49.89 49.89 0 01181 372.42a16 16 0 00-21.46-7.15l-42.94 21.47a16 16 0 00-7.16 21.46l.53 1A128 128 0 00224.49 480h68a123.68 123.68 0 00123-135.64 114.25 114.25 0 00-5.34-24.36z"
1584
+ }));
1585
+ });
1586
+
1587
+ function _extends$9() {
1588
+ _extends$9 = Object.assign || function (target) {
1589
+ for (var i = 1; i < arguments.length; i++) {
1590
+ var source = arguments[i];
1591
+
1592
+ for (var key in source) {
1593
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1594
+ target[key] = source[key];
1595
+ }
1596
+ }
1597
+ }
1598
+
1599
+ return target;
1600
+ };
1601
+
1602
+ return _extends$9.apply(this, arguments);
1603
+ }
1604
+ var LinkIcon = (function (_ref) {
1605
+ var _ref$styles = _ref.styles,
1606
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1607
+ props = _objectWithoutProperties(_ref, ["styles"]);
1608
+
1609
+ return React.createElement("svg", _extends$9({
1610
+ "aria-hidden": "true",
1611
+ "data-prefix": "fas",
1612
+ "data-icon": "link",
1613
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-link"] || "fa-link") + " " + (styles["fa-w-16"] || "fa-w-16"),
1614
+ xmlns: "http://www.w3.org/2000/svg",
1615
+ viewBox: "0 0 512 512"
1616
+ }, props), React.createElement("path", {
1617
+ fill: "currentColor",
1618
+ d: "M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 01-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0120.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0020.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 00-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"
1619
+ }));
1620
+ });
1621
+
1622
+ function HoveringToolbar(_ref) {
1623
+ var linkSelection = _ref.linkSelection,
1624
+ setLinkSelection = _ref.setLinkSelection;
1625
+ var ref = useRef();
1626
+ var outerRef = useRef();
1627
+ var editor = useSlate();
1628
+
1629
+ var _useI18n = useI18n({
1630
+ locale: 'ui'
1631
+ }),
1632
+ t = _useI18n.t;
1633
+
1634
+ useEffect(function () {
1635
+ var el = ref.current;
1636
+ var selection = editor.selection;
1637
+
1638
+ if (!el || !outerRef.current || linkSelection) {
1639
+ return;
1640
+ }
1641
+
1642
+ if (!selection || !ReactEditor.isFocused(editor) || Range.isCollapsed(selection) || Editor.string(editor, selection) === '') {
1643
+ el.removeAttribute('style');
1644
+ return;
1645
+ }
1646
+
1647
+ var domRange = ReactEditor.toDOMRange(editor, editor.selection);
1648
+ var rect = domRange.getBoundingClientRect();
1649
+ var outerRect = outerRef.current.getBoundingClientRect();
1650
+ el.style.opacity = 1;
1651
+ el.style.top = "".concat(rect.bottom - outerRect.top + 10, "px");
1652
+ el.style.left = "".concat(rect.left - outerRect.left, "px");
1653
+ });
1654
+ return (
1655
+ /*#__PURE__*/
1656
+ React.createElement("div", {
1657
+ ref: outerRef
1658
+ },
1659
+ /*#__PURE__*/
1660
+ React.createElement("div", {
1661
+ ref: ref,
1662
+ className: styles$7.hoveringToolbar
1663
+ }, !linkSelection && renderToolbar$1(editor, setLinkSelection, t), linkSelection && renderLinkInput(editor, linkSelection, setLinkSelection)))
1664
+ );
1665
+ }
1666
+
1667
+ function renderToolbar$1(editor, setLinkSelection, t) {
1668
+ var buttons = [{
1669
+ name: 'bold',
1670
+ text: t('pageflow_scrolled.inline_editing.formats.bold'),
1671
+ icon: BoldIcon
1672
+ }, {
1673
+ name: 'italic',
1674
+ text: t('pageflow_scrolled.inline_editing.formats.italic'),
1675
+ icon: ItalicIcon
1676
+ }, {
1677
+ name: 'underline',
1678
+ text: t('pageflow_scrolled.inline_editing.formats.underline'),
1679
+ icon: UnderlineIcon
1680
+ }, {
1681
+ name: 'strikethrough',
1682
+ text: t('pageflow_scrolled.inline_editing.formats.strikethrough'),
1683
+ icon: StrikethroughIcon
1684
+ }, {
1685
+ name: 'link',
1686
+ text: isButtonActive(editor, 'link') ? t('pageflow_scrolled.inline_editing.remove_link') : t('pageflow_scrolled.inline_editing.insert_link'),
1687
+ icon: LinkIcon
1688
+ }].map(function (button) {
1689
+ return _objectSpread2(_objectSpread2({}, button), {}, {
1690
+ active: isButtonActive(editor, button.name)
1691
+ });
1692
+ });
1693
+ return (
1694
+ /*#__PURE__*/
1695
+ React.createElement(Toolbar, {
1696
+ buttons: buttons,
1697
+ onButtonClick: function onButtonClick(name) {
1698
+ return handleButtonClick(editor, name, setLinkSelection);
1699
+ }
1700
+ })
1701
+ );
1702
+ }
1703
+
1704
+ function handleButtonClick(editor, format, setLinkSelection) {
1705
+ if (format === 'link') {
1706
+ if (isLinkActive(editor)) {
1707
+ unwrapLink(editor);
1708
+ } else {
1709
+ var selection = editor.selection; // Required to prevent slate from focusing the editor in Firefox
1710
+ // https://github.com/ianstormtaylor/slate/blob/44675c2080e3f6a2523170430bb92e426b7647e2/packages/slate-react/src/components/editable.tsx#L189
1711
+
1712
+ Transforms.deselect(editor);
1713
+ setLinkSelection(selection);
1714
+ }
1715
+ } else {
1716
+ toggleMark(editor, format);
1717
+ }
1718
+ }
1719
+
1720
+ function isButtonActive(editor, format) {
1721
+ if (format === 'link') {
1722
+ return isLinkActive(editor);
1723
+ } else {
1724
+ return isMarkActive(editor, format);
1725
+ }
1726
+ }
1727
+
1728
+ function renderLinkInput(editor, linkSelection, setLinkSelection) {
1729
+ function handleSubmit(href) {
1730
+ Transforms.select(editor, linkSelection);
1731
+ ReactEditor.focus(editor);
1732
+ wrapLink(editor, href);
1733
+ setLinkSelection(null);
1734
+ }
1735
+
1736
+ function handleCancel() {
1737
+ setLinkSelection(null);
1738
+ Transforms.select(editor, linkSelection);
1739
+ ReactEditor.focus(editor);
1740
+ }
1741
+
1742
+ return (
1743
+ /*#__PURE__*/
1744
+ React.createElement(LinkInput, {
1745
+ onSubmit: handleSubmit,
1746
+ onCancel: handleCancel
1747
+ })
1748
+ );
1749
+ }
1750
+
1751
+ function unwrapLink(editor) {
1752
+ Transforms.unwrapNodes(editor, {
1753
+ match: function match(n) {
1754
+ return n.type === 'link';
1755
+ }
1756
+ });
1757
+ }
1758
+
1759
+ function wrapLink(editor, href) {
1760
+ var link = {
1761
+ type: 'link',
1762
+ href: href,
1763
+ children: []
1764
+ };
1765
+ Transforms.wrapNodes(editor, link, {
1766
+ split: true
1767
+ });
1768
+ Transforms.collapse(editor, {
1769
+ edge: 'end'
1770
+ });
1771
+ }
1772
+
1773
+ function isLinkActive(editor) {
1774
+ var _Editor$nodes = Editor.nodes(editor, {
1775
+ match: function match(n) {
1776
+ return n.type === 'link';
1777
+ }
1778
+ }),
1779
+ _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
1780
+ link = _Editor$nodes2[0];
1781
+
1782
+ return !!link;
1783
+ }
1784
+
1785
+ function toggleMark(editor, format) {
1786
+ var isActive = isMarkActive(editor, format);
1787
+
1788
+ if (isActive) {
1789
+ Editor.removeMark(editor, format);
1790
+ } else {
1791
+ Editor.addMark(editor, format, true);
1792
+ }
1793
+ }
1794
+
1795
+ function isMarkActive(editor, format) {
1796
+ var marks = Editor.marks(editor);
1797
+ return marks ? marks[format] === true : false;
1798
+ }
1799
+
1800
+ function _extends$a() {
1801
+ _extends$a = Object.assign || function (target) {
1802
+ for (var i = 1; i < arguments.length; i++) {
1803
+ var source = arguments[i];
1804
+
1805
+ for (var key in source) {
1806
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1807
+ target[key] = source[key];
1808
+ }
1809
+ }
1810
+ }
1811
+
1812
+ return target;
1813
+ };
1814
+
1815
+ return _extends$a.apply(this, arguments);
1816
+ }
1817
+ var TextIcon = (function (_ref) {
1818
+ var _ref$styles = _ref.styles,
1819
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1820
+ props = _objectWithoutProperties(_ref, ["styles"]);
1821
+
1822
+ return React.createElement("svg", _extends$a({
1823
+ "aria-hidden": "true",
1824
+ "data-prefix": "fas",
1825
+ "data-icon": "align-justify",
1826
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-align-justify"] || "fa-align-justify") + " " + (styles["fa-w-14"] || "fa-w-14"),
1827
+ xmlns: "http://www.w3.org/2000/svg",
1828
+ viewBox: "0 0 448 512"
1829
+ }, props), React.createElement("path", {
1830
+ fill: "currentColor",
1831
+ d: "M432 416H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0-128H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0-128H16a16 16 0 00-16 16v32a16 16 0 0016 16h416a16 16 0 0016-16v-32a16 16 0 00-16-16zm0-128H16A16 16 0 000 48v32a16 16 0 0016 16h416a16 16 0 0016-16V48a16 16 0 00-16-16z"
1832
+ }));
1833
+ });
1834
+
1835
+ function _extends$b() {
1836
+ _extends$b = Object.assign || function (target) {
1837
+ for (var i = 1; i < arguments.length; i++) {
1838
+ var source = arguments[i];
1839
+
1840
+ for (var key in source) {
1841
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1842
+ target[key] = source[key];
1843
+ }
1844
+ }
1845
+ }
1846
+
1847
+ return target;
1848
+ };
1849
+
1850
+ return _extends$b.apply(this, arguments);
1851
+ }
1852
+ var HeadingIcon = (function (_ref) {
1853
+ var _ref$styles = _ref.styles,
1854
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1855
+ props = _objectWithoutProperties(_ref, ["styles"]);
1856
+
1857
+ return React.createElement("svg", _extends$b({
1858
+ "aria-hidden": "true",
1859
+ "data-prefix": "fas",
1860
+ "data-icon": "heading",
1861
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-heading"] || "fa-heading") + " " + (styles["fa-w-16"] || "fa-w-16"),
1862
+ xmlns: "http://www.w3.org/2000/svg",
1863
+ viewBox: "0 0 512 512"
1864
+ }, props), React.createElement("path", {
1865
+ fill: "currentColor",
1866
+ d: "M448 96v320h32a16 16 0 0116 16v32a16 16 0 01-16 16H320a16 16 0 01-16-16v-32a16 16 0 0116-16h32V288H160v128h32a16 16 0 0116 16v32a16 16 0 01-16 16H32a16 16 0 01-16-16v-32a16 16 0 0116-16h32V96H32a16 16 0 01-16-16V48a16 16 0 0116-16h160a16 16 0 0116 16v32a16 16 0 01-16 16h-32v128h192V96h-32a16 16 0 01-16-16V48a16 16 0 0116-16h160a16 16 0 0116 16v32a16 16 0 01-16 16z"
1867
+ }));
1868
+ });
1869
+
1870
+ function _extends$c() {
1871
+ _extends$c = Object.assign || function (target) {
1872
+ for (var i = 1; i < arguments.length; i++) {
1873
+ var source = arguments[i];
1874
+
1875
+ for (var key in source) {
1876
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1877
+ target[key] = source[key];
1878
+ }
1879
+ }
1880
+ }
1881
+
1882
+ return target;
1883
+ };
1884
+
1885
+ return _extends$c.apply(this, arguments);
1886
+ }
1887
+ var OlIcon = (function (_ref) {
1888
+ var _ref$styles = _ref.styles,
1889
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1890
+ props = _objectWithoutProperties(_ref, ["styles"]);
1891
+
1892
+ return React.createElement("svg", _extends$c({
1893
+ "aria-hidden": "true",
1894
+ "data-prefix": "fas",
1895
+ "data-icon": "list-ol",
1896
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-list-ol"] || "fa-list-ol") + " " + (styles["fa-w-16"] || "fa-w-16"),
1897
+ xmlns: "http://www.w3.org/2000/svg",
1898
+ viewBox: "0 0 512 512"
1899
+ }, props), React.createElement("path", {
1900
+ fill: "currentColor",
1901
+ d: "M61.77 401l17.5-20.15a19.92 19.92 0 005.07-14.19v-3.31C84.34 356 80.5 352 73 352H16a8 8 0 00-8 8v16a8 8 0 008 8h22.83a157.41 157.41 0 00-11 12.31l-5.61 7c-4 5.07-5.25 10.13-2.8 14.88l1.05 1.93c3 5.76 6.29 7.88 12.25 7.88h4.73c10.33 0 15.94 2.44 15.94 9.09 0 4.72-4.2 8.22-14.36 8.22a41.54 41.54 0 01-15.47-3.12c-6.49-3.88-11.74-3.5-15.6 3.12l-5.59 9.31c-3.72 6.13-3.19 11.72 2.63 15.94 7.71 4.69 20.38 9.44 37 9.44 34.16 0 48.5-22.75 48.5-44.12-.03-14.38-9.12-29.76-28.73-34.88zM496 224H176a16 16 0 00-16 16v32a16 16 0 0016 16h320a16 16 0 0016-16v-32a16 16 0 00-16-16zm0-160H176a16 16 0 00-16 16v32a16 16 0 0016 16h320a16 16 0 0016-16V80a16 16 0 00-16-16zm0 320H176a16 16 0 00-16 16v32a16 16 0 0016 16h320a16 16 0 0016-16v-32a16 16 0 00-16-16zM16 160h64a8 8 0 008-8v-16a8 8 0 00-8-8H64V40a8 8 0 00-8-8H32a8 8 0 00-7.14 4.42l-8 16A8 8 0 0024 64h8v64H16a8 8 0 00-8 8v16a8 8 0 008 8zm-3.91 160H80a8 8 0 008-8v-16a8 8 0 00-8-8H41.32c3.29-10.29 48.34-18.68 48.34-56.44 0-29.06-25-39.56-44.47-39.56-21.36 0-33.8 10-40.46 18.75-4.37 5.59-3 10.84 2.8 15.37l8.58 6.88c5.61 4.56 11 2.47 16.12-2.44a13.44 13.44 0 019.46-3.84c3.33 0 9.28 1.56 9.28 8.75C51 248.19 0 257.31 0 304.59v4C0 316 5.08 320 12.09 320z"
1902
+ }));
1903
+ });
1904
+
1905
+ function _extends$d() {
1906
+ _extends$d = Object.assign || function (target) {
1907
+ for (var i = 1; i < arguments.length; i++) {
1908
+ var source = arguments[i];
1909
+
1910
+ for (var key in source) {
1911
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1912
+ target[key] = source[key];
1913
+ }
1914
+ }
1915
+ }
1916
+
1917
+ return target;
1918
+ };
1919
+
1920
+ return _extends$d.apply(this, arguments);
1921
+ }
1922
+ var UlIcon = (function (_ref) {
1923
+ var _ref$styles = _ref.styles,
1924
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1925
+ props = _objectWithoutProperties(_ref, ["styles"]);
1926
+
1927
+ return React.createElement("svg", _extends$d({
1928
+ "aria-hidden": "true",
1929
+ "data-prefix": "fas",
1930
+ "data-icon": "list-ul",
1931
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-list-ul"] || "fa-list-ul") + " " + (styles["fa-w-16"] || "fa-w-16"),
1932
+ xmlns: "http://www.w3.org/2000/svg",
1933
+ viewBox: "0 0 512 512"
1934
+ }, props), React.createElement("path", {
1935
+ fill: "currentColor",
1936
+ d: "M48 48a48 48 0 1048 48 48 48 0 00-48-48zm0 160a48 48 0 1048 48 48 48 0 00-48-48zm0 160a48 48 0 1048 48 48 48 0 00-48-48zm448 16H176a16 16 0 00-16 16v32a16 16 0 0016 16h320a16 16 0 0016-16v-32a16 16 0 00-16-16zm0-320H176a16 16 0 00-16 16v32a16 16 0 0016 16h320a16 16 0 0016-16V80a16 16 0 00-16-16zm0 160H176a16 16 0 00-16 16v32a16 16 0 0016 16h320a16 16 0 0016-16v-32a16 16 0 00-16-16z"
1937
+ }));
1938
+ });
1939
+
1940
+ function _extends$e() {
1941
+ _extends$e = Object.assign || function (target) {
1942
+ for (var i = 1; i < arguments.length; i++) {
1943
+ var source = arguments[i];
1944
+
1945
+ for (var key in source) {
1946
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1947
+ target[key] = source[key];
1948
+ }
1949
+ }
1950
+ }
1951
+
1952
+ return target;
1953
+ };
1954
+
1955
+ return _extends$e.apply(this, arguments);
1956
+ }
1957
+ var QuoteIcon = (function (_ref) {
1958
+ var _ref$styles = _ref.styles,
1959
+ styles = _ref$styles === void 0 ? {} : _ref$styles,
1960
+ props = _objectWithoutProperties(_ref, ["styles"]);
1961
+
1962
+ return React.createElement("svg", _extends$e({
1963
+ "aria-hidden": "true",
1964
+ "data-prefix": "fas",
1965
+ "data-icon": "quote-right",
1966
+ className: (styles["svg-inline--fa"] || "svg-inline--fa") + " " + (styles["fa-quote-right"] || "fa-quote-right") + " " + (styles["fa-w-16"] || "fa-w-16"),
1967
+ xmlns: "http://www.w3.org/2000/svg",
1968
+ viewBox: "0 0 512 512"
1969
+ }, props), React.createElement("path", {
1970
+ fill: "currentColor",
1971
+ d: "M464 32H336c-26.5 0-48 21.5-48 48v128c0 26.5 21.5 48 48 48h80v64c0 35.3-28.7 64-64 64h-8c-13.3 0-24 10.7-24 24v48c0 13.3 10.7 24 24 24h8c88.4 0 160-71.6 160-160V80c0-26.5-21.5-48-48-48zm-288 0H48C21.5 32 0 53.5 0 80v128c0 26.5 21.5 48 48 48h80v64c0 35.3-28.7 64-64 64h-8c-13.3 0-24 10.7-24 24v48c0 13.3 10.7 24 24 24h8c88.4 0 160-71.6 160-160V80c0-26.5-21.5-48-48-48z"
1972
+ }));
1973
+ });
1974
+
1975
+ function Selection(props) {
1976
+ var editor = useSlate();
1977
+
1978
+ var _useI18n = useI18n({
1979
+ locale: 'ui'
1980
+ }),
1981
+ t = _useI18n.t;
1982
+
1983
+ var ref = useRef();
1984
+ var outerRef = useRef();
1985
+ var innerRef = useRef();
1986
+ var boundsRef = useRef();
1987
+
1988
+ var _useContentElementEdi = useContentElementEditorState(),
1989
+ setTransientState = _useContentElementEdi.setTransientState,
1990
+ select = _useContentElementEdi.select,
1991
+ isContentElementSelected = _useContentElementEdi.isSelected;
1992
+
1993
+ useEffect(function () {
1994
+ var selection = editor.selection;
1995
+
1996
+ if (!ref.current) {
1997
+ return;
1998
+ }
1999
+
2000
+ if (!selection) {
2001
+ if (boundsRef.current) {
2002
+ hideRect(ref.current);
2003
+ boundsRef.current = null;
2004
+ }
2005
+
2006
+ return;
2007
+ }
2008
+
2009
+ if (!isContentElementSelected && boundsRef.current) {
2010
+ hideRect(ref.current);
2011
+ return;
2012
+ }
2013
+
2014
+ if (!isContentElementSelected && !boundsRef.current) {
2015
+ select();
2016
+ }
2017
+
2018
+ var _computeBounds = computeBounds(editor),
2019
+ _computeBounds2 = _slicedToArray(_computeBounds, 2),
2020
+ start = _computeBounds2[0],
2021
+ end = _computeBounds2[1];
2022
+
2023
+ setTransientState({
2024
+ editableTextIsSingleBlock: editor.children.length <= 1
2025
+ });
2026
+ boundsRef.current = {
2027
+ start: start,
2028
+ end: end
2029
+ };
2030
+ updateRect(editor, start, end, outerRef.current, ref.current, innerRef.current);
2031
+ });
2032
+ return (
2033
+ /*#__PURE__*/
2034
+ React.createElement("div", {
2035
+ ref: outerRef
2036
+ },
2037
+ /*#__PURE__*/
2038
+ React.createElement("div", {
2039
+ ref: ref,
2040
+ className: styles$7.selection
2041
+ },
2042
+ /*#__PURE__*/
2043
+ React.createElement(SelectionRect, {
2044
+ selected: true,
2045
+ scrollPoint: isContentElementSelected,
2046
+ insertButtonTitles: t('pageflow_scrolled.inline_editing.insert_content_element'),
2047
+ onInsertButtonClick: function onInsertButtonClick(at) {
2048
+ if (at === 'before' && boundsRef.current.start === 0 || at === 'after' && !Node.has(editor, [boundsRef.current.end + 1])) {
2049
+ postInsertContentElementMessage({
2050
+ id: props.contentElementId,
2051
+ at: at
2052
+ });
2053
+ } else {
2054
+ postInsertContentElementMessage({
2055
+ id: props.contentElementId,
2056
+ at: 'split',
2057
+ splitPoint: at === 'before' ? boundsRef.current.start : boundsRef.current.end + 1
2058
+ });
2059
+ }
2060
+ },
2061
+ toolbarButtons: toolbarButtons(t).map(function (button) {
2062
+ return _objectSpread2(_objectSpread2({}, button), {}, {
2063
+ active: isBlockActive(editor, button.name)
2064
+ });
2065
+ }),
2066
+ onToolbarButtonClick: function onToolbarButtonClick(name) {
2067
+ return toggleBlock(editor, name);
2068
+ }
2069
+ },
2070
+ /*#__PURE__*/
2071
+ React.createElement("div", {
2072
+ ref: innerRef
2073
+ }))))
2074
+ );
2075
+ }
2076
+
2077
+ function computeBounds(editor) {
2078
+ var startPoint = Range.start(editor.selection);
2079
+ var endPoint = Range.end(editor.selection);
2080
+ var startPath = startPoint.path.slice(0, 1);
2081
+ var endPath = endPoint.path.slice(0, 1);
2082
+
2083
+ if (!Path.equals(startPath, endPath) && endPoint.offset === 0) {
2084
+ endPath = Path.previous(endPath);
2085
+ }
2086
+
2087
+ return [startPath[0], endPath[0]];
2088
+ }
2089
+
2090
+ function hideRect(el) {
2091
+ el.removeAttribute('style');
2092
+ }
2093
+
2094
+ function updateRect(editor, startIndex, endIndex, outer, el, inner) {
2095
+ var _getDOMNodes = getDOMNodes(editor, startIndex, endIndex),
2096
+ _getDOMNodes2 = _slicedToArray(_getDOMNodes, 2),
2097
+ startDOMNode = _getDOMNodes2[0],
2098
+ endDOMNode = _getDOMNodes2[1];
2099
+
2100
+ if (startDOMNode && endDOMNode) {
2101
+ var startRect = startDOMNode.getBoundingClientRect();
2102
+ var endRect = endDOMNode.getBoundingClientRect();
2103
+ var outerRect = outer.getBoundingClientRect();
2104
+ el.style.display = 'block';
2105
+ el.style.top = "".concat(startRect.top - outerRect.top, "px");
2106
+ inner.style.height = "".concat(endRect.bottom - startRect.top, "px");
2107
+ }
2108
+ }
2109
+
2110
+ function getDOMNodes(editor, startIndex, endIndex) {
2111
+ var startNode = Node.get(editor, [startIndex]);
2112
+ var endNode = Node.get(editor, [endIndex]);
2113
+
2114
+ try {
2115
+ var startDOMNode = ReactEditor.toDOMNode(editor, startNode);
2116
+ var endDOMNode = ReactEditor.toDOMNode(editor, endNode);
2117
+ return [startDOMNode, endDOMNode];
2118
+ } catch (e) {
2119
+ return [];
2120
+ }
2121
+ }
2122
+
2123
+ var listTypes = ['numbered-list', 'bulleted-list'];
2124
+
2125
+ function toggleBlock(editor, format) {
2126
+ var isActive = isBlockActive(editor, format);
2127
+ var isList = listTypes.includes(format);
2128
+ Transforms.unwrapNodes(editor, {
2129
+ match: function match(n) {
2130
+ return listTypes.includes(n.type);
2131
+ },
2132
+ split: true
2133
+ });
2134
+ Transforms.setNodes(editor, {
2135
+ type: isActive ? 'paragraph' : isList ? 'list-item' : format
2136
+ });
2137
+
2138
+ if (!isActive && isList) {
2139
+ var block = {
2140
+ type: format,
2141
+ children: []
2142
+ };
2143
+ Transforms.wrapNodes(editor, block);
2144
+ }
2145
+ }
2146
+
2147
+ function isBlockActive(editor, format) {
2148
+ var _Editor$nodes = Editor.nodes(editor, {
2149
+ match: function match(n) {
2150
+ return n.type === format;
2151
+ }
2152
+ }),
2153
+ _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
2154
+ match = _Editor$nodes2[0];
2155
+
2156
+ return !!match;
2157
+ }
2158
+
2159
+ function toolbarButtons(t) {
2160
+ return [{
2161
+ name: 'paragraph',
2162
+ text: t('pageflow_scrolled.inline_editing.formats.paragraph'),
2163
+ icon: TextIcon
2164
+ }, {
2165
+ name: 'heading',
2166
+ text: t('pageflow_scrolled.inline_editing.formats.heading'),
2167
+ icon: HeadingIcon
2168
+ }, {
2169
+ name: 'numbered-list',
2170
+ text: t('pageflow_scrolled.inline_editing.formats.ordered_list'),
2171
+ icon: OlIcon
2172
+ }, {
2173
+ name: 'bulleted-list',
2174
+ text: t('pageflow_scrolled.inline_editing.formats.bulleted_list'),
2175
+ icon: UlIcon
2176
+ }, {
2177
+ name: 'block-quote',
2178
+ text: t('pageflow_scrolled.inline_editing.formats.block_quote'),
2179
+ icon: QuoteIcon
2180
+ }];
2181
+ }
2182
+
2183
+ var styles$8 = {"container":"DropTargets-module_container__3vudG","dropTarget":"DropTargets-module_dropTarget__3mmox","dropIndicator":"DropTargets-module_dropIndicator__2zu4d","isOver":"DropTargets-module_isOver__2usWn"};
2184
+
2185
+ function DropTargets$1(_ref) {
2186
+ var contentElementId = _ref.contentElementId;
2187
+ var editor = useSlate();
2188
+
2189
+ var _useState = useState(),
2190
+ _useState2 = _slicedToArray(_useState, 2),
2191
+ targets = _useState2[0],
2192
+ setTargets = _useState2[1];
2193
+
2194
+ var containerRef = useRef();
2195
+ useEffect(function () {
2196
+ if (!targets) {
2197
+ setTargets(measureHeights(editor, containerRef.current));
2198
+ }
2199
+ }, [targets, editor]);
2200
+ return (
2201
+ /*#__PURE__*/
2202
+ React.createElement("div", {
2203
+ ref: containerRef,
2204
+ className: styles$8.container
2205
+ }, renderDropTargets(targets || [], contentElementId))
2206
+ );
2207
+ }
2208
+
2209
+ function renderDropTargets(targets, contentElementId) {
2210
+ function handleDrop(itemId, index) {
2211
+ if (index === 0) {
2212
+ postMoveContentElementMessage({
2213
+ id: itemId,
2214
+ to: {
2215
+ at: 'before',
2216
+ id: contentElementId
2217
+ }
2218
+ });
2219
+ } else if (index === targets.length - 1) {
2220
+ postMoveContentElementMessage({
2221
+ id: itemId,
2222
+ to: {
2223
+ at: 'after',
2224
+ id: contentElementId
2225
+ }
2226
+ });
2227
+ } else {
2228
+ postMoveContentElementMessage({
2229
+ id: itemId,
2230
+ to: {
2231
+ at: 'split',
2232
+ id: contentElementId,
2233
+ splitPoint: index
2234
+ }
2235
+ });
2236
+ }
2237
+ }
2238
+
2239
+ return targets.map(function (target, index) {
2240
+ return (
2241
+ /*#__PURE__*/
2242
+ React.createElement(DropTarget, Object.assign({}, target, {
2243
+ key: index,
2244
+ onDrop: function onDrop(itemId) {
2245
+ return handleDrop(itemId, index);
2246
+ }
2247
+ }))
2248
+ );
2249
+ });
2250
+ }
2251
+
2252
+ function DropTarget(_ref2) {
2253
+ var top = _ref2.top,
2254
+ height = _ref2.height,
2255
+ indicatorTop = _ref2.indicatorTop,
2256
+ onDrop = _ref2.onDrop;
2257
+
2258
+ var _useDrop = useDrop({
2259
+ accept: 'contentElement',
2260
+ collect: function collect(monitor) {
2261
+ return {
2262
+ isOver: monitor.isOver()
2263
+ };
2264
+ },
2265
+ drop: function drop(item) {
2266
+ return onDrop(item.id);
2267
+ }
2268
+ }),
2269
+ _useDrop2 = _slicedToArray(_useDrop, 2),
2270
+ isOver = _useDrop2[0].isOver,
2271
+ drop = _useDrop2[1];
2272
+
2273
+ return (
2274
+ /*#__PURE__*/
2275
+ React.createElement("div", {
2276
+ ref: drop,
2277
+ className: classNames(styles$8.dropTarget, _defineProperty({}, styles$8.isOver, isOver)),
2278
+ style: {
2279
+ top: top,
2280
+ height: height
2281
+ }
2282
+ },
2283
+ /*#__PURE__*/
2284
+ React.createElement("div", {
2285
+ className: styles$8.dropIndicator,
2286
+ style: {
2287
+ top: indicatorTop
2288
+ }
2289
+ }))
2290
+ );
2291
+ }
2292
+
2293
+ function measureHeights(editor, container) {
2294
+ var containerRect = container.getBoundingClientRect();
2295
+ var lastTargetDimensions = {
2296
+ top: 0,
2297
+ height: 0
2298
+ };
2299
+ var lastRectBottom = 0;
2300
+ var targetDimensions = editor.children.map(function (child, index) {
2301
+ var node = Node.get(editor, [index]);
2302
+ var domNode = ReactEditor.toDOMNode(editor, node);
2303
+ var rect = domNode.getBoundingClientRect();
2304
+ var top = lastTargetDimensions.top + lastTargetDimensions.height;
2305
+ var bottom = rect.top + rect.height / 2 - containerRect.top;
2306
+ var targetDimensions = {
2307
+ top: top,
2308
+ height: bottom - top,
2309
+ indicatorTop: index > 0 ? lastRectBottom + (rect.top - lastRectBottom) / 2 - containerRect.top - top : 0
2310
+ };
2311
+ lastRectBottom = rect.bottom;
2312
+ lastTargetDimensions = targetDimensions;
2313
+ return targetDimensions;
2314
+ });
2315
+ return [].concat(_toConsumableArray(targetDimensions), [{
2316
+ top: lastTargetDimensions.top + lastTargetDimensions.height,
2317
+ height: containerRect.height - (lastTargetDimensions.top + lastTargetDimensions.height),
2318
+ indicatorTop: containerRect.height - (lastTargetDimensions.top + lastTargetDimensions.height)
2319
+ }]);
2320
+ }
2321
+
2322
+ var EditableText = React.memo(function EditableText(_ref) {
2323
+ var value = _ref.value,
2324
+ contentElementId = _ref.contentElementId,
2325
+ placeholder = _ref.placeholder,
2326
+ onChange = _ref.onChange;
2327
+ var editor = useMemo(function () {
2328
+ return withLinks(withCustomInsertBreak(withReact(createEditor())));
2329
+ }, []);
2330
+
2331
+ var _useState = useState(),
2332
+ _useState2 = _slicedToArray(_useState, 2),
2333
+ linkSelection = _useState2[0],
2334
+ setLinkSelection = _useState2[1];
2335
+
2336
+ var _useCachedValue = useCachedValue(value, {
2337
+ defaultValue: [{
2338
+ type: 'paragraph',
2339
+ children: [{
2340
+ text: ''
2341
+ }]
2342
+ }],
2343
+ onDebouncedChange: onChange,
2344
+ onReset: function onReset(nextValue) {
2345
+ return resetSelectionIfOutsideNextValue(editor, nextValue);
2346
+ }
2347
+ }),
2348
+ _useCachedValue2 = _slicedToArray(_useCachedValue, 2),
2349
+ cachedValue = _useCachedValue2[0],
2350
+ setCachedValue = _useCachedValue2[1];
2351
+
2352
+ useContentElementEditorCommandSubscription(function (command) {
2353
+ if (command.type === 'REMOVE') {
2354
+ Transforms.removeNodes(editor, {
2355
+ mode: 'highest'
2356
+ });
2357
+ }
2358
+ });
2359
+
2360
+ var _useDropTargetsActive = useDropTargetsActive(),
2361
+ _useDropTargetsActive2 = _slicedToArray(_useDropTargetsActive, 2),
2362
+ dropTargetsActive = _useDropTargetsActive2[0],
2363
+ ref = _useDropTargetsActive2[1];
2364
+
2365
+ var decorate = useCallback(function (nodeEntry) {
2366
+ return decorateLinkSelection(nodeEntry, linkSelection);
2367
+ }, [linkSelection]); // Ensure Slate rerenders when decorations change
2368
+ // https://github.com/ianstormtaylor/slate/issues/3447
2369
+
2370
+ var renderLeaf = useCallback(function (options) {
2371
+ return renderLeafWithLinkSelection(options);
2372
+ }, [linkSelection]); // eslint-disable-line react-hooks/exhaustive-deps
2373
+
2374
+ return (
2375
+ /*#__PURE__*/
2376
+ React.createElement(Text$1, {
2377
+ scaleCategory: "body"
2378
+ },
2379
+ /*#__PURE__*/
2380
+ React.createElement("div", {
2381
+ className: styles$7.container,
2382
+ ref: ref
2383
+ },
2384
+ /*#__PURE__*/
2385
+ React.createElement(Slate, {
2386
+ editor: editor,
2387
+ value: cachedValue,
2388
+ onChange: setCachedValue
2389
+ },
2390
+ /*#__PURE__*/
2391
+ React.createElement(LinkTooltipProvider, {
2392
+ disabled: !!linkSelection
2393
+ },
2394
+ /*#__PURE__*/
2395
+ React.createElement(Selection, {
2396
+ contentElementId: contentElementId
2397
+ }), dropTargetsActive &&
2398
+ /*#__PURE__*/
2399
+ React.createElement(DropTargets$1, {
2400
+ contentElementId: contentElementId
2401
+ }),
2402
+ /*#__PURE__*/
2403
+ React.createElement(HoveringToolbar, {
2404
+ linkSelection: linkSelection,
2405
+ setLinkSelection: setLinkSelection
2406
+ }),
2407
+ /*#__PURE__*/
2408
+ React.createElement(Editable, {
2409
+ decorate: decorate,
2410
+ renderElement: renderElementWithLinkPreview,
2411
+ renderLeaf: renderLeaf
2412
+ }))),
2413
+ /*#__PURE__*/
2414
+ React.createElement(TextPlaceholder, {
2415
+ text: placeholder,
2416
+ visible: isBlank(cachedValue)
2417
+ })))
2418
+ );
2419
+ });
2420
+
2421
+ function isBlank(value) {
2422
+ var _value$, _value$2, _value$2$children$;
2423
+
2424
+ return value.length <= 1 && ((_value$ = value[0]) === null || _value$ === void 0 ? void 0 : _value$.children.length) <= 1 && value[0].type === 'paragraph' && !((_value$2 = value[0]) === null || _value$2 === void 0 ? void 0 : (_value$2$children$ = _value$2.children[0]) === null || _value$2$children$ === void 0 ? void 0 : _value$2$children$.text);
2425
+ }
2426
+
2427
+ function resetSelectionIfOutsideNextValue(editor, nextValue) {
2428
+ var nextEditor = {
2429
+ children: nextValue
2430
+ };
2431
+
2432
+ if (editor.selection && (!Node.has(nextEditor, editor.selection.anchor.path) || !Node.has(nextEditor, editor.selection.focus.path))) {
2433
+ Transforms.deselect(editor);
2434
+ }
2435
+ }
2436
+
2437
+ var EditableInlineText = memo(function EditableInlineText(_ref) {
2438
+ var _cachedValue$, _cachedValue$$childre;
2439
+
2440
+ var value = _ref.value,
2441
+ _ref$defaultValue = _ref.defaultValue,
2442
+ defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
2443
+ placeholder = _ref.placeholder,
2444
+ onChange = _ref.onChange;
2445
+ var editor = useMemo(function () {
2446
+ return withSingleLine(withReact(createEditor()));
2447
+ }, []);
2448
+
2449
+ var _useCachedValue = useCachedValue(value, {
2450
+ defaultValue: [{
2451
+ type: 'heading',
2452
+ children: [{
2453
+ text: defaultValue
2454
+ }]
2455
+ }],
2456
+ onDebouncedChange: onChange
2457
+ }),
2458
+ _useCachedValue2 = _slicedToArray(_useCachedValue, 2),
2459
+ cachedValue = _useCachedValue2[0],
2460
+ setCachedValue = _useCachedValue2[1];
2461
+
2462
+ return (
2463
+ /*#__PURE__*/
2464
+ React.createElement(React.Fragment, null,
2465
+ /*#__PURE__*/
2466
+ React.createElement(Slate, {
2467
+ editor: editor,
2468
+ value: cachedValue,
2469
+ onChange: setCachedValue
2470
+ },
2471
+ /*#__PURE__*/
2472
+ React.createElement(Editable, null)),
2473
+ /*#__PURE__*/
2474
+ React.createElement(TextPlaceholder, {
2475
+ text: placeholder,
2476
+ visible: !((_cachedValue$ = cachedValue[0]) === null || _cachedValue$ === void 0 ? void 0 : (_cachedValue$$childre = _cachedValue$.children[0]) === null || _cachedValue$$childre === void 0 ? void 0 : _cachedValue$$childre.text)
2477
+ }))
2478
+ );
2479
+ });
2480
+
2481
+ function withSingleLine(editor) {
2482
+ var normalizeNode = editor.normalizeNode;
2483
+
2484
+ editor.normalizeNode = function (_ref2) {
2485
+ var _ref3 = _slicedToArray(_ref2, 2),
2486
+ node = _ref3[0],
2487
+ path = _ref3[1];
2488
+
2489
+ if (path.length === 0) {
2490
+ if (editor.children.length > 1) {
2491
+ Transforms.mergeNodes(editor);
2492
+ }
2493
+ }
2494
+
2495
+ return normalizeNode([node, path]);
2496
+ };
2497
+
2498
+ return editor;
2499
+ }
2500
+
2501
+ function PhonePlatformProvider(_ref) {
2502
+ var children = _ref.children;
2503
+
2504
+ var _useState = useState(false),
2505
+ _useState2 = _slicedToArray(_useState, 2),
2506
+ phoneEmulationMode = _useState2[0],
2507
+ setPhoneEmulationMode = _useState2[1];
2508
+
2509
+ useEffect(function () {
2510
+ window.addEventListener('message', receive);
2511
+
2512
+ function receive(event) {
2513
+ if (event.data.type === 'CHANGE_EMULATION_MODE') {
2514
+ if (event.data['payload'] === 'phone') {
2515
+ setPhoneEmulationMode(true);
2516
+ } else {
2517
+ setPhoneEmulationMode(false);
2518
+ }
2519
+ }
2520
+ }
2521
+
2522
+ return function () {
2523
+ return window.removeEventListener('message', receive);
2524
+ };
2525
+ });
2526
+ return (
2527
+ /*#__PURE__*/
2528
+ React.createElement(PhonePlatformContext.Provider, {
2529
+ value: phoneEmulationMode
2530
+ }, children)
2531
+ );
2532
+ }
2533
+
2534
+ export { ContentElementDecorator, EditableInlineText, EditableText, EntryDecorator, LayoutWithPlaceholder, PhonePlatformProvider, SectionDecorator };