Browse Source

feat: paste option in cell right click context menu

pull/7173/head
Ramesh Mane 12 months ago
parent
commit
f62eac5fb1
  1. 17
      packages/nc-gui/components/smartsheet/grid/Table.vue
  2. 28
      packages/nc-gui/composables/usePaste.ts
  3. 3
      packages/nc-gui/lang/en.json
  4. 1
      packages/nc-gui/utils/iconUtils.ts

17
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -41,6 +41,7 @@ import {
useViewColumnsOrThrow, useViewColumnsOrThrow,
useViewsStore, useViewsStore,
watch, watch,
usePaste,
} from '#imports' } from '#imports'
import type { CellRange, Row } from '#imports' import type { CellRange, Row } from '#imports'
@ -168,6 +169,8 @@ const predictNextFormulas = async () => {
await _predictNextFormulas(meta) await _predictNextFormulas(meta)
} }
const { paste } = usePaste()
// #Refs // #Refs
const rowRefs = ref<any[]>() const rowRefs = ref<any[]>()
@ -1694,6 +1697,20 @@ onKeyStroke('ArrowDown', onDown)
</div> </div>
</NcMenuItem> </NcMenuItem>
<NcMenuItem
v-if="contextMenuTarget"
class="nc-base-menu-item"
data-testid="context-menu-item-paste"
:disabled="isSystemColumn(fields[contextMenuTarget.col])"
@click="paste"
>
<div v-e="['a:row:paste']" class="flex gap-2 items-center">
<GeneralIcon icon="paste" />
<!-- Paste -->
{{ $t('general.paste') }}
</div>
</NcMenuItem>
<!-- Clear cell --> <!-- Clear cell -->
<NcMenuItem <NcMenuItem
v-if=" v-if="

28
packages/nc-gui/composables/usePaste.ts

@ -0,0 +1,28 @@
export const usePaste = () => {
const paste = async (): Promise<boolean> => {
try {
// Check if the Clipboard API is supported
if (!navigator.clipboard) return false
// Read text from the clipboard
const clipboardText = await navigator.clipboard.readText()
// Create a new paste event
const pasteEvent = new Event('paste')
// Attach clipboard data to the event
const clipboardData = {
getData: () => clipboardText || '',
}
Object.defineProperty(pasteEvent, 'clipboardData', { value: clipboardData })
// Dispatch the event on the document or any other target element
document.dispatchEvent(pasteEvent)
return true
} catch (e) {
return false
}
}
return { paste }
}

3
packages/nc-gui/lang/en.json

@ -188,7 +188,8 @@
"useSurveyMode": "Use Survey Mode", "useSurveyMode": "Use Survey Mode",
"shift": "Shift", "shift": "Shift",
"enter": "Enter", "enter": "Enter",
"seconds": "Seconds" "seconds": "Seconds",
"paste": "Paste"
}, },
"objects": { "objects": {
"workspace": "Workspace", "workspace": "Workspace",

1
packages/nc-gui/utils/iconUtils.ts

@ -452,6 +452,7 @@ export const iconMap = {
role_no_access: NoAccess, role_no_access: NoAccess,
commentHere: NcCommentHere, commentHere: NcCommentHere,
fileImage: FileImageIcon, fileImage: FileImageIcon,
paste: h('span', { class: 'material-symbols' }, 'content_paste'),
} }
export const getMdiIcon = (type: string): any => { export const getMdiIcon = (type: string): any => {

Loading…
Cancel
Save