From a1d7b2d9cd8421dc749c79264bee1145b2d4272a Mon Sep 17 00:00:00 2001 From: XiNGRZ Date: Thu, 28 Mar 2024 19:06:24 +0800 Subject: [PATCH] Add dropdown menu to icon cells --- package-lock.json | 6 ++ package.json | 1 + src/components/BSMap/BSCell.vue | 29 +++++++-- src/components/BSMap/BSPopover.vue | 83 +++++++++++++++++++++++++ src/components/BSMap/BSPopoverIcon.vue | 35 +++++++++++ src/components/BSMap/BSPopoverLabel.vue | 55 ++++++++++++++++ 6 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 src/components/BSMap/BSPopover.vue create mode 100644 src/components/BSMap/BSPopoverIcon.vue create mode 100644 src/components/BSMap/BSPopoverLabel.vue diff --git a/package-lock.json b/package-lock.json index 8721a30..6c2bc6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "rdt-editor", "version": "5.0", "dependencies": { + "@vicons/ionicons5": "^0.12.0", "ace-code": "^1.32.8", "md5": "^2.3.0", "naive-ui": "^2.38.1", @@ -1041,6 +1042,11 @@ "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", "dev": true }, + "node_modules/@vicons/ionicons5": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@vicons/ionicons5/-/ionicons5-0.12.0.tgz", + "integrity": "sha512-Iy1EUVRpX0WWxeu1VIReR1zsZLMc4fqpt223czR+Rpnrwu7pt46nbnC2ycO7ItI/uqDLJxnbcMC7FujKs9IfFA==" + }, "node_modules/@vitejs/plugin-vue": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.0.4.tgz", diff --git a/package.json b/package.json index c2272bc..f357141 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "eslint --ext .ts,.vue src" }, "dependencies": { + "@vicons/ionicons5": "^0.12.0", "ace-code": "^1.32.8", "md5": "^2.3.0", "naive-ui": "^2.38.1", diff --git a/src/components/BSMap/BSCell.vue b/src/components/BSMap/BSCell.vue index d74dfe4..02db3cc 100644 --- a/src/components/BSMap/BSCell.vue +++ b/src/components/BSMap/BSCell.vue @@ -1,9 +1,13 @@ @@ -16,9 +20,11 @@ import { } from 'vue'; import { useEditorStore } from '@/stores/editor'; +import splitWithOffset from '@/utils/splitWithOffset'; import styleFromParams from '@/utils/styleFromParams'; import BSSelectable from './BSSelectable.vue'; +import BSPopover from './BSPopover.vue'; import BSIcon from './BSIcon.vue'; const props = defineProps<{ @@ -34,9 +40,13 @@ const ratio = ref(1); const parts = computed(() => { if (!props.src) return; - const [nonParam, ...params] = props.src.split('!_'); + const match = props.src.match(/^( *)([^ ]+)( *)$/); + const leading = (match?.[1] || '').length; + const nonSpace = match?.[2] || props.src; + + const [nonParam, ...params] = nonSpace.split('!_'); const [nonLink, ...links] = nonParam.split('!@'); - const icons = nonLink.split('!~').filter((icon) => !!icon); + const icons = splitWithOffset(nonLink, '!~', leading).filter(({ part }) => !!part); return { icons, links, params }; }); @@ -46,6 +56,8 @@ const style = computed(() => ({ '--bs-map-cell-ratio': (ratio.value == 1 ? undefined : ratio.value), }) as CSSProperties); +const popoverShown = ref(false); + function handleClick(): void { editorStore.selection = { row: props.row, @@ -55,6 +67,11 @@ function handleClick(): void { }; } +function handleRightClick(): void { + popoverShown.value = true; + handleClick(); +} + function updateRatio(layer: number, newRatio: number): void { if (layer == 0) { // Only ratio of the first icon affects the cell diff --git a/src/components/BSMap/BSPopover.vue b/src/components/BSMap/BSPopover.vue new file mode 100644 index 0000000..1bf2e68 --- /dev/null +++ b/src/components/BSMap/BSPopover.vue @@ -0,0 +1,83 @@ + + + diff --git a/src/components/BSMap/BSPopoverIcon.vue b/src/components/BSMap/BSPopoverIcon.vue new file mode 100644 index 0000000..1692242 --- /dev/null +++ b/src/components/BSMap/BSPopoverIcon.vue @@ -0,0 +1,35 @@ + + + + + + diff --git a/src/components/BSMap/BSPopoverLabel.vue b/src/components/BSMap/BSPopoverLabel.vue new file mode 100644 index 0000000..d23baac --- /dev/null +++ b/src/components/BSMap/BSPopoverLabel.vue @@ -0,0 +1,55 @@ + + + + +