@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.
- package/.eslintrc.js +15 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +7 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/messages.js +20 -0
- package/dist/cjs/nodeviews/blockCard.js +164 -0
- package/dist/cjs/nodeviews/datasource.js +173 -0
- package/dist/cjs/nodeviews/embedCard.js +398 -0
- package/dist/cjs/nodeviews/genericCard.js +118 -0
- package/dist/cjs/nodeviews/inlineCard.js +132 -0
- package/dist/cjs/plugin.js +138 -0
- package/dist/cjs/pm-plugins/actions.js +122 -0
- package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +48 -0
- package/dist/cjs/pm-plugins/analytics/events-from-tr.js +359 -0
- package/dist/cjs/pm-plugins/analytics/index.js +19 -0
- package/dist/cjs/pm-plugins/analytics/types.js +5 -0
- package/dist/cjs/pm-plugins/analytics/utils.js +178 -0
- package/dist/cjs/pm-plugins/doc.js +479 -0
- package/dist/cjs/pm-plugins/keymap.js +64 -0
- package/dist/cjs/pm-plugins/main.js +212 -0
- package/dist/cjs/pm-plugins/mountHyperlink.js +47 -0
- package/dist/cjs/pm-plugins/plugin-key.js +9 -0
- package/dist/cjs/pm-plugins/reducers.js +111 -0
- package/dist/cjs/pm-plugins/shouldReplaceLink.js +35 -0
- package/dist/cjs/pm-plugins/util/resolve.js +59 -0
- package/dist/cjs/pm-plugins/util/state.js +49 -0
- package/dist/cjs/toolbar.js +364 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/DatasourceModal/ModalWithState.js +25 -0
- package/dist/cjs/ui/DatasourceModal/index.js +60 -0
- package/dist/cjs/ui/EditLinkToolbar.js +258 -0
- package/dist/cjs/ui/EditorSmartCardEvents.js +21 -0
- package/dist/cjs/ui/EditorSmartCardEventsNext.js +215 -0
- package/dist/cjs/ui/HyperlinkToolbarAppearance.js +174 -0
- package/dist/cjs/ui/LayoutButton/index.js +121 -0
- package/dist/cjs/ui/LayoutButton/types.js +5 -0
- package/dist/cjs/ui/LayoutButton/utils.js +19 -0
- package/dist/cjs/ui/LinkToolbarAppearance.js +152 -0
- package/dist/cjs/ui/ResizableEmbedCard.js +364 -0
- package/dist/cjs/ui/SmallerEditIcon.js +22 -0
- package/dist/cjs/utils.js +60 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/messages.js +13 -0
- package/dist/es2019/nodeviews/blockCard.js +131 -0
- package/dist/es2019/nodeviews/datasource.js +137 -0
- package/dist/es2019/nodeviews/embedCard.js +370 -0
- package/dist/es2019/nodeviews/genericCard.js +92 -0
- package/dist/es2019/nodeviews/inlineCard.js +113 -0
- package/dist/es2019/plugin.js +129 -0
- package/dist/es2019/pm-plugins/actions.js +57 -0
- package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +38 -0
- package/dist/es2019/pm-plugins/analytics/events-from-tr.js +339 -0
- package/dist/es2019/pm-plugins/analytics/index.js +2 -0
- package/dist/es2019/pm-plugins/analytics/types.js +1 -0
- package/dist/es2019/pm-plugins/analytics/utils.js +160 -0
- package/dist/es2019/pm-plugins/doc.js +451 -0
- package/dist/es2019/pm-plugins/keymap.js +59 -0
- package/dist/es2019/pm-plugins/main.js +208 -0
- package/dist/es2019/pm-plugins/mountHyperlink.js +37 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/reducers.js +110 -0
- package/dist/es2019/pm-plugins/shouldReplaceLink.js +25 -0
- package/dist/es2019/pm-plugins/util/resolve.js +50 -0
- package/dist/es2019/pm-plugins/util/state.js +26 -0
- package/dist/es2019/toolbar.js +359 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/DatasourceModal/ModalWithState.js +19 -0
- package/dist/es2019/ui/DatasourceModal/index.js +48 -0
- package/dist/es2019/ui/EditLinkToolbar.js +226 -0
- package/dist/es2019/ui/EditorSmartCardEvents.js +15 -0
- package/dist/es2019/ui/EditorSmartCardEventsNext.js +199 -0
- package/dist/es2019/ui/HyperlinkToolbarAppearance.js +86 -0
- package/dist/es2019/ui/LayoutButton/index.js +114 -0
- package/dist/es2019/ui/LayoutButton/types.js +1 -0
- package/dist/es2019/ui/LayoutButton/utils.js +15 -0
- package/dist/es2019/ui/LinkToolbarAppearance.js +118 -0
- package/dist/es2019/ui/ResizableEmbedCard.js +335 -0
- package/dist/es2019/ui/SmallerEditIcon.js +14 -0
- package/dist/es2019/utils.js +46 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/messages.js +13 -0
- package/dist/esm/nodeviews/blockCard.js +156 -0
- package/dist/esm/nodeviews/datasource.js +165 -0
- package/dist/esm/nodeviews/embedCard.js +389 -0
- package/dist/esm/nodeviews/genericCard.js +111 -0
- package/dist/esm/nodeviews/inlineCard.js +124 -0
- package/dist/esm/plugin.js +130 -0
- package/dist/esm/pm-plugins/actions.js +102 -0
- package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +41 -0
- package/dist/esm/pm-plugins/analytics/events-from-tr.js +350 -0
- package/dist/esm/pm-plugins/analytics/index.js +2 -0
- package/dist/esm/pm-plugins/analytics/types.js +1 -0
- package/dist/esm/pm-plugins/analytics/utils.js +160 -0
- package/dist/esm/pm-plugins/doc.js +460 -0
- package/dist/esm/pm-plugins/keymap.js +58 -0
- package/dist/esm/pm-plugins/main.js +199 -0
- package/dist/esm/pm-plugins/mountHyperlink.js +39 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/reducers.js +103 -0
- package/dist/esm/pm-plugins/shouldReplaceLink.js +29 -0
- package/dist/esm/pm-plugins/util/resolve.js +52 -0
- package/dist/esm/pm-plugins/util/state.js +40 -0
- package/dist/esm/toolbar.js +350 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/DatasourceModal/ModalWithState.js +17 -0
- package/dist/esm/ui/DatasourceModal/index.js +49 -0
- package/dist/esm/ui/EditLinkToolbar.js +244 -0
- package/dist/esm/ui/EditorSmartCardEvents.js +14 -0
- package/dist/esm/ui/EditorSmartCardEventsNext.js +203 -0
- package/dist/esm/ui/HyperlinkToolbarAppearance.js +163 -0
- package/dist/esm/ui/LayoutButton/index.js +110 -0
- package/dist/esm/ui/LayoutButton/types.js +1 -0
- package/dist/esm/ui/LayoutButton/utils.js +12 -0
- package/dist/esm/ui/LinkToolbarAppearance.js +141 -0
- package/dist/esm/ui/ResizableEmbedCard.js +358 -0
- package/dist/esm/ui/SmallerEditIcon.js +14 -0
- package/dist/esm/utils.js +48 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/messages.d.ts +12 -0
- package/dist/types/nodeviews/blockCard.d.ts +26 -0
- package/dist/types/nodeviews/datasource.d.ts +42 -0
- package/dist/types/nodeviews/embedCard.d.ts +46 -0
- package/dist/types/nodeviews/genericCard.d.ts +37 -0
- package/dist/types/nodeviews/inlineCard.d.ts +23 -0
- package/dist/types/plugin.d.ts +24 -0
- package/dist/types/pm-plugins/actions.d.ts +23 -0
- package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
- package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +17 -0
- package/dist/types/pm-plugins/analytics/index.d.ts +2 -0
- package/dist/types/pm-plugins/analytics/types.d.ts +12 -0
- package/dist/types/pm-plugins/analytics/utils.d.ts +32 -0
- package/dist/types/pm-plugins/doc.d.ts +22 -0
- package/dist/types/pm-plugins/keymap.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +6 -0
- package/dist/types/pm-plugins/mountHyperlink.d.ts +5 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/reducers.d.ts +3 -0
- package/dist/types/pm-plugins/shouldReplaceLink.d.ts +2 -0
- package/dist/types/pm-plugins/util/resolve.d.ts +8 -0
- package/dist/types/pm-plugins/util/state.d.ts +31 -0
- package/dist/types/toolbar.d.ts +9 -0
- package/dist/types/types.d.ts +163 -0
- package/dist/types/ui/DatasourceModal/ModalWithState.d.ts +9 -0
- package/dist/types/ui/DatasourceModal/index.d.ts +11 -0
- package/dist/types/ui/EditLinkToolbar.d.ts +47 -0
- package/dist/types/ui/EditorSmartCardEvents.d.ts +5 -0
- package/dist/types/ui/EditorSmartCardEventsNext.d.ts +18 -0
- package/dist/types/ui/HyperlinkToolbarAppearance.d.ts +32 -0
- package/dist/types/ui/LayoutButton/index.d.ts +9 -0
- package/dist/types/ui/LayoutButton/types.d.ts +19 -0
- package/dist/types/ui/LayoutButton/utils.d.ts +5 -0
- package/dist/types/ui/LinkToolbarAppearance.d.ts +29 -0
- package/dist/types/ui/ResizableEmbedCard.d.ts +61 -0
- package/dist/types/ui/SmallerEditIcon.d.ts +3 -0
- package/dist/types/utils.d.ts +19 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/messages.d.ts +12 -0
- package/dist/types-ts4.5/nodeviews/blockCard.d.ts +26 -0
- package/dist/types-ts4.5/nodeviews/datasource.d.ts +42 -0
- package/dist/types-ts4.5/nodeviews/embedCard.d.ts +46 -0
- package/dist/types-ts4.5/nodeviews/genericCard.d.ts +37 -0
- package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +23 -0
- package/dist/types-ts4.5/plugin.d.ts +24 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +23 -0
- package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +17 -0
- package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +32 -0
- package/dist/types-ts4.5/pm-plugins/doc.d.ts +22 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/mountHyperlink.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/reducers.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/util/state.d.ts +31 -0
- package/dist/types-ts4.5/toolbar.d.ts +9 -0
- package/dist/types-ts4.5/types.d.ts +163 -0
- package/dist/types-ts4.5/ui/DatasourceModal/ModalWithState.d.ts +9 -0
- package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +11 -0
- package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +47 -0
- package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +5 -0
- package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +18 -0
- package/dist/types-ts4.5/ui/HyperlinkToolbarAppearance.d.ts +32 -0
- package/dist/types-ts4.5/ui/LayoutButton/index.d.ts +9 -0
- package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +19 -0
- package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +5 -0
- package/dist/types-ts4.5/ui/LinkToolbarAppearance.d.ts +29 -0
- package/dist/types-ts4.5/ui/ResizableEmbedCard.d.ts +61 -0
- package/dist/types-ts4.5/ui/SmallerEditIcon.d.ts +3 -0
- package/dist/types-ts4.5/utils.d.ts +19 -0
- package/package.json +126 -0
- package/report.api.md +146 -0
- package/tmp/api-report-tmp.d.ts +117 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import rafSchedule from 'raf-schd';
|
|
6
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
7
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
8
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
9
|
+
import { findOverflowScrollParent, MediaSingle as RichMediaWrapper, UnsupportedBlock } from '@atlaskit/editor-common/ui';
|
|
10
|
+
import { floatingLayouts, isRichMediaInsideOfBlockNode } from '@atlaskit/editor-common/utils';
|
|
11
|
+
import { DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
|
|
12
|
+
import { EmbedResizeMessageListener, Card as SmartCard } from '@atlaskit/smart-card';
|
|
13
|
+
import { registerCard } from '../pm-plugins/actions';
|
|
14
|
+
import ResizableEmbedCard from '../ui/ResizableEmbedCard';
|
|
15
|
+
import { Card } from './genericCard';
|
|
16
|
+
const CardInner = ({
|
|
17
|
+
pluginInjectionApi,
|
|
18
|
+
getPosSafely,
|
|
19
|
+
getLineLength,
|
|
20
|
+
view,
|
|
21
|
+
smartCard,
|
|
22
|
+
eventDispatcher,
|
|
23
|
+
updateSize,
|
|
24
|
+
getPos,
|
|
25
|
+
aspectRatio,
|
|
26
|
+
allowResizing,
|
|
27
|
+
hasPreview,
|
|
28
|
+
heightAlone,
|
|
29
|
+
cardProps,
|
|
30
|
+
dispatchAnalyticsEvent
|
|
31
|
+
}) => {
|
|
32
|
+
const {
|
|
33
|
+
widthState
|
|
34
|
+
} = useSharedPluginState(pluginInjectionApi, ['width']);
|
|
35
|
+
const widthStateLineLength = (widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || 0;
|
|
36
|
+
const widthStateWidth = (widthState === null || widthState === void 0 ? void 0 : widthState.width) || 0;
|
|
37
|
+
const pos = getPosSafely();
|
|
38
|
+
if (pos === undefined) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const lineLength = getLineLength(view, pos, widthStateLineLength);
|
|
42
|
+
const containerWidth = isRichMediaInsideOfBlockNode(view, pos) ? lineLength : widthStateWidth;
|
|
43
|
+
if (!allowResizing || !hasPreview) {
|
|
44
|
+
// There are two ways `width` and `height` can be defined here:
|
|
45
|
+
// 1) Either as `heightAlone` as height value and no width
|
|
46
|
+
// 2) or as `1` for height and aspectRation (defined or a default one) as a width
|
|
47
|
+
// See above for how aspectRation is calculated.
|
|
48
|
+
const defaultAspectRatio = DEFAULT_EMBED_CARD_WIDTH / DEFAULT_EMBED_CARD_HEIGHT;
|
|
49
|
+
let richMediaWrapperHeight = 1;
|
|
50
|
+
let richMediaWrapperWidth = aspectRatio || defaultAspectRatio;
|
|
51
|
+
if (heightAlone) {
|
|
52
|
+
richMediaWrapperHeight = heightAlone;
|
|
53
|
+
richMediaWrapperWidth = undefined;
|
|
54
|
+
}
|
|
55
|
+
return /*#__PURE__*/React.createElement(RichMediaWrapper, _extends({}, cardProps, {
|
|
56
|
+
height: richMediaWrapperHeight,
|
|
57
|
+
width: richMediaWrapperWidth,
|
|
58
|
+
nodeType: "embedCard",
|
|
59
|
+
hasFallbackContainer: hasPreview,
|
|
60
|
+
lineLength: lineLength,
|
|
61
|
+
containerWidth: containerWidth
|
|
62
|
+
}), smartCard);
|
|
63
|
+
}
|
|
64
|
+
const displayGrid = (visible, gridType, highlight) => {
|
|
65
|
+
var _pluginInjectionApi$d;
|
|
66
|
+
return pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.grid.actions) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.displayGrid(view)({
|
|
67
|
+
visible,
|
|
68
|
+
gridType,
|
|
69
|
+
highlight: highlight
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
return /*#__PURE__*/React.createElement(ResizableEmbedCard, _extends({}, cardProps, {
|
|
73
|
+
height: heightAlone,
|
|
74
|
+
aspectRatio: aspectRatio,
|
|
75
|
+
view: view,
|
|
76
|
+
getPos: getPos,
|
|
77
|
+
lineLength: lineLength,
|
|
78
|
+
gridSize: 12,
|
|
79
|
+
containerWidth: containerWidth,
|
|
80
|
+
displayGrid: displayGrid,
|
|
81
|
+
updateSize: updateSize,
|
|
82
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
83
|
+
}), smartCard);
|
|
84
|
+
};
|
|
85
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
86
|
+
export class EmbedCardComponent extends React.PureComponent {
|
|
87
|
+
constructor(...args) {
|
|
88
|
+
super(...args);
|
|
89
|
+
_defineProperty(this, "embedIframeRef", /*#__PURE__*/React.createRef());
|
|
90
|
+
_defineProperty(this, "onClick", () => {});
|
|
91
|
+
_defineProperty(this, "state", {
|
|
92
|
+
hasPreview: true
|
|
93
|
+
});
|
|
94
|
+
_defineProperty(this, "getPosSafely", () => {
|
|
95
|
+
const {
|
|
96
|
+
getPos
|
|
97
|
+
} = this.props;
|
|
98
|
+
if (!getPos || typeof getPos === 'boolean') {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
return getPos();
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// Can blow up in rare cases, when node has been removed.
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
_defineProperty(this, "onResolve", data => {
|
|
108
|
+
const {
|
|
109
|
+
view
|
|
110
|
+
} = this.props;
|
|
111
|
+
const {
|
|
112
|
+
title,
|
|
113
|
+
url,
|
|
114
|
+
aspectRatio
|
|
115
|
+
} = data;
|
|
116
|
+
const {
|
|
117
|
+
originalHeight,
|
|
118
|
+
originalWidth
|
|
119
|
+
} = this.props.node.attrs;
|
|
120
|
+
if (aspectRatio && !originalHeight && !originalWidth) {
|
|
121
|
+
// Assumption here is if ADF already have both height and width set,
|
|
122
|
+
// we will going to use that later on in this class as aspectRatio
|
|
123
|
+
// Most likely we dealing with an embed that received aspectRatio via onResolve previously
|
|
124
|
+
// and now this information already stored in ADF.
|
|
125
|
+
this.setState({
|
|
126
|
+
initialAspectRatio: aspectRatio
|
|
127
|
+
});
|
|
128
|
+
this.saveOriginalDimensionsAttributes(DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_HEIGHT * aspectRatio);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// don't dispatch immediately since we might be in the middle of
|
|
132
|
+
// rendering a nodeview
|
|
133
|
+
rafSchedule(() => {
|
|
134
|
+
const pos = this.getPosSafely();
|
|
135
|
+
if (pos === undefined) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
return view.dispatch(registerCard({
|
|
139
|
+
title,
|
|
140
|
+
url,
|
|
141
|
+
pos
|
|
142
|
+
})(view.state.tr));
|
|
143
|
+
})();
|
|
144
|
+
try {
|
|
145
|
+
const cardContext = this.context.contextAdapter ? this.context.contextAdapter.card : undefined;
|
|
146
|
+
const hasPreview = cardContext && cardContext.value.extractors.getPreview(url, this.props.platform);
|
|
147
|
+
if (!hasPreview) {
|
|
148
|
+
this.setState({
|
|
149
|
+
hasPreview: false
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {}
|
|
153
|
+
});
|
|
154
|
+
_defineProperty(this, "updateSize", (pctWidth, layout) => {
|
|
155
|
+
const {
|
|
156
|
+
state,
|
|
157
|
+
dispatch
|
|
158
|
+
} = this.props.view;
|
|
159
|
+
const pos = this.getPosSafely();
|
|
160
|
+
if (pos === undefined) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const tr = state.tr.setNodeMarkup(pos, undefined, {
|
|
164
|
+
...this.props.node.attrs,
|
|
165
|
+
width: pctWidth,
|
|
166
|
+
layout
|
|
167
|
+
});
|
|
168
|
+
tr.setMeta('scrollIntoView', false);
|
|
169
|
+
dispatch(tr);
|
|
170
|
+
return true;
|
|
171
|
+
});
|
|
172
|
+
_defineProperty(this, "getLineLength", (view, pos, originalLineLength) => {
|
|
173
|
+
if (typeof pos === 'number' && isRichMediaInsideOfBlockNode(view, pos)) {
|
|
174
|
+
const $pos = view.state.doc.resolve(pos);
|
|
175
|
+
const domNode = view.nodeDOM($pos.pos);
|
|
176
|
+
if ($pos.nodeAfter && floatingLayouts.indexOf($pos.nodeAfter.attrs.layout) > -1 && domNode && domNode.parentElement) {
|
|
177
|
+
return domNode.parentElement.offsetWidth;
|
|
178
|
+
}
|
|
179
|
+
if (domNode instanceof HTMLElement) {
|
|
180
|
+
return domNode.offsetWidth;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return originalLineLength;
|
|
184
|
+
});
|
|
185
|
+
/**
|
|
186
|
+
* Even though render is capable of listening and reacting to iframely wrapper iframe sent `resize` events
|
|
187
|
+
* it's good idea to store latest actual height in ADF, so that when renderer (well, editor as well) is loading
|
|
188
|
+
* we will show embed window of appropriate size and avoid unnecessary content jumping.
|
|
189
|
+
*/
|
|
190
|
+
_defineProperty(this, "saveOriginalDimensionsAttributes", (height, width) => {
|
|
191
|
+
const {
|
|
192
|
+
view
|
|
193
|
+
} = this.props;
|
|
194
|
+
|
|
195
|
+
// TODO: ED-15663
|
|
196
|
+
// Please, do not copy or use this kind of code below
|
|
197
|
+
// @ts-ignore
|
|
198
|
+
const fakeTableResizePluginKey = {
|
|
199
|
+
key: 'tableFlexiColumnResizing$',
|
|
200
|
+
getState: state => {
|
|
201
|
+
// eslint-disable-next-line
|
|
202
|
+
return state['tableFlexiColumnResizing$'];
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const fakeTableResizeState = fakeTableResizePluginKey.getState(view.state);
|
|
206
|
+
|
|
207
|
+
// We are not updating ADF when this function fired while table is resizing.
|
|
208
|
+
// Changing ADF in the middle of resize will break table resize plugin logic
|
|
209
|
+
// (tables will be considered different at the end of the drag and cell size won't be stored)
|
|
210
|
+
// But this is not a big problem, editor user will be seeing latest height anyway (via updated state)
|
|
211
|
+
// And even if page to be saved with slightly outdated height, renderer is capable of reading latest height value
|
|
212
|
+
// when embed loads, and so it won't be a problem.
|
|
213
|
+
if (fakeTableResizeState !== null && fakeTableResizeState !== void 0 && fakeTableResizeState.dragging) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
rafSchedule(() => {
|
|
217
|
+
const pos = this.getPosSafely();
|
|
218
|
+
if (pos === undefined) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
view.dispatch(view.state.tr.step(new SetAttrsStep(pos, {
|
|
222
|
+
originalHeight: height,
|
|
223
|
+
originalWidth: width
|
|
224
|
+
})).setMeta('addToHistory', false));
|
|
225
|
+
})();
|
|
226
|
+
});
|
|
227
|
+
_defineProperty(this, "onHeightUpdate", height => {
|
|
228
|
+
this.setState({
|
|
229
|
+
liveHeight: height
|
|
230
|
+
});
|
|
231
|
+
this.saveOriginalDimensionsAttributes(height, undefined);
|
|
232
|
+
});
|
|
233
|
+
_defineProperty(this, "onError", ({
|
|
234
|
+
err
|
|
235
|
+
}) => {
|
|
236
|
+
if (err) {
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
UNSAFE_componentWillMount() {
|
|
242
|
+
const {
|
|
243
|
+
view
|
|
244
|
+
} = this.props;
|
|
245
|
+
const scrollContainer = findOverflowScrollParent(view.dom);
|
|
246
|
+
this.scrollContainer = scrollContainer || undefined;
|
|
247
|
+
}
|
|
248
|
+
render() {
|
|
249
|
+
const {
|
|
250
|
+
node,
|
|
251
|
+
cardContext,
|
|
252
|
+
platform,
|
|
253
|
+
allowResizing,
|
|
254
|
+
fullWidthMode,
|
|
255
|
+
view,
|
|
256
|
+
dispatchAnalyticsEvent,
|
|
257
|
+
getPos,
|
|
258
|
+
pluginInjectionApi
|
|
259
|
+
} = this.props;
|
|
260
|
+
let {
|
|
261
|
+
url,
|
|
262
|
+
width: pctWidth,
|
|
263
|
+
layout,
|
|
264
|
+
originalHeight,
|
|
265
|
+
originalWidth
|
|
266
|
+
} = node.attrs;
|
|
267
|
+
const {
|
|
268
|
+
hasPreview,
|
|
269
|
+
liveHeight,
|
|
270
|
+
initialAspectRatio
|
|
271
|
+
} = this.state;
|
|
272
|
+
|
|
273
|
+
// We don't want to use `originalHeight` when `originalWidth` also present,
|
|
274
|
+
// since `heightAlone` is defined only when just height is available.
|
|
275
|
+
let heightAlone = liveHeight !== null && liveHeight !== void 0 ? liveHeight : !originalWidth && originalHeight || undefined;
|
|
276
|
+
const aspectRatio = !heightAlone && (
|
|
277
|
+
// No need getting aspectRatio if heightAlone defined already
|
|
278
|
+
initialAspectRatio ||
|
|
279
|
+
// If we have initialAspectRatio (coming from iframely) we should go with that
|
|
280
|
+
originalHeight && originalWidth && originalWidth / originalHeight) ||
|
|
281
|
+
// If ADF contains both width and height we get ratio from that
|
|
282
|
+
undefined;
|
|
283
|
+
const cardProps = {
|
|
284
|
+
layout,
|
|
285
|
+
pctWidth,
|
|
286
|
+
fullWidthMode
|
|
287
|
+
};
|
|
288
|
+
const smartCard = /*#__PURE__*/React.createElement(SmartCard, {
|
|
289
|
+
key: url,
|
|
290
|
+
url: url,
|
|
291
|
+
appearance: "embed",
|
|
292
|
+
onClick: this.onClick,
|
|
293
|
+
onResolve: this.onResolve,
|
|
294
|
+
onError: this.onError,
|
|
295
|
+
showActions: platform === 'web',
|
|
296
|
+
isFrameVisible: true,
|
|
297
|
+
inheritDimensions: true,
|
|
298
|
+
platform: platform,
|
|
299
|
+
container: this.scrollContainer,
|
|
300
|
+
embedIframeRef: this.embedIframeRef
|
|
301
|
+
});
|
|
302
|
+
const cardInner = /*#__PURE__*/React.createElement(EmbedResizeMessageListener, {
|
|
303
|
+
embedIframeRef: this.embedIframeRef,
|
|
304
|
+
onHeightUpdate: this.onHeightUpdate
|
|
305
|
+
}, /*#__PURE__*/React.createElement(CardInner, {
|
|
306
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
307
|
+
smartCard: smartCard,
|
|
308
|
+
hasPreview: hasPreview,
|
|
309
|
+
getPosSafely: this.getPosSafely,
|
|
310
|
+
view: view,
|
|
311
|
+
getLineLength: this.getLineLength,
|
|
312
|
+
eventDispatcher: this.props.eventDispatcher,
|
|
313
|
+
updateSize: this.updateSize,
|
|
314
|
+
getPos: getPos,
|
|
315
|
+
aspectRatio: aspectRatio,
|
|
316
|
+
allowResizing: allowResizing,
|
|
317
|
+
heightAlone: heightAlone,
|
|
318
|
+
cardProps: cardProps,
|
|
319
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
320
|
+
}));
|
|
321
|
+
|
|
322
|
+
// [WS-2307]: we only render card wrapped into a Provider when the value is ready
|
|
323
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
|
|
324
|
+
value: cardContext.value
|
|
325
|
+
}, cardInner) : null);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
_defineProperty(EmbedCardComponent, "contextTypes", {
|
|
329
|
+
contextAdapter: PropTypes.object
|
|
330
|
+
});
|
|
331
|
+
const WrappedBlockCard = Card(EmbedCardComponent, UnsupportedBlock);
|
|
332
|
+
export class EmbedCard extends ReactNodeView {
|
|
333
|
+
viewShouldUpdate(nextNode) {
|
|
334
|
+
if (this.node.attrs !== nextNode.attrs) {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
return super.viewShouldUpdate(nextNode);
|
|
338
|
+
}
|
|
339
|
+
createDomRef() {
|
|
340
|
+
const domRef = document.createElement('div');
|
|
341
|
+
if (this.reactComponentProps.platform !== 'mobile') {
|
|
342
|
+
// workaround Chrome bug in https://product-fabric.atlassian.net/browse/ED-5379
|
|
343
|
+
// see also: https://github.com/ProseMirror/prosemirror/issues/884
|
|
344
|
+
domRef.contentEditable = 'true';
|
|
345
|
+
domRef.setAttribute('spellcheck', 'false');
|
|
346
|
+
}
|
|
347
|
+
return domRef;
|
|
348
|
+
}
|
|
349
|
+
render() {
|
|
350
|
+
const {
|
|
351
|
+
eventDispatcher,
|
|
352
|
+
allowResizing,
|
|
353
|
+
platform,
|
|
354
|
+
fullWidthMode,
|
|
355
|
+
dispatchAnalyticsEvent,
|
|
356
|
+
pluginInjectionApi
|
|
357
|
+
} = this.reactComponentProps;
|
|
358
|
+
return /*#__PURE__*/React.createElement(WrappedBlockCard, {
|
|
359
|
+
node: this.node,
|
|
360
|
+
view: this.view,
|
|
361
|
+
eventDispatcher: eventDispatcher,
|
|
362
|
+
getPos: this.getPos,
|
|
363
|
+
allowResizing: allowResizing,
|
|
364
|
+
platform: platform,
|
|
365
|
+
fullWidthMode: fullWidthMode,
|
|
366
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
367
|
+
pluginInjectionApi: pluginInjectionApi
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { isSafeUrl } from '@atlaskit/adf-schema';
|
|
6
|
+
import { AnalyticsContext } from '@atlaskit/analytics-next';
|
|
7
|
+
import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
|
|
8
|
+
import { changeSelectedCardToLinkFallback } from '../pm-plugins/doc';
|
|
9
|
+
import { getPluginState } from '../pm-plugins/util/state';
|
|
10
|
+
import { titleUrlPairFromNode } from '../utils';
|
|
11
|
+
export function Card(SmartCardComponent, UnsupportedComponent) {
|
|
12
|
+
var _class;
|
|
13
|
+
return _class = class extends React.Component {
|
|
14
|
+
constructor(...args) {
|
|
15
|
+
super(...args);
|
|
16
|
+
_defineProperty(this, "state", {
|
|
17
|
+
isError: false
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
var _getPluginState;
|
|
22
|
+
const {
|
|
23
|
+
url
|
|
24
|
+
} = titleUrlPairFromNode(this.props.node);
|
|
25
|
+
if (url && !isSafeUrl(url)) {
|
|
26
|
+
return /*#__PURE__*/React.createElement(UnsupportedComponent, null);
|
|
27
|
+
}
|
|
28
|
+
if (this.state.isError) {
|
|
29
|
+
if (url) {
|
|
30
|
+
return /*#__PURE__*/React.createElement("a", {
|
|
31
|
+
href: url,
|
|
32
|
+
onClick: e => {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
}
|
|
35
|
+
}, url);
|
|
36
|
+
} else {
|
|
37
|
+
return /*#__PURE__*/React.createElement(UnsupportedComponent, null);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const cardContext = this.context.contextAdapter ? this.context.contextAdapter.card : undefined;
|
|
41
|
+
const editorAppearance = (_getPluginState = getPluginState(this.props.view.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance;
|
|
42
|
+
const analyticsEditorAppearance = getAnalyticsEditorAppearance(editorAppearance);
|
|
43
|
+
return /*#__PURE__*/React.createElement(AnalyticsContext, {
|
|
44
|
+
data: {
|
|
45
|
+
attributes: {
|
|
46
|
+
location: analyticsEditorAppearance
|
|
47
|
+
},
|
|
48
|
+
// Below is added for the future implementation of Linking Platform namespaced analytics context
|
|
49
|
+
location: analyticsEditorAppearance
|
|
50
|
+
}
|
|
51
|
+
}, /*#__PURE__*/React.createElement(SmartCardComponent, _extends({
|
|
52
|
+
key: url,
|
|
53
|
+
cardContext: cardContext
|
|
54
|
+
}, this.props)));
|
|
55
|
+
}
|
|
56
|
+
componentDidCatch(error) {
|
|
57
|
+
const maybeAPIError = error;
|
|
58
|
+
// NB: errors received in this component are propagated by the `@atlaskit/smart-card` component.
|
|
59
|
+
// Depending on the kind of error, the expectation for this component is to either:
|
|
60
|
+
// (1) Render a blue link whilst retaining `inlineCard` in the ADF (non-fatal errs);
|
|
61
|
+
// (2) Render a blue link whilst downgrading to `link` in the ADF (fatal errs).
|
|
62
|
+
|
|
63
|
+
if (maybeAPIError.kind && maybeAPIError.kind === 'fatal') {
|
|
64
|
+
var _pluginInjectionApi$d;
|
|
65
|
+
this.setState({
|
|
66
|
+
isError: true
|
|
67
|
+
});
|
|
68
|
+
const {
|
|
69
|
+
view,
|
|
70
|
+
node,
|
|
71
|
+
getPos,
|
|
72
|
+
pluginInjectionApi
|
|
73
|
+
} = this.props;
|
|
74
|
+
const {
|
|
75
|
+
url
|
|
76
|
+
} = titleUrlPairFromNode(node);
|
|
77
|
+
if (!getPos || typeof getPos === 'boolean') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
changeSelectedCardToLinkFallback(undefined, url, true, node, getPos(), pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.actions)(view.state, view.dispatch);
|
|
81
|
+
return null;
|
|
82
|
+
} else {
|
|
83
|
+
// Otherwise, render a blue link as fallback (above in render()).
|
|
84
|
+
this.setState({
|
|
85
|
+
isError: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, _defineProperty(_class, "contextTypes", {
|
|
90
|
+
contextAdapter: PropTypes.object
|
|
91
|
+
}), _class;
|
|
92
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import rafSchedule from 'raf-schd';
|
|
5
|
+
import { findOverflowScrollParent, UnsupportedInline } from '@atlaskit/editor-common/ui';
|
|
6
|
+
import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
7
|
+
import { registerCard } from '../pm-plugins/actions';
|
|
8
|
+
import { Card } from './genericCard';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
11
|
+
export class InlineCardComponent extends React.PureComponent {
|
|
12
|
+
constructor(...args) {
|
|
13
|
+
super(...args);
|
|
14
|
+
_defineProperty(this, "onClick", () => {});
|
|
15
|
+
_defineProperty(this, "onResolve", data => {
|
|
16
|
+
const {
|
|
17
|
+
getPos,
|
|
18
|
+
view
|
|
19
|
+
} = this.props;
|
|
20
|
+
if (!getPos || typeof getPos === 'boolean') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const {
|
|
24
|
+
title,
|
|
25
|
+
url
|
|
26
|
+
} = data;
|
|
27
|
+
// don't dispatch immediately since we might be in the middle of
|
|
28
|
+
// rendering a nodeview
|
|
29
|
+
rafSchedule(() => {
|
|
30
|
+
// prosemirror-bump-fix
|
|
31
|
+
const pos = getPos();
|
|
32
|
+
if (typeof pos !== 'number') {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
view.dispatch(registerCard({
|
|
36
|
+
title,
|
|
37
|
+
url,
|
|
38
|
+
pos
|
|
39
|
+
})(view.state.tr));
|
|
40
|
+
})();
|
|
41
|
+
});
|
|
42
|
+
_defineProperty(this, "onError", data => {
|
|
43
|
+
const {
|
|
44
|
+
url,
|
|
45
|
+
err
|
|
46
|
+
} = data;
|
|
47
|
+
if (err) {
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
this.onResolve({
|
|
51
|
+
url
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
UNSAFE_componentWillMount() {
|
|
56
|
+
const {
|
|
57
|
+
view
|
|
58
|
+
} = this.props;
|
|
59
|
+
const scrollContainer = findOverflowScrollParent(view.dom);
|
|
60
|
+
this.scrollContainer = scrollContainer || undefined;
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
const {
|
|
64
|
+
node,
|
|
65
|
+
cardContext,
|
|
66
|
+
showServerActions,
|
|
67
|
+
useAlternativePreloader
|
|
68
|
+
} = this.props;
|
|
69
|
+
const {
|
|
70
|
+
url,
|
|
71
|
+
data
|
|
72
|
+
} = node.attrs;
|
|
73
|
+
const card = /*#__PURE__*/React.createElement("span", {
|
|
74
|
+
className: "card"
|
|
75
|
+
}, /*#__PURE__*/React.createElement(SmartCard, {
|
|
76
|
+
key: url,
|
|
77
|
+
url: url,
|
|
78
|
+
data: data,
|
|
79
|
+
appearance: "inline",
|
|
80
|
+
onClick: this.onClick,
|
|
81
|
+
container: this.scrollContainer,
|
|
82
|
+
onResolve: this.onResolve,
|
|
83
|
+
onError: this.onError,
|
|
84
|
+
inlinePreloaderStyle: useAlternativePreloader ? 'on-right-without-skeleton' : undefined,
|
|
85
|
+
showServerActions: showServerActions
|
|
86
|
+
}));
|
|
87
|
+
// [WS-2307]: we only render card wrapped into a Provider when the value is ready,
|
|
88
|
+
// otherwise if we got data, we can render the card directly since it doesn't need the Provider
|
|
89
|
+
return cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
|
|
90
|
+
value: cardContext.value
|
|
91
|
+
}, card) : data ? card : null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_defineProperty(InlineCardComponent, "contextTypes", {
|
|
95
|
+
contextAdapter: PropTypes.object
|
|
96
|
+
});
|
|
97
|
+
const WrappedInlineCard = Card(InlineCardComponent, UnsupportedInline);
|
|
98
|
+
export function InlineCardNodeView(props) {
|
|
99
|
+
const {
|
|
100
|
+
useAlternativePreloader,
|
|
101
|
+
node,
|
|
102
|
+
view,
|
|
103
|
+
getPos,
|
|
104
|
+
showServerActions
|
|
105
|
+
} = props;
|
|
106
|
+
return /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
107
|
+
node: node,
|
|
108
|
+
view: view,
|
|
109
|
+
getPos: getPos,
|
|
110
|
+
showServerActions: showServerActions,
|
|
111
|
+
useAlternativePreloader: useAlternativePreloader
|
|
112
|
+
});
|
|
113
|
+
}
|