@promptbook/components 0.112.0-59 → 0.112.0-61
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/esm/index.es.js +502 -355
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-components/BookEditor/useBookEditorMonacoInteractions.d.ts +40 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +34 -0
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +2 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +502 -355
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-components/BookEditor/useBookEditorMonacoInteractions.d.ts +40 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +34 -0
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +2 -0
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -40,7 +40,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
40
40
|
* @generated
|
|
41
41
|
* @see https://github.com/webgptorg/promptbook
|
|
42
42
|
*/
|
|
43
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
43
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-61';
|
|
44
44
|
/**
|
|
45
45
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
46
46
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -23561,6 +23561,241 @@ function useBookEditorMonacoDiagnostics({ editor, monaco, diagnostics }) {
|
|
|
23561
23561
|
}, [diagnostics, editor, monaco]);
|
|
23562
23562
|
}
|
|
23563
23563
|
|
|
23564
|
+
/**
|
|
23565
|
+
* Clipboard MIME types treated as rich text documents for upload.
|
|
23566
|
+
*
|
|
23567
|
+
* @private function of BookEditorMonaco
|
|
23568
|
+
*/
|
|
23569
|
+
const RICH_CLIPBOARD_TEXT_MIME_TYPES = new Set(['text/html', 'text/rtf']);
|
|
23570
|
+
/**
|
|
23571
|
+
* Uploaded filename mapping for known rich clipboard MIME types.
|
|
23572
|
+
*
|
|
23573
|
+
* @private function of BookEditorMonaco
|
|
23574
|
+
*/
|
|
23575
|
+
const CLIPBOARD_RICH_CONTENT_FILENAMES = {
|
|
23576
|
+
'text/html': 'clipboard-content.html',
|
|
23577
|
+
'text/rtf': 'clipboard-content.rtf',
|
|
23578
|
+
'application/rtf': 'clipboard-content.rtf',
|
|
23579
|
+
};
|
|
23580
|
+
/**
|
|
23581
|
+
* Fallback filename used when clipboard MIME type is unknown.
|
|
23582
|
+
*
|
|
23583
|
+
* @private function of BookEditorMonaco
|
|
23584
|
+
*/
|
|
23585
|
+
const DEFAULT_CLIPBOARD_RICH_CONTENT_FILENAME = 'clipboard-content.txt';
|
|
23586
|
+
/**
|
|
23587
|
+
* Maximum pointer travel still treated as a tap on the touch focus overlay.
|
|
23588
|
+
*
|
|
23589
|
+
* @private function of BookEditorMonaco
|
|
23590
|
+
*/
|
|
23591
|
+
const TOUCH_TAP_THRESHOLD = 10;
|
|
23592
|
+
/**
|
|
23593
|
+
* Lists transferable items from a browser `DataTransfer` object.
|
|
23594
|
+
*
|
|
23595
|
+
* @private function of BookEditorMonaco
|
|
23596
|
+
*/
|
|
23597
|
+
function listDataTransferItems(dataTransfer) {
|
|
23598
|
+
const items = [];
|
|
23599
|
+
for (let index = 0; index < dataTransfer.items.length; index++) {
|
|
23600
|
+
const item = dataTransfer.items[index];
|
|
23601
|
+
if (item) {
|
|
23602
|
+
items.push(item);
|
|
23603
|
+
}
|
|
23604
|
+
}
|
|
23605
|
+
return items;
|
|
23606
|
+
}
|
|
23607
|
+
/**
|
|
23608
|
+
* Removes duplicate files by using stable file metadata signature.
|
|
23609
|
+
*
|
|
23610
|
+
* @private function of BookEditorMonaco
|
|
23611
|
+
*/
|
|
23612
|
+
function deduplicateFiles(files) {
|
|
23613
|
+
const uniqueFiles = new Map();
|
|
23614
|
+
for (const file of files) {
|
|
23615
|
+
uniqueFiles.set(`${file.name}:${file.type}:${file.size}`, file);
|
|
23616
|
+
}
|
|
23617
|
+
return Array.from(uniqueFiles.values());
|
|
23618
|
+
}
|
|
23619
|
+
/**
|
|
23620
|
+
* Extracts all file-like clipboard/drop payloads from a `DataTransfer`.
|
|
23621
|
+
*
|
|
23622
|
+
* @private function of BookEditorMonaco
|
|
23623
|
+
*/
|
|
23624
|
+
function getDataTransferFiles(dataTransfer) {
|
|
23625
|
+
const directFiles = Array.from(dataTransfer.files || []);
|
|
23626
|
+
const itemFiles = listDataTransferItems(dataTransfer)
|
|
23627
|
+
.filter((item) => item.kind === 'file')
|
|
23628
|
+
.map((item) => item.getAsFile())
|
|
23629
|
+
.filter((file) => file !== null);
|
|
23630
|
+
return deduplicateFiles([...directFiles, ...itemFiles]);
|
|
23631
|
+
}
|
|
23632
|
+
/**
|
|
23633
|
+
* Picks the richest textual clipboard item that should be uploaded as a document.
|
|
23634
|
+
*
|
|
23635
|
+
* @private function of BookEditorMonaco
|
|
23636
|
+
*/
|
|
23637
|
+
function getRichClipboardTextItem(dataTransfer) {
|
|
23638
|
+
const items = listDataTransferItems(dataTransfer);
|
|
23639
|
+
const hasPlainTextItem = items.some((item) => item.kind === 'string' && item.type.toLowerCase() === 'text/plain');
|
|
23640
|
+
const applicationItem = items.find((item) => item.kind === 'string' && item.type.toLowerCase().startsWith('application/'));
|
|
23641
|
+
if (applicationItem) {
|
|
23642
|
+
return applicationItem;
|
|
23643
|
+
}
|
|
23644
|
+
if (hasPlainTextItem) {
|
|
23645
|
+
return null;
|
|
23646
|
+
}
|
|
23647
|
+
const richTextItem = items.find((item) => {
|
|
23648
|
+
if (item.kind !== 'string') {
|
|
23649
|
+
return false;
|
|
23650
|
+
}
|
|
23651
|
+
return RICH_CLIPBOARD_TEXT_MIME_TYPES.has(item.type.toLowerCase());
|
|
23652
|
+
});
|
|
23653
|
+
return richTextItem || null;
|
|
23654
|
+
}
|
|
23655
|
+
/**
|
|
23656
|
+
* Resolves whether paste should route into upload workflow instead of text insert.
|
|
23657
|
+
*
|
|
23658
|
+
* @private function of BookEditorMonaco
|
|
23659
|
+
*/
|
|
23660
|
+
function hasUploadableClipboardContent(dataTransfer) {
|
|
23661
|
+
if (getDataTransferFiles(dataTransfer).length > 0) {
|
|
23662
|
+
return true;
|
|
23663
|
+
}
|
|
23664
|
+
return getRichClipboardTextItem(dataTransfer) !== null;
|
|
23665
|
+
}
|
|
23666
|
+
/**
|
|
23667
|
+
* Reads string payload from clipboard item.
|
|
23668
|
+
*
|
|
23669
|
+
* @private function of BookEditorMonaco
|
|
23670
|
+
*/
|
|
23671
|
+
function getClipboardItemString(item) {
|
|
23672
|
+
return new Promise((resolve) => {
|
|
23673
|
+
try {
|
|
23674
|
+
item.getAsString((value) => resolve(value || ''));
|
|
23675
|
+
}
|
|
23676
|
+
catch (_a) {
|
|
23677
|
+
resolve('');
|
|
23678
|
+
}
|
|
23679
|
+
});
|
|
23680
|
+
}
|
|
23681
|
+
/**
|
|
23682
|
+
* Determines filename for generated clipboard rich-content uploads.
|
|
23683
|
+
*
|
|
23684
|
+
* @private function of BookEditorMonaco
|
|
23685
|
+
*/
|
|
23686
|
+
function getClipboardRichContentFilename(mimeType) {
|
|
23687
|
+
return CLIPBOARD_RICH_CONTENT_FILENAMES[mimeType.toLowerCase()] || DEFAULT_CLIPBOARD_RICH_CONTENT_FILENAME;
|
|
23688
|
+
}
|
|
23689
|
+
/**
|
|
23690
|
+
* Converts clipboard payload into upload-ready files.
|
|
23691
|
+
*
|
|
23692
|
+
* @private function of BookEditorMonaco
|
|
23693
|
+
*/
|
|
23694
|
+
async function resolveClipboardUploadFiles(dataTransfer) {
|
|
23695
|
+
const files = getDataTransferFiles(dataTransfer);
|
|
23696
|
+
if (files.length > 0) {
|
|
23697
|
+
return files;
|
|
23698
|
+
}
|
|
23699
|
+
const richTextItem = getRichClipboardTextItem(dataTransfer);
|
|
23700
|
+
if (!richTextItem) {
|
|
23701
|
+
return [];
|
|
23702
|
+
}
|
|
23703
|
+
const content = await getClipboardItemString(richTextItem);
|
|
23704
|
+
const mimeType = richTextItem.type || 'text/plain';
|
|
23705
|
+
if (!content.trim()) {
|
|
23706
|
+
return [];
|
|
23707
|
+
}
|
|
23708
|
+
return [new File([content], getClipboardRichContentFilename(mimeType), { type: mimeType })];
|
|
23709
|
+
}
|
|
23710
|
+
/**
|
|
23711
|
+
* Manages drag, paste and file input interactions for `BookEditorMonaco`.
|
|
23712
|
+
*
|
|
23713
|
+
* @private function of BookEditorMonaco
|
|
23714
|
+
*/
|
|
23715
|
+
function useBookEditorMonacoInteractions({ editor, handleFiles, }) {
|
|
23716
|
+
const [isDragOver, setIsDragOver] = useState(false);
|
|
23717
|
+
const touchStartRef = useRef(null);
|
|
23718
|
+
const fileUploadInputRef = useRef(null);
|
|
23719
|
+
const cameraInputRef = useRef(null);
|
|
23720
|
+
const handleDrop = useCallback(async (event) => {
|
|
23721
|
+
event.preventDefault();
|
|
23722
|
+
setIsDragOver(false);
|
|
23723
|
+
const files = getDataTransferFiles(event.dataTransfer);
|
|
23724
|
+
await handleFiles(files);
|
|
23725
|
+
}, [handleFiles]);
|
|
23726
|
+
const handlePaste = useCallback(async (event) => {
|
|
23727
|
+
const clipboardData = event.clipboardData;
|
|
23728
|
+
if (!hasUploadableClipboardContent(clipboardData)) {
|
|
23729
|
+
return;
|
|
23730
|
+
}
|
|
23731
|
+
event.preventDefault();
|
|
23732
|
+
event.stopPropagation();
|
|
23733
|
+
const files = await resolveClipboardUploadFiles(clipboardData);
|
|
23734
|
+
await handleFiles(files);
|
|
23735
|
+
}, [handleFiles]);
|
|
23736
|
+
const handleUploadDocument = useCallback(() => {
|
|
23737
|
+
var _a;
|
|
23738
|
+
(_a = fileUploadInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
23739
|
+
}, []);
|
|
23740
|
+
const handleTakePhoto = useCallback(() => {
|
|
23741
|
+
var _a;
|
|
23742
|
+
(_a = cameraInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
23743
|
+
}, []);
|
|
23744
|
+
const handleFileInputChange = useCallback((event) => {
|
|
23745
|
+
const files = Array.from(event.target.files || []);
|
|
23746
|
+
void handleFiles(files);
|
|
23747
|
+
event.target.value = '';
|
|
23748
|
+
}, [handleFiles]);
|
|
23749
|
+
const handleDragOver = useCallback((event) => {
|
|
23750
|
+
event.preventDefault();
|
|
23751
|
+
setIsDragOver(true);
|
|
23752
|
+
}, []);
|
|
23753
|
+
const handleDragEnter = useCallback((event) => {
|
|
23754
|
+
event.preventDefault();
|
|
23755
|
+
setIsDragOver(true);
|
|
23756
|
+
}, []);
|
|
23757
|
+
const handleDragLeave = useCallback((event) => {
|
|
23758
|
+
event.preventDefault();
|
|
23759
|
+
setIsDragOver(false);
|
|
23760
|
+
}, []);
|
|
23761
|
+
const handleFocusOverlayTouchStart = useCallback((event) => {
|
|
23762
|
+
const touch = event.touches[0];
|
|
23763
|
+
if (touch) {
|
|
23764
|
+
touchStartRef.current = { x: touch.clientX, y: touch.clientY };
|
|
23765
|
+
}
|
|
23766
|
+
}, []);
|
|
23767
|
+
const handleFocusOverlayTouchEnd = useCallback((event) => {
|
|
23768
|
+
event.preventDefault();
|
|
23769
|
+
const touch = event.changedTouches[0];
|
|
23770
|
+
if (touch && touchStartRef.current) {
|
|
23771
|
+
const deltaX = Math.abs(touch.clientX - touchStartRef.current.x);
|
|
23772
|
+
const deltaY = Math.abs(touch.clientY - touchStartRef.current.y);
|
|
23773
|
+
if (deltaX < TOUCH_TAP_THRESHOLD && deltaY < TOUCH_TAP_THRESHOLD) {
|
|
23774
|
+
editor === null || editor === void 0 ? void 0 : editor.focus();
|
|
23775
|
+
}
|
|
23776
|
+
}
|
|
23777
|
+
touchStartRef.current = null;
|
|
23778
|
+
}, [editor]);
|
|
23779
|
+
const focusOverlayTouchHandlers = useMemo(() => ({
|
|
23780
|
+
onTouchStart: handleFocusOverlayTouchStart,
|
|
23781
|
+
onTouchEnd: handleFocusOverlayTouchEnd,
|
|
23782
|
+
}), [handleFocusOverlayTouchEnd, handleFocusOverlayTouchStart]);
|
|
23783
|
+
return {
|
|
23784
|
+
isDragOver,
|
|
23785
|
+
fileUploadInputRef,
|
|
23786
|
+
cameraInputRef,
|
|
23787
|
+
handleDrop,
|
|
23788
|
+
handlePaste,
|
|
23789
|
+
handleUploadDocument,
|
|
23790
|
+
handleTakePhoto,
|
|
23791
|
+
handleFileInputChange,
|
|
23792
|
+
handleDragOver,
|
|
23793
|
+
handleDragEnter,
|
|
23794
|
+
handleDragLeave,
|
|
23795
|
+
focusOverlayTouchHandlers,
|
|
23796
|
+
};
|
|
23797
|
+
}
|
|
23798
|
+
|
|
23564
23799
|
/**
|
|
23565
23800
|
* Priority order for the important commitments shown first in catalogues and intellisense.
|
|
23566
23801
|
*
|
|
@@ -24223,6 +24458,181 @@ function useBookEditorMonacoLanguage({ monaco, theme }) {
|
|
|
24223
24458
|
}, [monaco, theme]);
|
|
24224
24459
|
}
|
|
24225
24460
|
|
|
24461
|
+
/**
|
|
24462
|
+
* Local storage key that enables BookEditor Monaco lifecycle debug logs in development.
|
|
24463
|
+
*
|
|
24464
|
+
* @private function of BookEditorMonaco
|
|
24465
|
+
*/
|
|
24466
|
+
const BOOK_EDITOR_MONACO_DEBUG_STORAGE_KEY = 'promptbook-debug-book-editor-monaco';
|
|
24467
|
+
/**
|
|
24468
|
+
* Duration of the save notification.
|
|
24469
|
+
*
|
|
24470
|
+
* @private function of BookEditorMonaco
|
|
24471
|
+
*/
|
|
24472
|
+
const SAVE_NOTIFICATION_HIDE_DELAY_MS = 2000;
|
|
24473
|
+
/**
|
|
24474
|
+
* Resolves whether verbose BookEditor Monaco lifecycle logs are enabled.
|
|
24475
|
+
*
|
|
24476
|
+
* @private function of BookEditorMonaco
|
|
24477
|
+
*/
|
|
24478
|
+
function isBookEditorMonacoDebugEnabled() {
|
|
24479
|
+
if (process.env.NODE_ENV === 'production' || typeof window === 'undefined') {
|
|
24480
|
+
return false;
|
|
24481
|
+
}
|
|
24482
|
+
try {
|
|
24483
|
+
return window.localStorage.getItem(BOOK_EDITOR_MONACO_DEBUG_STORAGE_KEY) === '1';
|
|
24484
|
+
}
|
|
24485
|
+
catch (_a) {
|
|
24486
|
+
return false;
|
|
24487
|
+
}
|
|
24488
|
+
}
|
|
24489
|
+
/**
|
|
24490
|
+
* Prints one BookEditor Monaco debug line when the dev debug flag is enabled.
|
|
24491
|
+
*
|
|
24492
|
+
* @param message - Human-readable lifecycle message.
|
|
24493
|
+
*
|
|
24494
|
+
* @private function of BookEditorMonaco
|
|
24495
|
+
*/
|
|
24496
|
+
function logBookEditorMonacoDebug(message) {
|
|
24497
|
+
if (!isBookEditorMonacoDebugEnabled()) {
|
|
24498
|
+
return;
|
|
24499
|
+
}
|
|
24500
|
+
console.info(`[BookEditorMonaco] ${message}`);
|
|
24501
|
+
}
|
|
24502
|
+
/**
|
|
24503
|
+
* Detects whether the current device primarily uses a coarse pointer.
|
|
24504
|
+
*
|
|
24505
|
+
* @private function of BookEditorMonaco
|
|
24506
|
+
*/
|
|
24507
|
+
function detectIsTouchDevice() {
|
|
24508
|
+
if (typeof window === 'undefined') {
|
|
24509
|
+
return false;
|
|
24510
|
+
}
|
|
24511
|
+
return window.matchMedia('(pointer: coarse)').matches;
|
|
24512
|
+
}
|
|
24513
|
+
/**
|
|
24514
|
+
* Manages Monaco lifecycle wiring for `BookEditorMonaco`.
|
|
24515
|
+
*
|
|
24516
|
+
* @private function of BookEditorMonaco
|
|
24517
|
+
*/
|
|
24518
|
+
function useBookEditorMonacoLifecycle({ monaco, theme, }) {
|
|
24519
|
+
const [editor, setEditor] = useState(null);
|
|
24520
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
24521
|
+
const [isTouchDevice, setIsTouchDevice] = useState(false);
|
|
24522
|
+
const [isSavedShown, setIsSavedShown] = useState(false);
|
|
24523
|
+
/**
|
|
24524
|
+
* Re-applies Book language + theme to the currently mounted Monaco model.
|
|
24525
|
+
*/
|
|
24526
|
+
const reapplyBookLanguageAndTheme = useCallback((reason) => {
|
|
24527
|
+
if (!editor || !monaco) {
|
|
24528
|
+
return;
|
|
24529
|
+
}
|
|
24530
|
+
ensureBookEditorMonacoLanguageForEditor({ monaco, monacoEditor: editor, theme });
|
|
24531
|
+
logBookEditorMonacoDebug(`Re-applied Book Monaco language/theme (${reason}).`);
|
|
24532
|
+
}, [editor, monaco, theme]);
|
|
24533
|
+
/**
|
|
24534
|
+
* Re-triggers the transient save toast without preventing the browser save dialog.
|
|
24535
|
+
*/
|
|
24536
|
+
const showSavedNotification = useCallback(() => {
|
|
24537
|
+
setIsSavedShown(false);
|
|
24538
|
+
setTimeout(() => setIsSavedShown(true), 0);
|
|
24539
|
+
}, []);
|
|
24540
|
+
useEffect(() => {
|
|
24541
|
+
setIsTouchDevice(detectIsTouchDevice());
|
|
24542
|
+
}, []);
|
|
24543
|
+
useEffect(() => {
|
|
24544
|
+
if (!editor || !monaco) {
|
|
24545
|
+
return;
|
|
24546
|
+
}
|
|
24547
|
+
const focusListener = editor.onDidFocusEditorWidget(() => {
|
|
24548
|
+
setIsFocused(true);
|
|
24549
|
+
reapplyBookLanguageAndTheme('focus');
|
|
24550
|
+
});
|
|
24551
|
+
const blurListener = editor.onDidBlurEditorWidget(() => {
|
|
24552
|
+
setIsFocused(false);
|
|
24553
|
+
});
|
|
24554
|
+
const saveAction = editor.addAction({
|
|
24555
|
+
id: 'save-book',
|
|
24556
|
+
label: 'Save',
|
|
24557
|
+
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
|
|
24558
|
+
run: () => {
|
|
24559
|
+
showSavedNotification();
|
|
24560
|
+
// Note: We don't prevent default, so browser's save dialog still opens
|
|
24561
|
+
},
|
|
24562
|
+
});
|
|
24563
|
+
return () => {
|
|
24564
|
+
focusListener.dispose();
|
|
24565
|
+
blurListener.dispose();
|
|
24566
|
+
saveAction.dispose();
|
|
24567
|
+
};
|
|
24568
|
+
}, [editor, monaco, reapplyBookLanguageAndTheme, showSavedNotification]);
|
|
24569
|
+
useEffect(() => {
|
|
24570
|
+
reapplyBookLanguageAndTheme('editor-ready');
|
|
24571
|
+
}, [reapplyBookLanguageAndTheme]);
|
|
24572
|
+
useEffect(() => {
|
|
24573
|
+
if (!editor || !monaco) {
|
|
24574
|
+
return;
|
|
24575
|
+
}
|
|
24576
|
+
const handlePopState = () => {
|
|
24577
|
+
reapplyBookLanguageAndTheme('history-popstate');
|
|
24578
|
+
};
|
|
24579
|
+
const handlePageShow = () => {
|
|
24580
|
+
reapplyBookLanguageAndTheme('pageshow');
|
|
24581
|
+
};
|
|
24582
|
+
const handleWindowFocus = () => {
|
|
24583
|
+
reapplyBookLanguageAndTheme('window-focus');
|
|
24584
|
+
};
|
|
24585
|
+
const handleVisibilityChange = () => {
|
|
24586
|
+
if (document.visibilityState === 'visible') {
|
|
24587
|
+
reapplyBookLanguageAndTheme('visibility-visible');
|
|
24588
|
+
}
|
|
24589
|
+
};
|
|
24590
|
+
window.addEventListener('popstate', handlePopState);
|
|
24591
|
+
window.addEventListener('pageshow', handlePageShow);
|
|
24592
|
+
window.addEventListener('focus', handleWindowFocus);
|
|
24593
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
24594
|
+
return () => {
|
|
24595
|
+
window.removeEventListener('popstate', handlePopState);
|
|
24596
|
+
window.removeEventListener('pageshow', handlePageShow);
|
|
24597
|
+
window.removeEventListener('focus', handleWindowFocus);
|
|
24598
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
24599
|
+
};
|
|
24600
|
+
}, [editor, monaco, reapplyBookLanguageAndTheme]);
|
|
24601
|
+
useEffect(() => {
|
|
24602
|
+
if (!isSavedShown) {
|
|
24603
|
+
return;
|
|
24604
|
+
}
|
|
24605
|
+
const timer = setTimeout(() => {
|
|
24606
|
+
setIsSavedShown(false);
|
|
24607
|
+
}, SAVE_NOTIFICATION_HIDE_DELAY_MS);
|
|
24608
|
+
return () => {
|
|
24609
|
+
clearTimeout(timer);
|
|
24610
|
+
};
|
|
24611
|
+
}, [isSavedShown]);
|
|
24612
|
+
/**
|
|
24613
|
+
* Ensures Book language/tokenizer is ready before Monaco creates the editor model.
|
|
24614
|
+
*/
|
|
24615
|
+
const handleBeforeMonacoMount = useCallback((beforeMountMonaco) => {
|
|
24616
|
+
ensureBookEditorMonacoLanguage(beforeMountMonaco, theme);
|
|
24617
|
+
}, [theme]);
|
|
24618
|
+
/**
|
|
24619
|
+
* Re-applies Book language/theme once Monaco editor is mounted.
|
|
24620
|
+
*/
|
|
24621
|
+
const handleMonacoMount = useCallback((mountedEditor, mountedMonaco) => {
|
|
24622
|
+
setEditor(mountedEditor);
|
|
24623
|
+
ensureBookEditorMonacoLanguageForEditor({ monaco: mountedMonaco, monacoEditor: mountedEditor, theme });
|
|
24624
|
+
logBookEditorMonacoDebug('Mounted Monaco editor and re-applied Book language/theme.');
|
|
24625
|
+
}, [theme]);
|
|
24626
|
+
return {
|
|
24627
|
+
editor,
|
|
24628
|
+
isFocused,
|
|
24629
|
+
isTouchDevice,
|
|
24630
|
+
isSavedShown,
|
|
24631
|
+
handleBeforeMonacoMount,
|
|
24632
|
+
handleMonacoMount,
|
|
24633
|
+
};
|
|
24634
|
+
}
|
|
24635
|
+
|
|
24226
24636
|
/**
|
|
24227
24637
|
* Relative Y offset multiplier for aligning line background with Monaco rendering.
|
|
24228
24638
|
*
|
|
@@ -25032,190 +25442,101 @@ function BookEditorMonacoUploadPanel({ activeUploadItems, uploadStats, pauseUplo
|
|
|
25032
25442
|
*/
|
|
25033
25443
|
const INVALID_CSS_IDENTIFIER_CHARACTER_PATTERN = /[^a-zA-Z0-9_-]/g;
|
|
25034
25444
|
/**
|
|
25035
|
-
*
|
|
25445
|
+
* Base Book editor font size before zoom scaling.
|
|
25036
25446
|
*
|
|
25037
25447
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25038
25448
|
*/
|
|
25039
|
-
const
|
|
25449
|
+
const BASE_FONT_SIZE = 20;
|
|
25040
25450
|
/**
|
|
25041
|
-
*
|
|
25451
|
+
* Minimum supported Book editor font size after zoom scaling.
|
|
25042
25452
|
*
|
|
25043
25453
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25044
25454
|
*/
|
|
25045
|
-
const
|
|
25046
|
-
'text/html': 'clipboard-content.html',
|
|
25047
|
-
'text/rtf': 'clipboard-content.rtf',
|
|
25048
|
-
'application/rtf': 'clipboard-content.rtf',
|
|
25049
|
-
};
|
|
25455
|
+
const MIN_FONT_SIZE = 8;
|
|
25050
25456
|
/**
|
|
25051
|
-
*
|
|
25052
|
-
*
|
|
25053
|
-
* @private Internal utility of `BookEditorMonaco`.
|
|
25054
|
-
*/
|
|
25055
|
-
const DEFAULT_CLIPBOARD_RICH_CONTENT_FILENAME = 'clipboard-content.txt';
|
|
25056
|
-
/**
|
|
25057
|
-
* Local storage key that enables BookEditor Monaco lifecycle debug logs in development.
|
|
25058
|
-
*
|
|
25059
|
-
* @private Internal utility of `BookEditorMonaco`.
|
|
25060
|
-
*/
|
|
25061
|
-
const BOOK_EDITOR_MONACO_DEBUG_STORAGE_KEY = 'promptbook-debug-book-editor-monaco';
|
|
25062
|
-
/**
|
|
25063
|
-
* Resolves whether verbose BookEditor Monaco lifecycle logs are enabled.
|
|
25457
|
+
* Default Monaco scrollbar size before zoom scaling.
|
|
25064
25458
|
*
|
|
25065
25459
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25066
25460
|
*/
|
|
25067
|
-
|
|
25068
|
-
if (process.env.NODE_ENV === 'production' || typeof window === 'undefined') {
|
|
25069
|
-
return false;
|
|
25070
|
-
}
|
|
25071
|
-
try {
|
|
25072
|
-
return window.localStorage.getItem(BOOK_EDITOR_MONACO_DEBUG_STORAGE_KEY) === '1';
|
|
25073
|
-
}
|
|
25074
|
-
catch (_a) {
|
|
25075
|
-
return false;
|
|
25076
|
-
}
|
|
25077
|
-
}
|
|
25078
|
-
/**
|
|
25079
|
-
* Prints one BookEditor Monaco debug line when the dev debug flag is enabled.
|
|
25080
|
-
*
|
|
25081
|
-
* @param message - Human-readable lifecycle message.
|
|
25082
|
-
*
|
|
25083
|
-
* @private Internal utility of `BookEditorMonaco`.
|
|
25084
|
-
*/
|
|
25085
|
-
function logBookEditorMonacoDebug(message) {
|
|
25086
|
-
if (!isBookEditorMonacoDebugEnabled()) {
|
|
25087
|
-
return;
|
|
25088
|
-
}
|
|
25089
|
-
console.info(`[BookEditorMonaco] ${message}`);
|
|
25090
|
-
}
|
|
25091
|
-
/**
|
|
25092
|
-
* Lists transferable items from a browser `DataTransfer` object.
|
|
25093
|
-
*
|
|
25094
|
-
* @private Internal utility of `BookEditorMonaco`.
|
|
25095
|
-
*/
|
|
25096
|
-
function listDataTransferItems(dataTransfer) {
|
|
25097
|
-
const items = [];
|
|
25098
|
-
for (let index = 0; index < dataTransfer.items.length; index++) {
|
|
25099
|
-
const item = dataTransfer.items[index];
|
|
25100
|
-
if (item) {
|
|
25101
|
-
items.push(item);
|
|
25102
|
-
}
|
|
25103
|
-
}
|
|
25104
|
-
return items;
|
|
25105
|
-
}
|
|
25106
|
-
/**
|
|
25107
|
-
* Removes duplicate files by using stable file metadata signature.
|
|
25108
|
-
*
|
|
25109
|
-
* @private Internal utility of `BookEditorMonaco`.
|
|
25110
|
-
*/
|
|
25111
|
-
function deduplicateFiles(files) {
|
|
25112
|
-
const uniqueFiles = new Map();
|
|
25113
|
-
for (const file of files) {
|
|
25114
|
-
uniqueFiles.set(`${file.name}:${file.type}:${file.size}`, file);
|
|
25115
|
-
}
|
|
25116
|
-
return Array.from(uniqueFiles.values());
|
|
25117
|
-
}
|
|
25118
|
-
/**
|
|
25119
|
-
* Extracts all file-like clipboard/drop payloads from a `DataTransfer`.
|
|
25120
|
-
*
|
|
25121
|
-
* @private Internal utility of `BookEditorMonaco`.
|
|
25122
|
-
*/
|
|
25123
|
-
function getDataTransferFiles(dataTransfer) {
|
|
25124
|
-
const directFiles = Array.from(dataTransfer.files || []);
|
|
25125
|
-
const itemFiles = listDataTransferItems(dataTransfer)
|
|
25126
|
-
.filter((item) => item.kind === 'file')
|
|
25127
|
-
.map((item) => item.getAsFile())
|
|
25128
|
-
.filter((file) => file !== null);
|
|
25129
|
-
return deduplicateFiles([...directFiles, ...itemFiles]);
|
|
25130
|
-
}
|
|
25461
|
+
const BASE_SCROLLBAR_SIZE = 5;
|
|
25131
25462
|
/**
|
|
25132
|
-
*
|
|
25463
|
+
* Minimum Monaco scrollbar size after zoom scaling.
|
|
25133
25464
|
*
|
|
25134
25465
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25135
25466
|
*/
|
|
25136
|
-
|
|
25137
|
-
const items = listDataTransferItems(dataTransfer);
|
|
25138
|
-
const hasPlainTextItem = items.some((item) => item.kind === 'string' && item.type.toLowerCase() === 'text/plain');
|
|
25139
|
-
const applicationItem = items.find((item) => item.kind === 'string' && item.type.toLowerCase().startsWith('application/'));
|
|
25140
|
-
if (applicationItem) {
|
|
25141
|
-
return applicationItem;
|
|
25142
|
-
}
|
|
25143
|
-
if (hasPlainTextItem) {
|
|
25144
|
-
return null;
|
|
25145
|
-
}
|
|
25146
|
-
const richTextItem = items.find((item) => {
|
|
25147
|
-
if (item.kind !== 'string') {
|
|
25148
|
-
return false;
|
|
25149
|
-
}
|
|
25150
|
-
return RICH_CLIPBOARD_TEXT_MIME_TYPES.has(item.type.toLowerCase());
|
|
25151
|
-
});
|
|
25152
|
-
if (richTextItem) {
|
|
25153
|
-
return richTextItem;
|
|
25154
|
-
}
|
|
25155
|
-
return null;
|
|
25156
|
-
}
|
|
25467
|
+
const MIN_SCROLLBAR_SIZE = 2;
|
|
25157
25468
|
/**
|
|
25158
|
-
*
|
|
25469
|
+
* Minimum left padding Monaco reserves for custom line decorations.
|
|
25159
25470
|
*
|
|
25160
25471
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25161
25472
|
*/
|
|
25162
|
-
|
|
25163
|
-
if (getDataTransferFiles(dataTransfer).length > 0) {
|
|
25164
|
-
return true;
|
|
25165
|
-
}
|
|
25166
|
-
return getRichClipboardTextItem(dataTransfer) !== null;
|
|
25167
|
-
}
|
|
25473
|
+
const MIN_CONTENT_PADDING_LEFT = 8;
|
|
25168
25474
|
/**
|
|
25169
|
-
*
|
|
25475
|
+
* Creates a hydration-stable CSS class name from React's `useId()` value.
|
|
25170
25476
|
*
|
|
25171
25477
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25172
25478
|
*/
|
|
25173
|
-
function
|
|
25174
|
-
return
|
|
25175
|
-
try {
|
|
25176
|
-
item.getAsString((value) => resolve(value || ''));
|
|
25177
|
-
}
|
|
25178
|
-
catch (_a) {
|
|
25179
|
-
resolve('');
|
|
25180
|
-
}
|
|
25181
|
-
});
|
|
25479
|
+
function createStableBookEditorInstanceClassName(reactId) {
|
|
25480
|
+
return `book-editor-instance-${reactId.replace(INVALID_CSS_IDENTIFIER_CHARACTER_PATTERN, '-')}`;
|
|
25182
25481
|
}
|
|
25183
25482
|
/**
|
|
25184
|
-
*
|
|
25483
|
+
* Resolves Monaco layout values from the active Book editor zoom level.
|
|
25185
25484
|
*
|
|
25186
25485
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25187
25486
|
*/
|
|
25188
|
-
function
|
|
25189
|
-
return
|
|
25487
|
+
function createBookEditorMonacoScale(zoomLevel) {
|
|
25488
|
+
return {
|
|
25489
|
+
scaledLineHeight: Math.round(BookEditorMonacoConstants.LINE_HEIGHT * zoomLevel),
|
|
25490
|
+
scaledContentPaddingLeft: Math.max(MIN_CONTENT_PADDING_LEFT, Math.round(BookEditorMonacoConstants.CONTENT_PADDING_LEFT * zoomLevel)),
|
|
25491
|
+
scaledVerticalLineLeft: Math.max(0, Math.round(BookEditorMonacoConstants.VERTICAL_LINE_LEFT * zoomLevel)),
|
|
25492
|
+
scaledFontSize: Math.max(MIN_FONT_SIZE, Math.round(BASE_FONT_SIZE * zoomLevel)),
|
|
25493
|
+
scaledScrollbarSize: Math.max(MIN_SCROLLBAR_SIZE, Math.round(BASE_SCROLLBAR_SIZE * zoomLevel)),
|
|
25494
|
+
};
|
|
25190
25495
|
}
|
|
25191
25496
|
/**
|
|
25192
|
-
*
|
|
25497
|
+
* Determines whether the Book editor action bar should be shown.
|
|
25193
25498
|
*
|
|
25194
25499
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25195
25500
|
*/
|
|
25196
|
-
function
|
|
25197
|
-
return
|
|
25501
|
+
function isBookEditorMonacoActionbarVisible({ hoistedMenuItems, isUploadButtonShown, isCameraButtonShown, isDownloadButtonShown, isAboutButtonShown, isFullscreenButtonShown, }) {
|
|
25502
|
+
return (Boolean(hoistedMenuItems && hoistedMenuItems.length > 0) ||
|
|
25503
|
+
Boolean(isUploadButtonShown) ||
|
|
25504
|
+
Boolean(isCameraButtonShown) ||
|
|
25505
|
+
Boolean(isDownloadButtonShown) ||
|
|
25506
|
+
Boolean(isAboutButtonShown) ||
|
|
25507
|
+
Boolean(isFullscreenButtonShown));
|
|
25198
25508
|
}
|
|
25199
25509
|
/**
|
|
25200
|
-
*
|
|
25510
|
+
* Builds the Monaco editor options consumed by `MonacoEditorWithShadowDom`.
|
|
25201
25511
|
*
|
|
25202
25512
|
* @private Internal utility of `BookEditorMonaco`.
|
|
25203
25513
|
*/
|
|
25204
|
-
|
|
25205
|
-
|
|
25206
|
-
|
|
25207
|
-
|
|
25208
|
-
|
|
25209
|
-
|
|
25210
|
-
|
|
25211
|
-
|
|
25212
|
-
|
|
25213
|
-
|
|
25214
|
-
|
|
25215
|
-
|
|
25216
|
-
|
|
25217
|
-
|
|
25218
|
-
|
|
25514
|
+
function createBookEditorMonacoOptions({ isReadonly, translations, scaledFontSize, scaledLineHeight, scaledContentPaddingLeft, scaledScrollbarSize, }) {
|
|
25515
|
+
return {
|
|
25516
|
+
readOnly: isReadonly,
|
|
25517
|
+
readOnlyMessage: {
|
|
25518
|
+
value: (translations === null || translations === void 0 ? void 0 : translations.readonlyMessage) || 'You cannot edit this book',
|
|
25519
|
+
},
|
|
25520
|
+
wordWrap: 'on',
|
|
25521
|
+
minimap: { enabled: false },
|
|
25522
|
+
lineNumbers: 'off',
|
|
25523
|
+
fontSize: scaledFontSize,
|
|
25524
|
+
fontFamily: `"Playfair Display", serif`,
|
|
25525
|
+
lineHeight: scaledLineHeight,
|
|
25526
|
+
renderLineHighlight: 'none',
|
|
25527
|
+
lineDecorationsWidth: scaledContentPaddingLeft,
|
|
25528
|
+
glyphMargin: false,
|
|
25529
|
+
folding: false,
|
|
25530
|
+
lineNumbersMinChars: 0,
|
|
25531
|
+
links: true,
|
|
25532
|
+
scrollbar: {
|
|
25533
|
+
vertical: 'auto',
|
|
25534
|
+
horizontal: 'hidden',
|
|
25535
|
+
verticalScrollbarSize: scaledScrollbarSize,
|
|
25536
|
+
arrowSize: 0,
|
|
25537
|
+
useShadows: false,
|
|
25538
|
+
},
|
|
25539
|
+
};
|
|
25219
25540
|
}
|
|
25220
25541
|
/**
|
|
25221
25542
|
* Handles book editor monaco.
|
|
@@ -25225,29 +25546,40 @@ async function resolveClipboardUploadFiles(dataTransfer) {
|
|
|
25225
25546
|
function BookEditorMonaco(props) {
|
|
25226
25547
|
const { value, onChange, diagnostics, isReadonly, theme = 'LIGHT', translations, onFileUpload, isUploadButtonShown, isCameraButtonShown, isDownloadButtonShown, isAboutButtonShown = true, isFullscreenButtonShown = true, onFullscreenClick, isFullscreen, zoom = 1, monacoModelPath, hoistedMenuItems, } = props;
|
|
25227
25548
|
const zoomLevel = zoom;
|
|
25228
|
-
const scaledLineHeight =
|
|
25229
|
-
const scaledContentPaddingLeft = Math.max(8, Math.round(BookEditorMonacoConstants.CONTENT_PADDING_LEFT * zoomLevel));
|
|
25230
|
-
const scaledVerticalLineLeft = Math.max(0, Math.round(BookEditorMonacoConstants.VERTICAL_LINE_LEFT * zoomLevel));
|
|
25231
|
-
const baseFontSize = 20;
|
|
25232
|
-
const scaledFontSize = Math.max(8, Math.round(baseFontSize * zoomLevel));
|
|
25233
|
-
const scaledScrollbarSize = Math.max(2, Math.round(5 * zoomLevel));
|
|
25234
|
-
const [isDragOver, setIsDragOver] = useState(false);
|
|
25235
|
-
const [editor, setEditor] = useState(null);
|
|
25236
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
25237
|
-
const [isTouchDevice, setIsTouchDevice] = useState(false);
|
|
25238
|
-
const [isSavedShown, setIsSavedShown] = useState(false);
|
|
25549
|
+
const { scaledLineHeight, scaledContentPaddingLeft, scaledVerticalLineLeft, scaledFontSize, scaledScrollbarSize } = createBookEditorMonacoScale(zoomLevel);
|
|
25239
25550
|
const monaco = useMonaco();
|
|
25240
25551
|
const reactId = useId();
|
|
25241
25552
|
const instanceClass = createStableBookEditorInstanceClassName(reactId);
|
|
25242
|
-
const
|
|
25243
|
-
|
|
25244
|
-
|
|
25553
|
+
const { editor, isFocused, isTouchDevice, isSavedShown, handleBeforeMonacoMount, handleMonacoMount } = useBookEditorMonacoLifecycle({
|
|
25554
|
+
monaco,
|
|
25555
|
+
theme,
|
|
25556
|
+
});
|
|
25245
25557
|
const { activeUploadItems, uploadStats, pauseUpload, resumeUpload, handleFiles } = useBookEditorMonacoUploads({
|
|
25246
25558
|
editor,
|
|
25247
25559
|
monaco,
|
|
25248
25560
|
onFileUpload,
|
|
25249
25561
|
});
|
|
25562
|
+
const { isDragOver, fileUploadInputRef, cameraInputRef, handleDrop, handlePaste, handleUploadDocument, handleTakePhoto, handleFileInputChange, handleDragOver, handleDragEnter, handleDragLeave, focusOverlayTouchHandlers, } = useBookEditorMonacoInteractions({
|
|
25563
|
+
editor,
|
|
25564
|
+
handleFiles,
|
|
25565
|
+
});
|
|
25250
25566
|
const combinedDiagnostics = [...(diagnostics || []), ...createDeprecatedCommitmentDiagnostics(value)];
|
|
25567
|
+
const isActionBarVisible = isBookEditorMonacoActionbarVisible({
|
|
25568
|
+
hoistedMenuItems,
|
|
25569
|
+
isUploadButtonShown,
|
|
25570
|
+
isCameraButtonShown,
|
|
25571
|
+
isDownloadButtonShown,
|
|
25572
|
+
isAboutButtonShown,
|
|
25573
|
+
isFullscreenButtonShown,
|
|
25574
|
+
});
|
|
25575
|
+
const monacoOptions = createBookEditorMonacoOptions({
|
|
25576
|
+
isReadonly,
|
|
25577
|
+
translations,
|
|
25578
|
+
scaledFontSize,
|
|
25579
|
+
scaledLineHeight,
|
|
25580
|
+
scaledContentPaddingLeft,
|
|
25581
|
+
scaledScrollbarSize,
|
|
25582
|
+
});
|
|
25251
25583
|
useBookEditorMonacoLanguage({ monaco, theme });
|
|
25252
25584
|
useBookEditorMonacoDiagnostics({ monaco, editor, diagnostics: combinedDiagnostics });
|
|
25253
25585
|
useBookEditorMonacoDecorations({ editor, monaco });
|
|
@@ -25259,171 +25591,6 @@ function BookEditorMonaco(props) {
|
|
|
25259
25591
|
zoomLevel,
|
|
25260
25592
|
theme,
|
|
25261
25593
|
});
|
|
25262
|
-
/**
|
|
25263
|
-
* Re-applies Book language + theme to the currently mounted Monaco model.
|
|
25264
|
-
*/
|
|
25265
|
-
const reapplyBookLanguageAndTheme = useCallback((reason) => {
|
|
25266
|
-
if (!editor || !monaco) {
|
|
25267
|
-
return;
|
|
25268
|
-
}
|
|
25269
|
-
ensureBookEditorMonacoLanguageForEditor({ monaco, monacoEditor: editor, theme });
|
|
25270
|
-
logBookEditorMonacoDebug(`Re-applied Book Monaco language/theme (${reason}).`);
|
|
25271
|
-
}, [editor, monaco, theme]);
|
|
25272
|
-
useEffect(() => {
|
|
25273
|
-
setIsTouchDevice(typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches);
|
|
25274
|
-
}, []);
|
|
25275
|
-
useEffect(() => {
|
|
25276
|
-
if (!editor || !monaco) {
|
|
25277
|
-
return;
|
|
25278
|
-
}
|
|
25279
|
-
const focusListener = editor.onDidFocusEditorWidget(() => {
|
|
25280
|
-
setIsFocused(true);
|
|
25281
|
-
reapplyBookLanguageAndTheme('focus');
|
|
25282
|
-
});
|
|
25283
|
-
const blurListener = editor.onDidBlurEditorWidget(() => {
|
|
25284
|
-
setIsFocused(false);
|
|
25285
|
-
});
|
|
25286
|
-
const saveAction = editor.addAction({
|
|
25287
|
-
id: 'save-book',
|
|
25288
|
-
label: 'Save',
|
|
25289
|
-
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
|
|
25290
|
-
run: () => {
|
|
25291
|
-
setIsSavedShown(false);
|
|
25292
|
-
setTimeout(() => setIsSavedShown(true), 0);
|
|
25293
|
-
// Note: We don't prevent default, so browser's save dialog still opens
|
|
25294
|
-
},
|
|
25295
|
-
});
|
|
25296
|
-
return () => {
|
|
25297
|
-
focusListener.dispose();
|
|
25298
|
-
blurListener.dispose();
|
|
25299
|
-
saveAction.dispose();
|
|
25300
|
-
};
|
|
25301
|
-
}, [editor, monaco, reapplyBookLanguageAndTheme]);
|
|
25302
|
-
useEffect(() => {
|
|
25303
|
-
reapplyBookLanguageAndTheme('editor-ready');
|
|
25304
|
-
}, [reapplyBookLanguageAndTheme]);
|
|
25305
|
-
useEffect(() => {
|
|
25306
|
-
if (!editor || !monaco) {
|
|
25307
|
-
return;
|
|
25308
|
-
}
|
|
25309
|
-
const handlePopState = () => {
|
|
25310
|
-
reapplyBookLanguageAndTheme('history-popstate');
|
|
25311
|
-
};
|
|
25312
|
-
const handlePageShow = () => {
|
|
25313
|
-
reapplyBookLanguageAndTheme('pageshow');
|
|
25314
|
-
};
|
|
25315
|
-
const handleWindowFocus = () => {
|
|
25316
|
-
reapplyBookLanguageAndTheme('window-focus');
|
|
25317
|
-
};
|
|
25318
|
-
const handleVisibilityChange = () => {
|
|
25319
|
-
if (document.visibilityState === 'visible') {
|
|
25320
|
-
reapplyBookLanguageAndTheme('visibility-visible');
|
|
25321
|
-
}
|
|
25322
|
-
};
|
|
25323
|
-
window.addEventListener('popstate', handlePopState);
|
|
25324
|
-
window.addEventListener('pageshow', handlePageShow);
|
|
25325
|
-
window.addEventListener('focus', handleWindowFocus);
|
|
25326
|
-
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
25327
|
-
return () => {
|
|
25328
|
-
window.removeEventListener('popstate', handlePopState);
|
|
25329
|
-
window.removeEventListener('pageshow', handlePageShow);
|
|
25330
|
-
window.removeEventListener('focus', handleWindowFocus);
|
|
25331
|
-
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
25332
|
-
};
|
|
25333
|
-
}, [editor, monaco, reapplyBookLanguageAndTheme]);
|
|
25334
|
-
useEffect(() => {
|
|
25335
|
-
if (!isSavedShown) {
|
|
25336
|
-
return;
|
|
25337
|
-
}
|
|
25338
|
-
const timer = setTimeout(() => {
|
|
25339
|
-
setIsSavedShown(false);
|
|
25340
|
-
}, 2000);
|
|
25341
|
-
return () => {
|
|
25342
|
-
clearTimeout(timer);
|
|
25343
|
-
};
|
|
25344
|
-
}, [isSavedShown]);
|
|
25345
|
-
const handleDrop = useCallback(async (event) => {
|
|
25346
|
-
event.preventDefault();
|
|
25347
|
-
setIsDragOver(false);
|
|
25348
|
-
const files = getDataTransferFiles(event.dataTransfer);
|
|
25349
|
-
await handleFiles(files);
|
|
25350
|
-
}, [handleFiles]);
|
|
25351
|
-
const handlePaste = useCallback(async (event) => {
|
|
25352
|
-
const clipboardData = event.clipboardData;
|
|
25353
|
-
if (!hasUploadableClipboardContent(clipboardData)) {
|
|
25354
|
-
return;
|
|
25355
|
-
}
|
|
25356
|
-
event.preventDefault();
|
|
25357
|
-
event.stopPropagation();
|
|
25358
|
-
const files = await resolveClipboardUploadFiles(clipboardData);
|
|
25359
|
-
await handleFiles(files);
|
|
25360
|
-
}, [handleFiles]);
|
|
25361
|
-
const handleUploadDocument = useCallback(() => {
|
|
25362
|
-
var _a;
|
|
25363
|
-
(_a = fileUploadInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
25364
|
-
}, []);
|
|
25365
|
-
const handleTakePhoto = useCallback(() => {
|
|
25366
|
-
var _a;
|
|
25367
|
-
(_a = cameraInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
25368
|
-
}, []);
|
|
25369
|
-
const handleFileInputChange = useCallback((event) => {
|
|
25370
|
-
const files = Array.from(event.target.files || []);
|
|
25371
|
-
void handleFiles(files);
|
|
25372
|
-
event.target.value = '';
|
|
25373
|
-
}, [handleFiles]);
|
|
25374
|
-
/**
|
|
25375
|
-
* Ensures Book language/tokenizer is ready before Monaco creates the editor model.
|
|
25376
|
-
*/
|
|
25377
|
-
const handleBeforeMonacoMount = useCallback((beforeMountMonaco) => {
|
|
25378
|
-
ensureBookEditorMonacoLanguage(beforeMountMonaco, theme);
|
|
25379
|
-
}, [theme]);
|
|
25380
|
-
/**
|
|
25381
|
-
* Re-applies Book language/theme once Monaco editor is mounted.
|
|
25382
|
-
*/
|
|
25383
|
-
const handleMonacoMount = useCallback((mountedEditor, mountedMonaco) => {
|
|
25384
|
-
setEditor(mountedEditor);
|
|
25385
|
-
ensureBookEditorMonacoLanguageForEditor({ monaco: mountedMonaco, monacoEditor: mountedEditor, theme });
|
|
25386
|
-
logBookEditorMonacoDebug('Mounted Monaco editor and re-applied Book language/theme.');
|
|
25387
|
-
}, [theme]);
|
|
25388
|
-
const handleDragOver = useCallback((event) => {
|
|
25389
|
-
event.preventDefault();
|
|
25390
|
-
setIsDragOver(true);
|
|
25391
|
-
}, []);
|
|
25392
|
-
const handleDragEnter = useCallback((event) => {
|
|
25393
|
-
event.preventDefault();
|
|
25394
|
-
setIsDragOver(true);
|
|
25395
|
-
}, []);
|
|
25396
|
-
const handleDragLeave = useCallback((event) => {
|
|
25397
|
-
event.preventDefault();
|
|
25398
|
-
setIsDragOver(false);
|
|
25399
|
-
}, []);
|
|
25400
|
-
const focusOverlayTouchHandlers = {
|
|
25401
|
-
onTouchStart: (event) => {
|
|
25402
|
-
const touch = event.touches[0];
|
|
25403
|
-
if (touch) {
|
|
25404
|
-
touchStartRef.current = { x: touch.clientX, y: touch.clientY };
|
|
25405
|
-
}
|
|
25406
|
-
},
|
|
25407
|
-
onTouchEnd: (event) => {
|
|
25408
|
-
event.preventDefault();
|
|
25409
|
-
const touch = event.changedTouches[0];
|
|
25410
|
-
if (touch && touchStartRef.current) {
|
|
25411
|
-
const deltaX = Math.abs(touch.clientX - touchStartRef.current.x);
|
|
25412
|
-
const deltaY = Math.abs(touch.clientY - touchStartRef.current.y);
|
|
25413
|
-
const threshold = 10;
|
|
25414
|
-
if (deltaX < threshold && deltaY < threshold) {
|
|
25415
|
-
editor === null || editor === void 0 ? void 0 : editor.focus();
|
|
25416
|
-
}
|
|
25417
|
-
}
|
|
25418
|
-
touchStartRef.current = null;
|
|
25419
|
-
},
|
|
25420
|
-
};
|
|
25421
|
-
const isActionBarVisible = Boolean(hoistedMenuItems && hoistedMenuItems.length > 0) ||
|
|
25422
|
-
isUploadButtonShown ||
|
|
25423
|
-
isCameraButtonShown ||
|
|
25424
|
-
isDownloadButtonShown ||
|
|
25425
|
-
isAboutButtonShown ||
|
|
25426
|
-
isFullscreenButtonShown;
|
|
25427
25594
|
return (jsxs("div", { className: classNames(styles$d.bookEditorContainer, instanceClass), onDrop: handleDrop, onPaste: handlePaste, onDragOver: handleDragOver, onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, children: [isActionBarVisible && (jsx(BookEditorActionbar, { value,
|
|
25428
25595
|
isUploadButtonShown,
|
|
25429
25596
|
isCameraButtonShown: isCameraButtonShown !== null && isCameraButtonShown !== void 0 ? isCameraButtonShown : isTouchDevice,
|
|
@@ -25449,31 +25616,7 @@ function BookEditorMonaco(props) {
|
|
|
25449
25616
|
height: '100%',
|
|
25450
25617
|
width: '100%',
|
|
25451
25618
|
backgroundColor: 'transparent',
|
|
25452
|
-
}, ...focusOverlayTouchHandlers })), jsx(MonacoEditorWithShadowDom, { language: BookEditorMonacoConstants.BOOK_LANGUAGE_ID, theme: BookEditorMonacoConstants.BOOK_THEME_ID, path: monacoModelPath, saveViewState: Boolean(monacoModelPath), value: value, beforeMount: handleBeforeMonacoMount, onMount: handleMonacoMount, onChange: (newValue) => onChange === null || onChange === void 0 ? void 0 : onChange(newValue), options: {
|
|
25453
|
-
readOnly: isReadonly,
|
|
25454
|
-
readOnlyMessage: {
|
|
25455
|
-
value: (translations === null || translations === void 0 ? void 0 : translations.readonlyMessage) || 'You cannot edit this book',
|
|
25456
|
-
},
|
|
25457
|
-
wordWrap: 'on',
|
|
25458
|
-
minimap: { enabled: false },
|
|
25459
|
-
lineNumbers: 'off',
|
|
25460
|
-
fontSize: scaledFontSize,
|
|
25461
|
-
fontFamily: `"Playfair Display", serif`,
|
|
25462
|
-
lineHeight: scaledLineHeight,
|
|
25463
|
-
renderLineHighlight: 'none',
|
|
25464
|
-
lineDecorationsWidth: scaledContentPaddingLeft,
|
|
25465
|
-
glyphMargin: false,
|
|
25466
|
-
folding: false,
|
|
25467
|
-
lineNumbersMinChars: 0,
|
|
25468
|
-
links: true,
|
|
25469
|
-
scrollbar: {
|
|
25470
|
-
vertical: 'auto',
|
|
25471
|
-
horizontal: 'hidden',
|
|
25472
|
-
verticalScrollbarSize: scaledScrollbarSize,
|
|
25473
|
-
arrowSize: 0,
|
|
25474
|
-
useShadows: false,
|
|
25475
|
-
},
|
|
25476
|
-
}, loading: jsx("div", { className: styles$d.loading, children: "\uD83D\uDCD6" }) })] })] }));
|
|
25619
|
+
}, ...focusOverlayTouchHandlers })), jsx(MonacoEditorWithShadowDom, { language: BookEditorMonacoConstants.BOOK_LANGUAGE_ID, theme: BookEditorMonacoConstants.BOOK_THEME_ID, path: monacoModelPath, saveViewState: Boolean(monacoModelPath), value: value, beforeMount: handleBeforeMonacoMount, onMount: handleMonacoMount, onChange: (newValue) => onChange === null || onChange === void 0 ? void 0 : onChange(newValue), options: monacoOptions, loading: jsx("div", { className: styles$d.loading, children: "\uD83D\uDCD6" }) })] })] }));
|
|
25477
25620
|
}
|
|
25478
25621
|
|
|
25479
25622
|
/**
|
|
@@ -41090,8 +41233,8 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
41090
41233
|
* Prepares an AgentKit agent with optional knowledge sources and tool definitions.
|
|
41091
41234
|
*/
|
|
41092
41235
|
async prepareAgentKitAgent(options) {
|
|
41093
|
-
var _a, _b;
|
|
41094
|
-
const { name, instructions, knowledgeSources, tools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
|
|
41236
|
+
var _a, _b, _c;
|
|
41237
|
+
const { name, instructions, knowledgeSources, tools, nativeAgentKitTools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
|
|
41095
41238
|
await this.ensureAgentKitDefaults();
|
|
41096
41239
|
if (this.options.isVerbose) {
|
|
41097
41240
|
console.info('[🤰]', 'Preparing OpenAI AgentKit agent', {
|
|
@@ -41099,6 +41242,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
41099
41242
|
instructionsLength: instructions.length,
|
|
41100
41243
|
knowledgeSourcesCount: (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0,
|
|
41101
41244
|
toolsCount: (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0,
|
|
41245
|
+
nativeAgentKitToolsCount: (_c = nativeAgentKitTools === null || nativeAgentKitTools === void 0 ? void 0 : nativeAgentKitTools.length) !== null && _c !== void 0 ? _c : 0,
|
|
41102
41246
|
});
|
|
41103
41247
|
}
|
|
41104
41248
|
let vectorStoreId = cachedVectorStoreId;
|
|
@@ -41117,7 +41261,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
41117
41261
|
vectorStoreId,
|
|
41118
41262
|
});
|
|
41119
41263
|
}
|
|
41120
|
-
const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
|
|
41264
|
+
const agentKitTools = this.buildAgentKitTools({ tools, nativeAgentKitTools, vectorStoreId });
|
|
41121
41265
|
const openAiAgentKitAgent = new Agent$1({
|
|
41122
41266
|
name,
|
|
41123
41267
|
model: this.agentKitModelName,
|
|
@@ -41156,11 +41300,14 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
41156
41300
|
* Builds the tool list for AgentKit, including hosted file search when applicable.
|
|
41157
41301
|
*/
|
|
41158
41302
|
buildAgentKitTools(options) {
|
|
41159
|
-
const { tools, vectorStoreId } = options;
|
|
41303
|
+
const { tools, nativeAgentKitTools, vectorStoreId } = options;
|
|
41160
41304
|
const agentKitTools = [];
|
|
41161
41305
|
if (vectorStoreId) {
|
|
41162
41306
|
agentKitTools.push(fileSearchTool(vectorStoreId));
|
|
41163
41307
|
}
|
|
41308
|
+
if (nativeAgentKitTools && nativeAgentKitTools.length > 0) {
|
|
41309
|
+
agentKitTools.push(...nativeAgentKitTools);
|
|
41310
|
+
}
|
|
41164
41311
|
if (tools && tools.length > 0) {
|
|
41165
41312
|
let scriptTools = null;
|
|
41166
41313
|
for (const toolDefinition of tools) {
|