@atlaskit/editor-plugin-card 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/.eslintrc.js +15 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE.md +13 -0
  4. package/README.md +7 -0
  5. package/dist/cjs/index.js +12 -0
  6. package/dist/cjs/messages.js +20 -0
  7. package/dist/cjs/nodeviews/blockCard.js +164 -0
  8. package/dist/cjs/nodeviews/datasource.js +173 -0
  9. package/dist/cjs/nodeviews/embedCard.js +398 -0
  10. package/dist/cjs/nodeviews/genericCard.js +118 -0
  11. package/dist/cjs/nodeviews/inlineCard.js +132 -0
  12. package/dist/cjs/plugin.js +138 -0
  13. package/dist/cjs/pm-plugins/actions.js +122 -0
  14. package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +48 -0
  15. package/dist/cjs/pm-plugins/analytics/events-from-tr.js +359 -0
  16. package/dist/cjs/pm-plugins/analytics/index.js +19 -0
  17. package/dist/cjs/pm-plugins/analytics/types.js +5 -0
  18. package/dist/cjs/pm-plugins/analytics/utils.js +178 -0
  19. package/dist/cjs/pm-plugins/doc.js +479 -0
  20. package/dist/cjs/pm-plugins/keymap.js +64 -0
  21. package/dist/cjs/pm-plugins/main.js +212 -0
  22. package/dist/cjs/pm-plugins/mountHyperlink.js +47 -0
  23. package/dist/cjs/pm-plugins/plugin-key.js +9 -0
  24. package/dist/cjs/pm-plugins/reducers.js +111 -0
  25. package/dist/cjs/pm-plugins/shouldReplaceLink.js +35 -0
  26. package/dist/cjs/pm-plugins/util/resolve.js +59 -0
  27. package/dist/cjs/pm-plugins/util/state.js +49 -0
  28. package/dist/cjs/toolbar.js +364 -0
  29. package/dist/cjs/types.js +5 -0
  30. package/dist/cjs/ui/DatasourceModal/ModalWithState.js +25 -0
  31. package/dist/cjs/ui/DatasourceModal/index.js +60 -0
  32. package/dist/cjs/ui/EditLinkToolbar.js +258 -0
  33. package/dist/cjs/ui/EditorSmartCardEvents.js +21 -0
  34. package/dist/cjs/ui/EditorSmartCardEventsNext.js +215 -0
  35. package/dist/cjs/ui/HyperlinkToolbarAppearance.js +174 -0
  36. package/dist/cjs/ui/LayoutButton/index.js +121 -0
  37. package/dist/cjs/ui/LayoutButton/types.js +5 -0
  38. package/dist/cjs/ui/LayoutButton/utils.js +19 -0
  39. package/dist/cjs/ui/LinkToolbarAppearance.js +152 -0
  40. package/dist/cjs/ui/ResizableEmbedCard.js +364 -0
  41. package/dist/cjs/ui/SmallerEditIcon.js +22 -0
  42. package/dist/cjs/utils.js +60 -0
  43. package/dist/cjs/version.json +5 -0
  44. package/dist/es2019/index.js +1 -0
  45. package/dist/es2019/messages.js +13 -0
  46. package/dist/es2019/nodeviews/blockCard.js +131 -0
  47. package/dist/es2019/nodeviews/datasource.js +137 -0
  48. package/dist/es2019/nodeviews/embedCard.js +370 -0
  49. package/dist/es2019/nodeviews/genericCard.js +92 -0
  50. package/dist/es2019/nodeviews/inlineCard.js +113 -0
  51. package/dist/es2019/plugin.js +129 -0
  52. package/dist/es2019/pm-plugins/actions.js +57 -0
  53. package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +38 -0
  54. package/dist/es2019/pm-plugins/analytics/events-from-tr.js +339 -0
  55. package/dist/es2019/pm-plugins/analytics/index.js +2 -0
  56. package/dist/es2019/pm-plugins/analytics/types.js +1 -0
  57. package/dist/es2019/pm-plugins/analytics/utils.js +160 -0
  58. package/dist/es2019/pm-plugins/doc.js +451 -0
  59. package/dist/es2019/pm-plugins/keymap.js +59 -0
  60. package/dist/es2019/pm-plugins/main.js +208 -0
  61. package/dist/es2019/pm-plugins/mountHyperlink.js +37 -0
  62. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  63. package/dist/es2019/pm-plugins/reducers.js +110 -0
  64. package/dist/es2019/pm-plugins/shouldReplaceLink.js +25 -0
  65. package/dist/es2019/pm-plugins/util/resolve.js +50 -0
  66. package/dist/es2019/pm-plugins/util/state.js +26 -0
  67. package/dist/es2019/toolbar.js +359 -0
  68. package/dist/es2019/types.js +1 -0
  69. package/dist/es2019/ui/DatasourceModal/ModalWithState.js +19 -0
  70. package/dist/es2019/ui/DatasourceModal/index.js +48 -0
  71. package/dist/es2019/ui/EditLinkToolbar.js +226 -0
  72. package/dist/es2019/ui/EditorSmartCardEvents.js +15 -0
  73. package/dist/es2019/ui/EditorSmartCardEventsNext.js +199 -0
  74. package/dist/es2019/ui/HyperlinkToolbarAppearance.js +86 -0
  75. package/dist/es2019/ui/LayoutButton/index.js +114 -0
  76. package/dist/es2019/ui/LayoutButton/types.js +1 -0
  77. package/dist/es2019/ui/LayoutButton/utils.js +15 -0
  78. package/dist/es2019/ui/LinkToolbarAppearance.js +118 -0
  79. package/dist/es2019/ui/ResizableEmbedCard.js +335 -0
  80. package/dist/es2019/ui/SmallerEditIcon.js +14 -0
  81. package/dist/es2019/utils.js +46 -0
  82. package/dist/es2019/version.json +5 -0
  83. package/dist/esm/index.js +1 -0
  84. package/dist/esm/messages.js +13 -0
  85. package/dist/esm/nodeviews/blockCard.js +156 -0
  86. package/dist/esm/nodeviews/datasource.js +165 -0
  87. package/dist/esm/nodeviews/embedCard.js +389 -0
  88. package/dist/esm/nodeviews/genericCard.js +111 -0
  89. package/dist/esm/nodeviews/inlineCard.js +124 -0
  90. package/dist/esm/plugin.js +130 -0
  91. package/dist/esm/pm-plugins/actions.js +102 -0
  92. package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +41 -0
  93. package/dist/esm/pm-plugins/analytics/events-from-tr.js +350 -0
  94. package/dist/esm/pm-plugins/analytics/index.js +2 -0
  95. package/dist/esm/pm-plugins/analytics/types.js +1 -0
  96. package/dist/esm/pm-plugins/analytics/utils.js +160 -0
  97. package/dist/esm/pm-plugins/doc.js +460 -0
  98. package/dist/esm/pm-plugins/keymap.js +58 -0
  99. package/dist/esm/pm-plugins/main.js +199 -0
  100. package/dist/esm/pm-plugins/mountHyperlink.js +39 -0
  101. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  102. package/dist/esm/pm-plugins/reducers.js +103 -0
  103. package/dist/esm/pm-plugins/shouldReplaceLink.js +29 -0
  104. package/dist/esm/pm-plugins/util/resolve.js +52 -0
  105. package/dist/esm/pm-plugins/util/state.js +40 -0
  106. package/dist/esm/toolbar.js +350 -0
  107. package/dist/esm/types.js +1 -0
  108. package/dist/esm/ui/DatasourceModal/ModalWithState.js +17 -0
  109. package/dist/esm/ui/DatasourceModal/index.js +49 -0
  110. package/dist/esm/ui/EditLinkToolbar.js +244 -0
  111. package/dist/esm/ui/EditorSmartCardEvents.js +14 -0
  112. package/dist/esm/ui/EditorSmartCardEventsNext.js +203 -0
  113. package/dist/esm/ui/HyperlinkToolbarAppearance.js +163 -0
  114. package/dist/esm/ui/LayoutButton/index.js +110 -0
  115. package/dist/esm/ui/LayoutButton/types.js +1 -0
  116. package/dist/esm/ui/LayoutButton/utils.js +12 -0
  117. package/dist/esm/ui/LinkToolbarAppearance.js +141 -0
  118. package/dist/esm/ui/ResizableEmbedCard.js +358 -0
  119. package/dist/esm/ui/SmallerEditIcon.js +14 -0
  120. package/dist/esm/utils.js +48 -0
  121. package/dist/esm/version.json +5 -0
  122. package/dist/types/index.d.ts +2 -0
  123. package/dist/types/messages.d.ts +12 -0
  124. package/dist/types/nodeviews/blockCard.d.ts +26 -0
  125. package/dist/types/nodeviews/datasource.d.ts +42 -0
  126. package/dist/types/nodeviews/embedCard.d.ts +46 -0
  127. package/dist/types/nodeviews/genericCard.d.ts +37 -0
  128. package/dist/types/nodeviews/inlineCard.d.ts +23 -0
  129. package/dist/types/plugin.d.ts +24 -0
  130. package/dist/types/pm-plugins/actions.d.ts +23 -0
  131. package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
  132. package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +17 -0
  133. package/dist/types/pm-plugins/analytics/index.d.ts +2 -0
  134. package/dist/types/pm-plugins/analytics/types.d.ts +12 -0
  135. package/dist/types/pm-plugins/analytics/utils.d.ts +32 -0
  136. package/dist/types/pm-plugins/doc.d.ts +22 -0
  137. package/dist/types/pm-plugins/keymap.d.ts +3 -0
  138. package/dist/types/pm-plugins/main.d.ts +6 -0
  139. package/dist/types/pm-plugins/mountHyperlink.d.ts +5 -0
  140. package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
  141. package/dist/types/pm-plugins/reducers.d.ts +3 -0
  142. package/dist/types/pm-plugins/shouldReplaceLink.d.ts +2 -0
  143. package/dist/types/pm-plugins/util/resolve.d.ts +8 -0
  144. package/dist/types/pm-plugins/util/state.d.ts +31 -0
  145. package/dist/types/toolbar.d.ts +9 -0
  146. package/dist/types/types.d.ts +163 -0
  147. package/dist/types/ui/DatasourceModal/ModalWithState.d.ts +9 -0
  148. package/dist/types/ui/DatasourceModal/index.d.ts +11 -0
  149. package/dist/types/ui/EditLinkToolbar.d.ts +47 -0
  150. package/dist/types/ui/EditorSmartCardEvents.d.ts +5 -0
  151. package/dist/types/ui/EditorSmartCardEventsNext.d.ts +18 -0
  152. package/dist/types/ui/HyperlinkToolbarAppearance.d.ts +32 -0
  153. package/dist/types/ui/LayoutButton/index.d.ts +9 -0
  154. package/dist/types/ui/LayoutButton/types.d.ts +19 -0
  155. package/dist/types/ui/LayoutButton/utils.d.ts +5 -0
  156. package/dist/types/ui/LinkToolbarAppearance.d.ts +29 -0
  157. package/dist/types/ui/ResizableEmbedCard.d.ts +61 -0
  158. package/dist/types/ui/SmallerEditIcon.d.ts +3 -0
  159. package/dist/types/utils.d.ts +19 -0
  160. package/dist/types-ts4.5/index.d.ts +2 -0
  161. package/dist/types-ts4.5/messages.d.ts +12 -0
  162. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +26 -0
  163. package/dist/types-ts4.5/nodeviews/datasource.d.ts +42 -0
  164. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +46 -0
  165. package/dist/types-ts4.5/nodeviews/genericCard.d.ts +37 -0
  166. package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +23 -0
  167. package/dist/types-ts4.5/plugin.d.ts +24 -0
  168. package/dist/types-ts4.5/pm-plugins/actions.d.ts +23 -0
  169. package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
  170. package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +17 -0
  171. package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +2 -0
  172. package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +12 -0
  173. package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +32 -0
  174. package/dist/types-ts4.5/pm-plugins/doc.d.ts +22 -0
  175. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
  176. package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
  177. package/dist/types-ts4.5/pm-plugins/mountHyperlink.d.ts +5 -0
  178. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
  179. package/dist/types-ts4.5/pm-plugins/reducers.d.ts +3 -0
  180. package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +2 -0
  181. package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +8 -0
  182. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +31 -0
  183. package/dist/types-ts4.5/toolbar.d.ts +9 -0
  184. package/dist/types-ts4.5/types.d.ts +163 -0
  185. package/dist/types-ts4.5/ui/DatasourceModal/ModalWithState.d.ts +9 -0
  186. package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +11 -0
  187. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +47 -0
  188. package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +5 -0
  189. package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +18 -0
  190. package/dist/types-ts4.5/ui/HyperlinkToolbarAppearance.d.ts +32 -0
  191. package/dist/types-ts4.5/ui/LayoutButton/index.d.ts +9 -0
  192. package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +19 -0
  193. package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +5 -0
  194. package/dist/types-ts4.5/ui/LinkToolbarAppearance.d.ts +29 -0
  195. package/dist/types-ts4.5/ui/ResizableEmbedCard.d.ts +61 -0
  196. package/dist/types-ts4.5/ui/SmallerEditIcon.d.ts +3 -0
  197. package/dist/types-ts4.5/utils.d.ts +19 -0
  198. package/package.json +126 -0
  199. package/report.api.md +146 -0
  200. package/tmp/api-report-tmp.d.ts +117 -0
