pages_core 3.15.3 → 3.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/assets/builds/pages_core/admin-dist.js +1 -1
  4. data/app/assets/builds/pages_core/admin-dist.js.map +4 -4
  5. data/app/assets/builds/pages_core/admin.css +378 -253
  6. data/app/assets/builds/pages_core/mailer.css +41 -6
  7. data/app/assets/builds/pages_core_fonts/121b837e.woff2 +0 -0
  8. data/app/assets/builds/pages_core_fonts/216e5c23.woff2 +0 -0
  9. data/app/assets/builds/pages_core_fonts/3017b52f.woff2 +0 -0
  10. data/app/assets/builds/pages_core_fonts/489746b9.woff2 +0 -0
  11. data/app/assets/builds/pages_core_fonts/49775483.woff2 +0 -0
  12. data/app/assets/builds/pages_core_fonts/49c9e472.woff2 +0 -0
  13. data/app/assets/builds/pages_core_fonts/4a119645.woff2 +0 -0
  14. data/app/assets/builds/pages_core_fonts/5d56d7a8.woff2 +0 -0
  15. data/app/assets/builds/pages_core_fonts/61ea75a6.woff2 +0 -0
  16. data/app/assets/builds/pages_core_fonts/62cbb778.woff2 +0 -0
  17. data/app/assets/builds/pages_core_fonts/647d26c.woff2 +0 -0
  18. data/app/assets/builds/pages_core_fonts/67764053.woff2 +0 -0
  19. data/app/assets/builds/pages_core_fonts/6bb0fd00.woff2 +0 -0
  20. data/app/assets/builds/pages_core_fonts/6c0194a2.woff2 +0 -0
  21. data/app/assets/builds/pages_core_fonts/71423409.woff2 +0 -0
  22. data/app/assets/builds/pages_core_fonts/7584e61d.woff2 +0 -0
  23. data/app/assets/builds/pages_core_fonts/77bcfa1c.woff2 +0 -0
  24. data/app/assets/builds/pages_core_fonts/7aca0cc5.woff2 +0 -0
  25. data/app/assets/builds/pages_core_fonts/9a09533f.woff2 +0 -0
  26. data/app/assets/builds/pages_core_fonts/a51f5bc8.woff2 +0 -0
  27. data/app/assets/builds/pages_core_fonts/a80b2975.woff2 +0 -0
  28. data/app/assets/builds/pages_core_fonts/a891f617.woff2 +0 -0
  29. data/app/assets/builds/pages_core_fonts/ad6083f3.woff2 +0 -0
  30. data/app/assets/builds/pages_core_fonts/b29a61ff.woff2 +0 -0
  31. data/app/assets/builds/{fonts/6569749d.ttf → pages_core_fonts/b30b0656.ttf} +0 -0
  32. data/app/assets/builds/pages_core_fonts/b3a5f48c.woff2 +0 -0
  33. data/app/assets/builds/pages_core_fonts/bc73ee06.woff2 +0 -0
  34. data/app/assets/builds/pages_core_fonts/c38c6d45.woff2 +0 -0
  35. data/app/assets/builds/pages_core_fonts/c5ce0b1f.woff2 +0 -0
  36. data/app/assets/builds/pages_core_fonts/c8d53904.woff2 +0 -0
  37. data/app/assets/builds/pages_core_fonts/ce13c169.woff2 +0 -0
  38. data/app/assets/builds/pages_core_fonts/d43bd0d5.woff2 +0 -0
  39. data/app/assets/builds/pages_core_fonts/e1c7d368.woff2 +0 -0
  40. data/app/assets/builds/pages_core_fonts/e1e8175d.woff2 +0 -0
  41. data/app/assets/builds/pages_core_fonts/e318f796.woff2 +0 -0
  42. data/app/assets/builds/{fonts/ee32bc60.ttf → pages_core_fonts/e7acb7d9.ttf} +0 -0
  43. data/app/assets/builds/pages_core_fonts/ee5514c6.woff2 +0 -0
  44. data/app/assets/builds/pages_core_fonts/f4e495e2.woff2 +0 -0
  45. data/app/assets/builds/pages_core_fonts/f736ec65.woff2 +0 -0
  46. data/app/assets/builds/pages_core_fonts/f741c7ba.woff2 +0 -0
  47. data/app/assets/builds/pages_core_fonts/f7767345.woff2 +0 -0
  48. data/app/assets/builds/pages_core_fonts/fe9eb751.woff2 +0 -0
  49. data/app/assets/stylesheets/pages_core/admin/components/forms.css +2 -2
  50. data/app/assets/stylesheets/pages_core/admin/components/header.css +1 -1
  51. data/app/assets/stylesheets/pages_core/admin/controllers/pages.css +1 -1
  52. data/app/assets/stylesheets/pages_core/admin/global/fonts.css +38 -38
  53. data/app/controllers/{pages_core → admin}/admin_controller.rb +1 -3
  54. data/app/controllers/attachments_controller.rb +40 -0
  55. data/app/controllers/concerns/pages_core/document_title_controller.rb +16 -0
  56. data/app/controllers/concerns/pages_core/page_parameters.rb +1 -1
  57. data/app/controllers/concerns/pages_core/pages/preview_controller.rb +49 -0
  58. data/app/controllers/concerns/pages_core/pages/rss_controller.rb +43 -0
  59. data/app/controllers/errors_controller.rb +2 -0
  60. data/app/controllers/images_controller.rb +13 -0
  61. data/app/controllers/pages_core/frontend/pages_controller.rb +3 -4
  62. data/app/controllers/pages_core/frontend_controller.rb +6 -1
  63. data/app/controllers/pages_core/sitemaps_controller.rb +21 -52
  64. data/app/helpers/pages_core/admin/image_uploads_helper.rb +1 -1
  65. data/app/helpers/pages_core/application_helper.rb +0 -3
  66. data/app/helpers/pages_core/attachments_helper.rb +0 -10
  67. data/app/helpers/pages_core/feed_tags_helper.rb +31 -0
  68. data/app/helpers/pages_core/frontend_helper.rb +3 -0
  69. data/app/helpers/pages_core/head_tags_helper.rb +80 -70
  70. data/app/helpers/pages_core/page_path_helper.rb +1 -12
  71. data/app/javascript/components/Attachments/Attachment.tsx +3 -3
  72. data/app/javascript/components/Attachments/AttachmentEditor.tsx +5 -5
  73. data/app/javascript/components/Attachments/Deleted.tsx +28 -0
  74. data/app/javascript/components/Attachments/List.tsx +11 -24
  75. data/app/javascript/components/Attachments/Placeholder.tsx +0 -2
  76. data/app/javascript/components/Attachments.tsx +2 -3
  77. data/app/javascript/components/DateRangeSelect.tsx +13 -10
  78. data/app/javascript/components/DateTimeSelect.tsx +11 -11
  79. data/app/javascript/components/EditableImage.tsx +3 -3
  80. data/app/javascript/components/FileUploadButton.tsx +3 -3
  81. data/app/javascript/components/ImageCropper/FocalPoint.tsx +10 -14
  82. data/app/javascript/components/ImageCropper/Image.tsx +19 -25
  83. data/app/javascript/components/ImageCropper/Toolbar.tsx +27 -26
  84. data/app/javascript/components/ImageCropper/useContainerSize.ts +25 -0
  85. data/app/javascript/components/ImageCropper/useCrop.ts +28 -13
  86. data/app/javascript/components/ImageCropper/useImageCropperContext.ts +13 -0
  87. data/app/javascript/components/ImageCropper.tsx +24 -83
  88. data/app/javascript/components/ImageEditor/Form.tsx +25 -28
  89. data/app/javascript/components/ImageEditor/useImageEditor.ts +63 -0
  90. data/app/javascript/components/ImageEditor/useImageEditorContext.ts +14 -0
  91. data/app/javascript/components/ImageEditor.tsx +28 -42
  92. data/app/javascript/components/ImageGrid/Deleted.tsx +28 -0
  93. data/app/javascript/components/ImageGrid/DragElement.tsx +5 -5
  94. data/app/javascript/components/ImageGrid/FilePlaceholder.tsx +0 -2
  95. data/app/javascript/components/ImageGrid/Grid.tsx +15 -24
  96. data/app/javascript/components/ImageGrid/GridImage.tsx +4 -4
  97. data/app/javascript/components/ImageGrid/Placeholder.tsx +2 -4
  98. data/app/javascript/components/ImageGrid.tsx +2 -4
  99. data/app/javascript/components/ImageUploader.tsx +5 -5
  100. data/app/javascript/components/LabelledField.tsx +6 -6
  101. data/app/javascript/components/Modal.tsx +16 -13
  102. data/app/javascript/components/PageForm/Block.tsx +3 -3
  103. data/app/javascript/components/PageForm/Content.tsx +11 -15
  104. data/app/javascript/components/PageForm/Dates.tsx +3 -11
  105. data/app/javascript/components/PageForm/Files.tsx +2 -4
  106. data/app/javascript/components/PageForm/Form.tsx +3 -9
  107. data/app/javascript/components/PageForm/Images.tsx +2 -4
  108. data/app/javascript/components/PageForm/LocaleLinks.tsx +4 -11
  109. data/app/javascript/components/PageForm/Metadata.tsx +8 -13
  110. data/app/javascript/components/PageForm/Options.tsx +28 -11
  111. data/app/javascript/components/PageForm/PageDescription.tsx +7 -14
  112. data/app/javascript/components/PageForm/PathSegment.tsx +5 -10
  113. data/app/javascript/components/PageForm/TabPanel.tsx +3 -6
  114. data/app/javascript/components/PageForm/Tabs.tsx +2 -4
  115. data/app/javascript/components/PageForm/UnconfiguredContent.tsx +7 -12
  116. data/app/javascript/components/PageForm/pageParams.ts +3 -2
  117. data/app/javascript/components/PageForm/usePage.ts +1 -46
  118. data/app/javascript/components/PageForm/usePageFormContext.ts +8 -0
  119. data/app/javascript/components/PageForm/useTabs.ts +1 -1
  120. data/app/javascript/components/PageForm/utils.ts +49 -0
  121. data/app/javascript/components/PageForm.tsx +52 -48
  122. data/app/javascript/components/PageImages.tsx +1 -3
  123. data/app/javascript/components/PageTree/Button.tsx +25 -0
  124. data/app/javascript/components/PageTree/CollapseArrow.tsx +34 -0
  125. data/app/javascript/components/PageTree/CollapsedLabel.tsx +21 -0
  126. data/app/javascript/components/PageTree/EditPageName.tsx +68 -0
  127. data/app/javascript/components/PageTree/Node.tsx +143 -413
  128. data/app/javascript/components/PageTree/PageName.tsx +6 -4
  129. data/app/javascript/components/PageTree/StatusLabel.tsx +10 -0
  130. data/app/javascript/components/PageTree/tree.ts +268 -0
  131. data/app/javascript/components/PageTree/usePageTree.ts +268 -0
  132. data/app/javascript/components/PageTree/usePageTreeContext.ts +13 -0
  133. data/app/javascript/components/PageTree.tsx +194 -214
  134. data/app/javascript/components/{RichTextToolbarButton.tsx → RichTextArea/ToolbarButton.tsx} +3 -5
  135. data/app/javascript/components/RichTextArea/actions.ts +106 -0
  136. data/app/javascript/components/RichTextArea/useMaybeControlledValue.ts +14 -0
  137. data/app/javascript/components/RichTextArea.tsx +91 -209
  138. data/app/javascript/components/TagEditor/AddTagForm.tsx +2 -2
  139. data/app/javascript/components/TagEditor/Editor.tsx +3 -5
  140. data/app/javascript/components/TagEditor/Tag.tsx +3 -5
  141. data/app/javascript/components/TagEditor/useTags.ts +7 -4
  142. data/app/javascript/components/TagEditor.tsx +2 -4
  143. data/app/javascript/components/Toast.tsx +5 -5
  144. data/app/javascript/components/drag/draggedOrder.ts +6 -6
  145. data/app/javascript/components/drag/useDragCollection.ts +21 -25
  146. data/app/javascript/components/drag/useDragUploader.ts +20 -18
  147. data/app/javascript/components/drag/useDraggable.ts +3 -3
  148. data/app/javascript/features/RichText.tsx +0 -1
  149. data/app/javascript/features/contentTabs.ts +2 -2
  150. data/app/javascript/stores/useModalStore.ts +1 -1
  151. data/app/javascript/stores/useToastStore.ts +2 -2
  152. data/app/javascript/types/Attachments.ts +11 -11
  153. data/app/javascript/types/Crop.ts +16 -12
  154. data/app/javascript/types/Drag.ts +21 -23
  155. data/app/javascript/types/Images.ts +8 -8
  156. data/app/javascript/types/PageEditor.ts +11 -4
  157. data/app/javascript/types/Pages.ts +22 -27
  158. data/app/javascript/types/Tags.ts +5 -6
  159. data/app/javascript/types/Template.ts +4 -4
  160. data/app/javascript/types.ts +2 -2
  161. data/app/models/attachment.rb +5 -9
  162. data/app/models/autopublisher.rb +1 -1
  163. data/app/models/concerns/pages_core/page_model/redirectable.rb +1 -2
  164. data/app/models/concerns/pages_core/page_model/searchable.rb +1 -1
  165. data/app/models/concerns/pages_core/page_model/status.rb +2 -4
  166. data/app/models/concerns/pages_core/searchable_document.rb +2 -4
  167. data/app/models/image.rb +0 -15
  168. data/app/models/page_builder.rb +4 -6
  169. data/app/resources/admin/page_resource.rb +2 -2
  170. data/app/resources/export/page_resource.rb +1 -1
  171. data/app/services/pages_core/invite_service.rb +1 -2
  172. data/app/views/layouts/admin.html.erb +1 -0
  173. data/app/views/pages_core/sitemaps/index.xml.builder +10 -0
  174. data/config/routes.rb +4 -3
  175. data/db/migrate/20240917142300_add_skip_index_to_pages.rb +7 -0
  176. data/lib/pages_core/engine.rb +15 -17
  177. data/lib/pages_core/sitemap.rb +58 -0
  178. data/lib/pages_core/templates/configuration_proxy.rb +3 -3
  179. data/lib/pages_core.rb +7 -4
  180. data/lib/rails/generators/pages_core/frontend/frontend_generator.rb +2 -2
  181. data/lib/rails/generators/pages_core/frontend/templates/application.html.erb +13 -5
  182. data/lib/rails/generators/pages_core/frontend/templates/postcss.config.js +2 -6
  183. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/components/base.css +3 -1
  184. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/config.css +2 -3
  185. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/global/animation.css +1 -1
  186. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/global/colors.css +6 -5
  187. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/global/fonts.css +1 -1
  188. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/global/grid.css +9 -6
  189. data/lib/rails/generators/pages_core/frontend/templates/stylesheets/global/typography.css +42 -26
  190. data/lib/rails/generators/pages_core/install/templates/application_controller.rb +0 -6
  191. data/lib/rails/generators/pages_core/rspec/templates/rails_helper.rb +1 -1
  192. metadata +81 -49
  193. data/app/assets/builds/fonts/7b7db107.woff2 +0 -0
  194. data/app/assets/builds/fonts/921961e9.woff2 +0 -0
  195. data/app/controller_dummies/admin/admin_controller.rb +0 -6
  196. data/app/controller_dummies/application_controller.rb +0 -6
  197. data/app/controller_dummies/attachments_controller.rb +0 -4
  198. data/app/controller_dummies/frontend_controller.rb +0 -4
  199. data/app/controller_dummies/images_controller.rb +0 -4
  200. data/app/controller_dummies/page_files_controller.rb +0 -4
  201. data/app/controller_dummies/pages_controller.rb +0 -4
  202. data/app/controller_dummies/sitemaps_controller.rb +0 -4
  203. data/app/controllers/concerns/pages_core/preview_pages_controller.rb +0 -47
  204. data/app/controllers/concerns/pages_core/rss_controller.rb +0 -41
  205. data/app/controllers/pages_core/attachments_controller.rb +0 -42
  206. data/app/controllers/pages_core/frontend/page_files_controller.rb +0 -25
  207. data/app/controllers/pages_core/images_controller.rb +0 -15
  208. data/app/helpers/pages_core/meta_tags_helper.rb +0 -96
  209. data/app/helpers/pages_core/open_graph_tags_helper.rb +0 -49
  210. data/app/javascript/components/PageTree/Draggable.tsx +0 -338
  211. data/app/javascript/lib/Tree.ts +0 -305
  212. data/app/javascript/types/Trees.ts +0 -19
  213. data/app/views/sitemaps/show.xml.builder +0 -11
