Skip to content

Commit

Permalink
feat: ✨ add table bubble and icon components
Browse files Browse the repository at this point in the history
  • Loading branch information
isboyjc committed Dec 11, 2024
1 parent 31eab75 commit 6ad0b82
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 101 deletions.
15 changes: 15 additions & 0 deletions packages/core/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
"alignJustify": "Align Justify",
"table": "Table",

"tables": {
"addTable": "Add Table",
"deleteTable": "Delete Table",
"addColumnBefore": "Add Column Before",
"addColumnAfter": "Add Column After",
"deleteColumn": "Delete Column",
"addRowBefore": "Add Row Before",
"addRowAfter": "Add Row After",
"deleteRow": "Delete Row",
"mergeCells": "Merge Cells",
"splitCell": "Split Cell",
"headerRow": "Toggle Header Row",
"headerCol": "Toggle Header Column"
},

"edit": "Edit",
"textClear": "Clear",
"copy": "Copy",
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
"alignJustify": "两端对齐",
"table": "表格",

"tables": {
"addTable": "添加表格",
"deleteTable": "删除表格",
"addColumnBefore": "在左侧添加列",
"addColumnAfter": "在右侧添加列",
"deleteColumn": "删除列",
"addRowBefore": "在上方添加行",
"addRowAfter": "在下方添加行",
"deleteRow": "删除行",
"mergeCells": "合并单元格",
"splitCell": "拆分单元格",
"headerRow": "切换标题行",
"headerCol": "切换标题列"
},

"edit": "编辑",
"textClear": "清除",
"copy": "复制",
Expand Down
5 changes: 4 additions & 1 deletion packages/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"license": "MIT",
"dependencies": {
"@isle-editor/core": "workspace:*",
"lucide-vue-next": "^0.454.0",
"tippy.js": "^6.3.7",
"uuid": "^11.0.2"
},
Expand All @@ -36,5 +35,9 @@
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@iconify-json/lucide": "^1.2.14",
"@iconify-json/tabler": "^1.2.10"
}
}
8 changes: 8 additions & 0 deletions packages/vue3/src/components/bubble-menu/bubble-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { isString, isObject } from "@/utils";
import BubbleSelector from "./selector/bubble-menu-selector";
import BubbleLinkSelector from "./selector/bubble-menu-link-selector";
import BubbleTableSelector from "./selector/bubble-menu-table-selector";

