@atlaskit/editor-common 134.10.1 → 134.11.1
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 +34 -0
- package/afm-products/tsconfig.json +3 -0
- package/credit-guard/package.json +10 -0
- package/dist/cjs/credit-guard/CreditCheckedPopup.compiled.css +7 -0
- package/dist/cjs/credit-guard/CreditCheckedPopup.js +195 -0
- package/dist/cjs/credit-guard/checkAICreditStatus.js +25 -0
- package/dist/cjs/credit-guard/index.js +26 -0
- package/dist/cjs/credit-guard/types.js +5 -0
- package/dist/cjs/credit-guard/useAICreditGuard.js +51 -0
- package/dist/cjs/element-browser/components/ElementList/ElementList.js +67 -14
- package/dist/cjs/element-browser/components/StatelessElementBrowser.js +19 -5
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/quick-insert/insert-menu-check.js +15 -0
- package/dist/cjs/ui/DropList/index.js +1 -1
- package/dist/es2019/credit-guard/CreditCheckedPopup.compiled.css +7 -0
- package/dist/es2019/credit-guard/CreditCheckedPopup.js +174 -0
- package/dist/es2019/credit-guard/checkAICreditStatus.js +19 -0
- package/dist/es2019/credit-guard/index.js +5 -0
- package/dist/es2019/credit-guard/types.js +1 -0
- package/dist/es2019/credit-guard/useAICreditGuard.js +33 -0
- package/dist/es2019/element-browser/components/ElementList/ElementList.js +58 -6
- package/dist/es2019/element-browser/components/StatelessElementBrowser.js +19 -5
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/quick-insert/insert-menu-check.js +9 -0
- package/dist/es2019/ui/DropList/index.js +1 -1
- package/dist/esm/credit-guard/CreditCheckedPopup.compiled.css +7 -0
- package/dist/esm/credit-guard/CreditCheckedPopup.js +186 -0
- package/dist/esm/credit-guard/checkAICreditStatus.js +19 -0
- package/dist/esm/credit-guard/index.js +5 -0
- package/dist/esm/credit-guard/types.js +1 -0
- package/dist/esm/credit-guard/useAICreditGuard.js +44 -0
- package/dist/esm/element-browser/components/ElementList/ElementList.js +67 -14
- package/dist/esm/element-browser/components/StatelessElementBrowser.js +19 -5
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/quick-insert/insert-menu-check.js +9 -0
- package/dist/esm/ui/DropList/index.js +1 -1
- package/dist/types/credit-guard/CreditCheckedPopup.d.ts +34 -0
- package/dist/types/credit-guard/checkAICreditStatus.d.ts +3 -0
- package/dist/types/credit-guard/index.d.ts +6 -0
- package/dist/types/credit-guard/types.d.ts +13 -0
- package/dist/types/credit-guard/useAICreditGuard.d.ts +16 -0
- package/dist/types/element-browser/components/ElementList/ElementList.d.ts +1 -0
- package/dist/types/provider-factory/quick-insert-provider.d.ts +26 -0
- package/dist/types/quick-insert/insert-menu-check.d.ts +5 -0
- package/package.json +3 -2
- package/quick-insert/insert-menu-check/package.json +10 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/* CreditCheckedPopup.tsx generated by @compiled/babel-plugin v3.0.2 */
|
|
2
|
+
import "./CreditCheckedPopup.compiled.css";
|
|
3
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
+
import React, { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
5
|
+
import { bind } from 'bind-event-listener';
|
|
6
|
+
import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
|
|
7
|
+
import { Popup } from '@atlaskit/popup/popup';
|
|
8
|
+
import { Box } from '@atlaskit/primitives/compiled/box';
|
|
9
|
+
import { useAICreditGuard } from './useAICreditGuard';
|
|
10
|
+
const CreditPopupTrigger = ({
|
|
11
|
+
props,
|
|
12
|
+
id,
|
|
13
|
+
renderTrigger,
|
|
14
|
+
onElement
|
|
15
|
+
}) => {
|
|
16
|
+
const popupRef = props.ref;
|
|
17
|
+
const ref = useCallback(element => {
|
|
18
|
+
onElement(element);
|
|
19
|
+
if (typeof popupRef === 'function') {
|
|
20
|
+
popupRef(element);
|
|
21
|
+
} else if (popupRef) {
|
|
22
|
+
Object.assign(popupRef, {
|
|
23
|
+
current: element
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}, [onElement, popupRef]);
|
|
27
|
+
return renderTrigger({
|
|
28
|
+
...props,
|
|
29
|
+
ref,
|
|
30
|
+
id
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const styles = {
|
|
34
|
+
content: "_1bsb5jys _p12f1osq _vchhusvi _ca0qpxbi _u5f3pxbi _n3tdpxbi _19bvpxbi"
|
|
35
|
+
};
|
|
36
|
+
const stopPropagation = event => event.stopPropagation();
|
|
37
|
+
|
|
38
|
+
/** Editor owns popup behavior; products supply content through getAICreditStatus. */
|
|
39
|
+
const CreditPopup = ({
|
|
40
|
+
guard: {
|
|
41
|
+
feedback,
|
|
42
|
+
close
|
|
43
|
+
},
|
|
44
|
+
renderTrigger,
|
|
45
|
+
placement = 'right-start',
|
|
46
|
+
isNestedMenu = false,
|
|
47
|
+
shouldRenderToParent
|
|
48
|
+
}) => {
|
|
49
|
+
const id = useId();
|
|
50
|
+
const [contentElement, setContentElement] = useState(null);
|
|
51
|
+
const [triggerElement, setTriggerElement] = useState(null);
|
|
52
|
+
const returnFocus = useRef(null);
|
|
53
|
+
const wasOpen = useRef(false);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (feedback && !wasOpen.current) {
|
|
56
|
+
const active = triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.ownerDocument.activeElement;
|
|
57
|
+
returnFocus.current = active instanceof HTMLElement ? active : null;
|
|
58
|
+
}
|
|
59
|
+
wasOpen.current = feedback !== null;
|
|
60
|
+
}, [feedback, triggerElement]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!feedback || !contentElement || !isNestedMenu) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
return bind(contentElement.ownerDocument, {
|
|
66
|
+
type: 'scroll',
|
|
67
|
+
options: {
|
|
68
|
+
capture: true
|
|
69
|
+
},
|
|
70
|
+
listener: event => {
|
|
71
|
+
if (event.target instanceof Node && contentElement.contains(event.target)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
close();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}, [feedback, contentElement, isNestedMenu, close]);
|
|
78
|
+
const onKeyDown = useCallback(event => {
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
if (event.key === 'Escape') {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
close();
|
|
83
|
+
if (isNestedMenu) {
|
|
84
|
+
var _returnFocus$current;
|
|
85
|
+
(_returnFocus$current = returnFocus.current) === null || _returnFocus$current === void 0 ? void 0 : _returnFocus$current.focus();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, [close, isNestedMenu]);
|
|
89
|
+
const content = useCallback(() => /*#__PURE__*/React.createElement(Box, {
|
|
90
|
+
ref: setContentElement,
|
|
91
|
+
xcss: styles.content,
|
|
92
|
+
role: "none",
|
|
93
|
+
onClick: stopPropagation,
|
|
94
|
+
onKeyDown: onKeyDown
|
|
95
|
+
}, feedback === null || feedback === void 0 ? void 0 : feedback.renderCustomContent()), [feedback, onKeyDown]);
|
|
96
|
+
const trigger = useCallback(props => /*#__PURE__*/React.createElement(CreditPopupTrigger, {
|
|
97
|
+
props: props,
|
|
98
|
+
id: id,
|
|
99
|
+
renderTrigger: renderTrigger,
|
|
100
|
+
onElement: setTriggerElement
|
|
101
|
+
}), [renderTrigger, id]);
|
|
102
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
103
|
+
isOpen: feedback !== null,
|
|
104
|
+
onClose: close,
|
|
105
|
+
role: "dialog",
|
|
106
|
+
titleId: (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.id) || id,
|
|
107
|
+
placement: placement,
|
|
108
|
+
shouldFitViewport: true,
|
|
109
|
+
shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false,
|
|
110
|
+
zIndex: isNestedMenu ? akEditorFloatingDialogZIndex : undefined,
|
|
111
|
+
strategy: isNestedMenu ? 'fixed' : undefined,
|
|
112
|
+
shouldReturnFocus: !isNestedMenu,
|
|
113
|
+
shouldUseCaptureOnOutsideClick: true,
|
|
114
|
+
content: content,
|
|
115
|
+
trigger: trigger
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Props the trigger applies to anchor the popup and guard its native action. */
|
|
120
|
+
|
|
121
|
+
const CreditCheckedActionPopup = ({
|
|
122
|
+
creditCheck,
|
|
123
|
+
getAICreditStatus,
|
|
124
|
+
onAllowed,
|
|
125
|
+
placement,
|
|
126
|
+
renderTrigger
|
|
127
|
+
}) => {
|
|
128
|
+
const guard = useAICreditGuard(getAICreditStatus);
|
|
129
|
+
const {
|
|
130
|
+
check,
|
|
131
|
+
close,
|
|
132
|
+
feedback
|
|
133
|
+
} = guard;
|
|
134
|
+
const activate = useCallback(event => {
|
|
135
|
+
if (feedback) {
|
|
136
|
+
close();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (check(creditCheck)) {
|
|
140
|
+
onAllowed(event);
|
|
141
|
+
}
|
|
142
|
+
}, [feedback, close, check, creditCheck, onAllowed]);
|
|
143
|
+
const trigger = useCallback(props => renderTrigger({
|
|
144
|
+
...props,
|
|
145
|
+
'aria-haspopup': 'dialog',
|
|
146
|
+
isSelected: feedback !== null,
|
|
147
|
+
onClick: activate
|
|
148
|
+
}), [renderTrigger, feedback, activate]);
|
|
149
|
+
return /*#__PURE__*/React.createElement(CreditPopup, {
|
|
150
|
+
guard: guard,
|
|
151
|
+
placement: placement,
|
|
152
|
+
renderTrigger: trigger
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Reuses the toolbar action contract; insert-menu adapters can supply an externally triggered guard. */
|
|
157
|
+
export const CreditCheckedPopup = props => {
|
|
158
|
+
if ('guard' in props) {
|
|
159
|
+
return /*#__PURE__*/React.createElement(CreditPopup, {
|
|
160
|
+
guard: props.guard,
|
|
161
|
+
placement: props.placement,
|
|
162
|
+
renderTrigger: props.renderTrigger,
|
|
163
|
+
isNestedMenu: props.isNestedMenu,
|
|
164
|
+
shouldRenderToParent: props.shouldRenderToParent
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return /*#__PURE__*/React.createElement(CreditCheckedActionPopup, {
|
|
168
|
+
creditCheck: props.creditCheck,
|
|
169
|
+
getAICreditStatus: props.getAICreditStatus,
|
|
170
|
+
onAllowed: props.onAllowed,
|
|
171
|
+
placement: props.placement,
|
|
172
|
+
renderTrigger: props.renderTrigger
|
|
173
|
+
});
|
|
174
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Editor consumes cached decisions synchronously; legacy async providers fail open. */
|
|
2
|
+
export const checkAICreditStatus = (getAICreditStatus, creditCheck) => {
|
|
3
|
+
try {
|
|
4
|
+
const result = getAICreditStatus(creditCheck);
|
|
5
|
+
if ('then' in result) {
|
|
6
|
+
// Temporary compatibility: never defer an Editor action or apply a late decision.
|
|
7
|
+
void result.catch(() => {});
|
|
8
|
+
return {
|
|
9
|
+
isBlocked: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
} catch {
|
|
14
|
+
// Advisory checks fail open; action backends remain authoritative.
|
|
15
|
+
return {
|
|
16
|
+
isBlocked: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { checkAICreditStatus } from './checkAICreditStatus';
|
|
3
|
+
/** Shares advisory checks and feedback state without owning action execution or selection. */
|
|
4
|
+
export const useAICreditGuard = (getAICreditStatus, isActive = true) => {
|
|
5
|
+
const [feedback, setFeedback] = useState(null);
|
|
6
|
+
const [isBlocked, setIsBlocked] = useState(false);
|
|
7
|
+
const close = useCallback(() => setFeedback(null), []);
|
|
8
|
+
useLayoutEffect(() => {
|
|
9
|
+
if (!isActive) {
|
|
10
|
+
close();
|
|
11
|
+
setIsBlocked(false);
|
|
12
|
+
}
|
|
13
|
+
}, [isActive, close]);
|
|
14
|
+
const check = useCallback((creditCheck, {
|
|
15
|
+
showFeedback = true
|
|
16
|
+
} = {}) => {
|
|
17
|
+
if (!isActive) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const result = checkAICreditStatus(getAICreditStatus, creditCheck);
|
|
21
|
+
setIsBlocked(result.isBlocked);
|
|
22
|
+
if (showFeedback) {
|
|
23
|
+
setFeedback(result.isBlocked ? result : null);
|
|
24
|
+
}
|
|
25
|
+
return !result.isBlocked;
|
|
26
|
+
}, [getAICreditStatus, isActive]);
|
|
27
|
+
return {
|
|
28
|
+
check,
|
|
29
|
+
close,
|
|
30
|
+
feedback,
|
|
31
|
+
isBlocked
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -365,6 +365,7 @@ const ElementListMultipleColumns = props => {
|
|
|
365
365
|
const MemoizedElementItem = /*#__PURE__*/memo(ElementItem);
|
|
366
366
|
MemoizedElementItem.displayName = 'MemoizedElementItem';
|
|
367
367
|
|
|
368
|
+
/** Render an insert item, optionally wrapped by its interaction policy. */
|
|
368
369
|
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
369
370
|
export function ElementItem({
|
|
370
371
|
inlineMode,
|
|
@@ -377,6 +378,7 @@ export function ElementItem({
|
|
|
377
378
|
role
|
|
378
379
|
}) {
|
|
379
380
|
const ref = useFocus(focus);
|
|
381
|
+
const surface = inlineMode ? 'toolbar' : 'element-browser';
|
|
380
382
|
|
|
381
383
|
/**
|
|
382
384
|
* Note: props.onSelectItem(item) is not called here as the StatelessElementBrowser's
|
|
@@ -384,10 +386,17 @@ export function ElementItem({
|
|
|
384
386
|
* This implementation was changed for keyboard/click selection to work with `onInsertItem`.
|
|
385
387
|
*/
|
|
386
388
|
const onClick = useCallback(e => {
|
|
389
|
+
var _item$onBeforeSelect;
|
|
387
390
|
e.preventDefault();
|
|
388
391
|
e.stopPropagation();
|
|
389
392
|
setFocusedItemIndex(index);
|
|
390
|
-
|
|
393
|
+
const detail = e.nativeEvent.detail;
|
|
394
|
+
if (((_item$onBeforeSelect = item.onBeforeSelect) === null || _item$onBeforeSelect === void 0 ? void 0 : _item$onBeforeSelect.call(item, {
|
|
395
|
+
surface
|
|
396
|
+
})) === false) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
switch (detail) {
|
|
391
400
|
case 0:
|
|
392
401
|
onInsertItem(item);
|
|
393
402
|
break;
|
|
@@ -404,7 +413,47 @@ export function ElementItem({
|
|
|
404
413
|
default:
|
|
405
414
|
return;
|
|
406
415
|
}
|
|
407
|
-
}, [index, inlineMode, item, onInsertItem, setFocusedItemIndex]);
|
|
416
|
+
}, [index, inlineMode, item, onInsertItem, setFocusedItemIndex, surface]);
|
|
417
|
+
const renderItem = useCallback(triggerProps => jsx(ElementItemButton, {
|
|
418
|
+
item: item,
|
|
419
|
+
index: index,
|
|
420
|
+
inlineMode: inlineMode,
|
|
421
|
+
selected: selected,
|
|
422
|
+
role: role,
|
|
423
|
+
onClick: onClick,
|
|
424
|
+
focusRef: ref,
|
|
425
|
+
triggerProps: triggerProps
|
|
426
|
+
}), [item, index, inlineMode, selected, role, onClick, ref]);
|
|
427
|
+
return item.renderMenuItemWrapper ? item.renderMenuItemWrapper({
|
|
428
|
+
isActive: focus || selected,
|
|
429
|
+
surface,
|
|
430
|
+
renderItem
|
|
431
|
+
}) : renderItem();
|
|
432
|
+
}
|
|
433
|
+
const ElementItemButton = ({
|
|
434
|
+
item,
|
|
435
|
+
index,
|
|
436
|
+
inlineMode,
|
|
437
|
+
selected,
|
|
438
|
+
role,
|
|
439
|
+
onClick,
|
|
440
|
+
focusRef,
|
|
441
|
+
triggerProps
|
|
442
|
+
}) => {
|
|
443
|
+
var _triggerProps$isSelec;
|
|
444
|
+
const popupRef = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.ref;
|
|
445
|
+
const setTriggerRef = useCallback(element => {
|
|
446
|
+
Object.assign(focusRef, {
|
|
447
|
+
current: element
|
|
448
|
+
});
|
|
449
|
+
if (typeof popupRef === 'function') {
|
|
450
|
+
popupRef(element);
|
|
451
|
+
} else if (popupRef) {
|
|
452
|
+
Object.assign(popupRef, {
|
|
453
|
+
current: element
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}, [focusRef, popupRef]);
|
|
408
457
|
const {
|
|
409
458
|
icon,
|
|
410
459
|
title,
|
|
@@ -422,10 +471,13 @@ export function ElementItem({
|
|
|
422
471
|
icon: icon,
|
|
423
472
|
title: title
|
|
424
473
|
}),
|
|
425
|
-
isSelected: selected,
|
|
474
|
+
isSelected: (_triggerProps$isSelec = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.isSelected) !== null && _triggerProps$isSelec !== void 0 ? _triggerProps$isSelec : selected,
|
|
475
|
+
"aria-controls": triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps['aria-controls'],
|
|
426
476
|
"aria-label": title,
|
|
427
|
-
ref:
|
|
428
|
-
testId: `element-item-${index}
|
|
477
|
+
ref: setTriggerRef,
|
|
478
|
+
testId: `element-item-${index}`
|
|
479
|
+
// Keep the search combobox's aria-activedescendant target stable.
|
|
480
|
+
,
|
|
429
481
|
id: `searched-item-${index}`,
|
|
430
482
|
isDisabled: isDisabled,
|
|
431
483
|
role: role
|
|
@@ -442,7 +494,7 @@ export function ElementItem({
|
|
|
442
494
|
isDisabled: isDisabled,
|
|
443
495
|
lozenge: lozenge
|
|
444
496
|
})));
|
|
445
|
-
}
|
|
497
|
+
};
|
|
446
498
|
|
|
447
499
|
/**
|
|
448
500
|
* Inline mode should use the existing Align-items:center value.
|
|
@@ -192,6 +192,7 @@ function StatelessElementBrowser(props) {
|
|
|
192
192
|
/* Only for hitting enter to select item when focused on search bar,
|
|
193
193
|
* The actual enter key press is handled on individual items level.
|
|
194
194
|
*/
|
|
195
|
+
const surface = props.mode === 'inline' ? 'toolbar' : 'element-browser';
|
|
195
196
|
const selectedItem = selectedItemIndex !== undefined ? items[selectedItemIndex] : null;
|
|
196
197
|
const onItemsEnterTabKeyPress = useCallback(e => {
|
|
197
198
|
var _selectedItem$isDisab;
|
|
@@ -204,11 +205,16 @@ function StatelessElementBrowser(props) {
|
|
|
204
205
|
e.preventDefault();
|
|
205
206
|
return;
|
|
206
207
|
}
|
|
208
|
+
e.preventDefault();
|
|
207
209
|
if (onInsertItem && selectedItem != null && !((_selectedItem$isDisab = selectedItem.isDisabled) !== null && _selectedItem$isDisab !== void 0 ? _selectedItem$isDisab : false)) {
|
|
208
|
-
|
|
210
|
+
var _selectedItem$onBefor;
|
|
211
|
+
if (((_selectedItem$onBefor = selectedItem.onBeforeSelect) === null || _selectedItem$onBefor === void 0 ? void 0 : _selectedItem$onBefor.call(selectedItem, {
|
|
212
|
+
surface
|
|
213
|
+
})) !== false) {
|
|
214
|
+
onInsertItem(selectedItem);
|
|
215
|
+
}
|
|
209
216
|
}
|
|
210
|
-
|
|
211
|
-
}, [onInsertItem, selectedItem, setFocusedCategoryIndex, showCategories, selectedCategoryIndex]);
|
|
217
|
+
}, [onInsertItem, selectedItem, setFocusedCategoryIndex, showCategories, selectedCategoryIndex, surface]);
|
|
212
218
|
|
|
213
219
|
/**
|
|
214
220
|
* On arrow key selection and clicks the selectedItemIndex will change.
|
|
@@ -216,9 +222,17 @@ function StatelessElementBrowser(props) {
|
|
|
216
222
|
*/
|
|
217
223
|
useEffect(() => {
|
|
218
224
|
if (onSelectItem && selectedItem != null) {
|
|
219
|
-
|
|
225
|
+
var _selectedItem$onBefor2;
|
|
226
|
+
// Highlighting is eligibility-only: arrows must never open a popup or take focus.
|
|
227
|
+
// eslint-disable-next-line @atlassian/perf-linting/no-chain-state-updates -- Synchronize silent eligibility with the product-supplied guard before notifying the parent selection.
|
|
228
|
+
if (((_selectedItem$onBefor2 = selectedItem.onBeforeSelect) === null || _selectedItem$onBefor2 === void 0 ? void 0 : _selectedItem$onBefor2.call(selectedItem, {
|
|
229
|
+
surface,
|
|
230
|
+
showFeedback: false
|
|
231
|
+
})) !== false) {
|
|
232
|
+
onSelectItem(selectedItem);
|
|
233
|
+
}
|
|
220
234
|
}
|
|
221
|
-
}, [onSelectItem, selectedItem]);
|
|
235
|
+
}, [onSelectItem, selectedItem, surface, focusedItemIndex, selectedItemIndex]);
|
|
222
236
|
const onSelectCategoryCB = useCallback(category => {
|
|
223
237
|
onSelectCategory(category);
|
|
224
238
|
categoryBeenChosen.current = true;
|
|
@@ -13,7 +13,7 @@ const NETWORK_FAILURE_REGEX = /^network failure/i;
|
|
|
13
13
|
const RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
|
|
14
14
|
const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
|
|
15
15
|
const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
|
|
16
|
-
const packageVersion = "134.
|
|
16
|
+
const packageVersion = "134.11.0";
|
|
17
17
|
const sanitiseSentryEvents = (data, _hint) => {
|
|
18
18
|
// Remove URL as it has UGC
|
|
19
19
|
// Ignored via go/ees007
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility helper for existing package consumers; Editor callers check item.onBeforeSelect directly.
|
|
3
|
+
*/
|
|
4
|
+
export const runInsertMenuItemCheck = (item, options, onAllowed) => {
|
|
5
|
+
var _item$onBeforeSelect;
|
|
6
|
+
if (((_item$onBeforeSelect = item.onBeforeSelect) === null || _item$onBeforeSelect === void 0 ? void 0 : _item$onBeforeSelect.call(item, options)) !== false) {
|
|
7
|
+
onAllowed();
|
|
8
|
+
}
|
|
9
|
+
};
|
|
@@ -13,7 +13,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
|
|
|
13
13
|
import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
|
|
14
14
|
import Layer from '../Layer';
|
|
15
15
|
const packageName = "@atlaskit/editor-common";
|
|
16
|
-
const packageVersion = "134.
|
|
16
|
+
const packageVersion = "134.11.0";
|
|
17
17
|
const halfFocusRing = 1;
|
|
18
18
|
const dropOffset = '0, 8';
|
|
19
19
|
// Ignored via go/ees005
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
._19bvpxbi{padding-left:var(--ds-space-200,1pc)}
|
|
2
|
+
._1bsb5jys{width:11pc}
|
|
3
|
+
._ca0qpxbi{padding-top:var(--ds-space-200,1pc)}
|
|
4
|
+
._n3tdpxbi{padding-bottom:var(--ds-space-200,1pc)}
|
|
5
|
+
._p12f1osq{max-width:100%}
|
|
6
|
+
._u5f3pxbi{padding-right:var(--ds-space-200,1pc)}
|
|
7
|
+
._vchhusvi{box-sizing:border-box}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/* CreditCheckedPopup.tsx generated by @compiled/babel-plugin v3.0.2 */
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import "./CreditCheckedPopup.compiled.css";
|
|
5
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
import React, { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
9
|
+
import { bind } from 'bind-event-listener';
|
|
10
|
+
import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
|
|
11
|
+
import { Popup } from '@atlaskit/popup/popup';
|
|
12
|
+
import { Box } from '@atlaskit/primitives/compiled/box';
|
|
13
|
+
import { useAICreditGuard } from './useAICreditGuard';
|
|
14
|
+
var CreditPopupTrigger = function CreditPopupTrigger(_ref) {
|
|
15
|
+
var props = _ref.props,
|
|
16
|
+
id = _ref.id,
|
|
17
|
+
renderTrigger = _ref.renderTrigger,
|
|
18
|
+
onElement = _ref.onElement;
|
|
19
|
+
var popupRef = props.ref;
|
|
20
|
+
var ref = useCallback(function (element) {
|
|
21
|
+
onElement(element);
|
|
22
|
+
if (typeof popupRef === 'function') {
|
|
23
|
+
popupRef(element);
|
|
24
|
+
} else if (popupRef) {
|
|
25
|
+
Object.assign(popupRef, {
|
|
26
|
+
current: element
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}, [onElement, popupRef]);
|
|
30
|
+
return renderTrigger(_objectSpread(_objectSpread({}, props), {}, {
|
|
31
|
+
ref: ref,
|
|
32
|
+
id: id
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
var styles = {
|
|
36
|
+
content: "_1bsb5jys _p12f1osq _vchhusvi _ca0qpxbi _u5f3pxbi _n3tdpxbi _19bvpxbi"
|
|
37
|
+
};
|
|
38
|
+
var stopPropagation = function stopPropagation(event) {
|
|
39
|
+
return event.stopPropagation();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Editor owns popup behavior; products supply content through getAICreditStatus. */
|
|
43
|
+
var CreditPopup = function CreditPopup(_ref2) {
|
|
44
|
+
var _ref2$guard = _ref2.guard,
|
|
45
|
+
feedback = _ref2$guard.feedback,
|
|
46
|
+
close = _ref2$guard.close,
|
|
47
|
+
renderTrigger = _ref2.renderTrigger,
|
|
48
|
+
_ref2$placement = _ref2.placement,
|
|
49
|
+
placement = _ref2$placement === void 0 ? 'right-start' : _ref2$placement,
|
|
50
|
+
_ref2$isNestedMenu = _ref2.isNestedMenu,
|
|
51
|
+
isNestedMenu = _ref2$isNestedMenu === void 0 ? false : _ref2$isNestedMenu,
|
|
52
|
+
shouldRenderToParent = _ref2.shouldRenderToParent;
|
|
53
|
+
var id = useId();
|
|
54
|
+
var _useState = useState(null),
|
|
55
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
56
|
+
contentElement = _useState2[0],
|
|
57
|
+
setContentElement = _useState2[1];
|
|
58
|
+
var _useState3 = useState(null),
|
|
59
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
60
|
+
triggerElement = _useState4[0],
|
|
61
|
+
setTriggerElement = _useState4[1];
|
|
62
|
+
var returnFocus = useRef(null);
|
|
63
|
+
var wasOpen = useRef(false);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
if (feedback && !wasOpen.current) {
|
|
66
|
+
var active = triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.ownerDocument.activeElement;
|
|
67
|
+
returnFocus.current = active instanceof HTMLElement ? active : null;
|
|
68
|
+
}
|
|
69
|
+
wasOpen.current = feedback !== null;
|
|
70
|
+
}, [feedback, triggerElement]);
|
|
71
|
+
useEffect(function () {
|
|
72
|
+
if (!feedback || !contentElement || !isNestedMenu) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return bind(contentElement.ownerDocument, {
|
|
76
|
+
type: 'scroll',
|
|
77
|
+
options: {
|
|
78
|
+
capture: true
|
|
79
|
+
},
|
|
80
|
+
listener: function listener(event) {
|
|
81
|
+
if (event.target instanceof Node && contentElement.contains(event.target)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
close();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}, [feedback, contentElement, isNestedMenu, close]);
|
|
88
|
+
var onKeyDown = useCallback(function (event) {
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
if (event.key === 'Escape') {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
close();
|
|
93
|
+
if (isNestedMenu) {
|
|
94
|
+
var _returnFocus$current;
|
|
95
|
+
(_returnFocus$current = returnFocus.current) === null || _returnFocus$current === void 0 || _returnFocus$current.focus();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, [close, isNestedMenu]);
|
|
99
|
+
var content = useCallback(function () {
|
|
100
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
101
|
+
ref: setContentElement,
|
|
102
|
+
xcss: styles.content,
|
|
103
|
+
role: "none",
|
|
104
|
+
onClick: stopPropagation,
|
|
105
|
+
onKeyDown: onKeyDown
|
|
106
|
+
}, feedback === null || feedback === void 0 ? void 0 : feedback.renderCustomContent());
|
|
107
|
+
}, [feedback, onKeyDown]);
|
|
108
|
+
var trigger = useCallback(function (props) {
|
|
109
|
+
return /*#__PURE__*/React.createElement(CreditPopupTrigger, {
|
|
110
|
+
props: props,
|
|
111
|
+
id: id,
|
|
112
|
+
renderTrigger: renderTrigger,
|
|
113
|
+
onElement: setTriggerElement
|
|
114
|
+
});
|
|
115
|
+
}, [renderTrigger, id]);
|
|
116
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
117
|
+
isOpen: feedback !== null,
|
|
118
|
+
onClose: close,
|
|
119
|
+
role: "dialog",
|
|
120
|
+
titleId: (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.id) || id,
|
|
121
|
+
placement: placement,
|
|
122
|
+
shouldFitViewport: true,
|
|
123
|
+
shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false,
|
|
124
|
+
zIndex: isNestedMenu ? akEditorFloatingDialogZIndex : undefined,
|
|
125
|
+
strategy: isNestedMenu ? 'fixed' : undefined,
|
|
126
|
+
shouldReturnFocus: !isNestedMenu,
|
|
127
|
+
shouldUseCaptureOnOutsideClick: true,
|
|
128
|
+
content: content,
|
|
129
|
+
trigger: trigger
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** Props the trigger applies to anchor the popup and guard its native action. */
|
|
134
|
+
|
|
135
|
+
var CreditCheckedActionPopup = function CreditCheckedActionPopup(_ref3) {
|
|
136
|
+
var creditCheck = _ref3.creditCheck,
|
|
137
|
+
getAICreditStatus = _ref3.getAICreditStatus,
|
|
138
|
+
onAllowed = _ref3.onAllowed,
|
|
139
|
+
placement = _ref3.placement,
|
|
140
|
+
renderTrigger = _ref3.renderTrigger;
|
|
141
|
+
var guard = useAICreditGuard(getAICreditStatus);
|
|
142
|
+
var check = guard.check,
|
|
143
|
+
close = guard.close,
|
|
144
|
+
feedback = guard.feedback;
|
|
145
|
+
var activate = useCallback(function (event) {
|
|
146
|
+
if (feedback) {
|
|
147
|
+
close();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (check(creditCheck)) {
|
|
151
|
+
onAllowed(event);
|
|
152
|
+
}
|
|
153
|
+
}, [feedback, close, check, creditCheck, onAllowed]);
|
|
154
|
+
var trigger = useCallback(function (props) {
|
|
155
|
+
return renderTrigger(_objectSpread(_objectSpread({}, props), {}, {
|
|
156
|
+
'aria-haspopup': 'dialog',
|
|
157
|
+
isSelected: feedback !== null,
|
|
158
|
+
onClick: activate
|
|
159
|
+
}));
|
|
160
|
+
}, [renderTrigger, feedback, activate]);
|
|
161
|
+
return /*#__PURE__*/React.createElement(CreditPopup, {
|
|
162
|
+
guard: guard,
|
|
163
|
+
placement: placement,
|
|
164
|
+
renderTrigger: trigger
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/** Reuses the toolbar action contract; insert-menu adapters can supply an externally triggered guard. */
|
|
169
|
+
export var CreditCheckedPopup = function CreditCheckedPopup(props) {
|
|
170
|
+
if ('guard' in props) {
|
|
171
|
+
return /*#__PURE__*/React.createElement(CreditPopup, {
|
|
172
|
+
guard: props.guard,
|
|
173
|
+
placement: props.placement,
|
|
174
|
+
renderTrigger: props.renderTrigger,
|
|
175
|
+
isNestedMenu: props.isNestedMenu,
|
|
176
|
+
shouldRenderToParent: props.shouldRenderToParent
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return /*#__PURE__*/React.createElement(CreditCheckedActionPopup, {
|
|
180
|
+
creditCheck: props.creditCheck,
|
|
181
|
+
getAICreditStatus: props.getAICreditStatus,
|
|
182
|
+
onAllowed: props.onAllowed,
|
|
183
|
+
placement: props.placement,
|
|
184
|
+
renderTrigger: props.renderTrigger
|
|
185
|
+
});
|
|
186
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Editor consumes cached decisions synchronously; legacy async providers fail open. */
|
|
2
|
+
export var checkAICreditStatus = function checkAICreditStatus(getAICreditStatus, creditCheck) {
|
|
3
|
+
try {
|
|
4
|
+
var result = getAICreditStatus(creditCheck);
|
|
5
|
+
if ('then' in result) {
|
|
6
|
+
// Temporary compatibility: never defer an Editor action or apply a late decision.
|
|
7
|
+
void result.catch(function () {});
|
|
8
|
+
return {
|
|
9
|
+
isBlocked: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
} catch (_unused) {
|
|
14
|
+
// Advisory checks fail open; action backends remain authoritative.
|
|
15
|
+
return {
|
|
16
|
+
isBlocked: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|