@@ -0,0 +1,335 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ /** @jsx jsx */
4
+ import React from 'react';
5
+ import { jsx } from '@emotion/react';
6
+ import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from 'prosemirror-utils';
7
+ import { embedSpacingStyles } from '@atlaskit/editor-common/styles';
8
+ import { calcColumnsFromPx, calcMediaPxWidth, calcPctFromPx, calcPxFromColumns, handleSides, imageAlignmentMap, Resizer, snapTo, wrappedLayouts, wrapperStyle } from '@atlaskit/editor-common/ui';
9
+ import { akEditorBreakoutPadding, akEditorMediaResizeHandlerPaddingWide, akEditorWideLayoutWidth, breakoutWideScaleRatio, DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
10
+ import { embedHeaderHeight } from '@atlaskit/smart-card';
11
+ // eslint-disable-next-line @repo/internal/react/no-class-components
12
+ export default class ResizableEmbedCard extends React.Component {
13
+ constructor(...args) {
14
+ super(...args);
15
+ _defineProperty(this, "state", {
16
+ offsetLeft: this.calcOffsetLeft()
17
+ });
18
+ _defineProperty(this, "calcNewSize", (newWidth, stop) => {
19
+ const {
20
+ layout,
21
+ view: {
22
+ state
23
+ }
24
+ } = this.props;
25
+ const newPct = calcPctFromPx(newWidth, this.props.lineLength) * 100;
26
+ this.setState({
27
+ resizedPctWidth: newPct
28
+ });
29
+ let newLayout = hasParentNodeOfType(state.schema.nodes.table)(state.selection) ? layout : this.calcUnwrappedLayout(newPct, newWidth);
30
+ if (newPct <= 100) {
31
+ if (this.wrappedLayout && (stop ? newPct !== 100 : true)) {
32
+ newLayout = layout;
33
+ }
34
+ return {
35
+ width: newPct,
36
+ layout: newLayout
37
+ };
38
+ } else {
39
+ return {
40
+ width: this.props.pctWidth || null,
41
+ layout: newLayout
42
+ };
43
+ }
44
+ });
45
+ _defineProperty(this, "calcUnwrappedLayout", (pct, width) => {
46
+ if (pct <= 100) {
47
+ return 'center';
48
+ }
49
+ if (width <= this.wideLayoutWidth) {
50
+ return 'wide';
51
+ }
52
+ return 'full-width';
53
+ });
54
+ _defineProperty(this, "calcColumnLeftOffset", () => {
55
+ const {
56
+ offsetLeft
57
+ } = this.state;
58
+ return this.insideInlineLike ? calcColumnsFromPx(offsetLeft, this.props.lineLength, this.props.gridSize) : 0;
59
+ });
60
+ _defineProperty(this, "calcPxWidth", useLayout => {
61
+ const {
62
+ layout,
63
+ pctWidth,
64
+ lineLength,
65
+ containerWidth,
66
+ fullWidthMode,
67
+ getPos,
68
+ view: {
69
+ state
70
+ }
71
+ } = this.props;
72
+ const {
73
+ resizedPctWidth
74
+ } = this.state;
75
+ const pos = typeof getPos === 'function' ? getPos() : undefined;
76
+ return calcMediaPxWidth({
77
+ origWidth: DEFAULT_EMBED_CARD_WIDTH,
78
+ origHeight: DEFAULT_EMBED_CARD_HEIGHT,
79
+ pctWidth,
80
+ state,
81
+ containerWidth: {
82
+ width: containerWidth,
83
+ lineLength
84
+ },
85
+ isFullWidthModeEnabled: fullWidthMode,
86
+ layout: useLayout || layout,
87
+ pos: pos,
88
+ resizedPctWidth
89
+ });
90
+ });
91
+ _defineProperty(this, "highlights", (newWidth, snapPoints) => {
92
+ const snapWidth = snapTo(newWidth, snapPoints);
93
+ const {
94
+ layoutColumn,
95
+ table,
96
+ expand,
97
+ nestedExpand
98
+ } = this.props.view.state.schema.nodes;
99
+ if (this.$pos && !!findParentNodeOfTypeClosestToPos(this.$pos, [layoutColumn, table, expand, nestedExpand].filter(Boolean))) {
100
+ return [];
101
+ }
102
+ if (snapWidth > this.wideLayoutWidth) {
103
+ return ['full-width'];
104
+ }
105
+ const {
106
+ layout,
107
+ lineLength,
108
+ gridSize
109
+ } = this.props;
110
+ const columns = calcColumnsFromPx(snapWidth, lineLength, gridSize);
111
+ const columnWidth = Math.round(columns);
112
+ const highlight = [];
113
+ if (layout === 'wrap-left' || layout === 'align-start') {
114
+ highlight.push(0, columnWidth);
115
+ } else if (layout === 'wrap-right' || layout === 'align-end') {
116
+ highlight.push(gridSize, gridSize - columnWidth);
117
+ } else if (this.insideInlineLike) {
118
+ highlight.push(Math.round(columns + this.calcColumnLeftOffset()));
119
+ } else {
120
+ highlight.push(Math.floor((gridSize - columnWidth) / 2), Math.ceil((gridSize + columnWidth) / 2));
121
+ }
122
+ return highlight;
123
+ });
124
+ }
125
+ componentDidUpdate() {
126
+ const offsetLeft = this.calcOffsetLeft();
127
+ if (offsetLeft !== this.state.offsetLeft && offsetLeft >= 0) {
128
+ this.setState({
129
+ offsetLeft
130
+ });
131
+ }
132
+ }
133
+ get wrappedLayout() {
134
+ return wrappedLayouts.indexOf(this.props.layout) > -1;
135
+ }
136
+ UNSAFE_componentWillReceiveProps(nextProps) {
137
+ if (this.props.layout !== nextProps.layout) {
138
+ this.checkLayout(this.props.layout, nextProps.layout);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * When returning to center layout from a wrapped/aligned layout, it might actually
144
+ * be wide or full-width
145
+ */
146
+ checkLayout(oldLayout, newLayout) {
147
+ const {
148
+ resizedPctWidth
149
+ } = this.state;
150
+ if (wrappedLayouts.indexOf(oldLayout) > -1 && newLayout === 'center' && resizedPctWidth) {
151
+ const layout = this.calcUnwrappedLayout(resizedPctWidth, this.calcPxWidth(newLayout));
152
+ this.props.updateSize(resizedPctWidth, layout);
153
+ }
154
+ }
155
+ get $pos() {
156
+ if (typeof this.props.getPos !== 'function') {
157
+ return null;
158
+ }
159
+ const pos = this.props.getPos();
160
+ if (Number.isNaN(pos) || typeof pos !== 'number') {
161
+ return null;
162
+ }
163
+
164
+ // need to pass view because we may not get updated props in time
165
+ return this.props.view.state.doc.resolve(pos);
166
+ }
167
+
168
+ /**
169
+ * The maxmimum number of grid columns this node can resize to.
170
+ */
171
+ get gridWidth() {
172
+ const {
173
+ gridSize
174
+ } = this.props;
175
+ return !(this.wrappedLayout || this.insideInlineLike) ? gridSize / 2 : gridSize;
176
+ }
177
+ calcOffsetLeft() {
178
+ let offsetLeft = 0;
179
+ if (this.wrapper && this.insideInlineLike) {
180
+ const currentNode = this.wrapper;
181
+ const boundingRect = currentNode.getBoundingClientRect();
182
+ const pmRect = this.props.view.dom.getBoundingClientRect();
183
+ offsetLeft = boundingRect.left - pmRect.left;
184
+ }
185
+ return offsetLeft;
186
+ }
187
+ get wideLayoutWidth() {
188
+ const {
189
+ lineLength
190
+ } = this.props;
191
+ if (lineLength) {
192
+ return Math.ceil(lineLength * breakoutWideScaleRatio);
193
+ } else {
194
+ return akEditorWideLayoutWidth;
195
+ }
196
+ }
197
+ calcSnapPoints() {
198
+ const {
199
+ offsetLeft
200
+ } = this.state;
201
+ const {
202
+ containerWidth,
203
+ lineLength
204
+ } = this.props;
205
+ const snapTargets = [];
206
+ for (let i = 0; i < this.gridWidth; i++) {
207
+ snapTargets.push(calcPxFromColumns(i, lineLength, this.gridWidth) - offsetLeft);
208
+ }
209
+ // full width
210
+ snapTargets.push(lineLength - offsetLeft);
211
+ const minimumWidth = calcPxFromColumns(this.wrappedLayout || this.insideInlineLike ? 1 : 2, lineLength, this.props.gridSize);
212
+ let snapPoints = snapTargets.filter(width => width >= minimumWidth);
213
+ const $pos = this.$pos;
214
+ if (!$pos) {
215
+ return snapPoints;
216
+ }
217
+ const isTopLevel = $pos.parent.type.name === 'doc';
218
+ if (isTopLevel) {
219
+ snapPoints.push(this.wideLayoutWidth);
220
+ const fullWidthPoint = containerWidth - akEditorBreakoutPadding;
221
+ if (fullWidthPoint > this.wideLayoutWidth) {
222
+ snapPoints.push(fullWidthPoint);
223
+ }
224
+ }
225
+ return snapPoints;
226
+ }
227
+ get insideInlineLike() {
228
+ const $pos = this.$pos;
229
+ if (!$pos) {
230
+ return false;
231
+ }
232
+ const {
233
+ listItem
234
+ } = this.props.view.state.schema.nodes;
235
+ return !!findParentNodeOfTypeClosestToPos($pos, [listItem]);
236
+ }
237
+ /**
238
+ * Previously height of the box was controlled with paddingTop/paddingBottom trick inside Wrapper.
239
+ * It allowed height to be defined by a given percent ratio and so absolute value was defined by actual width.
240
+ * Also, it was part of styled component, which was fine because it was static through out life time of component.
241
+ *
242
+ * Now, two things changed:
243
+ * 1. If `height` is present we take it as actual height of the box, and hence we don't need
244
+ * (or even can't have, due to lack of width value) paddingTop trick.
245
+ * 2. Since `height` can be changing through out life time of a component, we can't have it as part of styled component,
246
+ * and hence we use `style` prop.
247
+ */
248
+ getHeightDefiningComponent() {
249
+ const {
250
+ height,
251
+ aspectRatio
252
+ } = this.props;
253
+ let heightDefiningStyles;
254
+ if (height) {
255
+ heightDefiningStyles = {
256
+ height: `${height}px`
257
+ };
258
+ } else {
259
+ // paddingBottom css trick defines ratio of `iframe height (y) + header (32)` to `width (x)`,
260
+ // where is `aspectRatio` defines iframe aspectRatio alone
261
+ // So, visually:
262
+ //
263
+ // x
264
+ // ┌──────────┐
265
+ // │ header │ 32
266
+ // ├──────────┤
267
+ // │ │
268
+ // │ iframe │ y
269
+ // │ │
270
+ // └──────────┘
271
+ //
272
+ // aspectRatio = x / y
273
+ // paddingBottom = (y + 32) / x
274
+ // which can be achieved with css calc() as (1 / (x/y)) * 100)% + 32px
275
+ heightDefiningStyles = {
276
+ paddingBottom: `calc(${(1 / aspectRatio * 100).toFixed(3)}% + ${embedHeaderHeight}px)`
277
+ };
278
+ }
279
+ return jsx("span", {
280
+ "data-testid": 'resizable-embed-card-height-definer',
281
+ style: {
282
+ display: 'block',
283
+ /* Fixes extra padding problem in Firefox */
284
+ fontSize: 0,
285
+ lineHeight: 0,
286
+ ...heightDefiningStyles
287
+ }
288
+ });
289
+ }
290
+ render() {
291
+ const {
292
+ layout,
293
+ pctWidth,
294
+ containerWidth,
295
+ fullWidthMode,
296
+ children
297
+ } = this.props;
298
+ const initialWidth = this.calcPxWidth() - akEditorMediaResizeHandlerPaddingWide;
299
+ const enable = {};
300
+ handleSides.forEach(side => {
301
+ const oppositeSide = side === 'left' ? 'right' : 'left';
302
+ enable[side] = ['full-width', 'wide', 'center'].concat(`wrap-${oppositeSide}`).concat(`align-${imageAlignmentMap[oppositeSide]}`).indexOf(layout) > -1;
303
+ if (side === 'left' && this.insideInlineLike) {
304
+ enable[side] = false;
305
+ }
306
+ });
307
+
308
+ /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
309
+ return jsx("div", {
310
+ css: embedSpacingStyles,
311
+ "data-testid": "resizable-embed-card-spacing"
312
+ }, jsx("div", {
313
+ css: wrapperStyle({
314
+ layout,
315
+ isResized: !!pctWidth,
316
+ containerWidth: containerWidth || DEFAULT_EMBED_CARD_WIDTH,
317
+ fullWidthMode
318
+ })
319
+ }, jsx(Resizer, _extends({}, this.props, {
320
+ width: initialWidth // Starting or initial width of embed <iframe> itself.
321
+ ,
322
+ enable: enable,
323
+ calcNewSize: this.calcNewSize,
324
+ snapPoints: this.calcSnapPoints(),
325
+ scaleFactor: !this.wrappedLayout && !this.insideInlineLike ? 2 : 1,
326
+ highlights: this.highlights,
327
+ innerPadding: akEditorMediaResizeHandlerPaddingWide,
328
+ nodeType: "embed"
329
+ }), children, this.getHeightDefiningComponent())));
330
+ /* eslint-enable @atlaskit/design-system/consistent-css-prop-usage */
331
+ }
332
+ }
333
+ _defineProperty(ResizableEmbedCard, "defaultProps", {
334
+ aspectRatio: DEFAULT_EMBED_CARD_WIDTH / DEFAULT_EMBED_CARD_HEIGHT
335
+ });
@@ -0,0 +1,14 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import { editIconStyles } from '@atlaskit/editor-common/styles';
4
+ import EditIcon from '@atlaskit/icon/glyph/edit';
5
+
6
+ /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
7
+ export const SmallerEditIcon = () => {
8
+ return jsx("div", {
9
+ css: editIconStyles
10
+ }, jsx(EditIcon, {
11
+ label: "edit"
12
+ }));
13
+ };
14
+ /* eslint-enable @atlaskit/design-system/consistent-css-prop-usage */
@@ -0,0 +1,46 @@
1
+ import { NodeSelection } from 'prosemirror-state';
2
+ import { pluginKey } from './pm-plugins/plugin-key';
3
+ export const appearanceForNodeType = spec => {
4
+ if (spec.name === 'inlineCard') {
5
+ return 'inline';
6
+ } else if (spec.name === 'blockCard') {
7
+ return 'block';
8
+ } else if (spec.name === 'embedCard') {
9
+ return 'embed';
10
+ }
11
+ return;
12
+ };
13
+ export const selectedCardAppearance = state => {
14
+ if (state.selection instanceof NodeSelection) {
15
+ return appearanceForNodeType(state.selection.node.type);
16
+ }
17
+ };
18
+ export const titleUrlPairFromNode = node => {
19
+ const {
20
+ attrs
21
+ } = node;
22
+ return {
23
+ url: attrs.url || attrs.data && attrs.data.url,
24
+ title: attrs.data && attrs.data.title
25
+ };
26
+ };
27
+
28
+ /**
29
+ * Merges the title and url from attributes and CardInfo from the resolved view, preferring the CardInfo.
30
+ * @param titleUrlPair title and url information from the node attributes
31
+ * @param info information stored in state from the resolved UI component view
32
+ */
33
+ export const mergeCardInfo = (titleUrlPair, info) => {
34
+ return {
35
+ title: info && info.title || titleUrlPair.title,
36
+ url: info && info.url || titleUrlPair.url
37
+ };
38
+ };
39
+ export const displayInfoForCard = (node, info) => mergeCardInfo(titleUrlPairFromNode(node), info);
40
+ export const findCardInfo = state => {
41
+ const pluginState = pluginKey.getState(state);
42
+ if (!pluginState) {
43
+ return undefined;
44
+ }
45
+ return pluginState.cards.find(cardInfo => cardInfo.pos === state.selection.from);
46
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-card",
3
+ "version": "0.1.0",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1 @@
1
+ export { cardPlugin } from './plugin';
@@ -0,0 +1,13 @@
1
+ import { defineMessages } from 'react-intl-next';
2
+ export var messages = defineMessages({
3
+ datasourceJiraIssue: {
4
+ id: 'fabric.editor.datasource.jiraIssue',
5
+ defaultMessage: 'Jira Issues',
6
+ description: 'Insert a jira datasource table'
7
+ },
8
+ datasourceJiraIssueDescription: {
9
+ id: 'fabric.editor.datasource.jiraIssue.description',
10
+ defaultMessage: 'Insert issues from Jira Cloud with enhanced search, filtering, and configuration',
11
+ description: 'Insert a jira datasource table'
12
+ }
13
+ });
@@ -0,0 +1,156 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
+ import React from 'react';
11
+ import PropTypes from 'prop-types';
12
+ import rafSchedule from 'raf-schd';
13
+ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
14
+ import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
15
+ import { browser } from '@atlaskit/editor-common/utils';
16
+ import { Card as SmartCard } from '@atlaskit/smart-card';
17
+ import { registerCard } from '../pm-plugins/actions';
18
+ import { Card } from './genericCard';
19
+
20
+ // eslint-disable-next-line @repo/internal/react/no-class-components
21
+ export var BlockCardComponent = /*#__PURE__*/function (_React$PureComponent) {
22
+ _inherits(BlockCardComponent, _React$PureComponent);
23
+ var _super = _createSuper(BlockCardComponent);
24
+ function BlockCardComponent() {
25
+ var _this;
26
+ _classCallCheck(this, BlockCardComponent);
27
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
28
+ args[_key] = arguments[_key];
29
+ }
30
+ _this = _super.call.apply(_super, [this].concat(args));
31
+ _defineProperty(_assertThisInitialized(_this), "onClick", function () {});
32
+ _defineProperty(_assertThisInitialized(_this), "onResolve", function (data) {
33
+ var _this$props = _this.props,
34
+ getPos = _this$props.getPos,
35
+ view = _this$props.view;
36
+ if (!getPos || typeof getPos === 'boolean') {
37
+ return;
38
+ }
39
+ var title = data.title,
40
+ url = data.url;
41
+
42
+ // don't dispatch immediately since we might be in the middle of
43
+ // rendering a nodeview
44
+ rafSchedule(function () {
45
+ var pos = getPos();
46
+ if (typeof pos !== 'number') {
47
+ return;
48
+ }
49
+ view.dispatch(registerCard({
50
+ title: title,
51
+ url: url,
52
+ pos: pos
53
+ })(view.state.tr));
54
+ })();
55
+ });
56
+ _defineProperty(_assertThisInitialized(_this), "gapCursorSpan", function () {
57
+ // Don't render in EdgeHTMl version <= 18 (Edge version 44)
58
+ // as it forces the edit popup to render 24px lower than it should
59
+ if (browser.ie && browser.ie_version < 79) {
60
+ return;
61
+ }
62
+
63
+ // render an empty span afterwards to get around Webkit bug
64
+ // that puts caret in next editable text element
65
+ return /*#__PURE__*/React.createElement("span", {
66
+ contentEditable: true
67
+ });
68
+ });
69
+ _defineProperty(_assertThisInitialized(_this), "onError", function (_ref) {
70
+ var err = _ref.err;
71
+ if (err) {
72
+ throw err;
73
+ }
74
+ });
75
+ return _this;
76
+ }
77
+ _createClass(BlockCardComponent, [{
78
+ key: "UNSAFE_componentWillMount",
79
+ value: function UNSAFE_componentWillMount() {
80
+ var view = this.props.view;
81
+ var scrollContainer = findOverflowScrollParent(view.dom);
82
+ this.scrollContainer = scrollContainer || undefined;
83
+ }
84
+ }, {
85
+ key: "render",
86
+ value: function render() {
87
+ var _this$props2 = this.props,
88
+ node = _this$props2.node,
89
+ cardContext = _this$props2.cardContext,
90
+ platform = _this$props2.platform,
91
+ showServerActions = _this$props2.showServerActions;
92
+ var _node$attrs = node.attrs,
93
+ url = _node$attrs.url,
94
+ data = _node$attrs.data;
95
+ var cardInner = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SmartCard, {
96
+ key: url,
97
+ url: url,
98
+ data: data,
99
+ container: this.scrollContainer,
100
+ appearance: "block",
101
+ onClick: this.onClick,
102
+ onResolve: this.onResolve,
103
+ onError: this.onError,
104
+ showActions: platform === 'web',
105
+ platform: platform,
106
+ showServerActions: showServerActions
107
+ }), this.gapCursorSpan());
108
+ // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
109
+ // otherwise if we got data, we can render the card directly since it doesn't need the Provider
110
+ return /*#__PURE__*/React.createElement("div", null, cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
111
+ value: cardContext.value
112
+ }, cardInner) : data ? cardInner : null);
113
+ }
114
+ }]);
115
+ return BlockCardComponent;
116
+ }(React.PureComponent);
117
+ _defineProperty(BlockCardComponent, "contextTypes", {
118
+ contextAdapter: PropTypes.object
119
+ });
120
+ var WrappedBlockCard = Card(BlockCardComponent, UnsupportedBlock);
121
+ export var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
122
+ _inherits(BlockCard, _ReactNodeView);
123
+ var _super2 = _createSuper(BlockCard);
124
+ function BlockCard() {
125
+ _classCallCheck(this, BlockCard);
126
+ return _super2.apply(this, arguments);
127
+ }
128
+ _createClass(BlockCard, [{
129
+ key: "createDomRef",
130
+ value: function createDomRef() {
131
+ var domRef = document.createElement('div');
132
+ if (this.reactComponentProps.platform !== 'mobile') {
133
+ // workaround Chrome bug in https://product-fabric.atlassian.net/browse/ED-5379
134
+ // see also: https://github.com/ProseMirror/prosemirror/issues/884
135
+ domRef.contentEditable = 'true';
136
+ domRef.setAttribute('spellcheck', 'false');
137
+ }
138
+ return domRef;
139
+ }
140
+ }, {
141
+ key: "render",
142
+ value: function render() {
143
+ var _this$reactComponentP = this.reactComponentProps,
144
+ platform = _this$reactComponentP.platform,
145
+ showServerActions = _this$reactComponentP.showServerActions;
146
+ return /*#__PURE__*/React.createElement(WrappedBlockCard, {
147
+ node: this.node,
148
+ view: this.view,
149
+ getPos: this.getPos,
150
+ platform: platform,
151
+ showServerActions: showServerActions
152
+ });
153
+ }
154
+ }]);
155
+ return BlockCard;
156
+ }(ReactNodeView);