import {
defineComponent,
Expand Down Expand Up @@ -225,6 +226,13 @@ export default defineComponent({
(menu) => menu.name === "link",
)?.options,
}),
isTable.value &&
h(BubbleTableSelector, {
editor: props.editor,
menu: props.editor.extensionManager.extensions.find(
(menu) => menu.name === "table",
)?.options,
}),
]);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default defineComponent({
},
{
icon: () =>
h(getIcon("openRight"), { size: 15, strokeWidth: 2.5 }),
h(getIcon("openRight"), { style: { fontSize: "12px" } }),
default: () =>
h(
"span",
Expand All @@ -86,8 +86,7 @@ export default defineComponent({
{
icon: () =>
h(getIcon(copyOk.value ? "check" : "copy"), {
size: 15,
strokeWidth: 2.5,
style: { fontSize: "12px" },
}),
},
),
Expand All @@ -107,7 +106,7 @@ export default defineComponent({
},
{
icon: () =>
h(getIcon("unlink"), { size: 15, strokeWidth: 2.5 }),
h(getIcon("unlink"), { style: { fontSize: "12px" } }),
},
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default defineComponent({
},
{
icon: () =>
h(getIcon(menu.name), { size: 15, strokeWidth: 2.5 }),
h(getIcon(menu.name), { style: { fontSize: "13px" } }),
},
),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { defineComponent, h } from "vue";
import { prefixClass, t } from "@isle-editor/core";
import { getIcon } from "@/utils";
import { ITooltip, IDivider, IButton } from "@/components/ui";
import DeleteTable from "~icons/tabler/table-minus";
import HeaderRow from "~icons/tabler/table-row";
import HeaderCol from "~icons/tabler/table-column";
import AddColumnBefore from "~icons/tabler/column-insert-left";
import AddColumnAfter from "~icons/tabler/column-insert-right";
import DeleteColumn from "~icons/tabler/column-remove";
import AddRowBefore from "~icons/tabler/row-insert-top";
import AddRowAfter from "~icons/tabler/row-insert-bottom";
import DeleteRow from "~icons/tabler/row-remove";
import MergeCells from "~icons/lucide/table-cells-merge";
import SplitCell from "~icons/lucide/table-cells-split";

export default defineComponent({
name: "BubbleTableSelector",
props: {
editor: {
type: Object,
required: true,
},
menu: {
type: Object,
required: true,
},
},
setup(props) {
const tableBubbleMenu = [
{
name: "tables.addColumnBefore",
command: ({ editor }) => editor.commands.addColumnBefore(),
isActive: () => false,
isDisabled: () => !props.editor.can().addColumnBefore(),
icon: () => h(AddColumnBefore, { style: { fontSize: "13px" } }),
},
{
name: "tables.addColumnAfter",
command: ({ editor }) => editor.commands.addColumnAfter(),
isActive: () => false,
isDisabled: () => !props.editor.can().addColumnAfter(),
icon: () => h(AddColumnAfter, { style: { fontSize: "13px" } }),
},
{
name: "tables.deleteColumn",
isDel: true,
command: ({ editor }) => editor.commands.deleteColumn(),
isActive: () => false,
isDisabled: () => !props.editor.can().deleteColumn(),
icon: () => h(DeleteColumn, { style: { fontSize: "13px" } }),
},
{
name: "|",
},
{
name: "tables.addRowBefore",
command: ({ editor }) => editor.commands.addRowBefore(),
isActive: () => false,
isDisabled: () => !props.editor.can().addRowBefore(),
icon: () => h(AddRowBefore, { style: { fontSize: "13px" } }),
},
{
name: "tables.addRowAfter",
command: ({ editor }) => editor.commands.addRowAfter(),
isActive: () => false,
isDisabled: () => !props.editor.can().addRowAfter(),
icon: () => h(AddRowAfter, { style: { fontSize: "13px" } }),
},
{
name: "tables.deleteRow",
isDel: true,
command: ({ editor }) => editor.commands.deleteRow(),
isActive: () => false,
isDisabled: () => !props.editor.can().deleteRow(),
icon: () => h(DeleteRow, { style: { fontSize: "13px" } }),
},
{
name: "|",
},
{
name: "tables.mergeCells",
command: ({ editor }) => editor.commands.mergeCells(),
isActive: () => false,
isDisabled: () => !props.editor.can().mergeCells(),
icon: () => h(MergeCells, { style: { fontSize: "13px" } }),
},
{
name: "tables.splitCell",
command: ({ editor }) => editor.commands.splitCell(),
isActive: () => false,
isDisabled: () => !props.editor.can().splitCell(),
icon: () => h(SplitCell, { style: { fontSize: "13px" } }),
},
{
name: "tables.headerRow",
icon: () => h(HeaderRow, { style: { fontSize: "13px" } }),
command: ({ editor }) => editor.commands.toggleHeaderRow(),
isActive: () => false,
isDisabled: () => !props.editor.can().toggleHeaderRow(),
},
{
name: "tables.headerCol",
icon: () => h(HeaderCol, { style: { fontSize: "13px" } }),
command: ({ editor }) => editor.commands.toggleHeaderColumn(),
isActive: () => false,
isDisabled: () => !props.editor.can().toggleHeaderColumn(),
},
{
name: "|",
},
{
name: "tables.deleteTable",
isDel: true,
command: ({ editor }) => editor.commands.deleteTable(),
isActive: () => false,
isDisabled: () => !props.editor.can().deleteTable(),
icon: () => h(DeleteTable, { style: { fontSize: "13px" } }),
},
];

return () => {
return h(
"div",
{
class: `${prefixClass}-bubble-menu`,
},
[
...tableBubbleMenu.map((item) => {
if (item.name === "|") {
return h(IDivider, {
type: "vertical",
style: { height: "1.5rem" },
});
}

return h(
ITooltip,
{
text: t(item.name),
shortcutkeys: item.shortcutkeys,
},
{
default: () =>
h(
IButton,
{
danger: item?.isDel,
disabled:
item?.isDisabled &&
item?.isDisabled({ editor: props.editor }),
active: item?.isActive({ editor: props.editor }),
onClick: () => item.command({ editor: props.editor }),
},
{
icon: () => item.icon(),
},
),
},
);
}),
],
);
};
},
});
3 changes: 1 addition & 2 deletions packages/vue3/src/components/slash-menu/slash-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ export default defineComponent({
[
h(getIcon(item.name), {
class: `${prefixClass}-slash-menu__item-left-icon`,
size: 16,
strokeWidth: 2.5,
style: { fontSize: "13px" },
}),
h(
"span",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export default defineComponent({
},
[
h(getIcon(props.menu.name || "background"), {
size: 13,
strokeWidth: 2.5,
style: { fontSize: "12px" },
}),
],
),
Expand All @@ -146,9 +145,8 @@ export default defineComponent({
style: {
marginLeft: "0.1rem",
marginTop: "0.1rem",
fontSize: "8px",
},
size: 8,
strokeWidth: 3,
}),
},
),
Expand Down
9 changes: 3 additions & 6 deletions packages/vue3/src/components/special-button/button-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export default defineComponent({
[
h(getIcon(props.menu.name), {
class: `${prefixClass}-special-button__color-box-item-icon`,
size: 14,
strokeWidth: 2,
style: { fontSize: "12px" },
}),
],
),
Expand Down Expand Up @@ -128,8 +127,7 @@ export default defineComponent({
},
[
h(getIcon(props.menu.name || "color"), {
size: 13,
strokeWidth: 2.5,
style: { fontSize: "12px" },
}),
],
),
Expand All @@ -138,9 +136,8 @@ export default defineComponent({
style: {
marginLeft: "0.1rem",
marginTop: "0.1rem",
fontSize: "8px",
},
size: 8,
strokeWidth: 3,
}),
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ export default defineComponent({
style: {
marginLeft: "0.1rem",
marginTop: "0.1rem",
fontSize: "8px",
},
size: 8,
strokeWidth: 3,
}),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ export default defineComponent({
style: {
marginLeft: "0.1rem",
marginTop: "0.1rem",
fontSize: "8px",
},
size: 8,
strokeWidth: 3,
}),
],
},
Expand Down
9 changes: 3 additions & 6 deletions packages/vue3/src/components/special-button/button-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ export default defineComponent({
icon: () =>
props.isEdit
? h(getIcon("edit"), {
size: 15,
strokeWidth: 2.5,
style: { fontSize: "13px" },
})
: h(getIcon(props.menu.name), {
size: 14,
strokeWidth: 2.5,
style: { fontSize: "12px" },
}),
},
),
Expand All @@ -124,8 +122,7 @@ export default defineComponent({
h("div", { class: `${prefixClass}-special-button__link-input` }, [
h(getIcon(props.menu.name || "link"), {
class: `${prefixClass}-special-button__link-input-icon`,
size: 15,
strokeWidth: 2.5,
style: { fontSize: "13px" },
}),
h("input", {
ref: linkInputRef,
Expand Down
Loading

0 comments on commit 6ad0b82

Please sign in to comment.