@ai-table/grid 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/ai-table-grid.mjs +70 -54
 - package/fesm2022/ai-table-grid.mjs.map +1 -1
 - package/grid.component.d.ts +2 -0
 - package/grid.component.d.ts.map +1 -1
 - package/package.json +1 -1
 - package/renderer/components/cells/single-text.component.d.ts +1 -0
 - package/renderer/components/cells/single-text.component.d.ts.map +1 -1
 - package/utils/clipboard/clipboard.d.ts +2 -2
 - package/utils/clipboard/clipboard.d.ts.map +1 -1
 - package/utils/clipboard/paste.d.ts +1 -1
 - package/utils/clipboard/paste.d.ts.map +1 -1
 
| 
         @@ -2414,7 +2414,7 @@ const isClipboardReadSupported = () => { 
     | 
|
| 
       2414 
2414 
     | 
    
         
             
            const isClipboardReadTextSupported = () => {
         
     | 
| 
       2415 
2415 
     | 
    
         
             
                return 'clipboard' in navigator && 'readText' in navigator.clipboard;
         
     | 
| 
       2416 
2416 
     | 
    
         
             
            };
         
     | 
| 
       2417 
     | 
    
         
            -
            const writeToClipboard = async (data) => {
         
     | 
| 
      
 2417 
     | 
    
         
            +
            const writeToClipboard = async (data, dataTransfer) => {
         
     | 
| 
       2418 
2418 
     | 
    
         
             
                try {
         
     | 
| 
       2419 
2419 
     | 
    
         
             
                    const { text, html } = data;
         
     | 
| 
       2420 
2420 
     | 
    
         
             
                    if (isClipboardWriteSupported()) {
         
     | 
| 
         @@ -2423,24 +2423,24 @@ const writeToClipboard = async (data) => { 
     | 
|
| 
       2423 
2423 
     | 
    
         
             
                            'text/html': new Blob([html], { type: 'text/html' })
         
     | 
| 
       2424 
2424 
     | 
    
         
             
                        });
         
     | 
| 
       2425 
2425 
     | 
    
         
             
                        await navigator.clipboard.write([clipboardItem]);
         
     | 
| 
      
 2426 
     | 
    
         
            +
                        return;
         
     | 
| 
       2426 
2427 
     | 
    
         
             
                    }
         
     | 
| 
       2427 
     | 
    
         
            -
                     
     | 
| 
       2428 
     | 
    
         
            -
                         
     | 
| 
      
 2428 
     | 
    
         
            +
                    if (dataTransfer) {
         
     | 
| 
      
 2429 
     | 
    
         
            +
                        dataTransfer.setData(`text/html`, html);
         
     | 
| 
      
 2430 
     | 
    
         
            +
                        dataTransfer.setData(`text/plain`, text);
         
     | 
| 
      
 2431 
     | 
    
         
            +
                        window.dataTransfer = dataTransfer;
         
     | 
| 
      
 2432 
     | 
    
         
            +
                        return;
         
     | 
| 
       2429 
2433 
     | 
    
         
             
                    }
         
     | 
| 
       2430 
     | 
    
         
            -
                     
     | 
| 
       2431 
     | 
    
         
            -
                         
     | 
| 
       2432 
     | 
    
         
            -
                         
     | 
| 
       2433 
     | 
    
         
            -
                        document.body.appendChild(textarea);
         
     | 
| 
       2434 
     | 
    
         
            -
                        textarea.select();
         
     | 
| 
       2435 
     | 
    
         
            -
                        document.execCommand('copy');
         
     | 
| 
       2436 
     | 
    
         
            -
                        document.body.removeChild(textarea);
         
     | 
| 
      
 2434 
     | 
    
         
            +
                    if (isClipboardWriteTextSupported()) {
         
     | 
| 
      
 2435 
     | 
    
         
            +
                        await navigator.clipboard.writeText(text);
         
     | 
| 
      
 2436 
     | 
    
         
            +
                        return;
         
     | 
| 
       2437 
2437 
     | 
    
         
             
                    }
         
     | 
| 
       2438 
2438 
     | 
    
         
             
                }
         
     | 
| 
       2439 
2439 
     | 
    
         
             
                catch (error) {
         
     | 
| 
       2440 
2440 
     | 
    
         
             
                    console.warn('Failed to write clipboard:', error);
         
     | 
| 
       2441 
2441 
     | 
    
         
             
                }
         
     | 
| 
       2442 
2442 
     | 
    
         
             
            };
         
     | 
| 
       2443 
     | 
    
         
            -
            const readFromClipboard = async () => {
         
     | 
| 
      
 2443 
     | 
    
         
            +
            const readFromClipboard = async (dataTransfer) => {
         
     | 
| 
       2444 
2444 
     | 
    
         
             
                try {
         
     | 
| 
       2445 
2445 
     | 
    
         
             
                    let clipboardData = {};
         
     | 
| 
       2446 
2446 
     | 
    
         
             
                    if (isClipboardReadSupported()) {
         
     | 
| 
         @@ -2457,32 +2457,28 @@ const readFromClipboard = async () => { 
     | 
|
| 
       2457 
2457 
     | 
    
         
             
                                }
         
     | 
| 
       2458 
2458 
     | 
    
         
             
                            }
         
     | 
| 
       2459 
2459 
     | 
    
         
             
                        }
         
     | 
| 
      
 2460 
     | 
    
         
            +
                        const { html, text } = clipboardData;
         
     | 
| 
      
 2461 
     | 
    
         
            +
                        if (html || text) {
         
     | 
| 
      
 2462 
     | 
    
         
            +
                            return clipboardData;
         
     | 
| 
      
 2463 
     | 
    
         
            +
                        }
         
     | 
| 
       2460 
2464 
     | 
    
         
             
                    }
         
     | 
| 
       2461 
     | 
    
         
            -
                     
     | 
| 
       2462 
     | 
    
         
            -
                        const  
     | 
| 
       2463 
     | 
    
         
            -
                         
     | 
| 
      
 2465 
     | 
    
         
            +
                    if (dataTransfer) {
         
     | 
| 
      
 2466 
     | 
    
         
            +
                        const html = dataTransfer.getData(`text/html`);
         
     | 
| 
      
 2467 
     | 
    
         
            +
                        const text = dataTransfer.getData(`text/plain`);
         
     | 
| 
      
 2468 
     | 
    
         
            +
                        html && (clipboardData.html = html);
         
     | 
| 
      
 2469 
     | 
    
         
            +
                        text && (clipboardData.text = text);
         
     | 
| 
      
 2470 
     | 
    
         
            +
                        if (html || text) {
         
     | 
| 
      
 2471 
     | 
    
         
            +
                            return clipboardData;
         
     | 
| 
      
 2472 
     | 
    
         
            +
                        }
         
     | 
| 
       2464 
2473 
     | 
    
         
             
                    }
         
     | 
| 
       2465 
     | 
    
         
            -
                     
     | 
| 
       2466 
     | 
    
         
            -
                        const  
     | 
| 
       2467 
     | 
    
         
            -
             
     | 
| 
       2468 
     | 
    
         
            -
             
     | 
| 
       2469 
     | 
    
         
            -
                             
     | 
| 
       2470 
     | 
    
         
            -
             
     | 
| 
       2471 
     | 
    
         
            -
                                const html = e.clipboardData?.getData('text/html') || '';
         
     | 
| 
       2472 
     | 
    
         
            -
                                resolve({
         
     | 
| 
       2473 
     | 
    
         
            -
                                    text,
         
     | 
| 
       2474 
     | 
    
         
            -
                                    html: html || undefined
         
     | 
| 
       2475 
     | 
    
         
            -
                                });
         
     | 
| 
       2476 
     | 
    
         
            -
                                textarea.removeEventListener('paste', handlePaste);
         
     | 
| 
       2477 
     | 
    
         
            -
                            };
         
     | 
| 
       2478 
     | 
    
         
            -
                            textarea.addEventListener('paste', handlePaste);
         
     | 
| 
       2479 
     | 
    
         
            -
                            textarea.focus();
         
     | 
| 
       2480 
     | 
    
         
            -
                            document.execCommand('paste');
         
     | 
| 
       2481 
     | 
    
         
            -
                            document.body.removeChild(textarea);
         
     | 
| 
       2482 
     | 
    
         
            -
                        });
         
     | 
