@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,199 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { NodeSelection } from 'prosemirror-state';
|
|
3
|
+
import { findDomRefAtPos } from 'prosemirror-utils';
|
|
4
|
+
import rafSchedule from 'raf-schd';
|
|
5
|
+
import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/styles';
|
|
8
|
+
import { canRenderDatasource } from '@atlaskit/editor-common/utils';
|
|
9
|
+
import { BlockCard } from '../nodeviews/blockCard';
|
|
10
|
+
import { Datasource } from '../nodeviews/datasource';
|
|
11
|
+
import { EmbedCard } from '../nodeviews/embedCard';
|
|
12
|
+
import { InlineCardNodeView } from '../nodeviews/inlineCard';
|
|
13
|
+
import { setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
|
|
14
|
+
import { createAnalyticsQueue, eventsFromTransaction } from './analytics';
|
|
15
|
+
import { pluginKey } from './plugin-key';
|
|
16
|
+
import reducer from './reducers';
|
|
17
|
+
import { handleProvider, resolveWithProvider } from './util/resolve';
|
|
18
|
+
import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
|
|
19
|
+
export { pluginKey } from './plugin-key';
|
|
20
|
+
export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
21
|
+
return function (pmPluginFactoryParams) {
|
|
22
|
+
var lpAnalyticsEventsNext = pmPluginFactoryParams.featureFlags.lpAnalyticsEventsNext;
|
|
23
|
+
var analyticsQueue = createAnalyticsQueue(!!lpAnalyticsEventsNext);
|
|
24
|
+
var editorAppearance = options.editorAppearance,
|
|
25
|
+
platform = options.platform,
|
|
26
|
+
allowResizing = options.allowResizing,
|
|
27
|
+
useAlternativePreloader = options.useAlternativePreloader,
|
|
28
|
+
fullWidthMode = options.fullWidthMode,
|
|
29
|
+
showServerActions = options.showServerActions;
|
|
30
|
+
var inlineCardViewProducer = getInlineNodeViewProducer({
|
|
31
|
+
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
32
|
+
Component: InlineCardNodeView,
|
|
33
|
+
extraComponentProps: {
|
|
34
|
+
useAlternativePreloader: useAlternativePreloader,
|
|
35
|
+
showServerActions: showServerActions
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return new SafePlugin({
|
|
39
|
+
state: {
|
|
40
|
+
init: function init() {
|
|
41
|
+
return {
|
|
42
|
+
requests: [],
|
|
43
|
+
provider: null,
|
|
44
|
+
cards: [],
|
|
45
|
+
showLinkingToolbar: false,
|
|
46
|
+
smartLinkEvents: undefined,
|
|
47
|
+
smartLinkEventsNext: undefined,
|
|
48
|
+
editorAppearance: editorAppearance,
|
|
49
|
+
showDatasourceModal: false,
|
|
50
|
+
datasourceModalType: undefined,
|
|
51
|
+
datasourceTableRef: undefined,
|
|
52
|
+
layout: undefined
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
apply: function apply(tr, pluginState, prevEditorState) {
|
|
56
|
+
// Update all the positions of outstanding requests and
|
|
57
|
+
// cards in the plugin state.
|
|
58
|
+
var pluginStateWithUpdatedPos = getPluginStateWithUpdatedPos(pluginState, tr);
|
|
59
|
+
|
|
60
|
+
// apply any actions
|
|
61
|
+
var meta = tr.getMeta(pluginKey);
|
|
62
|
+
var events = eventsFromTransaction(tr, prevEditorState);
|
|
63
|
+
analyticsQueue.push.apply(analyticsQueue, _toConsumableArray(events));
|
|
64
|
+
if (meta) {
|
|
65
|
+
var nextState = reducer(pluginStateWithUpdatedPos, meta);
|
|
66
|
+
if (!pluginState.smartLinkEventsNext && nextState.smartLinkEventsNext) {
|
|
67
|
+
analyticsQueue.setCallbacks(nextState.smartLinkEventsNext);
|
|
68
|
+
}
|
|
69
|
+
return nextState;
|
|
70
|
+
}
|
|
71
|
+
return pluginStateWithUpdatedPos;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
view: function view(_view) {
|
|
75
|
+
var subscriptionHandler = function subscriptionHandler(name, provider) {
|
|
76
|
+
return handleProvider(name, provider, _view);
|
|
77
|
+
};
|
|
78
|
+
var domAtPos = _view.domAtPos.bind(_view);
|
|
79
|
+
var rafCancellationCallbacks = [];
|
|
80
|
+
pmPluginFactoryParams.providerFactory.subscribe('cardProvider', subscriptionHandler);
|
|
81
|
+
return {
|
|
82
|
+
update: function update(view, prevState) {
|
|
83
|
+
var _selection$node;
|
|
84
|
+
var currentState = getPluginState(view.state);
|
|
85
|
+
var oldState = getPluginState(prevState);
|
|
86
|
+
var state = view.state,
|
|
87
|
+
dispatch = view.dispatch;
|
|
88
|
+
var selection = state.selection,
|
|
89
|
+
tr = state.tr,
|
|
90
|
+
schema = state.schema;
|
|
91
|
+
var isBlockCardSelected = selection instanceof NodeSelection && ((_selection$node = selection.node) === null || _selection$node === void 0 ? void 0 : _selection$node.type) === schema.nodes.blockCard;
|
|
92
|
+
if (isBlockCardSelected) {
|
|
93
|
+
var _findDomRefAtPos, _node$attrs;
|
|
94
|
+
var datasourceTableRef = (_findDomRefAtPos = findDomRefAtPos(selection.from, domAtPos)) === null || _findDomRefAtPos === void 0 ? void 0 : _findDomRefAtPos.querySelector(".".concat(DATASOURCE_INNER_CONTAINER_CLASSNAME));
|
|
95
|
+
var node = selection.node;
|
|
96
|
+
var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource);
|
|
97
|
+
var shouldUpdateTableRef = datasourceTableRef && (currentState === null || currentState === void 0 ? void 0 : currentState.datasourceTableRef) !== datasourceTableRef;
|
|
98
|
+
if (isDatasource && shouldUpdateTableRef) {
|
|
99
|
+
var _node$attrs2;
|
|
100
|
+
// since we use the plugin state, which is a shared state, we need to update the datasourceTableRef, layout on each selection
|
|
101
|
+
var layout = (node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || 'center';
|
|
102
|
+
|
|
103
|
+
// we use cardAction to set the same meta, hence, we will need to combine both layout+datasourceTableRef in one transaction
|
|
104
|
+
dispatch(setCardLayoutAndDatasourceTableRef({
|
|
105
|
+
datasourceTableRef: datasourceTableRef,
|
|
106
|
+
layout: layout
|
|
107
|
+
})(tr));
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (currentState !== null && currentState !== void 0 && currentState.datasourceTableRef) {
|
|
111
|
+
dispatch(setDatasourceTableRef(undefined)(tr));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (currentState && currentState.provider) {
|
|
115
|
+
// Find requests in this state that weren't in the old one.
|
|
116
|
+
var newRequests = getNewRequests(oldState, currentState);
|
|
117
|
+
// Ask the CardProvider to resolve all new requests.
|
|
118
|
+
var provider = currentState.provider;
|
|
119
|
+
newRequests.forEach(function (request) {
|
|
120
|
+
/**
|
|
121
|
+
* Queue each asynchronous resolve request on separate frames.
|
|
122
|
+
* ---
|
|
123
|
+
* NB: The promise for each request is queued to take place on separate animation frames. This avoids
|
|
124
|
+
* the scenario debugged and discovered in EDM-668, wherein the queuing of too many promises in quick succession
|
|
125
|
+
* leads to the browser's macrotask queue being overwhelmed, locking interactivity of the browser tab.
|
|
126
|
+
* By using this approach, the browser is free to schedule the resolution of the promises below in between rendering/network/
|
|
127
|
+
* other tasks as per common implementations of the JavaScript event loop in browsers.
|
|
128
|
+
*/
|
|
129
|
+
var invoke = rafSchedule(function () {
|
|
130
|
+
var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4;
|
|
131
|
+
return resolveWithProvider(view, provider, request, options, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.actions, (_pluginInjectionApi$d2 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d3 = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : (_pluginInjectionApi$d4 = _pluginInjectionApi$d3.sharedState.currentState()) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.createAnalyticsEvent) !== null && _pluginInjectionApi$d2 !== void 0 ? _pluginInjectionApi$d2 : undefined);
|
|
132
|
+
});
|
|
133
|
+
rafCancellationCallbacks.push(invoke.cancel);
|
|
134
|
+
invoke();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
analyticsQueue.flush();
|
|
138
|
+
},
|
|
139
|
+
destroy: function destroy() {
|
|
140
|
+
// Cancel any outstanding raf callbacks.
|
|
141
|
+
rafCancellationCallbacks.forEach(function (cancellationCallback) {
|
|
142
|
+
return cancellationCallback();
|
|
143
|
+
});
|
|
144
|
+
pmPluginFactoryParams.providerFactory.unsubscribe('cardProvider', subscriptionHandler);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
props: {
|
|
149
|
+
nodeViews: {
|
|
150
|
+
inlineCard: inlineCardViewProducer,
|
|
151
|
+
blockCard: function blockCard(node, view, getPos, decorations) {
|
|
152
|
+
var _node$attrs3;
|
|
153
|
+
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
154
|
+
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
155
|
+
var reactComponentProps = {
|
|
156
|
+
platform: platform,
|
|
157
|
+
showServerActions: showServerActions
|
|
158
|
+
};
|
|
159
|
+
var hasIntlContext = true;
|
|
160
|
+
var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
|
|
161
|
+
if (isDatasource) {
|
|
162
|
+
var _node$attrs4, _node$attrs4$datasour;
|
|
163
|
+
if (platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : (_node$attrs4$datasour = _node$attrs4.datasource) === null || _node$attrs4$datasour === void 0 ? void 0 : _node$attrs4$datasour.id)) {
|
|
164
|
+
return new Datasource({
|
|
165
|
+
node: node,
|
|
166
|
+
view: view,
|
|
167
|
+
getPos: getPos,
|
|
168
|
+
portalProviderAPI: portalProviderAPI,
|
|
169
|
+
eventDispatcher: eventDispatcher,
|
|
170
|
+
hasIntlContext: hasIntlContext,
|
|
171
|
+
pluginInjectionApi: pluginInjectionApi
|
|
172
|
+
}).init();
|
|
173
|
+
} else {
|
|
174
|
+
return inlineCardViewProducer(node, view, getPos, decorations);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
|
|
178
|
+
},
|
|
179
|
+
embedCard: function embedCard(node, view, getPos) {
|
|
180
|
+
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
181
|
+
eventDispatcher = pmPluginFactoryParams.eventDispatcher,
|
|
182
|
+
dispatchAnalyticsEvent = pmPluginFactoryParams.dispatchAnalyticsEvent;
|
|
183
|
+
var reactComponentProps = {
|
|
184
|
+
eventDispatcher: eventDispatcher,
|
|
185
|
+
allowResizing: allowResizing,
|
|
186
|
+
platform: platform,
|
|
187
|
+
fullWidthMode: fullWidthMode,
|
|
188
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
189
|
+
pluginInjectionApi: pluginInjectionApi
|
|
190
|
+
};
|
|
191
|
+
var hasIntlContext = true;
|
|
192
|
+
return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
key: pluginKey
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { HyperlinkToolbarAppearance } from '../ui/HyperlinkToolbarAppearance';
|
|
4
|
+
export var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionApi, options) {
|
|
5
|
+
return new SafePlugin({
|
|
6
|
+
view: function view(editorView) {
|
|
7
|
+
requestAnimationFrame(function () {
|
|
8
|
+
var _pluginInjectionApi$d, _pluginInjectionApi$d2;
|
|
9
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.hyperlink) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.actions) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.prependToolbarButtons({
|
|
10
|
+
items: function items(state, intl, providerFactory, link) {
|
|
11
|
+
return [{
|
|
12
|
+
type: 'custom',
|
|
13
|
+
fallback: [],
|
|
14
|
+
render: function render(editorView) {
|
|
15
|
+
var _pluginInjectionApi$d3, _pluginInjectionApi$d4;
|
|
16
|
+
return /*#__PURE__*/React.createElement(HyperlinkToolbarAppearance, {
|
|
17
|
+
key: "link-appearance",
|
|
18
|
+
url: link,
|
|
19
|
+
intl: intl,
|
|
20
|
+
editorView: editorView,
|
|
21
|
+
editorState: state,
|
|
22
|
+
cardOptions: options,
|
|
23
|
+
providerFactory: providerFactory,
|
|
24
|
+
platform: options === null || options === void 0 ? void 0 : options.platform,
|
|
25
|
+
editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d3 = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : _pluginInjectionApi$d3.actions,
|
|
26
|
+
cardActions: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies.card) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}];
|
|
30
|
+
},
|
|
31
|
+
onEscapeCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.hideLinkToolbar,
|
|
32
|
+
onInsertLinkCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.queueCardsFromChangedTr,
|
|
33
|
+
view: editorView
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
var queue = function queue(state, action) {
|
|
5
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
6
|
+
requests: state.requests.concat(action.requests)
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
var resolve = function resolve(state, action) {
|
|
10
|
+
var requests = state.requests.reduce(function (requests, request) {
|
|
11
|
+
if (request.url !== action.url) {
|
|
12
|
+
requests.push(request);
|
|
13
|
+
}
|
|
14
|
+
return requests;
|
|
15
|
+
}, []);
|
|
16
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
17
|
+
requests: requests
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var register = function register(state, action) {
|
|
21
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
22
|
+
cards: state.cards.filter(function (card) {
|
|
23
|
+
return card.pos !== action.info.pos;
|
|
24
|
+
}).concat(action.info)
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var setProvider = function setProvider(state, action) {
|
|
28
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
29
|
+
provider: action.provider
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var setCardLayout = function setCardLayout(state, action) {
|
|
33
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
34
|
+
layout: action.layout
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var setDatasourceTableRef = function setDatasourceTableRef(state, action) {
|
|
38
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
39
|
+
datasourceTableRef: action.datasourceTableRef
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var setCardLayoutDatasourceTableRef = function setCardLayoutDatasourceTableRef(state, action) {
|
|
43
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
44
|
+
datasourceTableRef: action.datasourceTableRef,
|
|
45
|
+
layout: action.layout
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var registerEvents = function registerEvents(state, action) {
|
|
49
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
50
|
+
smartLinkEvents: action.smartLinkEvents
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
var registerEventsNext = function registerEventsNext(state, action) {
|
|
54
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
55
|
+
smartLinkEventsNext: action.smartLinkEvents
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var setLinkToolbar = function setLinkToolbar(state, action) {
|
|
59
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
60
|
+
showLinkingToolbar: action.type === 'SHOW_LINK_TOOLBAR'
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var showDatasourceModal = function showDatasourceModal(state, action) {
|
|
64
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
65
|
+
showDatasourceModal: true,
|
|
66
|
+
datasourceModalType: action.type === 'SHOW_DATASOURCE_MODAL' ? action.modalType : undefined
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
var hideDatasourceModal = function hideDatasourceModal(state) {
|
|
70
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
71
|
+
showDatasourceModal: false,
|
|
72
|
+
datasourceModalType: undefined
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
export default (function (state, action) {
|
|
76
|
+
switch (action.type) {
|
|
77
|
+
case 'QUEUE':
|
|
78
|
+
return queue(state, action);
|
|
79
|
+
case 'SET_PROVIDER':
|
|
80
|
+
return setProvider(state, action);
|
|
81
|
+
case 'RESOLVE':
|
|
82
|
+
return resolve(state, action);
|
|
83
|
+
case 'REGISTER':
|
|
84
|
+
return register(state, action);
|
|
85
|
+
case 'REGISTER_EVENTS':
|
|
86
|
+
return registerEvents(state, action);
|
|
87
|
+
case 'REGISTER_EVENTS_NEXT':
|
|
88
|
+
return registerEventsNext(state, action);
|
|
89
|
+
case 'SET_DATASOURCE_TABLE_REF':
|
|
90
|
+
return setDatasourceTableRef(state, action);
|
|
91
|
+
case 'SET_CARD_LAYOUT':
|
|
92
|
+
return setCardLayout(state, action);
|
|
93
|
+
case 'SET_CARD_LAYOUT_AND_DATASOURCE_TABLE_REF':
|
|
94
|
+
return setCardLayoutDatasourceTableRef(state, action);
|
|
95
|
+
case 'SHOW_LINK_TOOLBAR':
|
|
96
|
+
case 'HIDE_LINK_TOOLBAR':
|
|
97
|
+
return setLinkToolbar(state, action);
|
|
98
|
+
case 'SHOW_DATASOURCE_MODAL':
|
|
99
|
+
return showDatasourceModal(state, action);
|
|
100
|
+
case 'HIDE_DATASOURCE_MODAL':
|
|
101
|
+
return hideDatasourceModal(state);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { normalizeUrl } from '@atlaskit/adf-schema';
|
|
2
|
+
import { md } from '@atlaskit/editor-common/paste';
|
|
3
|
+
export function shouldReplaceLink(node) {
|
|
4
|
+
var compareLinkText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
5
|
+
var compareToUrl = arguments.length > 2 ? arguments[2] : undefined;
|
|
6
|
+
var linkMark = node.marks.find(function (mark) {
|
|
7
|
+
return mark.type.name === 'link';
|
|
8
|
+
});
|
|
9
|
+
if (!linkMark) {
|
|
10
|
+
// not a link anymore
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ED-6041: compare normalised link text after linkfy from Markdown transformer
|
|
15
|
+
// instead, since it always decodes URL ('%20' -> ' ') on the link text
|
|
16
|
+
|
|
17
|
+
var normalisedHref = normalizeUrl(md.normalizeLinkText(linkMark.attrs.href));
|
|
18
|
+
var normalizedLinkText = normalizeUrl(md.normalizeLinkText(node.text || ''));
|
|
19
|
+
if (compareLinkText && normalisedHref !== normalizedLinkText) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (compareToUrl) {
|
|
23
|
+
var normalizedUrl = normalizeUrl(md.normalizeLinkText(compareToUrl));
|
|
24
|
+
if (normalizedUrl !== normalisedHref) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { setProvider } from '../actions';
|
|
2
|
+
import { handleFallbackWithAnalytics, replaceQueuedUrlWithCard } from '../doc';
|
|
3
|
+
|
|
4
|
+
// ============================================================================ //
|
|
5
|
+
// ============================== PROVIDER UTILS ============================== //
|
|
6
|
+
// ============================================================================ //
|
|
7
|
+
// Used for all interactions with the EditorCardProvider.
|
|
8
|
+
// ============================================================================ //
|
|
9
|
+
export var resolveWithProvider = function resolveWithProvider(view, provider, request, options, editorAnalyticsApi, createAnalyticsEvent) {
|
|
10
|
+
// When user manually changes appearance from blue link to smart link, we should respect that,
|
|
11
|
+
var shouldForceAppearance =
|
|
12
|
+
// This flag is set to true only in one place atm:
|
|
13
|
+
// packages/editor/editor-core/src/plugins/card/pm-plugins/doc.ts @ convertHyperlinkToSmartCard
|
|
14
|
+
// Which is used when user switching from URL to smart link appearance.
|
|
15
|
+
!!request.shouldReplaceLink;
|
|
16
|
+
var handleResolve = provider.resolve(request.url, request.appearance, shouldForceAppearance).then(handleResolved(view, request, editorAnalyticsApi, createAnalyticsEvent, options), handleRejected(view, request, editorAnalyticsApi));
|
|
17
|
+
return handleResolve;
|
|
18
|
+
};
|
|
19
|
+
var updateCardType = function updateCardType(resolvedCard, options) {
|
|
20
|
+
if ((resolvedCard === null || resolvedCard === void 0 ? void 0 : resolvedCard.type) === 'blockCard' && !options.allowBlockCards || (resolvedCard === null || resolvedCard === void 0 ? void 0 : resolvedCard.type) === 'embedCard' && !options.allowEmbeds) {
|
|
21
|
+
// clean out the 'layout' attr from an embedCard type that should be transformed into the inlineCard type.
|
|
22
|
+
if (resolvedCard.type === 'embedCard') {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
delete resolvedCard.attrs.layout;
|
|
25
|
+
}
|
|
26
|
+
resolvedCard.type = 'inlineCard';
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var handleResolved = function handleResolved(view, request, editorAnalyticsApi, createAnalyticsEvent, options) {
|
|
30
|
+
return function (resolvedCard) {
|
|
31
|
+
updateCardType(resolvedCard, options);
|
|
32
|
+
replaceQueuedUrlWithCard(request.url, resolvedCard, request.analyticsAction, editorAnalyticsApi, createAnalyticsEvent)(view.state, view.dispatch);
|
|
33
|
+
return resolvedCard;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
var handleRejected = function handleRejected(view, request, editorAnalyticsApi) {
|
|
37
|
+
return function () {
|
|
38
|
+
handleFallbackWithAnalytics(request, editorAnalyticsApi)(view.state, view.dispatch);
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// listen for card provider changes
|
|
43
|
+
export var handleProvider = function handleProvider(_, provider, view) {
|
|
44
|
+
if (!provider) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
provider.then(function (cardProvider) {
|
|
48
|
+
var state = view.state,
|
|
49
|
+
dispatch = view.dispatch;
|
|
50
|
+
dispatch(setProvider(cardProvider)(state.tr));
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
import { pluginKey } from '../plugin-key';
|
|
5
|
+
|
|
6
|
+
// ============================================================================ //
|
|
7
|
+
// ============================== PLUGIN STATE ================================ //
|
|
8
|
+
// ============================================================================ //
|
|
9
|
+
// Used for interactions with the Card Plugin's state.
|
|
10
|
+
// ============================================================================ //
|
|
11
|
+
export var getPluginState = function getPluginState(editorState) {
|
|
12
|
+
return pluginKey.getState(editorState);
|
|
13
|
+
};
|
|
14
|
+
export var getPluginStateWithUpdatedPos = function getPluginStateWithUpdatedPos(pluginState, tr) {
|
|
15
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
16
|
+
requests: pluginState.requests.map(function (request) {
|
|
17
|
+
return _objectSpread(_objectSpread({}, request), {}, {
|
|
18
|
+
pos: tr.mapping.map(request.pos)
|
|
19
|
+
});
|
|
20
|
+
}),
|
|
21
|
+
cards: pluginState.cards.map(function (card) {
|
|
22
|
+
return _objectSpread(_objectSpread({}, card), {}, {
|
|
23
|
+
pos: tr.mapping.map(card.pos)
|
|
24
|
+
});
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export var getNewRequests = function getNewRequests(oldState, currentState) {
|
|
29
|
+
if (oldState) {
|
|
30
|
+
return currentState.requests.filter(function (req) {
|
|
31
|
+
return !oldState.requests.find(function (oldReq) {
|
|
32
|
+
return isSameRequest(oldReq, req);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return currentState.requests;
|
|
37
|
+
};
|
|
38
|
+
var isSameRequest = function isSameRequest(requestA, requestB) {
|
|
39
|
+
return requestA.url === requestB.url && requestA.pos === requestB.pos;
|
|
40
|
+
};
|