@@ -1,338 +0,0 @@
1
- /*
2
- Based on react-ui-tree
3
- https://github.com/pqx/react-ui-tree
4
-
5
- The MIT License (MIT)
6
-
7
- Copyright (c) 2015 pqx Limited
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- SOFTWARE.
26
- */
27
-
28
- import React, { Component } from "react";
29
-
30
- import Tree from "../../lib/Tree";
31
- import * as Trees from "../../types/Trees";
32
- import * as Pages from "../../types/Pages";
33
-
34
- import Node from "./Node";
35
-
36
- interface DragState {
37
- id?: Trees.Id;
38
- x: number | null;
39
- y: number | null;
40
- w: number | null;
41
- h: number | null;
42
- scrollTop: number | null;
43
- scrollLeft: number | null;
44
- }
45
-
46
- interface Props {
47
- addChild: (id: Trees.Id, attrs: Pages.TreeNode) => void;
48
- dir: string;
49
- locale: string;
50
- movedPage: (id: Trees.Id) => void;
51
- paddingLeft?: number;
52
- toggleCollapsed: (id: Trees.Id) => void;
53
- tree: Tree<Pages.TreeNode>;
54
- updatePage: (id: Trees.Id, attributes: Partial<Pages.TreeItem>) => void;
55
- updateTree: (Tree) => void;
56
- }
57
-
58
- interface State {
59
- dragging: DragState;
60
- }
61
-
62
- const defaultPadding = 20;
63
-
64
- export default class Draggable extends Component<Props, State> {
65
- _dragListener: (evt: MouseEvent) => void;
66
- _dragEndListener: () => void;
67
- _start: boolean;
68
- _startX: number;
69
- _startY: number;
70
- _offsetX: number;
71
- _offsetY: number;
72
- dragging: DragState;
73
-
74
- constructor(props: Props) {
75
- super(props);
76
- this.state = {
77
- dragging: this.initDragging()
78
- };
79
- }
80
-
81
- initDragging(): DragState {
82
- return {
83
- id: null,
84
- x: null,
85
- y: null,
86
- w: null,
87
- h: null,
88
- scrollTop: null,
89
- scrollLeft: null
90
- };
91
- }
92
-
93
- getDraggingDom() {
94
- const tree = this.props.tree;
95
- const dragging = this.state.dragging;
96
- if (dragging && dragging.id) {
97
- const draggingIndex = tree.getIndex(dragging.id);
98
- const draggingStyles = {
99
- top: dragging.y,
100
- left: dragging.x,
101
- width: dragging.w
102
- };
103
-
104
- return (
105
- <div className="draggable" style={draggingStyles}>
106
- <Node
107
- tree={tree}
108
- index={draggingIndex}
109
- locale={this.props.locale}
110
- paddingLeft={this.props.paddingLeft || defaultPadding}
111
- />
112
- </div>
113
- );
114
- }
115
-
116
- return null;
117
- }
118
-
119
- render() {
120
- const { tree, dir, locale } = this.props;
121
- const dragging = this.state.dragging;
122
-
123
- if (!tree) {
124
- return <div className="page-tree">{this.getDraggingDom()}</div>;
125
- } else {
126
- const root = tree.getIndex(1);
127
- return (
128
- <div className="page-tree">
129
- {this.getDraggingDom()}
130
- <Node
131
- tree={tree}
132
- index={root}
133
- key={root.id}
134
- paddingLeft={this.props.paddingLeft || defaultPadding}
135
- addChild={(idx: Trees.Index<Pages.TreeNode>) => this.addChild(idx)}
136
- onDragStart={this.dragStart}
137
- onCollapse={(nodeId) => this.toggleCollapse(nodeId)}
138
- updatePage={(idx, attrs) => this.updatePage(idx, attrs)}
139
- dragging={dragging && dragging.id}
140
- dir={dir}
141
- locale={locale}
142
- />
143
- </div>
144
- );
145
- }
146
- }
147
-
148
- addChild(parent: Trees.Index<Pages.TreeNode>) {
149
- const newNode: Pages.TreeNode = {
150
- blocks: { name: { [this.props.locale]: "" } },
151
- status: 0,
152
- editing: true,
153
- children: [],
154
- published_at: new Date(),
155
- pinned: false,
156
- parent_page_id: parent.node.id,
157
- collapsed: false
158
- };
159
- this.props.addChild(parent.id, newNode);
160
- }
161
-
162
- prevAddButtonCount(tree: Tree, index: Trees.Index) {
163
- let count = 0;
164
- const parentNodes = [];
165
- let pointer = tree.getIndex(index.parent);
166
- while (pointer) {
167
- parentNodes.push(pointer);
168
- pointer = tree.getIndex(pointer.parent);
169
- }
170
-
171
- pointer = index;
172
-
173
- pointer = tree.getNodeByTop(index.top - 1);
174
- while (pointer) {
175
- if (
176
- parentNodes.indexOf(pointer) == -1 &&
177
- !pointer.node.collapsed &&
178
- pointer.node.children.filter((p: Pages.TreeNode) => p.status != 4)
179
- .length > 0
180
- ) {
181
- count += 1;
182
- }
183
- pointer = tree.getNodeByTop(pointer.top - 1);
184
- }
185
-
186
- return count;
187
- }
188
-
189
- scrollOffset() {
190
- const dragging = this.state.dragging;
191
- return {
192
- top: document.body.scrollTop - dragging.scrollTop,
193
- left: document.body.scrollLeft - dragging.scrollLeft
194
- };
195
- }
196
-
197
- drag(e: MouseEvent) {
198
- if (this._start) {
199
- const distance =
200
- Math.abs(e.clientX - this._offsetX) +
201
- Math.abs(e.clientY - this._offsetY);
202
- if (distance >= 15) {
203
- this.setState({
204
- dragging: this.dragging
205
- });
206
- this._start = false;
207
- } else {
208
- return null;
209
- }
210
- }
211
-
212
- const tree = this.props.tree;
213
- const dragging = this.state.dragging;
214
- const paddingLeft = this.props.paddingLeft || defaultPadding;
215
- let newIndex: Trees.Index<Pages.TreeNode> = null;
216
- let index = tree.getIndex(dragging.id);
217
- const collapsed = index.node.collapsed;
218
-
219
- const _startX = this._startX;
220
- const _startY = this._startY;
221
- const _offsetX = this._offsetX;
222
- const _offsetY = this._offsetY;
223
-
224
- const pos = {
225
- x: _startX + e.clientX - _offsetX + this.scrollOffset().left,
226
- y: _startY + e.clientY - _offsetY + this.scrollOffset().top
227
- };
228
- dragging.x = pos.x;
229
- dragging.y = pos.y;
230
-
231
- const diffX = dragging.x - paddingLeft / 2 - (index.left - 2) * paddingLeft;
232
- const diffY =
233
- dragging.y -
234
- dragging.h / 2 -
235
- (index.top - 2 + this.prevAddButtonCount(tree, index)) * dragging.h;
236
-
237
- if (diffX < 0) {
238
- // left
239
- if (index.parent && !index.next) {
240
- newIndex = tree.move(index.id, index.parent, "after");
241
- }
242
- } else if (diffX > paddingLeft) {
243
- // right
244
- if ("prev" in index) {
245
- const prev = tree.getIndex(index.prev);
246
-
247
- if (!prev.node.collapsed) {
248
- newIndex = tree.move(index.id, index.prev, "append");
249
- }
250
- }
251
- }
252
-
253
- if (newIndex) {
254
- index = newIndex;
255
- newIndex.node.collapsed = collapsed;
256
- dragging.id = newIndex.id;
257
- }
258
-
259
- if (diffY < 0 - dragging.h * 0.5) {
260
- // up
261
- const above = tree.getNodeByTop(index.top - 1);
262
- newIndex = tree.move(index.id, above.id, "before");
263
- } else if (diffY > dragging.h * 1.5) {
264
- // down
265
- const below = index.next
266
- ? tree.getIndex(index.next)
267
- : tree.getNodeByTop(index.top + index.height);
268
-
269
- if (below && below.parent !== index.id) {
270
- if (below.children && below.children.length && !below.node.collapsed) {
271
- newIndex = tree.move(index.id, below.id, "prepend");
272
- } else {
273
- newIndex = tree.move(index.id, below.id, "after");
274
- }
275
- }
276
- }
277
-
278
- if (newIndex) {
279
- newIndex.node.collapsed = collapsed;
280
- dragging.id = newIndex.id;
281
- }
282
-
283
- this.setState({ dragging: dragging });
284
- }
285
-
286
- dragStart = (id: Trees.Id, dom: HTMLDivElement, e: React.MouseEvent) => {
287
- // Only drag on left click
288
- if (e.button !== 0) {
289
- return;
290
- }
291
-
292
- this.dragging = {
293
- id: id,
294
- w: dom.offsetWidth,
295
- h: dom.offsetHeight,
296
- x: dom.offsetLeft,
297
- y: dom.offsetTop,
298
- scrollTop: document.body.scrollTop,
299
- scrollLeft: document.body.scrollLeft
300
- };
301
-
302
- this._startX = dom.offsetLeft;
303
- this._startY = dom.offsetTop;
304
- this._offsetX = e.clientX;
305
- this._offsetY = e.clientY;
306
- this._start = true;
307
-
308
- this._dragListener = (e: MouseEvent) => {
309
- this.drag(e);
310
- };
311
- this._dragEndListener = () => this.dragEnd();
312
-
313
- window.addEventListener("mousemove", this._dragListener);
314
- window.addEventListener("mouseup", this._dragEndListener);
315
- };
316
-
317
- dragEnd() {
318
- if (!this._start) {
319
- this.props.updateTree(this.props.tree);
320
- this.props.movedPage(this.state.dragging.id);
321
- }
322
-
323
- this.setState({
324
- dragging: this.initDragging()
325
- });
326
-
327
- window.removeEventListener("mousemove", this._dragListener);
328
- window.removeEventListener("mouseup", this._dragEndListener);
329
- }
330
-
331
- toggleCollapse(nodeId: Trees.Id) {
332
- this.props.toggleCollapsed(nodeId);
333
- }
334
-
335
- updatePage(index: Trees.Index, attributes: Partial<Pages.TreeItem>) {
336
- this.props.updatePage(index.id, attributes);
337
- }
338
- }
@@ -1,305 +0,0 @@
1
- /*
2
- Based on
3
-
4
- js-tree by Wang Zuo
5
- https://github.com/wangzuo/js-tree
6
-
7
- react-ui-tree
8
- https://github.com/pqx/react-ui-tree
9
-
10
- The MIT License (MIT)
11
-
12
- Copyright (c) 2015 Wang Zuo
13
-
14
- Permission is hereby granted, free of charge, to any person obtaining a copy
15
- of this software and associated documentation files (the "Software"), to deal
16
- in the Software without restriction, including without limitation the rights
17
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- copies of the Software, and to permit persons to whom the Software is
19
- furnished to do so, subject to the following conditions:
20
-
21
- The above copyright notice and this permission notice shall be included in
22
- all copies or substantial portions of the Software.
23
-
24
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- SOFTWARE.
31
-
32
- Copyright (c) 2015 pqx Limited
33
-
34
- Permission is hereby granted, free of charge, to any person obtaining a copy
35
- of this software and associated documentation files (the "Software"), to deal
36
- in the Software without restriction, including without limitation the rights
37
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
- copies of the Software, and to permit persons to whom the Software is
39
- furnished to do so, subject to the following conditions:
40
-
41
- The above copyright notice and this permission notice shall be included in
42
- all copies or substantial portions of the Software.
43
-
44
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
- SOFTWARE.
51
- */
52
-
53
- import * as Trees from "../types/Trees";
54
-
55
- type MovePlacement = "before" | "after" | "prepend" | "append";
56
-
57
- function indexName(id: Trees.Id): string {
58
- return `${id}`;
59
- }
60
-
61
- export default class Tree<N extends Trees.Node = Trees.Node> {
62
- cnt: number;
63
- obj: N;
64
- indexes: Record<string, Trees.Index<N>>;
65
-
66
- constructor(obj: N) {
67
- this.cnt = 1;
68
- this.obj = obj || ({ children: [] } as N);
69
- this.indexes = {};
70
- this.build(this.obj);
71
- }
72
-
73
- build(obj: N): Trees.Index<N> {
74
- const indexes = this.indexes;
75
- const startId = this.cnt;
76
-
77
- const index = { id: startId, node: obj };
78
- indexes[indexName(this.cnt)] = index;
79
- this.cnt++;
80
-
81
- const walk = (objs: Trees.Node[], parent: Trees.Index<N>) => {
82
- const children: Trees.Id[] = [];
83
- objs.forEach((obj: N) => {
84
- const index: Trees.Index<N> = {
85
- id: this.cnt,
86
- node: obj
87
- };
88
-
89
- if (parent) {
90
- index.parent = parent.id;
91
- }
92
-
93
- indexes[indexName(this.cnt)] = index;
94
- children.push(this.cnt);
95
- this.cnt++;
96
-
97
- if (obj.children && obj.children.length) {
98
- walk(obj.children, index);
99
- }
100
- });
101
- parent.children = children;
102
-
103
- children.forEach(function (id, i) {
104
- const index = indexes[indexName(id)];
105
- if (i > 0) {
106
- index.prev = children[i - 1];
107
- }
108
- if (i < children.length - 1) {
109
- index.next = children[i + 1];
110
- }
111
- });
112
- };
113
-
114
- if (obj.children && obj.children.length) {
115
- walk(obj.children, index);
116
- }
117
-
118
- return index;
119
- }
120
-
121
- getIndex(id: Trees.Id) {
122
- return this.indexes[indexName(id)];
123
- }
124
-
125
- removeIndex(index: Trees.Index<N>) {
126
- const del = (index: Trees.Index<N>) => {
127
- delete this.indexes[indexName(index.id)];
128
- if (index.children && index.children.length) {
129
- index.children.forEach((child) => {
130
- del(this.getIndex(child));
131
- });
132
- }
133
- };
134
- del(index);
135
- }
136
-
137
- get(id: Trees.Id) {
138
- return this.getIndex(id).node;
139
- }
140
-
141
- remove(id: Trees.Id) {
142
- const index = this.getIndex(id);
143
- const node = this.get(id);
144
-
145
- const parentIndex = this.getIndex(index.parent);
146
- const parentNode = this.get(index.parent);
147
-
148
- parentNode.children.splice(parentNode.children.indexOf(node), 1);
149
- parentIndex.children.splice(parentIndex.children.indexOf(id), 1);
150
-
151
- this.removeIndex(index);
152
- this.updateChildren(parentIndex.children);
153
-
154
- return node;
155
- }
156
-
157
- updateChildren(children: Trees.Id[]) {
158
- children.forEach((id, i) => {
159
- const index = this.getIndex(id);
160
- index.prev = index.next = null;
161
- if (i > 0) {
162
- index.prev = children[i - 1];
163
- }
164
- if (i < children.length - 1) {
165
- index.next = children[i + 1];
166
- }
167
- });
168
- }
169
-
170
- insert(obj: N, parentId: Trees.Id, i: number) {
171
- const parentIndex = this.getIndex(parentId);
172
- const parentNode = this.get(parentId);
173
-
174
- const index = this.build(obj);
175
- index.parent = parentId;
176
-
177
- parentNode.children = parentNode.children || [];
178
- parentIndex.children = parentIndex.children || [];
179
-
180
- parentNode.children.splice(i, 0, obj);
181
- parentIndex.children.splice(i, 0, index.id);
182
-
183
- this.updateChildren(parentIndex.children);
184
- if (parentIndex.parent) {
185
- this.updateChildren(this.getIndex(parentIndex.parent).children);
186
- }
187
-
188
- return index;
189
- }
190
-
191
- insertBefore(obj: N, destId: Trees.Id) {
192
- const destIndex = this.getIndex(destId);
193
- const parentId = destIndex.parent;
194
- const i = this.getIndex(parentId).children.indexOf(destId);
195
- return this.insert(obj, parentId, i);
196
- }
197
-
198
- insertAfter(obj: N, destId: Trees.Id) {
199
- const destIndex = this.getIndex(destId);
200
- const parentId = destIndex.parent;
201
- const i = this.getIndex(parentId).children.indexOf(destId);
202
- return this.insert(obj, parentId, i + 1);
203
- }
204
-
205
- prepend(obj: N, destId: Trees.Id) {
206
- return this.insert(obj, destId, 0);
207
- }
208
-
209
- append(obj: N, destId: Trees.Id) {
210
- const destIndex = this.getIndex(destId);
211
- destIndex.children = destIndex.children || [];
212
- return this.insert(obj, destId, destIndex.children.length);
213
- }
214
-
215
- // react-ui-tree methods
216
-
217
- updateNodesPosition() {
218
- let top = 1;
219
- let left = 1;
220
- const root = this.getIndex(1);
221
-
222
- root.top = top++;
223
- root.left = left++;
224
-
225
- const walk = (
226
- children: Trees.Id[],
227
- parent: Trees.Index<N>,
228
- left: number,
229
- collapsed: boolean
230
- ) => {
231
- let height = 1;
232
- children.forEach((id: Trees.Id) => {
233
- const node = this.getIndex(id);
234
- if (collapsed) {
235
- node.top = null;
236
- node.left = null;
237
- } else {
238
- node.top = top++;
239
- node.left = left;
240
- }
241
-
242
- if (node.children && node.children.length) {
243
- height += walk(
244
- node.children,
245
- node,
246
- left + 1,
247
- collapsed || node.node.collapsed
248
- );
249
- } else {
250
- node.height = 1;
251
- height += 1;
252
- }
253
- });
254
-
255
- if (parent.node.collapsed) parent.height = 1;
256
- else parent.height = height;
257
- return parent.height;
258
- };
259
-
260
- if (root.children && root.children.length) {
261
- walk(root.children, root, left, root.node.collapsed);
262
- }
263
- }
264
-
265
- move(fromId: Trees.Id, toId: Trees.Id, placement: MovePlacement) {
266
- if (fromId === toId || toId === 1) {
267
- return;
268
- }
269
-
270
- const obj = this.remove(fromId);
271
- let index: Trees.Index<N>;
272
-
273
- if (placement === "before") {
274
- index = this.insertBefore(obj, toId);
275
- } else if (placement === "after") {
276
- index = this.insertAfter(obj, toId);
277
- } else if (placement === "prepend") {
278
- index = this.prepend(obj, toId);
279
- } else if (placement === "append") {
280
- index = this.append(obj, toId);
281
- }
282
-
283
- // todo: perf
284
- this.updateNodesPosition();
285
- return index;
286
- }
287
-
288
- getParent(id: string) {
289
- const indexes = this.indexes;
290
- if (Object.prototype.hasOwnProperty.call(indexes, id)) {
291
- return this.getIndex(indexes[id].parent);
292
- }
293
- }
294
-
295
- getNodeByTop(top: Trees.Id) {
296
- const indexes = this.indexes;
297
- for (const id in indexes) {
298
- if (Object.prototype.hasOwnProperty.call(indexes, id)) {
299
- if (indexes[id].top === top) {
300
- return indexes[id];
301
- }
302
- }
303
- }
304
- }
305
- }
@@ -1,19 +0,0 @@
1
- export type Id = number | string;
2
-
3
- export interface Node {
4
- children: Array<Node>;
5
- collapsed: boolean;
6
- root?: boolean;
7
- }
8
-
9
- export interface Index<T extends Node = Node> {
10
- id: number;
11
- node: T;
12
- children?: Id[];
13
- parent?: Id;
14
- top?: number;
15
- height?: number;
16
- next?: Id;
17
- prev?: Id;
18
- left?: number;
19
- }
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- xml.instruct!
4
- xml.urlset xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" do |urlset|
5
- @entries.each do |entry|
6
- urlset.url do |url|
7
- url.loc entry[:loc]
8
- url.lastmod entry[:lastmod]
9
- end
10
- end
11
- end