@tumaet/prompt-ui-components 0.0.3 → 0.0.5
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/components/DatePicker.js +18 -0
- package/dist/components/DatePicker.js.map +1 -0
- package/dist/components/DateRangePicker.js +12 -0
- package/dist/components/DateRangePicker.js.map +1 -0
- package/dist/components/DeleteConfirmationDialog.js +13 -0
- package/dist/components/DeleteConfirmationDialog.js.map +1 -0
- package/dist/components/ErrorPage.js +9 -0
- package/dist/components/ErrorPage.js.map +1 -0
- package/dist/components/LoadingPage.js +6 -0
- package/dist/components/LoadingPage.js.map +1 -0
- package/dist/components/ManagementPageHeader.js +5 -0
- package/dist/components/ManagementPageHeader.js.map +1 -0
- package/dist/components/MultiSelect.js +96 -0
- package/dist/components/MultiSelect.js.map +1 -0
- package/dist/components/SaveChangesAlert.js +31 -0
- package/dist/components/SaveChangesAlert.js.map +1 -0
- package/dist/components/UnauthorizedPage.js +13 -0
- package/dist/components/UnauthorizedPage.js.map +1 -0
- package/dist/components/index.js +9 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/minimal-tiptap/components/bubble-menu/link-bubble-menu.js +65 -0
- package/dist/components/minimal-tiptap/components/bubble-menu/link-bubble-menu.js.map +1 -0
- package/dist/components/minimal-tiptap/components/image/image-edit-block.js +38 -0
- package/dist/components/minimal-tiptap/components/image/image-edit-block.js.map +1 -0
- package/dist/components/minimal-tiptap/components/image/image-edit-dialog.js +12 -0
- package/dist/components/minimal-tiptap/components/image/image-edit-dialog.js.map +1 -0
- package/dist/components/minimal-tiptap/components/link/link-edit-block.js +34 -0
- package/dist/components/minimal-tiptap/components/link/link-edit-block.js.map +1 -0
- package/dist/components/minimal-tiptap/components/link/link-edit-popover.js +38 -0
- package/dist/components/minimal-tiptap/components/link/link-edit-popover.js.map +1 -0
- package/dist/components/minimal-tiptap/components/link/link-popover-block.js +28 -0
- package/dist/components/minimal-tiptap/components/link/link-popover-block.js.map +1 -0
- package/dist/components/minimal-tiptap/components/measured-container.js +16 -0
- package/dist/components/minimal-tiptap/components/measured-container.js.map +1 -0
- package/dist/components/minimal-tiptap/components/section/five.js +39 -0
- package/dist/components/minimal-tiptap/components/section/five.js.map +1 -0
- package/dist/components/minimal-tiptap/components/section/four.js +29 -0
- package/dist/components/minimal-tiptap/components/section/four.js.map +1 -0
- package/dist/components/minimal-tiptap/components/section/mailingPlaceholders.js +23 -0
- package/dist/components/minimal-tiptap/components/section/mailingPlaceholders.js.map +1 -0
- package/dist/components/minimal-tiptap/components/section/one.js +77 -0
- package/dist/components/minimal-tiptap/components/section/one.js.map +1 -0
- package/dist/components/minimal-tiptap/components/section/three.js +79 -0
- package/dist/components/minimal-tiptap/components/section/three.js.map +1 -0
- package/dist/components/minimal-tiptap/components/section/two.js +65 -0
- package/dist/components/minimal-tiptap/components/section/two.js.map +1 -0
- package/dist/components/minimal-tiptap/components/shortcut-key.js +11 -0
- package/dist/components/minimal-tiptap/components/shortcut-key.js.map +1 -0
- package/dist/components/minimal-tiptap/components/spinner.js +9 -0
- package/dist/components/minimal-tiptap/components/spinner.js.map +1 -0
- package/dist/components/minimal-tiptap/components/toolbar-button.js +15 -0
- package/dist/components/minimal-tiptap/components/toolbar-button.js.map +1 -0
- package/dist/components/minimal-tiptap/components/toolbar-section.js +27 -0
- package/dist/components/minimal-tiptap/components/toolbar-section.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/code-block-lowlight/code-block-lowlight.js +16 -0
- package/dist/components/minimal-tiptap/extensions/code-block-lowlight/code-block-lowlight.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/code-block-lowlight/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/code-block-lowlight/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/color/color.js +20 -0
- package/dist/components/minimal-tiptap/extensions/color/color.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/color/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/color/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/file-handler/index.js +74 -0
- package/dist/components/minimal-tiptap/extensions/file-handler/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/horizontal-rule/horizontal-rule.js +16 -0
- package/dist/components/minimal-tiptap/extensions/horizontal-rule/horizontal-rule.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/horizontal-rule/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/horizontal-rule/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/components/image-actions.js +39 -0
- package/dist/components/minimal-tiptap/extensions/image/components/image-actions.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/components/image-overlay.js +9 -0
- package/dist/components/minimal-tiptap/extensions/image/components/image-overlay.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/components/image-view-block.js +167 -0
- package/dist/components/minimal-tiptap/extensions/image/components/image-view-block.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/components/resize-handle.js +11 -0
- package/dist/components/minimal-tiptap/extensions/image/components/resize-handle.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/hooks/use-drag-resize.js +88 -0
- package/dist/components/minimal-tiptap/extensions/image/hooks/use-drag-resize.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/hooks/use-image-actions.js +32 -0
- package/dist/components/minimal-tiptap/extensions/image/hooks/use-image-actions.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/image.js +225 -0
- package/dist/components/minimal-tiptap/extensions/image/image.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/image/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/image/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/index.js +10 -0
- package/dist/components/minimal-tiptap/extensions/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/link/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/link/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/link/link.js +74 -0
- package/dist/components/minimal-tiptap/extensions/link/link.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/reset-marks-on-enter/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/reset-marks-on-enter/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/reset-marks-on-enter/reset-marks-on-enter.js +20 -0
- package/dist/components/minimal-tiptap/extensions/reset-marks-on-enter/reset-marks-on-enter.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/selection/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/selection/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/selection/selection.js +31 -0
- package/dist/components/minimal-tiptap/extensions/selection/selection.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/unset-all-marks/index.js +2 -0
- package/dist/components/minimal-tiptap/extensions/unset-all-marks/index.js.map +1 -0
- package/dist/components/minimal-tiptap/extensions/unset-all-marks/unset-all-marks.js +9 -0
- package/dist/components/minimal-tiptap/extensions/unset-all-marks/unset-all-marks.js.map +1 -0
- package/dist/components/minimal-tiptap/form-description-tiptap.js +26 -0
- package/dist/components/minimal-tiptap/form-description-tiptap.js.map +1 -0
- package/dist/components/minimal-tiptap/hooks/use-container-size.js +44 -0
- package/dist/components/minimal-tiptap/hooks/use-container-size.js.map +1 -0
- package/dist/components/minimal-tiptap/hooks/use-minimal-tiptap.js +160 -0
- package/dist/components/minimal-tiptap/hooks/use-minimal-tiptap.js.map +1 -0
- package/dist/components/minimal-tiptap/hooks/use-theme.js +19 -0
- package/dist/components/minimal-tiptap/hooks/use-theme.js.map +1 -0
- package/dist/components/minimal-tiptap/hooks/use-throttle.js +24 -0
- package/dist/components/minimal-tiptap/hooks/use-throttle.js.map +1 -0
- package/dist/components/minimal-tiptap/index.js +2 -0
- package/dist/components/minimal-tiptap/index.js.map +1 -0
- package/dist/components/minimal-tiptap/mailing-tiptap.js +30 -0
- package/dist/components/minimal-tiptap/mailing-tiptap.js.map +1 -0
- package/dist/components/minimal-tiptap/minimal-tiptap.js +29 -0
- package/dist/components/minimal-tiptap/minimal-tiptap.js.map +1 -0
- package/dist/components/minimal-tiptap/types.js +2 -0
- package/dist/components/minimal-tiptap/types.js.map +1 -0
- package/dist/components/minimal-tiptap/utils.js +156 -0
- package/dist/components/minimal-tiptap/utils.js.map +1 -0
- package/dist/components/table/GroupActionDialog.js +8 -0
- package/dist/components/table/GroupActionDialog.js.map +1 -0
- package/dist/components/table/SortableHeader.js +7 -0
- package/dist/components/table/SortableHeader.js.map +1 -0
- package/dist/components/ui/accordion.js +1 -1
- package/dist/components/ui/alert-dialog.js +2 -2
- package/dist/components/ui/alert.js +1 -1
- package/dist/components/ui/avatar.js +1 -1
- package/dist/components/ui/badge.js +1 -1
- package/dist/components/ui/breadcrumb.js +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/calendar.js +2 -2
- package/dist/components/ui/card.js +1 -1
- package/dist/components/ui/chart.js +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/command.js +2 -2
- package/dist/components/ui/dialog.js +1 -1
- package/dist/components/ui/dropdown-menu.js +1 -1
- package/dist/components/ui/form.js +2 -2
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/label.js +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/progress.js +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/scroll-area.js +1 -1
- package/dist/components/ui/select.js +1 -1
- package/dist/components/ui/separator.js +1 -1
- package/dist/components/ui/sheet.js +1 -1
- package/dist/components/ui/sidebar.js +8 -8
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/table.js +1 -1
- package/dist/components/ui/tabs.js +1 -1
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/toast.js +1 -1
- package/dist/components/ui/toaster.js +2 -2
- package/dist/components/ui/toggle-group.js +2 -2
- package/dist/components/ui/toggle.js +1 -1
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/index.css +2 -3
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/components/DatePicker.d.ts +6 -0
- package/dist/types/components/DateRangePicker.d.ts +8 -0
- package/dist/types/components/DeleteConfirmationDialog.d.ts +9 -0
- package/dist/types/components/ErrorPage.d.ts +9 -0
- package/dist/types/components/LoadingPage.d.ts +1 -0
- package/dist/types/components/ManagementPageHeader.d.ts +5 -0
- package/dist/types/components/MultiSelect.d.ts +68 -0
- package/dist/types/components/SaveChangesAlert.d.ts +8 -0
- package/dist/types/components/UnauthorizedPage.d.ts +7 -0
- package/dist/types/components/index.d.ts +9 -0
- package/dist/types/components/minimal-tiptap/components/bubble-menu/link-bubble-menu.d.ts +7 -0
- package/dist/types/components/minimal-tiptap/components/image/image-edit-block.d.ts +8 -0
- package/dist/types/components/minimal-tiptap/components/image/image-edit-dialog.d.ts +8 -0
- package/dist/types/components/minimal-tiptap/components/link/link-edit-block.d.ts +9 -0
- package/dist/types/components/minimal-tiptap/components/link/link-edit-popover.d.ts +8 -0
- package/dist/types/components/minimal-tiptap/components/link/link-popover-block.d.ts +8 -0
- package/dist/types/components/minimal-tiptap/components/measured-container.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/components/section/five.d.ts +12 -0
- package/dist/types/components/minimal-tiptap/components/section/four.d.ts +12 -0
- package/dist/types/components/minimal-tiptap/components/section/mailingPlaceholders.d.ts +10 -0
- package/dist/types/components/minimal-tiptap/components/section/one.d.ts +11 -0
- package/dist/types/components/minimal-tiptap/components/section/three.d.ts +9 -0
- package/dist/types/components/minimal-tiptap/components/section/two.d.ts +12 -0
- package/dist/types/components/minimal-tiptap/components/shortcut-key.d.ts +5 -0
- package/dist/types/components/minimal-tiptap/components/spinner.d.ts +5 -0
- package/dist/types/components/minimal-tiptap/components/toolbar-button.d.ts +10 -0
- package/dist/types/components/minimal-tiptap/components/toolbar-section.d.ts +16 -0
- package/dist/types/components/minimal-tiptap/extensions/code-block-lowlight/code-block-lowlight.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/extensions/code-block-lowlight/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/color/color.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/color/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/file-handler/index.d.ts +12 -0
- package/dist/types/components/minimal-tiptap/extensions/horizontal-rule/horizontal-rule.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/extensions/horizontal-rule/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/image/components/image-actions.d.ts +17 -0
- package/dist/types/components/minimal-tiptap/extensions/image/components/image-overlay.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/extensions/image/components/image-view-block.d.ts +3 -0
- package/dist/types/components/minimal-tiptap/extensions/image/components/resize-handle.d.ts +6 -0
- package/dist/types/components/minimal-tiptap/extensions/image/hooks/use-drag-resize.d.ts +24 -0
- package/dist/types/components/minimal-tiptap/extensions/image/hooks/use-image-actions.d.ts +24 -0
- package/dist/types/components/minimal-tiptap/extensions/image/image.d.ts +52 -0
- package/dist/types/components/minimal-tiptap/extensions/image/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/index.d.ts +9 -0
- package/dist/types/components/minimal-tiptap/extensions/link/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/link/link.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/extensions/reset-marks-on-enter/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/reset-marks-on-enter/reset-marks-on-enter.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/extensions/selection/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/selection/selection.d.ts +3 -0
- package/dist/types/components/minimal-tiptap/extensions/unset-all-marks/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/extensions/unset-all-marks/unset-all-marks.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/form-description-tiptap.d.ts +4 -0
- package/dist/types/components/minimal-tiptap/hooks/use-container-size.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/hooks/use-minimal-tiptap.d.ts +13 -0
- package/dist/types/components/minimal-tiptap/hooks/use-theme.d.ts +2 -0
- package/dist/types/components/minimal-tiptap/hooks/use-throttle.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/index.d.ts +1 -0
- package/dist/types/components/minimal-tiptap/mailing-tiptap.d.ts +13 -0
- package/dist/types/components/minimal-tiptap/minimal-tiptap.d.ts +12 -0
- package/dist/types/components/minimal-tiptap/types.d.ts +25 -0
- package/dist/types/components/minimal-tiptap/utils.d.ts +38 -0
- package/dist/types/components/table/GroupActionDialog.d.ts +11 -0
- package/dist/types/components/table/SortableHeader.d.ts +4 -0
- package/dist/types/components/ui/sidebar.d.ts +2 -2
- package/dist/types/hooks/use-toast.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +24 -2
- package/src/index.css +1 -2
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { Image as TiptapImage } from '@tiptap/extension-image';
|
|
2
|
+
import { ReactNodeViewRenderer } from '@tiptap/react';
|
|
3
|
+
import { ImageViewBlock } from './components/image-view-block';
|
|
4
|
+
import { filterFiles, randomId } from '../../utils';
|
|
5
|
+
import { ReplaceStep } from '@tiptap/pm/transform';
|
|
6
|
+
const handleError = (error, props, errorHandler) => {
|
|
7
|
+
const typedError = error instanceof Error ? error : new Error('Unknown error');
|
|
8
|
+
errorHandler?.(typedError, props);
|
|
9
|
+
};
|
|
10
|
+
const handleDataUrl = (src) => {
|
|
11
|
+
const [header, base64Data] = src.split(',');
|
|
12
|
+
const mimeType = header.split(':')[1].split(';')[0];
|
|
13
|
+
const extension = mimeType.split('/')[1];
|
|
14
|
+
const byteCharacters = atob(base64Data);
|
|
15
|
+
const byteArray = new Uint8Array(byteCharacters.length);
|
|
16
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
17
|
+
byteArray[i] = byteCharacters.charCodeAt(i);
|
|
18
|
+
}
|
|
19
|
+
const blob = new Blob([byteArray], { type: mimeType });
|
|
20
|
+
return { blob, extension };
|
|
21
|
+
};
|
|
22
|
+
const handleImageUrl = async (src) => {
|
|
23
|
+
const response = await fetch(src);
|
|
24
|
+
if (!response.ok)
|
|
25
|
+
throw new Error('Failed to fetch image');
|
|
26
|
+
const blob = await response.blob();
|
|
27
|
+
const extension = blob.type.split(/\/|\+/)[1];
|
|
28
|
+
return { blob, extension };
|
|
29
|
+
};
|
|
30
|
+
const fetchImageBlob = async (src) => {
|
|
31
|
+
return src.startsWith('data:') ? handleDataUrl(src) : handleImageUrl(src);
|
|
32
|
+
};
|
|
33
|
+
const saveImage = async (blob, name, extension) => {
|
|
34
|
+
const imageURL = URL.createObjectURL(blob);
|
|
35
|
+
const link = document.createElement('a');
|
|
36
|
+
link.href = imageURL;
|
|
37
|
+
link.download = `${name}.${extension}`;
|
|
38
|
+
document.body.appendChild(link);
|
|
39
|
+
link.click();
|
|
40
|
+
document.body.removeChild(link);
|
|
41
|
+
URL.revokeObjectURL(imageURL);
|
|
42
|
+
};
|
|
43
|
+
const downloadImage = async (props, options) => {
|
|
44
|
+
const { src, alt } = props;
|
|
45
|
+
const potentialName = alt || 'image';
|
|
46
|
+
try {
|
|
47
|
+
const { blob, extension } = await fetchImageBlob(src);
|
|
48
|
+
await saveImage(blob, potentialName, extension);
|
|
49
|
+
options.onActionSuccess?.({ ...props, action: 'download' });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
handleError(error, { ...props, action: 'download' }, options.onActionError);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const copyImage = async (props, options) => {
|
|
56
|
+
const { src } = props;
|
|
57
|
+
try {
|
|
58
|
+
const res = await fetch(src);
|
|
59
|
+
const blob = await res.blob();
|
|
60
|
+
await navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]);
|
|
61
|
+
options.onActionSuccess?.({ ...props, action: 'copyImage' });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
handleError(error, { ...props, action: 'copyImage' }, options.onActionError);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const copyLink = async (props, options) => {
|
|
68
|
+
const { src } = props;
|
|
69
|
+
try {
|
|
70
|
+
await navigator.clipboard.writeText(src);
|
|
71
|
+
options.onActionSuccess?.({ ...props, action: 'copyLink' });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
handleError(error, { ...props, action: 'copyLink' }, options.onActionError);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export const Image = TiptapImage.extend({
|
|
78
|
+
atom: true,
|
|
79
|
+
addOptions() {
|
|
80
|
+
return {
|
|
81
|
+
...this.parent?.(),
|
|
82
|
+
allowedMimeTypes: [],
|
|
83
|
+
maxFileSize: 0,
|
|
84
|
+
uploadFn: undefined,
|
|
85
|
+
onToggle: undefined,
|
|
86
|
+
downloadImage: undefined,
|
|
87
|
+
copyImage: undefined,
|
|
88
|
+
copyLink: undefined
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
addAttributes() {
|
|
92
|
+
return {
|
|
93
|
+
src: {
|
|
94
|
+
default: null
|
|
95
|
+
},
|
|
96
|
+
alt: {
|
|
97
|
+
default: null
|
|
98
|
+
},
|
|
99
|
+
title: {
|
|
100
|
+
default: null
|
|
101
|
+
},
|
|
102
|
+
id: {
|
|
103
|
+
default: null
|
|
104
|
+
},
|
|
105
|
+
width: {
|
|
106
|
+
default: null
|
|
107
|
+
},
|
|
108
|
+
height: {
|
|
109
|
+
default: null
|
|
110
|
+
},
|
|
111
|
+
fileName: {
|
|
112
|
+
default: null
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
addCommands() {
|
|
117
|
+
return {
|
|
118
|
+
setImages: attrs => ({ commands }) => {
|
|
119
|
+
const [validImages, errors] = filterFiles(attrs, {
|
|
120
|
+
allowedMimeTypes: this.options.allowedMimeTypes,
|
|
121
|
+
maxFileSize: this.options.maxFileSize,
|
|
122
|
+
allowBase64: this.options.allowBase64
|
|
123
|
+
});
|
|
124
|
+
if (errors.length > 0 && this.options.onValidationError) {
|
|
125
|
+
this.options.onValidationError(errors);
|
|
126
|
+
}
|
|
127
|
+
if (validImages.length > 0) {
|
|
128
|
+
return commands.insertContent(validImages.map(image => {
|
|
129
|
+
if (image.src instanceof File) {
|
|
130
|
+
const blobUrl = URL.createObjectURL(image.src);
|
|
131
|
+
const id = randomId();
|
|
132
|
+
return {
|
|
133
|
+
type: this.type.name,
|
|
134
|
+
attrs: {
|
|
135
|
+
id,
|
|
136
|
+
src: blobUrl,
|
|
137
|
+
alt: image.alt,
|
|
138
|
+
title: image.title,
|
|
139
|
+
fileName: image.src.name
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return {
|
|
145
|
+
type: this.type.name,
|
|
146
|
+
attrs: {
|
|
147
|
+
id: randomId(),
|
|
148
|
+
src: image.src,
|
|
149
|
+
alt: image.alt,
|
|
150
|
+
title: image.title,
|
|
151
|
+
fileName: null
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
},
|
|
159
|
+
downloadImage: attrs => () => {
|
|
160
|
+
const downloadFunc = this.options.downloadImage || downloadImage;
|
|
161
|
+
void downloadFunc({ ...attrs, action: 'download' }, this.options);
|
|
162
|
+
return true;
|
|
163
|
+
},
|
|
164
|
+
copyImage: attrs => () => {
|
|
165
|
+
const copyImageFunc = this.options.copyImage || copyImage;
|
|
166
|
+
void copyImageFunc({ ...attrs, action: 'copyImage' }, this.options);
|
|
167
|
+
return true;
|
|
168
|
+
},
|
|
169
|
+
copyLink: attrs => () => {
|
|
170
|
+
const copyLinkFunc = this.options.copyLink || copyLink;
|
|
171
|
+
void copyLinkFunc({ ...attrs, action: 'copyLink' }, this.options);
|
|
172
|
+
return true;
|
|
173
|
+
},
|
|
174
|
+
toggleImage: () => ({ editor }) => {
|
|
175
|
+
const input = document.createElement('input');
|
|
176
|
+
input.type = 'file';
|
|
177
|
+
input.accept = this.options.allowedMimeTypes.join(',');
|
|
178
|
+
input.onchange = () => {
|
|
179
|
+
const files = input.files;
|
|
180
|
+
if (!files)
|
|
181
|
+
return;
|
|
182
|
+
const [validImages, errors] = filterFiles(Array.from(files), {
|
|
183
|
+
allowedMimeTypes: this.options.allowedMimeTypes,
|
|
184
|
+
maxFileSize: this.options.maxFileSize,
|
|
185
|
+
allowBase64: this.options.allowBase64
|
|
186
|
+
});
|
|
187
|
+
if (errors.length > 0 && this.options.onValidationError) {
|
|
188
|
+
this.options.onValidationError(errors);
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (validImages.length === 0)
|
|
192
|
+
return false;
|
|
193
|
+
if (this.options.onToggle) {
|
|
194
|
+
this.options.onToggle(editor, validImages, editor.state.selection.from);
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
};
|
|
198
|
+
input.click();
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
onTransaction({ transaction }) {
|
|
204
|
+
transaction.steps.forEach(step => {
|
|
205
|
+
if (step instanceof ReplaceStep && step.slice.size === 0) {
|
|
206
|
+
const deletedPages = transaction.before.content.cut(step.from, step.to);
|
|
207
|
+
deletedPages.forEach(node => {
|
|
208
|
+
if (node.type.name === 'image') {
|
|
209
|
+
const attrs = node.attrs;
|
|
210
|
+
if (attrs.src.startsWith('blob:')) {
|
|
211
|
+
URL.revokeObjectURL(attrs.src);
|
|
212
|
+
}
|
|
213
|
+
this.options.onImageRemoved?.(attrs);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
addNodeView() {
|
|
220
|
+
return ReactNodeViewRenderer(ImageViewBlock, {
|
|
221
|
+
className: 'block-node'
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/image/image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAA8C,MAAM,aAAa,CAAA;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAqDlD,MAAM,WAAW,GAAG,CAClB,KAAc,EACd,KAAuB,EACvB,YAA8D,EACxD,EAAE;IACR,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;IAC9E,YAAY,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;AACnC,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,GAAW,EAAqC,EAAE;IACvE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACxC,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,CAAA;IACvC,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IACvD,KAAK,IAAI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../src/components/minimal-tiptap/extensions/image/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './code-block-lowlight';
|
|
2
|
+
export * from './color';
|
|
3
|
+
export * from './horizontal-rule';
|
|
4
|
+
export * from './image';
|
|
5
|
+
export * from './link';
|
|
6
|
+
export * from './selection';
|
|
7
|
+
export * from './unset-all-marks';
|
|
8
|
+
export * from './reset-marks-on-enter';
|
|
9
|
+
export * from './file-handler';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/minimal-tiptap/extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/link/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { mergeAttributes } from '@tiptap/react';
|
|
2
|
+
import TiptapLink from '@tiptap/extension-link';
|
|
3
|
+
import { getMarkRange } from '@tiptap/react';
|
|
4
|
+
import { Plugin, TextSelection } from '@tiptap/pm/state';
|
|
5
|
+
export const Link = TiptapLink.extend({
|
|
6
|
+
/*
|
|
7
|
+
* Determines whether typing next to a link automatically becomes part of the link.
|
|
8
|
+
* In this case, we dont want any characters to be included as part of the link.
|
|
9
|
+
*/
|
|
10
|
+
inclusive: false,
|
|
11
|
+
/*
|
|
12
|
+
* Match all <a> elements that have an href attribute, except for:
|
|
13
|
+
* - <a> elements with a data-type attribute set to button
|
|
14
|
+
* - <a> elements with an href attribute that contains 'javascript:'
|
|
15
|
+
*/
|
|
16
|
+
parseHTML() {
|
|
17
|
+
return [{ tag: 'a[href]:not([data-type="button"]):not([href *= "javascript:" i])' }];
|
|
18
|
+
},
|
|
19
|
+
renderHTML({ HTMLAttributes }) {
|
|
20
|
+
return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
21
|
+
},
|
|
22
|
+
addOptions() {
|
|
23
|
+
return {
|
|
24
|
+
...this.parent?.(),
|
|
25
|
+
openOnClick: false,
|
|
26
|
+
HTMLAttributes: {
|
|
27
|
+
class: 'link',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
addProseMirrorPlugins() {
|
|
32
|
+
const { editor } = this;
|
|
33
|
+
return [
|
|
34
|
+
...(this.parent?.() || []),
|
|
35
|
+
new Plugin({
|
|
36
|
+
props: {
|
|
37
|
+
handleKeyDown: (_, event) => {
|
|
38
|
+
const { selection } = editor.state;
|
|
39
|
+
/*
|
|
40
|
+
* Handles the 'Escape' key press when there's a selection within the link.
|
|
41
|
+
* This will move the cursor to the end of the link.
|
|
42
|
+
*/
|
|
43
|
+
if (event.key === 'Escape' && selection.empty !== true) {
|
|
44
|
+
editor.commands.focus(selection.to, { scrollIntoView: false });
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
},
|
|
48
|
+
handleClick(view, pos) {
|
|
49
|
+
/*
|
|
50
|
+
* Marks the entire link when the user clicks on it.
|
|
51
|
+
*/
|
|
52
|
+
const { schema, doc, tr } = view.state;
|
|
53
|
+
const range = getMarkRange(doc.resolve(pos), schema.marks.link);
|
|
54
|
+
if (!range) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const { from, to } = range;
|
|
58
|
+
const start = Math.min(from, to);
|
|
59
|
+
const end = Math.max(from, to);
|
|
60
|
+
if (pos < start || pos > end) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const $start = doc.resolve(start);
|
|
64
|
+
const $end = doc.resolve(end);
|
|
65
|
+
const transaction = tr.setSelection(new TextSelection($start, $end));
|
|
66
|
+
view.dispatch(transaction);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
];
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
export default Link;
|
|
74
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/link/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,UAAU,MAAM,wBAAwB,CAAA;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAExD,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC;;;OAGG;IACH,SAAS,EAAE,KAAK;IAEhB;;;;OAIG;IACH,SAAS;QACP,OAAO,CAAC,EAAE,GAAG,EAAE,kEAAkE,EAAE,CAAC,CAAA;IACtF,CAAC;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/E,CAAC;IAED,UAAU;QACR,OAAO;YACL,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE;YAClB,WAAW,EAAE,KAAK;YAClB,cAAc,EAAE;gBACd,KAAK,EAAE,MAAM;aACd;SACF,CAAA;IACH,CAAC;IAED,qBAAqB;QACnB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAEvB,OAAO;YACL,GAAG,CAAC,IAAI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AC,CAAA;wBAC7B,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;wBAEpE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;oBAC5B,CAAC;iBACF;aACF,CAAC;SACH,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAEF,eAAe,IAAI,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/reset-marks-on-enter/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
package/dist/components/minimal-tiptap/extensions/reset-marks-on-enter/reset-marks-on-enter.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/react';
|
|
2
|
+
export const ResetMarksOnEnter = Extension.create({
|
|
3
|
+
name: 'resetMarksOnEnter',
|
|
4
|
+
addKeyboardShortcuts() {
|
|
5
|
+
return {
|
|
6
|
+
Enter: ({ editor }) => {
|
|
7
|
+
if (editor.isActive('bold') ||
|
|
8
|
+
editor.isActive('italic') ||
|
|
9
|
+
editor.isActive('strike') ||
|
|
10
|
+
editor.isActive('underline') ||
|
|
11
|
+
editor.isActive('code')) {
|
|
12
|
+
editor.commands.splitBlock({ keepMarks: false });
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=reset-marks-on-enter.js.map
|
package/dist/components/minimal-tiptap/extensions/reset-marks-on-enter/reset-marks-on-enter.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reset-marks-on-enter.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/reset-marks-on-enter/reset-marks-on-enter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,CAAC;IAChD,IAAI,EAAE,mBAAmB;IAEzB,oBAAoB;QAClB,OAAO;YACL,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;gBACpB,IACE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;oBACvB,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBACzB,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBACzB,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;oBAC5B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EACvB,CAAC;oBACD,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;oBAEhD,OAAO,IAAI,CAAA;gBACb,CAAC;gBAED,OAAO,KAAK,CAAA;YACd,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/selection/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/react';
|
|
2
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
3
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
4
|
+
export const Selection = Extension.create({
|
|
5
|
+
name: 'selection',
|
|
6
|
+
addProseMirrorPlugins() {
|
|
7
|
+
const { editor } = this;
|
|
8
|
+
return [
|
|
9
|
+
new Plugin({
|
|
10
|
+
key: new PluginKey('selection'),
|
|
11
|
+
props: {
|
|
12
|
+
decorations(state) {
|
|
13
|
+
if (state.selection.empty) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (editor.isFocused === true) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return DecorationSet.create(state.doc, [
|
|
20
|
+
Decoration.inline(state.selection.from, state.selection.to, {
|
|
21
|
+
class: 'selection',
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
];
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
export default Selection;
|
|
31
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/selection/selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE3D,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,WAAW;IAEjB,qBAAqB;QACnB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAEvB,OAAO;YACL,IAAI,MAAM,CAAC;gBACT,GAAG,EAAE,IAAI,SAAS,CAAC,WAAW,CAAC;gBAC/B,KAAK,EAAE;oBACL,WAAW,CAAC,KAAK;wBACf,IAAI,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;4BAC1B,OAAO,IAAI,CAAA;wBACb,CAAC;wBAED,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;4BAC9B,OAAO,IAAI,CAAA;wBACb,CAAC;wBAED,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;4BACrC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE;gCAC1D,KAAK,EAAE,WAAW;6BACnB,CAAC;yBACH,CAAC,CAAA;oBACJ,CAAC;iBACF;aACF,CAAC;SACH,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAEF,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/unset-all-marks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unset-all-marks.js","sourceRoot":"","sources":["../../../../../src/components/minimal-tiptap/extensions/unset-all-marks/unset-all-marks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC;IAC5C,oBAAoB;QAClB,OAAO;YACL,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;SACrD,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import './styles/index.css';
|
|
4
|
+
import { EditorContent } from '@tiptap/react';
|
|
5
|
+
import { Separator } from '../../components/ui/separator';
|
|
6
|
+
import { cn } from '../../lib/utils';
|
|
7
|
+
import { SectionTwo } from './components/section/two';
|
|
8
|
+
import { SectionFour } from './components/section/four';
|
|
9
|
+
import { LinkBubbleMenu } from './components/bubble-menu/link-bubble-menu';
|
|
10
|
+
import { useMinimalTiptapEditor } from './hooks/use-minimal-tiptap';
|
|
11
|
+
import { MeasuredContainer } from './components/measured-container';
|
|
12
|
+
import { LinkEditPopover } from './components/link/link-edit-popover';
|
|
13
|
+
const DescriptionEditorToolbar = ({ editor }) => (_jsx("div", { className: 'shrink-0 overflow-x-auto border-b border-border p-2', children: _jsxs("div", { className: 'flex w-max items-center gap-px', children: [_jsx(SectionTwo, { editor: editor, activeActions: ['bold', 'italic', 'underline', 'strikethrough', 'code', 'clearFormatting'], mainActionCount: 3 }), _jsx(Separator, { orientation: 'vertical', className: 'mx-2 h-7' }), _jsx(SectionFour, { editor: editor, activeActions: ['orderedList', 'bulletList'], mainActionCount: 0 }), _jsx(Separator, { orientation: 'vertical', className: 'mx-2 h-7' }), _jsx(LinkEditPopover, { editor: editor })] }) }));
|
|
14
|
+
export const DescriptionMinimalTiptapEditor = React.forwardRef(({ value, onChange, className, editorContentClassName, ...props }, ref) => {
|
|
15
|
+
const editor = useMinimalTiptapEditor({
|
|
16
|
+
value,
|
|
17
|
+
onUpdate: onChange,
|
|
18
|
+
...props,
|
|
19
|
+
});
|
|
20
|
+
if (!editor) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return (_jsxs(MeasuredContainer, { as: 'div', name: 'editor', ref: ref, className: cn('flex h-auto min-h-70 w-full flex-col rounded-md border border-input shadow-sm focus-within:border-primary', className), children: [_jsx(DescriptionEditorToolbar, { editor: editor }), _jsx(EditorContent, { editor: editor, className: cn('minimal-tiptap-editor', editorContentClassName) }), _jsx(LinkBubbleMenu, { editor: editor })] }));
|
|
24
|
+
});
|
|
25
|
+
DescriptionMinimalTiptapEditor.displayName = 'DescriptionMinimalTiptapEditor';
|
|
26
|
+
//# sourceMappingURL=form-description-tiptap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-description-tiptap.js","sourceRoot":"","sources":["../../../src/components/minimal-tiptap/form-description-tiptap.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,oBAAoB,CAAA;AAG3B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACr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AE,QAAQ;QAClB,GAAG,KAAK;KACT,CAAC,CAAA;IAEF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CACL,MAAC,iBAAiB,IAChB,EAAE,EAAC,KAAK,EACR,IAAI,EAAC,QAAQ,EACb,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,2GAA2G,EAC3G,SAAS,CACV,aAED,KAAC,wBAAwB,IAAC,MAAM,EAAE,MAAM,GAAI,EAC5C,KAAC,aAAa,IACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,EAAE,CAAC,uBAAuB,EAAE,sBAAsB,CAAC,GAC9D,EACF,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,GAAI,IAChB,CACrB,CAAA;AACH,CAAC,CACF,CAAA;AAED,8BAA8B,CAAC,WAAW,GAAG,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
const DEFAULT_RECT = {
|
|
3
|
+
top: 0,
|
|
4
|
+
left: 0,
|
|
5
|
+
bottom: 0,
|
|
6
|
+
right: 0,
|
|
7
|
+
x: 0,
|
|
8
|
+
y: 0,
|
|
9
|
+
width: 0,
|
|
10
|
+
height: 0,
|
|
11
|
+
toJSON: () => '{}',
|
|
12
|
+
};
|
|
13
|
+
export function useContainerSize(element) {
|
|
14
|
+
const [size, setSize] = useState(() => element?.getBoundingClientRect() ?? DEFAULT_RECT);
|
|
15
|
+
const handleResize = useCallback(() => {
|
|
16
|
+
if (!element)
|
|
17
|
+
return;
|
|
18
|
+
const newRect = element.getBoundingClientRect();
|
|
19
|
+
setSize((prevRect) => {
|
|
20
|
+
if (Math.round(prevRect.width) === Math.round(newRect.width) &&
|
|
21
|
+
Math.round(prevRect.height) === Math.round(newRect.height) &&
|
|
22
|
+
Math.round(prevRect.x) === Math.round(newRect.x) &&
|
|
23
|
+
Math.round(prevRect.y) === Math.round(newRect.y)) {
|
|
24
|
+
return prevRect;
|
|
25
|
+
}
|
|
26
|
+
return newRect;
|
|
27
|
+
});
|
|
28
|
+
}, [element]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!element)
|
|
31
|
+
return;
|
|
32
|
+
const resizeObserver = new ResizeObserver(handleResize);
|
|
33
|
+
resizeObserver.observe(element);
|
|
34
|
+
window.addEventListener('click', handleResize);
|
|
35
|
+
window.addEventListener('resize', handleResize);
|
|
36
|
+
return () => {
|
|
37
|
+
resizeObserver.disconnect();
|
|
38
|
+
window.removeEventListener('click', handleResize);
|
|
39
|
+
window.removeEventListener('resize', handleResize);
|
|
40
|
+
};
|
|
41
|
+
}, [element, handleResize]);
|
|
42
|
+
return size;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=use-container-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-container-size.js","sourceRoot":"","sources":["../../../../src/components/minimal-tiptap/hooks/use-container-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAExD,MAAM,YAAY,GAAY;IAC5B,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI;CACnB,CAAA;AAED,MAAM,UAAU,gBAAgB,CAAC,OAA2B;IAC1D,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAU,GAAG,EAAE,CAAC,OAAO,EAAE,qBAAqB,EAAE,IAAI,YAAY,CAAC,CAAA;IAEjG,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;QACpC,IAAI,CAAC,OAAO;YAAE,OAA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