fix copy/paste

This commit is contained in:
samunohito 2024-02-18 15:24:22 +09:00
parent bfdfc2c778
commit 106e7910b9
2 changed files with 61 additions and 7 deletions

View File

@ -312,7 +312,7 @@ function setupGrid(): GridSetting {
bindTo: 'roleIdsThatCanBeUsedThisEmojiAsReaction', title: 'role', type: 'text', editable: true, width: 140, bindTo: 'roleIdsThatCanBeUsedThisEmojiAsReaction', title: 'role', type: 'text', editable: true, width: 140,
valueTransformer: (row) => { valueTransformer: (row) => {
// IDID // IDID
return (gridItems.value[row.index].roleIdsThatCanBeUsedThisEmojiAsReaction ?? []) return gridItems.value[row.index].roleIdsThatCanBeUsedThisEmojiAsReaction
.map((it) => it.name) .map((it) => it.name)
.join(','); .join(',');
}, },
@ -597,15 +597,15 @@ async function onGridKeyDown(event: GridKeyDownEvent, currentState: GridContext)
try { try {
const obj = JSON.parse(value); const obj = JSON.parse(value);
if (!Array.isArray(obj)) { if (!Array.isArray(obj)) {
return undefined; return [];
} }
if (!obj.every(it => typeof it === 'object' && 'id' in it && 'name' in it)) { if (!obj.every(it => typeof it === 'object' && 'id' in it && 'name' in it)) {
return undefined; return [];
} }
return obj.map(it => ({ id: it.id, name: it.name })); return obj.map(it => ({ id: it.id, name: it.name }));
} catch (ex) { } catch (ex) {
return undefined; return [];
} }
} }

View File

@ -98,6 +98,7 @@ import { DroppedFile, extractDroppedItems, flattenDroppedFiles } from '@/scripts
import { optInGridUtils } from '@/components/grid/optin-utils.js'; import { optInGridUtils } from '@/components/grid/optin-utils.js';
import XRegisterLogs from '@/pages/admin/custom-emojis-manager.local.logs.vue'; import XRegisterLogs from '@/pages/admin/custom-emojis-manager.local.logs.vue';
import { GridSetting } from '@/components/grid/grid.js'; import { GridSetting } from '@/components/grid/grid.js';
import { CellValue } from '@/components/grid/cell.js';
const MAXIMUM_EMOJI_REGISTER_COUNT = 100; const MAXIMUM_EMOJI_REGISTER_COUNT = 100;
@ -163,7 +164,7 @@ function setupGrid(): GridSetting {
bindTo: 'roleIdsThatCanBeUsedThisEmojiAsReaction', title: 'role', type: 'text', editable: true, width: 140, bindTo: 'roleIdsThatCanBeUsedThisEmojiAsReaction', title: 'role', type: 'text', editable: true, width: 140,
valueTransformer: (row) => { valueTransformer: (row) => {
// IDID // IDID
return (gridItems.value[row.index].roleIdsThatCanBeUsedThisEmojiAsReaction ?? []) return gridItems.value[row.index].roleIdsThatCanBeUsedThisEmojiAsReaction
.map((it) => it.name) .map((it) => it.name)
.join(','); .join(',');
}, },
@ -383,8 +384,61 @@ function onGridCellValueChange(event: GridCellValueChangeEvent) {
} }
} }
function onGridKeyDown(event: GridKeyDownEvent, currentState: GridContext) { async function onGridKeyDown(event: GridKeyDownEvent, context: GridContext) {
optInGridUtils.defaultKeyDownHandler(gridItems, event, currentState); function roleIdConverter(value: string): CellValue {
try {
const obj = JSON.parse(value);
if (!Array.isArray(obj)) {
return [];
}
if (!obj.every(it => typeof it === 'object' && 'id' in it && 'name' in it)) {
return [];
}
return obj.map(it => ({ id: it.id, name: it.name }));
} catch (ex) {
return [];
}
}
const { ctrlKey, shiftKey, code } = event.event;
switch (true) {
case ctrlKey && shiftKey: {
break;
}
case ctrlKey: {
switch (code) {
case 'KeyC': {
optInGridUtils.copyToClipboard(gridItems, context);
break;
}
case 'KeyV': {
await optInGridUtils.pasteFromClipboard(
gridItems,
context,
[
{ bindTo: 'roleIdsThatCanBeUsedThisEmojiAsReaction', converter: roleIdConverter },
],
);
break;
}
}
break;
}
case shiftKey: {
break;
}
default: {
switch (code) {
case 'Delete': {
optInGridUtils.deleteSelectionRange(gridItems, context);
break;
}
}
break;
}
}
} }
function fromDriveFile(it: Misskey.entities.DriveFile): GridItem { function fromDriveFile(it: Misskey.entities.DriveFile): GridItem {