| 
       2483 
     | 
    
         
            -
                        clipboardData = await pastePromise;
         
     | 
| 
      
 2474 
     | 
    
         
            +
                    if (isClipboardReadTextSupported()) {
         
     | 
| 
      
 2475 
     | 
    
         
            +
                        const text = await navigator.clipboard.readText();
         
     | 
| 
      
 2476 
     | 
    
         
            +
                        text && (clipboardData.text = text);
         
     | 
| 
      
 2477 
     | 
    
         
            +
                        if (text) {
         
     | 
| 
      
 2478 
     | 
    
         
            +
                            return clipboardData;
         
     | 
| 
      
 2479 
     | 
    
         
            +
                        }
         
     | 
| 
       2484 
2480 
     | 
    
         
             
                    }
         
     | 
| 
       2485 
     | 
    
         
            -
                    return  
     | 
| 
      
 2481 
     | 
    
         
            +
                    return null;
         
     | 
| 
       2486 
2482 
     | 
    
         
             
                }
         
     | 
| 
       2487 
2483 
     | 
    
         
             
                catch (error) {
         
     | 
| 
       2488 
2484 
     | 
    
         
             
                    console.warn('Failed to read clipboard:', error);
         
     | 
| 
         @@ -3666,8 +3662,8 @@ function extractAITableContentFromClipboardHtml(clipboardHtml) { 
     | 
|
| 
       3666 
3662 
     | 
    
         
             
                }
         
     | 
| 
       3667 
3663 
     | 
    
         
             
                return null;
         
     | 
| 
       3668 
3664 
     | 
    
         
             
            }
         
     | 
