@maily-to/core 0.2.6 → 0.2.8
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/dist/blocks/index.d.cts +1 -1
- package/dist/blocks/index.d.ts +1 -1
- package/dist/extensions/index.cjs +3180 -3134
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +4 -4
- package/dist/extensions/index.d.ts +4 -4
- package/dist/extensions/index.mjs +3219 -3173
- package/dist/extensions/index.mjs.map +1 -1
- package/dist/index.cjs +180 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +7 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +192 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +32 -33
package/dist/index.mjs
CHANGED
|
@@ -53,7 +53,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
53
53
|
|
|
54
54
|
// src/editor/index.tsx
|
|
55
55
|
import { EditorContent, useEditor } from "@tiptap/react";
|
|
56
|
-
import { useMemo as
|
|
56
|
+
import { useMemo as useMemo13, useRef as useRef13 } from "react";
|
|
57
57
|
|
|
58
58
|
// src/editor/components/column-menu/columns-bubble-menu.tsx
|
|
59
59
|
import { BubbleMenu } from "@tiptap/react";
|
|
@@ -108,7 +108,7 @@ function isTextSelected(editor) {
|
|
|
108
108
|
// src/editor/utils/columns.ts
|
|
109
109
|
import { Fragment } from "@tiptap/pm/model";
|
|
110
110
|
import { TextSelection } from "@tiptap/pm/state";
|
|
111
|
-
import { v4 as
|
|
111
|
+
import { v4 as uuidv42 } from "uuid";
|
|
112
112
|
import { findParentNode } from "@tiptap/core";
|
|
113
113
|
|
|
114
114
|
// src/editor/utils/update-attribute.ts
|
|
@@ -147,7 +147,7 @@ function updateAttributes(type, attrs) {
|
|
|
147
147
|
|
|
148
148
|
// src/editor/nodes/columns/column.ts
|
|
149
149
|
import { Node, mergeAttributes } from "@tiptap/core";
|
|
150
|
-
import { v4 as
|
|
150
|
+
import { v4 as uuidv4 } from "uuid";
|
|
151
151
|
var DEFAULT_COLUMN_WIDTH = "auto";
|
|
152
152
|
var DEFAULT_COLUMN_VERTICAL_ALIGN = "top";
|
|
153
153
|
var ColumnExtension = Node.create({
|
|
@@ -158,11 +158,11 @@ var ColumnExtension = Node.create({
|
|
|
158
158
|
return {
|
|
159
159
|
columnId: {
|
|
160
160
|
default: null,
|
|
161
|
-
parseHTML: (element) => element.getAttribute("data-column-id") ||
|
|
161
|
+
parseHTML: (element) => element.getAttribute("data-column-id") || uuidv4(),
|
|
162
162
|
renderHTML: (attributes) => {
|
|
163
163
|
if (!attributes.columnId) {
|
|
164
164
|
return {
|
|
165
|
-
"data-column-id":
|
|
165
|
+
"data-column-id": uuidv4()
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
return {
|
|
@@ -319,7 +319,7 @@ function addColumnByIndex(editor, index = -1) {
|
|
|
319
319
|
const newColumn = state.schema.nodes.column.create(
|
|
320
320
|
{
|
|
321
321
|
width: DEFAULT_COLUMN_WIDTH,
|
|
322
|
-
columnId:
|
|
322
|
+
columnId: uuidv42()
|
|
323
323
|
},
|
|
324
324
|
state.schema.nodes.paragraph.create(null)
|
|
325
325
|
);
|
|
@@ -2106,10 +2106,10 @@ var DEFAULT_SECTION_MARGIN_TOP = 0;
|
|
|
2106
2106
|
var DEFAULT_SECTION_MARGIN_RIGHT = 0;
|
|
2107
2107
|
var DEFAULT_SECTION_MARGIN_BOTTOM = 0;
|
|
2108
2108
|
var DEFAULT_SECTION_MARGIN_LEFT = 0;
|
|
2109
|
-
var DEFAULT_SECTION_PADDING_TOP =
|
|
2110
|
-
var DEFAULT_SECTION_PADDING_RIGHT =
|
|
2111
|
-
var DEFAULT_SECTION_PADDING_BOTTOM =
|
|
2112
|
-
var DEFAULT_SECTION_PADDING_LEFT =
|
|
2109
|
+
var DEFAULT_SECTION_PADDING_TOP = 0;
|
|
2110
|
+
var DEFAULT_SECTION_PADDING_RIGHT = 0;
|
|
2111
|
+
var DEFAULT_SECTION_PADDING_BOTTOM = 0;
|
|
2112
|
+
var DEFAULT_SECTION_PADDING_LEFT = 0;
|
|
2113
2113
|
var DEFAULT_SECTION_SHOW_IF_KEY = null;
|
|
2114
2114
|
var SectionExtension = Node3.create({
|
|
2115
2115
|
name: "section",
|
|
@@ -2577,6 +2577,7 @@ function getNewWidth(height, aspectRatio) {
|
|
|
2577
2577
|
import { Fragment as Fragment3, jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2578
2578
|
var MIN_WIDTH = 20;
|
|
2579
2579
|
var IMAGE_MAX_WIDTH = 600;
|
|
2580
|
+
var IMAGE_MAX_HEIGHT = 400;
|
|
2580
2581
|
function ImageView(props) {
|
|
2581
2582
|
const { node, updateAttributes: updateAttributes2, selected, editor } = props;
|
|
2582
2583
|
const [status, setStatus] = useState4("idle");
|
|
@@ -2601,11 +2602,13 @@ function ImageView(props) {
|
|
|
2601
2602
|
event.preventDefault();
|
|
2602
2603
|
const direction = event.currentTarget.dataset.direction || "--";
|
|
2603
2604
|
const initialXPosition = event.clientX;
|
|
2605
|
+
const initialYPosition = event.clientY;
|
|
2604
2606
|
const currentWidth = imgRef.current.width;
|
|
2605
2607
|
const currentHeight = imgRef.current.height;
|
|
2606
2608
|
let newWidth = currentWidth;
|
|
2607
2609
|
let newHeight = currentHeight;
|
|
2608
|
-
const
|
|
2610
|
+
const transformX = direction[1] === "w" ? -1 : 1;
|
|
2611
|
+
const transformY = direction[0] === "n" ? -1 : 1;
|
|
2609
2612
|
const removeListeners = () => {
|
|
2610
2613
|
window.removeEventListener("mousemove", mouseMoveHandler);
|
|
2611
2614
|
window.removeEventListener("mouseup", removeListeners);
|
|
@@ -2615,13 +2618,22 @@ function ImageView(props) {
|
|
|
2615
2618
|
};
|
|
2616
2619
|
const mouseMoveHandler = (event2) => {
|
|
2617
2620
|
newWidth = Math.max(
|
|
2618
|
-
currentWidth +
|
|
2621
|
+
currentWidth + transformX * (event2.clientX - initialXPosition),
|
|
2622
|
+
MIN_WIDTH
|
|
2623
|
+
);
|
|
2624
|
+
newHeight = Math.max(
|
|
2625
|
+
currentHeight + transformY * (event2.clientY - initialYPosition),
|
|
2619
2626
|
MIN_WIDTH
|
|
2620
2627
|
);
|
|
2621
2628
|
if (newWidth > imageParentWidth) {
|
|
2622
2629
|
newWidth = imageParentWidth;
|
|
2623
2630
|
}
|
|
2624
|
-
newHeight
|
|
2631
|
+
if (newHeight > IMAGE_MAX_HEIGHT) {
|
|
2632
|
+
newHeight = IMAGE_MAX_HEIGHT;
|
|
2633
|
+
}
|
|
2634
|
+
if (node.attrs.lockAspectRatio) {
|
|
2635
|
+
newHeight = getNewHeight(newWidth, node.attrs.aspectRatio);
|
|
2636
|
+
}
|
|
2625
2637
|
setResizingStyle({ width: newWidth, height: newHeight });
|
|
2626
2638
|
if (!event2.buttons) {
|
|
2627
2639
|
return removeListeners();
|
|
@@ -2846,8 +2858,11 @@ function ImageView(props) {
|
|
|
2846
2858
|
ref: imgRef,
|
|
2847
2859
|
style: __spreadProps(__spreadValues({}, resizingStyle), {
|
|
2848
2860
|
cursor: "default",
|
|
2861
|
+
objectFit: "fill",
|
|
2849
2862
|
marginBottom: 0,
|
|
2850
|
-
borderRadius: borderRadius2
|
|
2863
|
+
borderRadius: borderRadius2,
|
|
2864
|
+
width: (resizingStyle == null ? void 0 : resizingStyle.width) ? `${resizingStyle.width}px` : width ? `${width}px` : "auto",
|
|
2865
|
+
height: (resizingStyle == null ? void 0 : resizingStyle.height) ? `${resizingStyle.height}px` : height ? `${height}px` : "auto"
|
|
2851
2866
|
}),
|
|
2852
2867
|
draggable: editor.isEditable,
|
|
2853
2868
|
className: cn(
|
|
@@ -3097,6 +3112,7 @@ function LogoView(props) {
|
|
|
3097
3112
|
|
|
3098
3113
|
// src/editor/nodes/logo/logo.ts
|
|
3099
3114
|
var allowedLogoSize = ["sm", "md", "lg"];
|
|
3115
|
+
var allowedLogoAlignment = ["left", "center", "right"];
|
|
3100
3116
|
var DEFAULT_ALIGNMENT = "left";
|
|
3101
3117
|
var DEFAULT_LOGO_SIZE = "sm";
|
|
3102
3118
|
var logoSizes = {
|
|
@@ -3230,7 +3246,10 @@ import { sticky as sticky3 } from "tippy.js";
|
|
|
3230
3246
|
import { AlignCenter as AlignCenter2, AlignLeft as AlignLeft2, AlignRight as AlignRight2 } from "lucide-react";
|
|
3231
3247
|
import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
3232
3248
|
function AlignmentSwitch(props) {
|
|
3233
|
-
const { alignment
|
|
3249
|
+
const { alignment: rawAlignment, onAlignmentChange } = props;
|
|
3250
|
+
const alignment = allowedLogoAlignment.includes(
|
|
3251
|
+
rawAlignment
|
|
3252
|
+
) ? rawAlignment : "left";
|
|
3234
3253
|
const alignments = {
|
|
3235
3254
|
left: {
|
|
3236
3255
|
icon: AlignLeft2,
|
|
@@ -4691,7 +4710,7 @@ function LinkInputPopover(props) {
|
|
|
4691
4710
|
variant: "ghost",
|
|
4692
4711
|
size: "sm",
|
|
4693
4712
|
type: "button",
|
|
4694
|
-
className: "mly-size-7",
|
|
4713
|
+
className: "!mly-size-7",
|
|
4695
4714
|
"data-state": !!defaultValue,
|
|
4696
4715
|
children: /* @__PURE__ */ jsx35(Icon, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-midnight-gray" })
|
|
4697
4716
|
}
|
|
@@ -4973,11 +4992,14 @@ function ImageBubbleMenu(props) {
|
|
|
4973
4992
|
value: (_c = state == null ? void 0 : state.width) != null ? _c : "",
|
|
4974
4993
|
onValueChange: (value) => {
|
|
4975
4994
|
const width = Math.min(Number(value) || 0, IMAGE_MAX_WIDTH);
|
|
4995
|
+
const currentHeight = Number(state.height) || 0;
|
|
4996
|
+
const currentWidth = Number(state.width) || 0;
|
|
4997
|
+
const currentAspectRatio = state.aspectRatio || currentWidth / currentHeight || 1;
|
|
4976
4998
|
editor == null ? void 0 : editor.chain().updateAttributes("image", __spreadValues({
|
|
4977
4999
|
width: String(width)
|
|
4978
5000
|
}, lockAspectRatio && value ? {
|
|
4979
5001
|
height: String(
|
|
4980
|
-
getNewHeight(width,
|
|
5002
|
+
getNewHeight(width, currentAspectRatio)
|
|
4981
5003
|
)
|
|
4982
5004
|
} : {})).run();
|
|
4983
5005
|
}
|
|
@@ -4990,11 +5012,14 @@ function ImageBubbleMenu(props) {
|
|
|
4990
5012
|
value: (_d = state == null ? void 0 : state.height) != null ? _d : "",
|
|
4991
5013
|
onValueChange: (value) => {
|
|
4992
5014
|
const height = Number(value) || 0;
|
|
5015
|
+
const currentHeight = Number(state.height) || 0;
|
|
5016
|
+
const currentWidth = Number(state.width) || 0;
|
|
5017
|
+
const currentAspectRatio = state.aspectRatio || currentWidth / currentHeight || 1;
|
|
4993
5018
|
editor == null ? void 0 : editor.chain().updateAttributes("image", __spreadValues({
|
|
4994
5019
|
height: String(height)
|
|
4995
5020
|
}, lockAspectRatio && value ? {
|
|
4996
5021
|
width: String(
|
|
4997
|
-
getNewWidth(height,
|
|
5022
|
+
getNewWidth(height, currentAspectRatio)
|
|
4998
5023
|
)
|
|
4999
5024
|
} : {})).run();
|
|
5000
5025
|
}
|
|
@@ -6016,7 +6041,7 @@ function SpacerBubbleMenu(props) {
|
|
|
6016
6041
|
// src/editor/nodes/columns/columns.ts
|
|
6017
6042
|
import { mergeAttributes as mergeAttributes5 } from "@tiptap/core";
|
|
6018
6043
|
import { Node as Node6 } from "@tiptap/core";
|
|
6019
|
-
import { v4 as
|
|
6044
|
+
import { v4 as uuidv43 } from "uuid";
|
|
6020
6045
|
var DEFAULT_COLUMNS_GAP = 8;
|
|
6021
6046
|
var ColumnsExtension = Node6.create({
|
|
6022
6047
|
name: "columns",
|
|
@@ -6066,7 +6091,7 @@ var ColumnsExtension = Node6.create({
|
|
|
6066
6091
|
{
|
|
6067
6092
|
type: "column",
|
|
6068
6093
|
attrs: {
|
|
6069
|
-
columnId:
|
|
6094
|
+
columnId: uuidv43()
|
|
6070
6095
|
},
|
|
6071
6096
|
content: [
|
|
6072
6097
|
{
|
|
@@ -6077,7 +6102,7 @@ var ColumnsExtension = Node6.create({
|
|
|
6077
6102
|
{
|
|
6078
6103
|
type: "column",
|
|
6079
6104
|
attrs: {
|
|
6080
|
-
columnId:
|
|
6105
|
+
columnId: uuidv43()
|
|
6081
6106
|
},
|
|
6082
6107
|
content: [
|
|
6083
6108
|
{
|
|
@@ -7331,8 +7356,10 @@ function HTMLCodeBlockView(props) {
|
|
|
7331
7356
|
}, "");
|
|
7332
7357
|
const htmlParser = new DOMParser();
|
|
7333
7358
|
const htmlDoc = htmlParser.parseFromString(text2, "text/html");
|
|
7359
|
+
const style = htmlDoc.querySelectorAll("style");
|
|
7334
7360
|
const body = htmlDoc.body;
|
|
7335
|
-
|
|
7361
|
+
const combinedStyle = Array.from(style).map((s) => s.innerHTML).join("\n");
|
|
7362
|
+
return `<style>${combinedStyle}</style>${body.innerHTML}`;
|
|
7336
7363
|
}, [activeTab]);
|
|
7337
7364
|
const isEmpty = html2 === "";
|
|
7338
7365
|
return /* @__PURE__ */ jsxs29(
|
|
@@ -7821,13 +7848,16 @@ function SlashCommandItem(props) {
|
|
|
7821
7848
|
selectedCommandIndex,
|
|
7822
7849
|
editor,
|
|
7823
7850
|
activeCommandRef,
|
|
7824
|
-
selectItem
|
|
7851
|
+
selectItem,
|
|
7852
|
+
hoveredItemKey,
|
|
7853
|
+
onHover
|
|
7825
7854
|
} = props;
|
|
7826
7855
|
const [open, setOpen] = useState10(false);
|
|
7827
|
-
const [isHovered, setIsHovered] = useState10(false);
|
|
7828
7856
|
const isActive = groupIndex === selectedGroupIndex && commandIndex === selectedCommandIndex;
|
|
7829
|
-
const
|
|
7830
|
-
const
|
|
7857
|
+
const itemKey = `${groupIndex}-${commandIndex}`;
|
|
7858
|
+
const isHovered = hoveredItemKey === itemKey;
|
|
7859
|
+
const isSubCommand2 = item && "commands" in item;
|
|
7860
|
+
const shouldOpenTooltip = !!(item == null ? void 0 : item.preview) && (isHovered || isActive && !hoveredItemKey);
|
|
7831
7861
|
const hasRenderFunction = typeof item.render === "function";
|
|
7832
7862
|
const renderFunctionValue = hasRenderFunction ? (_a = item.render) == null ? void 0 : _a.call(item, editor) : null;
|
|
7833
7863
|
let value = /* @__PURE__ */ jsxs31(Fragment6, { children: [
|
|
@@ -7836,7 +7866,7 @@ function SlashCommandItem(props) {
|
|
|
7836
7866
|
/* @__PURE__ */ jsx53("p", { className: "mly-font-medium", children: item.title }),
|
|
7837
7867
|
/* @__PURE__ */ jsx53("p", { className: "mly-text-xs mly-text-gray-400", children: item.description })
|
|
7838
7868
|
] }),
|
|
7839
|
-
|
|
7869
|
+
isSubCommand2 && /* @__PURE__ */ jsx53("span", { className: "mly-block mly-px-1 mly-text-gray-400", children: /* @__PURE__ */ jsx53(ChevronRightIcon, { className: "mly-size-3.5 mly-stroke-[2.5]" }) })
|
|
7840
7870
|
] });
|
|
7841
7871
|
if (renderFunctionValue !== null && renderFunctionValue !== true) {
|
|
7842
7872
|
value = renderFunctionValue;
|
|
@@ -7876,8 +7906,8 @@ function SlashCommandItem(props) {
|
|
|
7876
7906
|
isActive ? "mly-bg-gray-100 mly-text-gray-900" : "mly-bg-transparent"
|
|
7877
7907
|
),
|
|
7878
7908
|
onClick: () => selectItem(groupIndex, commandIndex),
|
|
7879
|
-
onMouseEnter: () =>
|
|
7880
|
-
onMouseLeave: () =>
|
|
7909
|
+
onMouseEnter: () => onHover(true),
|
|
7910
|
+
onMouseLeave: () => onHover(false),
|
|
7881
7911
|
type: "button",
|
|
7882
7912
|
ref: isActive ? activeCommandRef : null,
|
|
7883
7913
|
children: value
|
|
@@ -7905,12 +7935,94 @@ function SlashCommandItem(props) {
|
|
|
7905
7935
|
] }, `${groupIndex}-${commandIndex}`);
|
|
7906
7936
|
}
|
|
7907
7937
|
|
|
7938
|
+
// src/editor/extensions/slash-command/slash-command-search.tsx
|
|
7939
|
+
function filterSlashCommands(options) {
|
|
7940
|
+
const { groups, query, editor } = options;
|
|
7941
|
+
const newGroups = [...groups];
|
|
7942
|
+
let searchQuery = query == null ? void 0 : query.toLowerCase();
|
|
7943
|
+
const subCommandMatch = searchQuery.match(/^([^.]+)\./);
|
|
7944
|
+
if (subCommandMatch) {
|
|
7945
|
+
const [match, subCommandId] = subCommandMatch;
|
|
7946
|
+
const subCommandGroup = findSubCommandGroup(groups, subCommandId);
|
|
7947
|
+
if (subCommandGroup) {
|
|
7948
|
+
const remainingSearch = searchQuery.slice(match.length);
|
|
7949
|
+
const filteredCommands = subCommandGroup.commands.filter(
|
|
7950
|
+
(item) => !remainingSearch || isCommandMatch(item, remainingSearch)
|
|
7951
|
+
);
|
|
7952
|
+
return filteredCommands.length ? [
|
|
7953
|
+
__spreadProps(__spreadValues({}, subCommandGroup), {
|
|
7954
|
+
commands: filteredCommands
|
|
7955
|
+
})
|
|
7956
|
+
] : [];
|
|
7957
|
+
}
|
|
7958
|
+
}
|
|
7959
|
+
const filteredGroups = newGroups.map((group) => {
|
|
7960
|
+
return __spreadProps(__spreadValues({}, group), {
|
|
7961
|
+
commands: group.commands.flatMap(
|
|
7962
|
+
(item) => processCommand({ item, search: searchQuery, editor })
|
|
7963
|
+
)
|
|
7964
|
+
});
|
|
7965
|
+
}).filter((group) => group.commands.length > 0);
|
|
7966
|
+
return filteredGroups;
|
|
7967
|
+
}
|
|
7968
|
+
function findSubCommandGroup(groups, subCommandId) {
|
|
7969
|
+
return groups.flatMap((group) => group.commands).find(
|
|
7970
|
+
(item) => {
|
|
7971
|
+
var _a;
|
|
7972
|
+
return "commands" in item && ((_a = item.id) == null ? void 0 : _a.toLowerCase()) === subCommandId.toLowerCase();
|
|
7973
|
+
}
|
|
7974
|
+
);
|
|
7975
|
+
}
|
|
7976
|
+
function containsText(text2, search) {
|
|
7977
|
+
if (!text2) {
|
|
7978
|
+
return false;
|
|
7979
|
+
}
|
|
7980
|
+
return text2.toLowerCase().includes(search.toLowerCase());
|
|
7981
|
+
}
|
|
7982
|
+
function isCommandMatch(item, search) {
|
|
7983
|
+
var _a, _b;
|
|
7984
|
+
return containsText(item.title, search) || containsText(item.description, search) || ((_b = (_a = item.searchTerms) == null ? void 0 : _a.some((term) => containsText(term, search))) != null ? _b : false);
|
|
7985
|
+
}
|
|
7986
|
+
function isSubCommand(item) {
|
|
7987
|
+
return "commands" in item && Array.isArray(item.commands) && !!item.id;
|
|
7988
|
+
}
|
|
7989
|
+
function processCommand(options) {
|
|
7990
|
+
var _a, _b, _c, _d;
|
|
7991
|
+
const { item, search, editor } = options;
|
|
7992
|
+
const show = (_a = item == null ? void 0 : item.render) == null ? void 0 : _a.call(item, editor);
|
|
7993
|
+
if (show === null) {
|
|
7994
|
+
return [];
|
|
7995
|
+
}
|
|
7996
|
+
const isSearching = search.length > 0;
|
|
7997
|
+
if (isSubCommand(item)) {
|
|
7998
|
+
const navigableCommand = __spreadProps(__spreadValues({}, item), {
|
|
7999
|
+
command: (options2) => {
|
|
8000
|
+
const { editor: editor2, range } = options2;
|
|
8001
|
+
editor2.chain().focus().insertContentAt(range, `/${item.id}.`).run();
|
|
8002
|
+
}
|
|
8003
|
+
});
|
|
8004
|
+
const matched = isCommandMatch(navigableCommand, search);
|
|
8005
|
+
if (matched) {
|
|
8006
|
+
return [navigableCommand];
|
|
8007
|
+
}
|
|
8008
|
+
const hasMatchingCommands = (_c = (_b = navigableCommand == null ? void 0 : navigableCommand.commands) == null ? void 0 : _b.some(
|
|
8009
|
+
(command) => isCommandMatch(command, search)
|
|
8010
|
+
)) != null ? _c : false;
|
|
8011
|
+
if (!hasMatchingCommands) {
|
|
8012
|
+
return [];
|
|
8013
|
+
}
|
|
8014
|
+
return (_d = navigableCommand == null ? void 0 : navigableCommand.commands) != null ? _d : [];
|
|
8015
|
+
}
|
|
8016
|
+
return !isSearching || isCommandMatch(item, search) ? [item] : [];
|
|
8017
|
+
}
|
|
8018
|
+
|
|
7908
8019
|
// src/editor/extensions/slash-command/slash-command-view.tsx
|
|
7909
8020
|
import { jsx as jsx54, jsxs as jsxs32 } from "react/jsx-runtime";
|
|
7910
|
-
var CommandList = forwardRef8(
|
|
8021
|
+
var CommandList = forwardRef8((props, ref) => {
|
|
7911
8022
|
const { items: groups, command, editor, range, query } = props;
|
|
7912
8023
|
const [selectedGroupIndex, setSelectedGroupIndex] = useState11(0);
|
|
7913
8024
|
const [selectedCommandIndex, setSelectedCommandIndex] = useState11(0);
|
|
8025
|
+
const [hoveredItemKey, setHoveredItemKey] = useState11(null);
|
|
7914
8026
|
const prevQuery = useRef11("");
|
|
7915
8027
|
const prevSelectedGroupIndex = useRef11(0);
|
|
7916
8028
|
const prevSelectedCommandIndex = useRef11(0);
|
|
@@ -8040,7 +8152,10 @@ var CommandList = forwardRef8(function CommandList2(props, ref) {
|
|
|
8040
8152
|
prevSelectedCommandIndex.current = 0;
|
|
8041
8153
|
};
|
|
8042
8154
|
}, []);
|
|
8043
|
-
|
|
8155
|
+
if (!groups || groups.length === 0) {
|
|
8156
|
+
return null;
|
|
8157
|
+
}
|
|
8158
|
+
return /* @__PURE__ */ jsx54(TooltipProvider, { children: /* @__PURE__ */ jsxs32("div", { className: "mly-z-50 mly-w-72 mly-overflow-hidden mly-rounded-md mly-border mly-border-gray-200 mly-bg-white mly-shadow-md mly-transition-all", children: [
|
|
8044
8159
|
/* @__PURE__ */ jsx54(
|
|
8045
8160
|
"div",
|
|
8046
8161
|
{
|
|
@@ -8059,6 +8174,7 @@ var CommandList = forwardRef8(function CommandList2(props, ref) {
|
|
|
8059
8174
|
}
|
|
8060
8175
|
),
|
|
8061
8176
|
/* @__PURE__ */ jsx54("div", { className: "mly-space-y-0.5 mly-p-1", children: group.commands.map((item, commandIndex) => {
|
|
8177
|
+
const itemKey = `${groupIndex}-${commandIndex}`;
|
|
8062
8178
|
return /* @__PURE__ */ jsx54(
|
|
8063
8179
|
SlashCommandItem,
|
|
8064
8180
|
{
|
|
@@ -8069,9 +8185,11 @@ var CommandList = forwardRef8(function CommandList2(props, ref) {
|
|
|
8069
8185
|
selectedCommandIndex,
|
|
8070
8186
|
selectItem: () => selectItem(groupIndex, commandIndex),
|
|
8071
8187
|
editor,
|
|
8072
|
-
activeCommandRef
|
|
8188
|
+
activeCommandRef,
|
|
8189
|
+
hoveredItemKey,
|
|
8190
|
+
onHover: (isHovered) => setHoveredItemKey(isHovered ? itemKey : null)
|
|
8073
8191
|
},
|
|
8074
|
-
|
|
8192
|
+
itemKey
|
|
8075
8193
|
);
|
|
8076
8194
|
}) })
|
|
8077
8195
|
] }, groupIndex))
|
|
@@ -8091,77 +8209,12 @@ var CommandList = forwardRef8(function CommandList2(props, ref) {
|
|
|
8091
8209
|
"to select"
|
|
8092
8210
|
] })
|
|
8093
8211
|
] }) })
|
|
8094
|
-
] }) })
|
|
8212
|
+
] }) });
|
|
8095
8213
|
});
|
|
8096
8214
|
function getSlashCommandSuggestions(groups = DEFAULT_SLASH_COMMANDS) {
|
|
8097
8215
|
return {
|
|
8098
8216
|
items: ({ query, editor }) => {
|
|
8099
|
-
|
|
8100
|
-
let newGroups = groups;
|
|
8101
|
-
let search = query.toLowerCase();
|
|
8102
|
-
const subCommandIds = newGroups.map((group) => {
|
|
8103
|
-
return group.commands.filter((item) => "commands" in item).map((item) => item == null ? void 0 : item.id.toLowerCase());
|
|
8104
|
-
}).flat().map((id) => `${id}.`);
|
|
8105
|
-
const shouldEnterSubCommand = subCommandIds.some(
|
|
8106
|
-
(id) => search.startsWith(id)
|
|
8107
|
-
);
|
|
8108
|
-
if (shouldEnterSubCommand) {
|
|
8109
|
-
const subCommandId = subCommandIds.find((id) => search.startsWith(id));
|
|
8110
|
-
const sanitizedSubCommandId = subCommandId == null ? void 0 : subCommandId.slice(0, -1);
|
|
8111
|
-
const group = (_a = newGroups.find((group2) => {
|
|
8112
|
-
return group2.commands.some(
|
|
8113
|
-
// @ts-ignore
|
|
8114
|
-
(item) => {
|
|
8115
|
-
var _a2;
|
|
8116
|
-
return ((_a2 = item == null ? void 0 : item.id) == null ? void 0 : _a2.toLowerCase()) === sanitizedSubCommandId;
|
|
8117
|
-
}
|
|
8118
|
-
);
|
|
8119
|
-
})) == null ? void 0 : _a.commands.find(
|
|
8120
|
-
// @ts-ignore
|
|
8121
|
-
(item) => {
|
|
8122
|
-
var _a2;
|
|
8123
|
-
return ((_a2 = item == null ? void 0 : item.id) == null ? void 0 : _a2.toLowerCase()) === sanitizedSubCommandId;
|
|
8124
|
-
}
|
|
8125
|
-
);
|
|
8126
|
-
if (!group) {
|
|
8127
|
-
return groups;
|
|
8128
|
-
}
|
|
8129
|
-
search = search.replace(subCommandId || "", "");
|
|
8130
|
-
newGroups = [
|
|
8131
|
-
__spreadProps(__spreadValues({}, group), {
|
|
8132
|
-
commands: (group == null ? void 0 : group.commands) || []
|
|
8133
|
-
})
|
|
8134
|
-
];
|
|
8135
|
-
}
|
|
8136
|
-
const filteredGroups = newGroups.map((group) => {
|
|
8137
|
-
return __spreadProps(__spreadValues({}, group), {
|
|
8138
|
-
commands: group.commands.filter((item) => {
|
|
8139
|
-
var _a2;
|
|
8140
|
-
if (typeof query === "string" && query.length > 0) {
|
|
8141
|
-
const show = (_a2 = item == null ? void 0 : item.render) == null ? void 0 : _a2.call(item, editor);
|
|
8142
|
-
if (show === null) {
|
|
8143
|
-
return false;
|
|
8144
|
-
}
|
|
8145
|
-
return item.title.toLowerCase().includes(search) || (item == null ? void 0 : item.description) && (item == null ? void 0 : item.description.toLowerCase().includes(search)) || item.searchTerms && item.searchTerms.some(
|
|
8146
|
-
(term) => term.includes(search)
|
|
8147
|
-
);
|
|
8148
|
-
}
|
|
8149
|
-
return true;
|
|
8150
|
-
}).map((item) => {
|
|
8151
|
-
const isSubCommandItem = "commands" in item;
|
|
8152
|
-
if (isSubCommandItem) {
|
|
8153
|
-
item = __spreadProps(__spreadValues({}, item), {
|
|
8154
|
-
command: (options) => {
|
|
8155
|
-
const { editor: editor2, range } = options;
|
|
8156
|
-
editor2.chain().focus().insertContentAt(range, `/${item.id}.`).run();
|
|
8157
|
-
}
|
|
8158
|
-
});
|
|
8159
|
-
}
|
|
8160
|
-
return item;
|
|
8161
|
-
})
|
|
8162
|
-
});
|
|
8163
|
-
}).filter((group) => group.commands.length > 0);
|
|
8164
|
-
return filteredGroups;
|
|
8217
|
+
return filterSlashCommands({ query, editor, groups });
|
|
8165
8218
|
},
|
|
8166
8219
|
allow: ({ editor }) => {
|
|
8167
8220
|
const isInsideHTMLCodeBlock = editor.isActive("htmlCodeBlock");
|
|
@@ -8611,13 +8664,13 @@ function TextBubbleContent(props) {
|
|
|
8611
8664
|
|
|
8612
8665
|
// src/editor/components/text-menu/turn-into-block.tsx
|
|
8613
8666
|
import { ChevronDownIcon as ChevronDownIcon2, PilcrowIcon } from "lucide-react";
|
|
8614
|
-
import { useMemo as
|
|
8667
|
+
import { useMemo as useMemo12 } from "react";
|
|
8615
8668
|
import { jsx as jsx57, jsxs as jsxs34 } from "react/jsx-runtime";
|
|
8616
8669
|
var isOption = (option) => option.type === "option";
|
|
8617
8670
|
var isCategory = (option) => option.type === "category";
|
|
8618
8671
|
function TurnIntoBlock(props) {
|
|
8619
8672
|
const { options } = props;
|
|
8620
|
-
const activeItem =
|
|
8673
|
+
const activeItem = useMemo12(
|
|
8621
8674
|
() => options.find((option) => option.type === "option" && option.isActive()),
|
|
8622
8675
|
[options]
|
|
8623
8676
|
);
|
|
@@ -8652,7 +8705,7 @@ function TurnIntoBlock(props) {
|
|
|
8652
8705
|
{
|
|
8653
8706
|
onClick: option.onClick,
|
|
8654
8707
|
variant: "ghost",
|
|
8655
|
-
className: "mly-h-auto mly-justify-start mly-gap-2 !mly-rounded mly-px-2 mly-py-1 mly-text-sm mly-font-normal mly-text-midnight-gray",
|
|
8708
|
+
className: "mly-mb-0.5 mly-h-auto mly-justify-start mly-gap-2 !mly-rounded mly-px-2 mly-py-1 mly-text-sm mly-font-normal mly-text-midnight-gray",
|
|
8656
8709
|
children: [
|
|
8657
8710
|
/* @__PURE__ */ jsx57(option.icon, { className: "mly-size-[15px] mly-shrink-0" }),
|
|
8658
8711
|
option.label
|
|
@@ -8873,6 +8926,37 @@ function VariableBubbleMenu(props) {
|
|
|
8873
8926
|
);
|
|
8874
8927
|
}
|
|
8875
8928
|
|
|
8929
|
+
// src/editor/extensions/selection/selection.ts
|
|
8930
|
+
import { Extension as Extension4 } from "@tiptap/core";
|
|
8931
|
+
import { Plugin as Plugin4, PluginKey as PluginKey5 } from "@tiptap/pm/state";
|
|
8932
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
8933
|
+
var SelectionExtension = Extension4.create({
|
|
8934
|
+
name: "selection",
|
|
8935
|
+
addProseMirrorPlugins() {
|
|
8936
|
+
const { editor } = this;
|
|
8937
|
+
return [
|
|
8938
|
+
new Plugin4({
|
|
8939
|
+
key: new PluginKey5("selection"),
|
|
8940
|
+
props: {
|
|
8941
|
+
decorations(state) {
|
|
8942
|
+
if (state.selection.empty) {
|
|
8943
|
+
return null;
|
|
8944
|
+
}
|
|
8945
|
+
if (editor.isFocused === true) {
|
|
8946
|
+
return null;
|
|
8947
|
+
}
|
|
8948
|
+
return DecorationSet.create(state.doc, [
|
|
8949
|
+
Decoration.inline(state.selection.from, state.selection.to, {
|
|
8950
|
+
class: "selection mly-bg-blue-200 mly-inline mly-py-1"
|
|
8951
|
+
})
|
|
8952
|
+
]);
|
|
8953
|
+
}
|
|
8954
|
+
}
|
|
8955
|
+
})
|
|
8956
|
+
];
|
|
8957
|
+
}
|
|
8958
|
+
});
|
|
8959
|
+
|
|
8876
8960
|
// src/editor/extensions/index.tsx
|
|
8877
8961
|
function extensions(props) {
|
|
8878
8962
|
const { blocks, extensions: extensions2 = [] } = props;
|
|
@@ -8886,7 +8970,8 @@ function extensions(props) {
|
|
|
8886
8970
|
}),
|
|
8887
8971
|
HTMLCodeBlockExtension,
|
|
8888
8972
|
InlineImageExtension,
|
|
8889
|
-
PlaceholderExtension
|
|
8973
|
+
PlaceholderExtension,
|
|
8974
|
+
SelectionExtension
|
|
8890
8975
|
].filter((ext) => {
|
|
8891
8976
|
return !extensions2.some((e) => e.name === ext.name);
|
|
8892
8977
|
});
|
|
@@ -8930,6 +9015,7 @@ function Editor13(props) {
|
|
|
8930
9015
|
contentClassName = "",
|
|
8931
9016
|
bodyClassName = "",
|
|
8932
9017
|
hasMenuBar = true,
|
|
9018
|
+
hideContextMenu = false,
|
|
8933
9019
|
spellCheck = false,
|
|
8934
9020
|
autofocus = "end",
|
|
8935
9021
|
immediatelyRender = false
|
|
@@ -8943,7 +9029,7 @@ function Editor13(props) {
|
|
|
8943
9029
|
editable = true,
|
|
8944
9030
|
placeholderUrl = DEFAULT_PLACEHOLDER_URL
|
|
8945
9031
|
} = props;
|
|
8946
|
-
const formattedContent =
|
|
9032
|
+
const formattedContent = useMemo13(() => {
|
|
8947
9033
|
if (contentJson) {
|
|
8948
9034
|
const json = (contentJson == null ? void 0 : contentJson.type) === "doc" ? contentJson : {
|
|
8949
9035
|
type: "doc",
|
|
@@ -9015,7 +9101,7 @@ function Editor13(props) {
|
|
|
9015
9101
|
/* @__PURE__ */ jsx60(EditorContent, { editor }),
|
|
9016
9102
|
/* @__PURE__ */ jsx60(SectionBubbleMenu, { editor, appendTo: menuContainerRef }),
|
|
9017
9103
|
/* @__PURE__ */ jsx60(ColumnsBubbleMenu, { editor, appendTo: menuContainerRef }),
|
|
9018
|
-
/* @__PURE__ */ jsx60(ContentMenu, { editor }),
|
|
9104
|
+
!hideContextMenu && /* @__PURE__ */ jsx60(ContentMenu, { editor }),
|
|
9019
9105
|
/* @__PURE__ */ jsx60(VariableBubbleMenu, { editor, appendTo: menuContainerRef }),
|
|
9020
9106
|
/* @__PURE__ */ jsx60(RepeatBubbleMenu, { editor, appendTo: menuContainerRef }),
|
|
9021
9107
|
/* @__PURE__ */ jsx60(HTMLBubbleMenu, { editor, appendTo: menuContainerRef }),
|