@atlaskit/editor-plugin-synced-block 5.1.11 → 5.1.13
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/CHANGELOG.md +16 -0
- package/afm-cc/tsconfig.json +10 -4
- package/afm-jira/tsconfig.json +9 -0
- package/afm-products/tsconfig.json +10 -1
- package/dist/cjs/ui/SyncedLocationDropdown.compiled.css +34 -0
- package/dist/cjs/ui/SyncedLocationDropdown.js +329 -0
- package/dist/cjs/ui/floating-toolbar.js +21 -0
- package/dist/es2019/ui/SyncedLocationDropdown.compiled.css +34 -0
- package/dist/es2019/ui/SyncedLocationDropdown.js +283 -0
- package/dist/es2019/ui/floating-toolbar.js +22 -0
- package/dist/esm/ui/SyncedLocationDropdown.compiled.css +34 -0
- package/dist/esm/ui/SyncedLocationDropdown.js +320 -0
- package/dist/esm/ui/floating-toolbar.js +21 -0
- package/dist/types/ui/SyncedLocationDropdown.d.ts +12 -0
- package/dist/types-ts4.5/ui/SyncedLocationDropdown.d.ts +12 -0
- package/package.json +11 -7
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/* SyncedLocationDropdown.tsx generated by @compiled/babel-plugin v0.38.1 */
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import "./SyncedLocationDropdown.compiled.css";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
+
import { useState, useEffect } from 'react';
|
|
7
|
+
import DropdownMenu, { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
|
|
8
|
+
import { syncBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
10
|
+
import { IconTile } from '@atlaskit/icon';
|
|
11
|
+
import PageLiveDocIcon from '@atlaskit/icon-lab/core/page-live-doc';
|
|
12
|
+
import ChevronDownIcon from '@atlaskit/icon/core/chevron-down';
|
|
13
|
+
import PageIcon from '@atlaskit/icon/core/page';
|
|
14
|
+
import QuotationMarkIcon from '@atlaskit/icon/core/quotation-mark';
|
|
15
|
+
import StatusErrorIcon from '@atlaskit/icon/core/status-error';
|
|
16
|
+
import { ConfluenceIcon, JiraIcon, AtlassianIcon } from '@atlaskit/logo';
|
|
17
|
+
import Lozenge from '@atlaskit/lozenge';
|
|
18
|
+
import { Box, Text, Inline, Anchor, Stack } from '@atlaskit/primitives/compiled';
|
|
19
|
+
import Spinner from '@atlaskit/spinner';
|
|
20
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
21
|
+
const fadeIn = null;
|
|
22
|
+
const headingStyles = null;
|
|
23
|
+
const dropdownItemStyles = null;
|
|
24
|
+
|
|
25
|
+
// logo icon does not fit in ADS IconTile, hence we need custom styles to match with other icons
|
|
26
|
+
const logoTileStyles = null;
|
|
27
|
+
const styles = {
|
|
28
|
+
title: "_1reo15vq _18m915vq _syazazsu _1bto1l2s _o5721q9c",
|
|
29
|
+
note: "_syaz1rpy _o5721q9c",
|
|
30
|
+
lozenge: "_ahbq12x7 _1ul91wqb",
|
|
31
|
+
noResultsContainer: "_1bsbo8uj _y3gn1h6o",
|
|
32
|
+
dropdownContent: "_1rjcv77o _1bsbsmdz _1tkeqkoa _c71lko4j _1e0c1txw _1bah1h6o _4cvr1h6o",
|
|
33
|
+
contentContainer: "_y44vfmxe _1bsb1osq _1wpz1fhb _18m91wug",
|
|
34
|
+
errorContainer: "_1bsbo8uj _1e0c1txw",
|
|
35
|
+
errorIcon: "_1mour5cr",
|
|
36
|
+
learnMoreLink: "_4bfu1r31 _1hmsglyw _ajmmnqa1",
|
|
37
|
+
requestAccess: "_1bsb19n7 _o5721q9c _ahbq12x7 _syaz1rpy"
|
|
38
|
+
};
|
|
39
|
+
const ItemTitle = ({
|
|
40
|
+
title,
|
|
41
|
+
formatMessage,
|
|
42
|
+
onSamePage,
|
|
43
|
+
isSource,
|
|
44
|
+
hasAccess
|
|
45
|
+
}) => {
|
|
46
|
+
return /*#__PURE__*/React.createElement(Inline, null, /*#__PURE__*/React.createElement(Box, {
|
|
47
|
+
as: "span",
|
|
48
|
+
xcss: styles.title
|
|
49
|
+
}, title), onSamePage && /*#__PURE__*/React.createElement(Box, {
|
|
50
|
+
as: "span",
|
|
51
|
+
xcss: styles.note
|
|
52
|
+
}, "\xA0- ", formatMessage(messages.syncedLocationDropdownTitleNote)), isSource && /*#__PURE__*/React.createElement(Box, {
|
|
53
|
+
as: "span",
|
|
54
|
+
xcss: styles.lozenge
|
|
55
|
+
}, /*#__PURE__*/React.createElement(Lozenge, null, formatMessage(messages.syncedLocationDropdownSourceLozenge))), !hasAccess && /*#__PURE__*/React.createElement(Box, {
|
|
56
|
+
as: "span",
|
|
57
|
+
xcss: styles.requestAccess
|
|
58
|
+
}, formatMessage(messages.syncedLocationDropdownRequestAccess)));
|
|
59
|
+
};
|
|
60
|
+
const productIconMap = {
|
|
61
|
+
'confluence-page': ConfluenceIcon,
|
|
62
|
+
'jira-work-item': JiraIcon
|
|
63
|
+
};
|
|
64
|
+
const subTypeIconMap = {
|
|
65
|
+
live: PageLiveDocIcon,
|
|
66
|
+
page: PageIcon,
|
|
67
|
+
blogpost: QuotationMarkIcon
|
|
68
|
+
};
|
|
69
|
+
const getSubTypeIcon = subType => {
|
|
70
|
+
return subType && subType in subTypeIconMap ? subTypeIconMap[subType] : PageIcon;
|
|
71
|
+
};
|
|
72
|
+
const ProductIcon = ({
|
|
73
|
+
product
|
|
74
|
+
}) => {
|
|
75
|
+
var _productIconMap$produ;
|
|
76
|
+
const ProductIcon = product ? (_productIconMap$produ = productIconMap[product]) !== null && _productIconMap$produ !== void 0 ? _productIconMap$produ : AtlassianIcon : AtlassianIcon;
|
|
77
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
78
|
+
className: ax(["_2rkol0p1 _bfhki8nm _1bsbgktf _4t3igktf _1e0c1txw _4cvr1h6o _1bah1h6o"])
|
|
79
|
+
}, /*#__PURE__*/React.createElement(ProductIcon, {
|
|
80
|
+
size: "xxsmall",
|
|
81
|
+
appearance: "neutral"
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
const ItemIcon = ({
|
|
85
|
+
reference
|
|
86
|
+
}) => {
|
|
87
|
+
const {
|
|
88
|
+
hasAccess,
|
|
89
|
+
subType
|
|
90
|
+
} = reference;
|
|
91
|
+
if (hasAccess) {
|
|
92
|
+
return /*#__PURE__*/React.createElement(IconTile, {
|
|
93
|
+
icon: getSubTypeIcon(subType),
|
|
94
|
+
label: "",
|
|
95
|
+
appearance: 'gray',
|
|
96
|
+
size: "xsmall"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return /*#__PURE__*/React.createElement(ProductIcon, {
|
|
100
|
+
product: reference.productType
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
export const processReferenceData = (referenceData, intl) => {
|
|
104
|
+
const {
|
|
105
|
+
formatMessage
|
|
106
|
+
} = intl;
|
|
107
|
+
const sourceInfoMap = new Map();
|
|
108
|
+
referenceData === null || referenceData === void 0 ? void 0 : referenceData.forEach(reference => {
|
|
109
|
+
if (!reference) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (sourceInfoMap.has(reference.sourceAri)) {
|
|
113
|
+
var _sourceInfoMap$get;
|
|
114
|
+
(_sourceInfoMap$get = sourceInfoMap.get(reference.sourceAri)) === null || _sourceInfoMap$get === void 0 ? void 0 : _sourceInfoMap$get.push(reference);
|
|
115
|
+
} else {
|
|
116
|
+
sourceInfoMap.set(reference.sourceAri, [reference]);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
for (const references of sourceInfoMap.values()) {
|
|
120
|
+
if (references.length > 1) {
|
|
121
|
+
references.forEach((reference, index) => reference.title = `${reference.title}: ${formatMessage(messages.syncedLocationDropdownTitleBlockIndex, {
|
|
122
|
+
index: index + 1
|
|
123
|
+
})}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const sortedReferences = Array.from(sourceInfoMap.values()).flat().sort((a, b) => {
|
|
127
|
+
if (a.isSource !== b.isSource) {
|
|
128
|
+
return b.isSource ? 1 : -1;
|
|
129
|
+
}
|
|
130
|
+
if (a.hasAccess !== b.hasAccess) {
|
|
131
|
+
return a.hasAccess ? -1 : 1;
|
|
132
|
+
}
|
|
133
|
+
return (a.title || '').localeCompare(b.title || '');
|
|
134
|
+
});
|
|
135
|
+
return sortedReferences;
|
|
136
|
+
};
|
|
137
|
+
export const SyncedLocationDropdown = ({
|
|
138
|
+
syncBlockStore,
|
|
139
|
+
resourceId,
|
|
140
|
+
intl,
|
|
141
|
+
isSource,
|
|
142
|
+
localId
|
|
143
|
+
}) => {
|
|
144
|
+
const {
|
|
145
|
+
formatMessage
|
|
146
|
+
} = intl;
|
|
147
|
+
const triggerTitle = formatMessage(messages.syncedLocationDropdownTitle);
|
|
148
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
149
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
150
|
+
isOpen: isOpen,
|
|
151
|
+
onOpenChange: ({
|
|
152
|
+
isOpen
|
|
153
|
+
}) => setIsOpen(isOpen),
|
|
154
|
+
trigger: ({
|
|
155
|
+
triggerRef,
|
|
156
|
+
...triggerProps
|
|
157
|
+
}) => /*#__PURE__*/React.createElement(Button, _extends({
|
|
158
|
+
ref: triggerRef,
|
|
159
|
+
areAnyNewToolbarFlagsEnabled: true,
|
|
160
|
+
iconAfter: /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
161
|
+
color: "currentColor",
|
|
162
|
+
spacing: "spacious",
|
|
163
|
+
label: "",
|
|
164
|
+
size: "small"
|
|
165
|
+
})
|
|
166
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
167
|
+
}, triggerProps), triggerTitle)
|
|
168
|
+
}, isOpen && /*#__PURE__*/React.createElement(DropdownContent, {
|
|
169
|
+
syncBlockStore: syncBlockStore,
|
|
170
|
+
resourceId: resourceId,
|
|
171
|
+
intl: intl,
|
|
172
|
+
isSource: isSource,
|
|
173
|
+
localId: localId
|
|
174
|
+
}));
|
|
175
|
+
};
|
|
176
|
+
const DropdownContent = ({
|
|
177
|
+
syncBlockStore,
|
|
178
|
+
resourceId,
|
|
179
|
+
intl,
|
|
180
|
+
isSource,
|
|
181
|
+
localId
|
|
182
|
+
}) => {
|
|
183
|
+
const {
|
|
184
|
+
formatMessage
|
|
185
|
+
} = intl;
|
|
186
|
+
const [fetchStatus, setFetchStatus] = useState('none');
|
|
187
|
+
const [referenceData, setReferenceData] = useState([]);
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
setFetchStatus('loading');
|
|
190
|
+
const getReferenceData = async () => {
|
|
191
|
+
const response = await syncBlockStore.fetchReferencesSourceInfo(resourceId, localId, isSource);
|
|
192
|
+
if (response.error) {
|
|
193
|
+
setFetchStatus('error');
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
setReferenceData(processReferenceData(response.references, intl));
|
|
197
|
+
setFetchStatus('success');
|
|
198
|
+
};
|
|
199
|
+
getReferenceData();
|
|
200
|
+
}, [syncBlockStore, intl, isSource, localId, resourceId]);
|
|
201
|
+
const content = () => {
|
|
202
|
+
switch (fetchStatus) {
|
|
203
|
+
case 'loading':
|
|
204
|
+
return /*#__PURE__*/React.createElement(LoadingScreen, null);
|
|
205
|
+
case 'error':
|
|
206
|
+
return /*#__PURE__*/React.createElement(ErrorScreen, {
|
|
207
|
+
formatMessage: formatMessage
|
|
208
|
+
});
|
|
209
|
+
case 'success':
|
|
210
|
+
if (referenceData.length > 0) {
|
|
211
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
212
|
+
"data-testid": "synced-locations-dropdown-content",
|
|
213
|
+
className: ax([styles.contentContainer, "_ku9g126e _18bk1rpy"])
|
|
214
|
+
}, /*#__PURE__*/React.createElement(DropdownItemGroup, {
|
|
215
|
+
title: formatMessage(messages.syncedLocationDropdownHeading, {
|
|
216
|
+
count: `${referenceData.length > 99 ? '99+' : referenceData.length}`
|
|
217
|
+
})
|
|
218
|
+
}, referenceData.map(reference => /*#__PURE__*/React.createElement("div", {
|
|
219
|
+
key: reference.title,
|
|
220
|
+
className: ax(["_2ll012x7"])
|
|
221
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
222
|
+
content: reference.title || reference.url || ''
|
|
223
|
+
}, /*#__PURE__*/React.createElement(DropdownItem, {
|
|
224
|
+
elemBefore: /*#__PURE__*/React.createElement(ItemIcon, {
|
|
225
|
+
reference: reference
|
|
226
|
+
}),
|
|
227
|
+
href: reference.url,
|
|
228
|
+
target: "_blank",
|
|
229
|
+
key: reference.title
|
|
230
|
+
}, /*#__PURE__*/React.createElement(ItemTitle, {
|
|
231
|
+
title: reference.title || reference.url || '',
|
|
232
|
+
formatMessage: formatMessage,
|
|
233
|
+
onSamePage: reference.onSamePage,
|
|
234
|
+
isSource: reference.isSource,
|
|
235
|
+
hasAccess: reference.hasAccess
|
|
236
|
+
})))))));
|
|
237
|
+
} else {
|
|
238
|
+
return /*#__PURE__*/React.createElement(NoResultScreen, {
|
|
239
|
+
formatMessage: formatMessage
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
245
|
+
xcss: styles.dropdownContent
|
|
246
|
+
}, content());
|
|
247
|
+
};
|
|
248
|
+
const LoadingScreen = () => {
|
|
249
|
+
return /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Spinner, null));
|
|
250
|
+
};
|
|
251
|
+
const ErrorScreen = ({
|
|
252
|
+
formatMessage
|
|
253
|
+
}) => {
|
|
254
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
255
|
+
xcss: styles.errorContainer
|
|
256
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
257
|
+
xcss: styles.errorIcon
|
|
258
|
+
}, /*#__PURE__*/React.createElement(StatusErrorIcon, {
|
|
259
|
+
color: "var(--ds-icon-danger, #C9372C)",
|
|
260
|
+
spacing: "spacious",
|
|
261
|
+
label: "",
|
|
262
|
+
size: "small"
|
|
263
|
+
})), /*#__PURE__*/React.createElement(Text, {
|
|
264
|
+
as: "p",
|
|
265
|
+
size: "medium"
|
|
266
|
+
}, formatMessage(messages.syncedLocationDropdownError)));
|
|
267
|
+
};
|
|
268
|
+
const NoResultScreen = ({
|
|
269
|
+
formatMessage
|
|
270
|
+
}) => {
|
|
271
|
+
return /*#__PURE__*/React.createElement(Stack, {
|
|
272
|
+
xcss: styles.noResultsContainer,
|
|
273
|
+
space: "space.100"
|
|
274
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
275
|
+
as: "p"
|
|
276
|
+
}, formatMessage(messages.syncedLocationDropdownNoResults)), /*#__PURE__*/React.createElement(Text, {
|
|
277
|
+
as: "p"
|
|
278
|
+
}, /*#__PURE__*/React.createElement(Anchor, {
|
|
279
|
+
href: "https://hello.atlassian.net/wiki/x/tAtCeAE",
|
|
280
|
+
target: "_blank",
|
|
281
|
+
xcss: styles.learnMoreLink
|
|
282
|
+
}, formatMessage(messages.syncedLocationDropdownLearnMoreLink))));
|
|
283
|
+
};
|
|
@@ -9,6 +9,7 @@ import EditIcon from '@atlaskit/icon/core/edit';
|
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
import { copySyncedBlockReferenceToClipboard, editSyncedBlockSource, removeSyncedBlock } from '../editor-commands';
|
|
11
11
|
import { findSyncBlockOrBodiedSyncBlock, isBodiedSyncBlockNode } from '../pm-plugins/utils/utils';
|
|
12
|
+
import { SyncedLocationDropdown } from './SyncedLocationDropdown';
|
|
12
13
|
export const getToolbarConfig = (state, intl, api, syncBlockStore) => {
|
|
13
14
|
var _api$decorations, _api$connectivity, _api$connectivity$sha;
|
|
14
15
|
const syncBlockObject = findSyncBlockOrBodiedSyncBlock(state.schema, state.selection);
|
|
@@ -17,6 +18,7 @@ export const getToolbarConfig = (state, intl, api, syncBlockStore) => {
|
|
|
17
18
|
}
|
|
18
19
|
const syncBlockInstance = syncBlockStore.referenceManager.getFromCache(syncBlockObject.node.attrs.resourceId);
|
|
19
20
|
const isUnsyncedBlock = (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) === SyncBlockError.NotFound;
|
|
21
|
+
const isErroredBlock = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error;
|
|
20
22
|
const {
|
|
21
23
|
schema: {
|
|
22
24
|
nodes: {
|
|
@@ -25,6 +27,10 @@ export const getToolbarConfig = (state, intl, api, syncBlockStore) => {
|
|
|
25
27
|
}
|
|
26
28
|
} = state;
|
|
27
29
|
const isBodiedSyncBlock = isBodiedSyncBlockNode(syncBlockObject.node, bodiedSyncBlock);
|
|
30
|
+
const {
|
|
31
|
+
resourceId,
|
|
32
|
+
localId
|
|
33
|
+
} = syncBlockObject.node.attrs;
|
|
28
34
|
const {
|
|
29
35
|
formatMessage
|
|
30
36
|
} = intl;
|
|
@@ -48,6 +54,22 @@ export const getToolbarConfig = (state, intl, api, syncBlockStore) => {
|
|
|
48
54
|
};
|
|
49
55
|
items.push(deleteButton);
|
|
50
56
|
} else {
|
|
57
|
+
if (!isErroredBlock && fg('platform_synced_block_dogfooding')) {
|
|
58
|
+
const syncedLocation = {
|
|
59
|
+
type: 'custom',
|
|
60
|
+
fallback: [],
|
|
61
|
+
render: () => {
|
|
62
|
+
return /*#__PURE__*/React.createElement(SyncedLocationDropdown, {
|
|
63
|
+
syncBlockStore: syncBlockStore,
|
|
64
|
+
resourceId: resourceId,
|
|
65
|
+
localId: localId,
|
|
66
|
+
intl: intl,
|
|
67
|
+
isSource: isBodiedSyncBlock
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
items.push(syncedLocation);
|
|
72
|
+
}
|
|
51
73
|
const copyButton = {
|
|
52
74
|
id: 'editor.syncedBlock.copy',
|
|
53
75
|
type: 'button',
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
._2rkol0p1{border-radius:var(--ds-radius-tile,25%)}
|
|
3
|
+
._y44vfmxe{animation:kgnpaw5 .7s ease-in-out}
|
|
4
|
+
._1mour5cr{margin-block:var(--ds-space-negative-050,-4px)}
|
|
5
|
+
._1rjcv77o{padding-block:var(--ds-space-025,2px)}
|
|
6
|
+
._ku9g126e [data-ds--menu--heading-item]{margin-block:var(--ds-space-050,4px)!important}._18bk1rpy [data-ds--menu--heading-item]{color:var(--ds-text-subtlest,#6b6e76)}
|
|
7
|
+
._18m915vq{overflow-y:hidden}
|
|
8
|
+
._18m91wug{overflow-y:auto}
|
|
9
|
+
._1bah1h6o{justify-content:center}
|
|
10
|
+
._1bsb19n7{width:106px}
|
|
11
|
+
._1bsb1osq{width:100%}
|
|
12
|
+
._1bsbgktf{width:20px}
|
|
13
|
+
._1bsbo8uj{width:235px}
|
|
14
|
+
._1bsbsmdz{width:342px}
|
|
15
|
+
._1bto1l2s{text-overflow:ellipsis}
|
|
16
|
+
._1e0c1txw{display:flex}
|
|
17
|
+
._1hmsglyw{text-decoration-line:none}
|
|
18
|
+
._1reo15vq{overflow-x:hidden}
|
|
19
|
+
._1tkeqkoa{min-height:9pc}
|
|
20
|
+
._1ul91wqb{min-width:60px}
|
|
21
|
+
._1wpz1fhb{align-self:stretch}
|
|
22
|
+
._2ll012x7 a>span{column-gap:var(--ds-space-075,6px)}
|
|
23
|
+
._4bfu1r31{text-decoration-color:currentColor}
|
|
24
|
+
._4cvr1h6o{align-items:center}
|
|
25
|
+
._4t3igktf{height:20px}
|
|
26
|
+
._ahbq12x7{margin-inline-start:var(--ds-space-075,6px)}
|
|
27
|
+
._ajmmnqa1{text-decoration-style:solid}
|
|
28
|
+
._bfhki8nm{background-color:var(--ds-background-neutral,#0515240f)}
|
|
29
|
+
._c71lko4j{max-height:19pc}
|
|
30
|
+
._o5721q9c{white-space:nowrap}
|
|
31
|
+
._syaz1rpy{color:var(--ds-text-subtlest,#6b6e76)}
|
|
32
|
+
._syazazsu{color:var(--ds-text-subtle,#505258)}
|
|
33
|
+
._y3gn1h6o{text-align:center}
|
|
34
|
+
@keyframes kgnpaw5{0%{opacity:0}to{opacity:1}}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/* SyncedLocationDropdown.tsx generated by @compiled/babel-plugin v0.38.1 */
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
6
|
+
var _excluded = ["triggerRef"];
|
|
7
|
+
import "./SyncedLocationDropdown.compiled.css";
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
10
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
+
import { useState, useEffect } from 'react';
|
|
15
|
+
import DropdownMenu, { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
|
|
16
|
+
import { syncBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
17
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
18
|
+
import { IconTile } from '@atlaskit/icon';
|
|
19
|
+
import PageLiveDocIcon from '@atlaskit/icon-lab/core/page-live-doc';
|
|
20
|
+
import ChevronDownIcon from '@atlaskit/icon/core/chevron-down';
|
|
21
|
+
import PageIcon from '@atlaskit/icon/core/page';
|
|
22
|
+
import QuotationMarkIcon from '@atlaskit/icon/core/quotation-mark';
|
|
23
|
+
import StatusErrorIcon from '@atlaskit/icon/core/status-error';
|
|
24
|
+
import { ConfluenceIcon, JiraIcon, AtlassianIcon } from '@atlaskit/logo';
|
|
25
|
+
import Lozenge from '@atlaskit/lozenge';
|
|
26
|
+
import { Box, Text, Inline, Anchor, Stack } from '@atlaskit/primitives/compiled';
|
|
27
|
+
import Spinner from '@atlaskit/spinner';
|
|
28
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
29
|
+
var fadeIn = null;
|
|
30
|
+
var headingStyles = null;
|
|
31
|
+
var dropdownItemStyles = null;
|
|
32
|
+
|
|
33
|
+
// logo icon does not fit in ADS IconTile, hence we need custom styles to match with other icons
|
|
34
|
+
var logoTileStyles = null;
|
|
35
|
+
var styles = {
|
|
36
|
+
title: "_1reo15vq _18m915vq _syazazsu _1bto1l2s _o5721q9c",
|
|
37
|
+
note: "_syaz1rpy _o5721q9c",
|
|
38
|
+
lozenge: "_ahbq12x7 _1ul91wqb",
|
|
39
|
+
noResultsContainer: "_1bsbo8uj _y3gn1h6o",
|
|
40
|
+
dropdownContent: "_1rjcv77o _1bsbsmdz _1tkeqkoa _c71lko4j _1e0c1txw _1bah1h6o _4cvr1h6o",
|
|
41
|
+
contentContainer: "_y44vfmxe _1bsb1osq _1wpz1fhb _18m91wug",
|
|
42
|
+
errorContainer: "_1bsbo8uj _1e0c1txw",
|
|
43
|
+
errorIcon: "_1mour5cr",
|
|
44
|
+
learnMoreLink: "_4bfu1r31 _1hmsglyw _ajmmnqa1",
|
|
45
|
+
requestAccess: "_1bsb19n7 _o5721q9c _ahbq12x7 _syaz1rpy"
|
|
46
|
+
};
|
|
47
|
+
var ItemTitle = function ItemTitle(_ref) {
|
|
48
|
+
var title = _ref.title,
|
|
49
|
+
formatMessage = _ref.formatMessage,
|
|
50
|
+
onSamePage = _ref.onSamePage,
|
|
51
|
+
isSource = _ref.isSource,
|
|
52
|
+
hasAccess = _ref.hasAccess;
|
|
53
|
+
return /*#__PURE__*/React.createElement(Inline, null, /*#__PURE__*/React.createElement(Box, {
|
|
54
|
+
as: "span",
|
|
55
|
+
xcss: styles.title
|
|
56
|
+
}, title), onSamePage && /*#__PURE__*/React.createElement(Box, {
|
|
57
|
+
as: "span",
|
|
58
|
+
xcss: styles.note
|
|
59
|
+
}, "\xA0- ", formatMessage(messages.syncedLocationDropdownTitleNote)), isSource && /*#__PURE__*/React.createElement(Box, {
|
|
60
|
+
as: "span",
|
|
61
|
+
xcss: styles.lozenge
|
|
62
|
+
}, /*#__PURE__*/React.createElement(Lozenge, null, formatMessage(messages.syncedLocationDropdownSourceLozenge))), !hasAccess && /*#__PURE__*/React.createElement(Box, {
|
|
63
|
+
as: "span",
|
|
64
|
+
xcss: styles.requestAccess
|
|
65
|
+
}, formatMessage(messages.syncedLocationDropdownRequestAccess)));
|
|
66
|
+
};
|
|
67
|
+
var productIconMap = {
|
|
68
|
+
'confluence-page': ConfluenceIcon,
|
|
69
|
+
'jira-work-item': JiraIcon
|
|
70
|
+
};
|
|
71
|
+
var subTypeIconMap = {
|
|
72
|
+
live: PageLiveDocIcon,
|
|
73
|
+
page: PageIcon,
|
|
74
|
+
blogpost: QuotationMarkIcon
|
|
75
|
+
};
|
|
76
|
+
var getSubTypeIcon = function getSubTypeIcon(subType) {
|
|
77
|
+
return subType && subType in subTypeIconMap ? subTypeIconMap[subType] : PageIcon;
|
|
78
|
+
};
|
|
79
|
+
var ProductIcon = function ProductIcon(_ref2) {
|
|
80
|
+
var _productIconMap$produ;
|
|
81
|
+
var product = _ref2.product;
|
|
82
|
+
var ProductIcon = product ? (_productIconMap$produ = productIconMap[product]) !== null && _productIconMap$produ !== void 0 ? _productIconMap$produ : AtlassianIcon : AtlassianIcon;
|
|
83
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
84
|
+
className: ax(["_2rkol0p1 _bfhki8nm _1bsbgktf _4t3igktf _1e0c1txw _4cvr1h6o _1bah1h6o"])
|
|
85
|
+
}, /*#__PURE__*/React.createElement(ProductIcon, {
|
|
86
|
+
size: "xxsmall",
|
|
87
|
+
appearance: "neutral"
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
var ItemIcon = function ItemIcon(_ref3) {
|
|
91
|
+
var reference = _ref3.reference;
|
|
92
|
+
var hasAccess = reference.hasAccess,
|
|
93
|
+
subType = reference.subType;
|
|
94
|
+
if (hasAccess) {
|
|
95
|
+
return /*#__PURE__*/React.createElement(IconTile, {
|
|
96
|
+
icon: getSubTypeIcon(subType),
|
|
97
|
+
label: "",
|
|
98
|
+
appearance: 'gray',
|
|
99
|
+
size: "xsmall"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return /*#__PURE__*/React.createElement(ProductIcon, {
|
|
103
|
+
product: reference.productType
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
export var processReferenceData = function processReferenceData(referenceData, intl) {
|
|
107
|
+
var formatMessage = intl.formatMessage;
|
|
108
|
+
var sourceInfoMap = new Map();
|
|
109
|
+
referenceData === null || referenceData === void 0 || referenceData.forEach(function (reference) {
|
|
110
|
+
if (!reference) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (sourceInfoMap.has(reference.sourceAri)) {
|
|
114
|
+
var _sourceInfoMap$get;
|
|
115
|
+
(_sourceInfoMap$get = sourceInfoMap.get(reference.sourceAri)) === null || _sourceInfoMap$get === void 0 || _sourceInfoMap$get.push(reference);
|
|
116
|
+
} else {
|
|
117
|
+
sourceInfoMap.set(reference.sourceAri, [reference]);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
var _iterator = _createForOfIteratorHelper(sourceInfoMap.values()),
|
|
121
|
+
_step;
|
|
122
|
+
try {
|
|
123
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
124
|
+
var references = _step.value;
|
|
125
|
+
if (references.length > 1) {
|
|
126
|
+
references.forEach(function (reference, index) {
|
|
127
|
+
return reference.title = "".concat(reference.title, ": ").concat(formatMessage(messages.syncedLocationDropdownTitleBlockIndex, {
|
|
128
|
+
index: index + 1
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
_iterator.e(err);
|
|
135
|
+
} finally {
|
|
136
|
+
_iterator.f();
|
|
137
|
+
}
|
|
138
|
+
var sortedReferences = Array.from(sourceInfoMap.values()).flat().sort(function (a, b) {
|
|
139
|
+
if (a.isSource !== b.isSource) {
|
|
140
|
+
return b.isSource ? 1 : -1;
|
|
141
|
+
}
|
|
142
|
+
if (a.hasAccess !== b.hasAccess) {
|
|
143
|
+
return a.hasAccess ? -1 : 1;
|
|
144
|
+
}
|
|
145
|
+
return (a.title || '').localeCompare(b.title || '');
|
|
146
|
+
});
|
|
147
|
+
return sortedReferences;
|
|
148
|
+
};
|
|
149
|
+
export var SyncedLocationDropdown = function SyncedLocationDropdown(_ref4) {
|
|
150
|
+
var syncBlockStore = _ref4.syncBlockStore,
|
|
151
|
+
resourceId = _ref4.resourceId,
|
|
152
|
+
intl = _ref4.intl,
|
|
153
|
+
isSource = _ref4.isSource,
|
|
154
|
+
localId = _ref4.localId;
|
|
155
|
+
var formatMessage = intl.formatMessage;
|
|
156
|
+
var triggerTitle = formatMessage(messages.syncedLocationDropdownTitle);
|
|
157
|
+
var _useState = useState(false),
|
|
158
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
159
|
+
isOpen = _useState2[0],
|
|
160
|
+
setIsOpen = _useState2[1];
|
|
161
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
162
|
+
isOpen: isOpen,
|
|
163
|
+
onOpenChange: function onOpenChange(_ref5) {
|
|
164
|
+
var isOpen = _ref5.isOpen;
|
|
165
|
+
return setIsOpen(isOpen);
|
|
166
|
+
},
|
|
167
|
+
trigger: function trigger(_ref6) {
|
|
168
|
+
var triggerRef = _ref6.triggerRef,
|
|
169
|
+
triggerProps = _objectWithoutProperties(_ref6, _excluded);
|
|
170
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
171
|
+
ref: triggerRef,
|
|
172
|
+
areAnyNewToolbarFlagsEnabled: true,
|
|
173
|
+
iconAfter: /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
174
|
+
color: "currentColor",
|
|
175
|
+
spacing: "spacious",
|
|
176
|
+
label: "",
|
|
177
|
+
size: "small"
|
|
178
|
+
})
|
|
179
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
180
|
+
}, triggerProps), triggerTitle);
|
|
181
|
+
}
|
|
182
|
+
}, isOpen && /*#__PURE__*/React.createElement(DropdownContent, {
|
|
183
|
+
syncBlockStore: syncBlockStore,
|
|
184
|
+
resourceId: resourceId,
|
|
185
|
+
intl: intl,
|
|
186
|
+
isSource: isSource,
|
|
187
|
+
localId: localId
|
|
188
|
+
}));
|
|
189
|
+
};
|
|
190
|
+
var DropdownContent = function DropdownContent(_ref7) {
|
|
191
|
+
var syncBlockStore = _ref7.syncBlockStore,
|
|
192
|
+
resourceId = _ref7.resourceId,
|
|
193
|
+
intl = _ref7.intl,
|
|
194
|
+
isSource = _ref7.isSource,
|
|
195
|
+
localId = _ref7.localId;
|
|
196
|
+
var formatMessage = intl.formatMessage;
|
|
197
|
+
var _useState3 = useState('none'),
|
|
198
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
199
|
+
fetchStatus = _useState4[0],
|
|
200
|
+
setFetchStatus = _useState4[1];
|
|
201
|
+
var _useState5 = useState([]),
|
|
202
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
203
|
+
referenceData = _useState6[0],
|
|
204
|
+
setReferenceData = _useState6[1];
|
|
205
|
+
useEffect(function () {
|
|
206
|
+
setFetchStatus('loading');
|
|
207
|
+
var getReferenceData = /*#__PURE__*/function () {
|
|
208
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
209
|
+
var response;
|
|
210
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
211
|
+
while (1) switch (_context.prev = _context.next) {
|
|
212
|
+
case 0:
|
|
213
|
+
_context.next = 2;
|
|
214
|
+
return syncBlockStore.fetchReferencesSourceInfo(resourceId, localId, isSource);
|
|
215
|
+
case 2:
|
|
216
|
+
response = _context.sent;
|
|
217
|
+
if (!response.error) {
|
|
218
|
+
_context.next = 6;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
setFetchStatus('error');
|
|
222
|
+
return _context.abrupt("return");
|
|
223
|
+
case 6:
|
|
224
|
+
setReferenceData(processReferenceData(response.references, intl));
|
|
225
|
+
setFetchStatus('success');
|
|
226
|
+
case 8:
|
|
227
|
+
case "end":
|
|
228
|
+
return _context.stop();
|
|
229
|
+
}
|
|
230
|
+
}, _callee);
|
|
231
|
+
}));
|
|
232
|
+
return function getReferenceData() {
|
|
233
|
+
return _ref8.apply(this, arguments);
|
|
234
|
+
};
|
|
235
|
+
}();
|
|
236
|
+
getReferenceData();
|
|
237
|
+
}, [syncBlockStore, intl, isSource, localId, resourceId]);
|
|
238
|
+
var content = function content() {
|
|
239
|
+
switch (fetchStatus) {
|
|
240
|
+
case 'loading':
|
|
241
|
+
return /*#__PURE__*/React.createElement(LoadingScreen, null);
|
|
242
|
+
case 'error':
|
|
243
|
+
return /*#__PURE__*/React.createElement(ErrorScreen, {
|
|
244
|
+
formatMessage: formatMessage
|
|
245
|
+
});
|
|
246
|
+
case 'success':
|
|
247
|
+
if (referenceData.length > 0) {
|
|
248
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
249
|
+
"data-testid": "synced-locations-dropdown-content",
|
|
250
|
+
className: ax([styles.contentContainer, "_ku9g126e _18bk1rpy"])
|
|
251
|
+
}, /*#__PURE__*/React.createElement(DropdownItemGroup, {
|
|
252
|
+
title: formatMessage(messages.syncedLocationDropdownHeading, {
|
|
253
|
+
count: "".concat(referenceData.length > 99 ? '99+' : referenceData.length)
|
|
254
|
+
})
|
|
255
|
+
}, referenceData.map(function (reference) {
|
|
256
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
257
|
+
key: reference.title,
|
|
258
|
+
className: ax(["_2ll012x7"])
|
|
259
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
260
|
+
content: reference.title || reference.url || ''
|
|
261
|
+
}, /*#__PURE__*/React.createElement(DropdownItem, {
|
|
262
|
+
elemBefore: /*#__PURE__*/React.createElement(ItemIcon, {
|
|
263
|
+
reference: reference
|
|
264
|
+
}),
|
|
265
|
+
href: reference.url,
|
|
266
|
+
target: "_blank",
|
|
267
|
+
key: reference.title
|
|
268
|
+
}, /*#__PURE__*/React.createElement(ItemTitle, {
|
|
269
|
+
title: reference.title || reference.url || '',
|
|
270
|
+
formatMessage: formatMessage,
|
|
271
|
+
onSamePage: reference.onSamePage,
|
|
272
|
+
isSource: reference.isSource,
|
|
273
|
+
hasAccess: reference.hasAccess
|
|
274
|
+
}))));
|
|
275
|
+
})));
|
|
276
|
+
} else {
|
|
277
|
+
return /*#__PURE__*/React.createElement(NoResultScreen, {
|
|
278
|
+
formatMessage: formatMessage
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
284
|
+
xcss: styles.dropdownContent
|
|
285
|
+
}, content());
|
|
286
|
+
};
|
|
287
|
+
var LoadingScreen = function LoadingScreen() {
|
|
288
|
+
return /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Spinner, null));
|
|
289
|
+
};
|
|
290
|
+
var ErrorScreen = function ErrorScreen(_ref9) {
|
|
291
|
+
var formatMessage = _ref9.formatMessage;
|
|
292
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
293
|
+
xcss: styles.errorContainer
|
|
294
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
295
|
+
xcss: styles.errorIcon
|
|
296
|
+
}, /*#__PURE__*/React.createElement(StatusErrorIcon, {
|
|
297
|
+
color: "var(--ds-icon-danger, #C9372C)",
|
|
298
|
+
spacing: "spacious",
|
|
299
|
+
label: "",
|
|
300
|
+
size: "small"
|
|
301
|
+
})), /*#__PURE__*/React.createElement(Text, {
|
|
302
|
+
as: "p",
|
|
303
|
+
size: "medium"
|
|
304
|
+
}, formatMessage(messages.syncedLocationDropdownError)));
|
|
305
|
+
};
|
|
306
|
+
var NoResultScreen = function NoResultScreen(_ref0) {
|
|
307
|
+
var formatMessage = _ref0.formatMessage;
|
|
308
|
+
return /*#__PURE__*/React.createElement(Stack, {
|
|
309
|
+
xcss: styles.noResultsContainer,
|
|
310
|
+
space: "space.100"
|
|
311
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
312
|
+
as: "p"
|
|
313
|
+
}, formatMessage(messages.syncedLocationDropdownNoResults)), /*#__PURE__*/React.createElement(Text, {
|
|
314
|
+
as: "p"
|
|
315
|
+
}, /*#__PURE__*/React.createElement(Anchor, {
|
|
316
|
+
href: "https://hello.atlassian.net/wiki/x/tAtCeAE",
|
|
317
|
+
target: "_blank",
|
|
318
|
+
xcss: styles.learnMoreLink
|
|
319
|
+
}, formatMessage(messages.syncedLocationDropdownLearnMoreLink))));
|
|
320
|
+
};
|