| 
       3669 
     | 
    
         
            -
            const readClipboardData = async () => {
         
     | 
| 
       3670 
     | 
    
         
            -
                const clipboardData = await readFromClipboard();
         
     | 
| 
      
 3665 
     | 
    
         
            +
            const readClipboardData = async (dataTransfer) => {
         
     | 
| 
      
 3666 
     | 
    
         
            +
                const clipboardData = await readFromClipboard(dataTransfer);
         
     | 
| 
       3671 
3667 
     | 
    
         
             
                let clipboardContent = [];
         
     | 
| 
       3672 
3668 
     | 
    
         
             
                let aiTableContent = null;
         
     | 
| 
       3673 
3669 
     | 
    
         
             
                if (clipboardData) {
         
     | 
| 
         @@ -3737,7 +3733,7 @@ function appendField(aiTable, originField, actions) { 
     | 
|
| 
       3737 
3733 
     | 
    
         
             
                    defaultValue: defaultFieldValue
         
     | 
| 
       3738 
3734 
     | 
    
         
             
                });
         
     | 
| 
       3739 
3735 
     | 
    
         
             
            }
         
     | 
| 
       3740 
     | 
    
         
            -
            const writeToAITable = async (aiTable, actions) => {
         
     | 
| 
      
 3736 
     | 
    
         
            +
            const writeToAITable = async (aiTable, actions, dataTransfer) => {
         
     | 
| 
       3741 
3737 
     | 
    
         
             
                const selectedCells = Array.from(aiTable.selection().selectedCells);
         
     | 
| 
       3742 
3738 
     | 
    
         
             
                const result = {
         
     | 
| 
       3743 
3739 
     | 
    
         
             
                    isPasteSuccess: false,
         
     | 
| 
         @@ -3747,7 +3743,7 @@ const writeToAITable = async (aiTable, actions) => { 
     | 
|
| 
       3747 
3743 
     | 
    
         
             
                if (!selectedCells.length) {
         
     | 
| 
       3748 
3744 
     | 
    
         
             
                    return result;
         
     | 
| 
       3749 
3745 
     | 
    
         
             
                }
         
     | 
| 
       3750 
     | 
    
         
            -
                const { clipboardContent, aiTableContent } = await readClipboardData();
         
     | 
| 
      
 3746 
     | 
    
         
            +
                const { clipboardContent, aiTableContent } = await readClipboardData(dataTransfer);
         
     | 
| 
       3751 
3747 
     | 
    
         
             
                if (!clipboardContent.length) {
         
     | 
| 
       3752 
3748 
     | 
    
         
             
                    return result;
         
     | 
| 
       3753 
3749 
     | 
    
         
             
                }
         
     | 
| 
         @@ -10849,11 +10845,16 @@ class AITableCellText extends CoverCellBase { 
     | 
|
| 
       10849 
10845 
     | 
    
         
             
                        const { columnWidth } = render;
         
     | 
| 
       10850 
10846 
     | 
    
         
             
                        if (isExpand) {
         
     | 
| 
       10851 
10847 
     | 
    
         
             
                            return {
         
     | 
| 
      
 10848 
     | 
    
         
            +
                                name: generateTargetName({
         
     | 
| 
      
 10849 
     | 
    
         
            +
                                    targetName: AI_TABLE_CELL,
         
     | 
| 
      
 10850 
     | 
    
         
            +
                                    fieldId: field._id,
         
     | 
| 
      
 10851 
     | 
    
         
            +
                                    recordId
         
     | 
| 
      
 10852 
     | 
    
         
            +
                                }),
         
     | 
| 
       10852 
10853 
     | 
    
         
             
                                width: columnWidth - AI_TABLE_CELL_BORDER / 2,
         
     | 
| 
       10853 
10854 
     | 
    
         
             
                                height: this.height(),
         
     | 
| 
       10854 
10855 
     | 
    
         
             
                                stroke: Colors.primary,
         
     | 
| 
       10855 
10856 
     | 
    
         
             
                                strokeWidth: 2,
         
     | 
| 
       10856 
     | 
    
         
            -
                                listening:  
     | 
| 
      
 10857 
     | 
    
         
            +
                                listening: true
         
     | 
| 
       10857 
10858 
     | 
    
         
             
                            };
         
     | 
| 
       10858 
10859 
     | 
    
         
             
                        }
         
     | 
| 
       10859 
10860 
     | 
    
         
             
                        return null;
         
     | 
| 
         @@ -13258,6 +13259,8 @@ class AITableGrid extends AITableGridBase { 
     | 
|
| 
       13258 
13259 
     | 
    
         
             
                        this.bindGlobalMousedown();
         
     | 
| 
       13259 
13260 
     | 
    
         
             
                        this.containerResizeListener();
         
     | 
| 
       13260 
13261 
     | 
    
         
             
                        this.bindShortcuts();
         
     | 
| 
      
 13262 
     | 
    
         
            +
                        this.subscribeCopyEvent();
         
     | 
| 
      
 13263 
     | 
    
         
            +
                        this.subscribePasteEvent();
         
     | 
| 
       13261 
13264 
     | 
    
         
             
                    });
         
     | 
| 
       13262 
13265 
     | 
    
         
             
                    effect(() => {
         
     | 
| 
       13263 
13266 
     | 
    
         
             
                        if (this.hasContainerRect() && this.horizontalBarRef() && this.verticalBarRef()) {
         
     | 
| 
         @@ -13749,6 +13752,30 @@ class AITableGrid extends AITableGridBase { 
     | 
|
| 
       13749 
13752 
     | 
    
         
             
                        clearCoverCell(this.aiTable);
         
     | 
| 
       13750 
13753 
     | 
    
         
             
                    });
         
     | 
| 
       13751 
13754 
     | 
    
         
             
                }
         
     | 
| 
      
 13755 
     | 
    
         
            +
                subscribeCopyEvent() {
         
     | 
| 
      
 13756 
     | 
    
         
            +
                    fromEvent(document, 'copy')
         
     | 
| 
      
 13757 
     | 
    
         
            +
                        .pipe(takeUntilDestroyed(this.destroyRef))
         
     | 
| 
      
 13758 
     | 
    
         
            +
                        .subscribe((event) => {
         
     | 
| 
      
 13759 
     | 
    
         
            +
                        if (this.aiReadonly()) {
         
     | 
| 
      
 13760 
     | 
    
         
            +
                            return;
         
     | 
| 
      
 13761 
     | 
    
         
            +
                        }
         
     | 
| 
      
 13762 
     | 
    
         
            +
                        const dataTransfer = event.clipboardData;
         
     | 
| 
      
 13763 
     | 
    
         
            +
                        this.copyCells(dataTransfer);
         
     | 
| 
      
 13764 
     | 
    
         
            +
                        event.preventDefault();
         
     | 
| 
      
 13765 
     | 
    
         
            +
                    });
         
     | 
| 
      
 13766 
     | 
    
         
            +
                }
         
     | 
| 
      
 13767 
     | 
    
         
            +
                subscribePasteEvent() {
         
     | 
| 
      
 13768 
     | 
    
         
            +
                    fromEvent(document, 'paste')
         
     | 
| 
      
 13769 
     | 
    
         
            +
                        .pipe(takeUntilDestroyed(this.destroyRef))
         
     | 
| 
      
 13770 
     | 
    
         
            +
                        .subscribe((event) => {
         
     | 
| 
      
 13771 
     | 
    
         
            +
                        if (this.aiReadonly()) {
         
     | 
| 
      
 13772 
     | 
    
         
            +
                            return;
         
     | 
| 
      
 13773 
     | 
    
         
            +
                        }
         
     | 
| 
      
 13774 
     | 
    
         
            +
                        const dataTransfer = event.clipboardData;
         
     | 
| 
      
 13775 
     | 
    
         
            +
                        this.pasteCells(dataTransfer);
         
     | 
| 
      
 13776 
     | 
    
         
            +
                        event.preventDefault();
         
     | 
| 
      
 13777 
     | 
    
         
            +
                    });
         
     | 
| 
      
 13778 
     | 
    
         
            +
                }
         
     | 
| 
       13752 
13779 
     | 
    
         
             
                updateDragSelectState(isDragging, startCell) {
         
     | 
| 
       13753 
13780 
     | 
    
         
             
                    this.dragSelectState = {
         
     | 
| 
       13754 
13781 
     | 
    
         
             
                        isDragging: isDragging,
         
     | 
| 
         @@ -13865,7 +13892,6 @@ class AITableGrid extends AITableGridBase { 
     | 
|
| 
       13865 
13892 
     | 
    
         
             
                        if (hasContentEditable) {
         
     | 
| 
       13866 
13893 
     | 
    
         
             
                            return;
         
     | 
| 
       13867 
13894 
     | 
    
         
             
                        }
         
     | 
| 
       13868 
     | 
    
         
            -
                        const isCopyOrPaste = (event.ctrlKey || event.metaKey) && (event.key === 'c' || event.key === 'v');
         
     | 
| 
       13869 
13895 
     | 
    
         
             
                        const isDeleteOrBackspace = event.key === 'Backspace' || event.key === 'Delete';
         
     | 
| 
       13870 
13896 
     | 
    
         
             
                        const isDirectionKey = event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight';
         
     | 
| 
       13871 
13897 
     | 
    
         
             
                        const isShiftDirectionKey = event.shiftKey &&
         
     | 
| 
         @@ -13908,16 +13934,6 @@ class AITableGrid extends AITableGridBase { 
     | 
|
| 
       13908 
13934 
     | 
    
         
             
                            event.preventDefault();
         
     | 
| 
       13909 
13935 
     | 
    
         
             
                            return;
         
     | 
| 
       13910 
13936 
     | 
    
         
             
                        }
         
     | 
| 
       13911 
     | 
    
         
            -
                        if (isCopyOrPaste) {
         
     | 
| 
       13912 
     | 
    
         
            -
                            if (event.key === 'c') {
         
     | 
| 
       13913 
     | 
    
         
            -
                                this.copyCells();
         
     | 
| 
       13914 
     | 
    
         
            -
                            }
         
     | 
| 
       13915 
     | 
    
         
            -
                            else if (event.key === 'v') {
         
     | 
| 
       13916 
     | 
    
         
            -
                                this.pasteCells();
         
     | 
| 
       13917 
     | 
    
         
            -
                            }
         
     | 
| 
       13918 
     | 
    
         
            -
                            event.preventDefault();
         
     | 
| 
       13919 
     | 
    
         
            -
                            return;
         
     | 
| 
       13920 
     | 
    
         
            -
                        }
         
     | 
| 
       13921 
13937 
     | 
    
         
             
                        if (isDeleteOrBackspace) {
         
     | 
| 
       13922 
13938 
     | 
    
         
             
                            clearCells(this.aiTable, this.actions);
         
     | 
| 
       13923 
13939 
     | 
    
         
             
                            event.preventDefault();
         
     | 
| 
         @@ -13945,10 +13961,10 @@ class AITableGrid extends AITableGridBase { 
     | 
|
| 
       13945 
13961 
     | 
    
         
             
                        }
         
     | 
| 
       13946 
13962 
     | 
    
         
             
                    });
         
     | 
| 
       13947 
13963 
     | 
    
         
             
                }
         
     | 
| 
       13948 
     | 
    
         
            -
                copyCells() {
         
     | 
| 
      
 13964 
     | 
    
         
            +
                copyCells(dataTransfer) {
         
     | 
| 
       13949 
13965 
     | 
    
         
             
                    const clipboardData = buildClipboardData(this.aiTable);
         
     | 
| 
       13950 
13966 
     | 
    
         
             
                    if (clipboardData) {
         
     | 
| 
       13951 
     | 
    
         
            -
                        writeToClipboard(clipboardData).then(() => {
         
     | 
| 
      
 13967 
     | 
    
         
            +
                        writeToClipboard(clipboardData, dataTransfer).then(() => {
         
     | 
| 
       13952 
13968 
     | 
    
         
             
                            const copiedCellsCount = this.aiTable.selection().selectedCells.size;
         
     | 
| 
       13953 
13969 
     | 
    
         
             
                            const message = getI18nTextByKey(this.aiTable, AITableGridI18nKey.copiedCells).replace('{count}', copiedCellsCount.toString());
         
     | 
| 
       13954 
13970 
     | 
    
         
             
                            this.notifyService.success(message, undefined, {
         
     | 
| 
         @@ -13957,8 +13973,8 @@ class AITableGrid extends AITableGridBase { 
     | 
|
| 
       13957 
13973 
     | 
    
         
             
                        });
         
     | 
| 
       13958 
13974 
     | 
    
         
             
                    }
         
     | 
| 
       13959 
13975 
     | 
    
         
             
                }
         
     | 
| 
       13960 
     | 
    
         
            -
                pasteCells() {
         
     | 
| 
       13961 
     | 
    
         
            -
                    writeToAITable(this.aiTable, this.actions).then((result) => {
         
     | 
| 
      
 13976 
     | 
    
         
            +
                pasteCells(dataTransfer) {
         
     | 
| 
      
 13977 
     | 
    
         
            +
                    writeToAITable(this.aiTable, this.actions, dataTransfer).then((result) => {
         
     | 
| 
       13962 
13978 
     | 
    
         
             
                        if (result.isPasteOverMaxRecords || result.isPasteOverMaxFields) {
         
     | 
| 
       13963 
13979 
     | 
    
         
             
                            return;
         
     | 
| 
       13964 
13980 
     | 
    
         
             
                        }
         
     |