@seorii/tiptap 0.4.5 → 0.4.6
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/plugin/columns/index.d.ts +3 -1
- package/dist/plugin/columns/index.js +71 -0
- package/dist/plugin/columns/style.css +45 -0
- package/dist/plugin/image/index.d.ts +5 -1
- package/dist/plugin/image/index.js +1 -1
- package/dist/plugin/resize/index.js +1 -2
- package/dist/plugin/upload/skeleton/UploadSkeleton.svelte +6 -1
- package/dist/plugin/upload/skeleton/index.js +1 -1
- package/dist/tiptap/TipTap.svelte +6 -1
- package/package.json +19 -19
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { NodeSelection, Plugin, PluginKey } from '@tiptap/pm/state';
|
|
2
3
|
import './style.css';
|
|
3
4
|
const normalizeColumnCount = (value) => (Number(value) === 3 ? 3 : 2);
|
|
5
|
+
const columnsSelectionPluginKey = new PluginKey('tiptap-columns-selection');
|
|
6
|
+
const isColumnsSelectHandleHit = (element, event) => {
|
|
7
|
+
const rect = element.getBoundingClientRect();
|
|
8
|
+
const handleInset = 4;
|
|
9
|
+
const handleSize = 32;
|
|
10
|
+
return (event.clientX >= rect.right - handleSize - handleInset &&
|
|
11
|
+
event.clientX <= rect.right - handleInset &&
|
|
12
|
+
event.clientY >= rect.top + handleInset &&
|
|
13
|
+
event.clientY <= rect.top + handleSize + handleInset);
|
|
14
|
+
};
|
|
15
|
+
const findNodePosByDOM = (view, element, nodeName) => {
|
|
16
|
+
let found = null;
|
|
17
|
+
view.state.doc.descendants((node, pos) => {
|
|
18
|
+
if (found !== null || node.type.name !== nodeName)
|
|
19
|
+
return;
|
|
20
|
+
if (view.nodeDOM(pos) === element) {
|
|
21
|
+
found = pos;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return found;
|
|
26
|
+
};
|
|
27
|
+
const tryCreateNodeSelection = (doc, pos) => {
|
|
28
|
+
if (pos < 0 || pos > doc.content.size)
|
|
29
|
+
return null;
|
|
30
|
+
const node = doc.nodeAt(pos);
|
|
31
|
+
if (!node || node.type.spec.selectable === false)
|
|
32
|
+
return null;
|
|
33
|
+
try {
|
|
34
|
+
return NodeSelection.create(doc, pos);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
4
40
|
const Column = Node.create({
|
|
5
41
|
name: 'column',
|
|
6
42
|
content: 'block+',
|
|
@@ -31,6 +67,7 @@ const Columns = Node.create({
|
|
|
31
67
|
isolating: true,
|
|
32
68
|
defining: true,
|
|
33
69
|
draggable: true,
|
|
70
|
+
selectable: true,
|
|
34
71
|
addOptions() {
|
|
35
72
|
return {
|
|
36
73
|
HTMLAttributes: {}
|
|
@@ -83,6 +120,40 @@ const Columns = Node.create({
|
|
|
83
120
|
setTwoColumns: () => ({ commands }) => commands.setColumns(2),
|
|
84
121
|
setThreeColumns: () => ({ commands }) => commands.setColumns(3)
|
|
85
122
|
};
|
|
123
|
+
},
|
|
124
|
+
addProseMirrorPlugins() {
|
|
125
|
+
const editor = this.editor;
|
|
126
|
+
const nodeName = this.name;
|
|
127
|
+
return [
|
|
128
|
+
new Plugin({
|
|
129
|
+
key: columnsSelectionPluginKey,
|
|
130
|
+
props: {
|
|
131
|
+
handleDOMEvents: {
|
|
132
|
+
mousedown(view, event) {
|
|
133
|
+
if (!editor.isEditable)
|
|
134
|
+
return false;
|
|
135
|
+
if (!(event.target instanceof HTMLElement))
|
|
136
|
+
return false;
|
|
137
|
+
const columnsElement = event.target.closest('.tiptap-columns');
|
|
138
|
+
if (!columnsElement || !isColumnsSelectHandleHit(columnsElement, event)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const pos = findNodePosByDOM(view, columnsElement, nodeName);
|
|
142
|
+
if (pos === null)
|
|
143
|
+
return false;
|
|
144
|
+
const selection = tryCreateNodeSelection(view.state.doc, pos);
|
|
145
|
+
if (!selection)
|
|
146
|
+
return false;
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
event.stopPropagation();
|
|
149
|
+
view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
|
|
150
|
+
view.focus();
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
];
|
|
86
157
|
}
|
|
87
158
|
});
|
|
88
159
|
export default [Columns, Column];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
.tiptap-columns {
|
|
2
|
+
position: relative;
|
|
2
3
|
display: grid;
|
|
3
4
|
gap: 12px;
|
|
4
5
|
margin: 12px 0;
|
|
@@ -12,6 +13,13 @@
|
|
|
12
13
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
@media (max-width: 768px) {
|
|
17
|
+
.tiptap-columns.columns-2,
|
|
18
|
+
.tiptap-columns.columns-3 {
|
|
19
|
+
grid-template-columns: minmax(0, 1fr);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
.tiptap-column {
|
|
16
24
|
min-width: 0;
|
|
17
25
|
padding: 10px 12px;
|
|
@@ -35,3 +43,40 @@
|
|
|
35
43
|
.editable .tiptap-column:hover {
|
|
36
44
|
border-color: var(--primary-light7, rgba(112, 112, 112, 0.65));
|
|
37
45
|
}
|
|
46
|
+
|
|
47
|
+
.editable .tiptap-columns::before {
|
|
48
|
+
position: absolute;
|
|
49
|
+
z-index: 1;
|
|
50
|
+
top: 4px;
|
|
51
|
+
right: 4px;
|
|
52
|
+
box-sizing: border-box;
|
|
53
|
+
width: 32px;
|
|
54
|
+
height: 32px;
|
|
55
|
+
border: 1px solid var(--primary-light4, rgba(112, 112, 112, 0.4));
|
|
56
|
+
border-radius: 6px;
|
|
57
|
+
background-color: var(--surface, Canvas);
|
|
58
|
+
background-image: radial-gradient(currentColor 1.2px, transparent 1.2px);
|
|
59
|
+
background-position: 7px 7px;
|
|
60
|
+
background-size: 8px 8px;
|
|
61
|
+
color: var(--primary-light8, rgba(112, 112, 112, 0.75));
|
|
62
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
|
|
63
|
+
content: '';
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
opacity: 0;
|
|
66
|
+
transition:
|
|
67
|
+
opacity 0.15s ease,
|
|
68
|
+
border-color 0.15s ease,
|
|
69
|
+
color 0.15s ease;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.editable .tiptap-columns:hover::before,
|
|
73
|
+
.editable .tiptap-columns.ProseMirror-selectednode::before {
|
|
74
|
+
opacity: 1;
|
|
75
|
+
border-color: var(--primary-light7, rgba(112, 112, 112, 0.65));
|
|
76
|
+
color: var(--primary, currentColor);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.editable .tiptap-columns.ProseMirror-selectednode {
|
|
80
|
+
outline: 3px solid var(--primary);
|
|
81
|
+
outline-offset: 2px;
|
|
82
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ImageOptions } from '@tiptap/extension-image';
|
|
2
|
+
type ImageOptionsWithSizes = ImageOptions & {
|
|
3
|
+
sizes: string[];
|
|
4
|
+
};
|
|
5
|
+
declare const _default: (crossorigin?: string) => import("@tiptap/core").Node<ImageOptionsWithSizes, any>;
|
|
2
6
|
export default _default;
|
|
@@ -453,7 +453,6 @@ function createResizeHandleDecoration(nodePos, widgetPos, resizeMeta, node) {
|
|
|
453
453
|
optionButton.setAttribute('aria-pressed', isActive ? 'true' : 'false');
|
|
454
454
|
toolbar.append(optionButton);
|
|
455
455
|
}
|
|
456
|
-
hasToolbarItems = true;
|
|
457
456
|
if (supportsBottomWidthPreset) {
|
|
458
457
|
const separator = document.createElement('span');
|
|
459
458
|
separator.className = 'tiptap-media-toolbar-separator';
|
|
@@ -816,7 +815,7 @@ export default Extension.create({
|
|
|
816
815
|
const startY = event.clientY;
|
|
817
816
|
const startHeight = resolveStartHeight(resizeMeta.kind, node, target);
|
|
818
817
|
const targetParent = target.parentElement;
|
|
819
|
-
const shouldShowProxy =
|
|
818
|
+
const shouldShowProxy = Boolean(targetParent);
|
|
820
819
|
const currentHorizontalAlign = normalizeHorizontalAlignAttr(node.attrs.horizontalAlign);
|
|
821
820
|
const startWidth = Math.max(1, resolveElementWidth(node, target) ||
|
|
822
821
|
targetParent?.getBoundingClientRect().width ||
|
|
@@ -47,7 +47,12 @@
|
|
|
47
47
|
position: absolute;
|
|
48
48
|
inset: 0;
|
|
49
49
|
transform: translateX(-120%);
|
|
50
|
-
background: linear-gradient(
|
|
50
|
+
background: linear-gradient(
|
|
51
|
+
105deg,
|
|
52
|
+
transparent 20%,
|
|
53
|
+
rgba(255, 255, 255, 0.36),
|
|
54
|
+
transparent 80%
|
|
55
|
+
);
|
|
51
56
|
animation: shimmer 1.35s ease-in-out infinite;
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -113,7 +113,7 @@ export default Node.create({
|
|
|
113
113
|
kind: {
|
|
114
114
|
default: 'block',
|
|
115
115
|
parseHTML: (element) => element.getAttribute('data-upload-kind') || 'block',
|
|
116
|
-
renderHTML: (attributes) => attributes.kind ? { 'data-upload-kind': attributes.kind } : {}
|
|
116
|
+
renderHTML: (attributes) => (attributes.kind ? { 'data-upload-kind': attributes.kind } : {})
|
|
117
117
|
},
|
|
118
118
|
height: {
|
|
119
119
|
default: defaultHeight.block,
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
resize?: boolean | ResizeOptions;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/* eslint-disable no-useless-assignment -- Svelte bindable props are read by parent bindings. */
|
|
46
47
|
let {
|
|
47
48
|
body = $bindable<string>(),
|
|
48
49
|
editable = false,
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
codeBlockLanguageLabels = {},
|
|
74
75
|
resize = true
|
|
75
76
|
}: Props = $props();
|
|
77
|
+
/* eslint-enable no-useless-assignment */
|
|
76
78
|
|
|
77
79
|
const scopedI18n: I18nTranslate = (...args) => translateWithLocale(locale, ...args);
|
|
78
80
|
const resizeDataAttrs = [
|
|
@@ -154,6 +156,9 @@
|
|
|
154
156
|
Promise.all([import('./tiptap'), import('@justinribeiro/lite-youtube')]).then(
|
|
155
157
|
([{ default: tt }]) => {
|
|
156
158
|
if (!untrack(() => mounted)) return;
|
|
159
|
+
const initialBody = untrack(() => san(body));
|
|
160
|
+
body = initialBody;
|
|
161
|
+
last = initialBody;
|
|
157
162
|
const editorPlaceholder = placeholder ?? scopedI18n('placeholder');
|
|
158
163
|
const optionPlugins = Array.isArray(options.plugins)
|
|
159
164
|
? [...options.plugins]
|
|
@@ -164,7 +169,7 @@
|
|
|
164
169
|
const resizeOptions = typeof resize === 'object' ? resize : {};
|
|
165
170
|
optionPlugins.unshift(MediaResize.configure(resizeOptions));
|
|
166
171
|
}
|
|
167
|
-
tiptap.v = ref = tt(element,
|
|
172
|
+
tiptap.v = ref = tt(element, initialBody, {
|
|
168
173
|
placeholder: editorPlaceholder,
|
|
169
174
|
editable,
|
|
170
175
|
onTransaction: () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seorii/tiptap",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "svelte-kit sync && svelte-package",
|
|
@@ -14,30 +14,30 @@
|
|
|
14
14
|
"page": "npm run build-page && node gh-pages.js"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@eslint/js": "^
|
|
17
|
+
"@eslint/js": "^10.0.1",
|
|
18
18
|
"@sveltejs/adapter-auto": "^7.0.1",
|
|
19
19
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
20
|
-
"@sveltejs/kit": "^2.
|
|
20
|
+
"@sveltejs/kit": "^2.61.0",
|
|
21
21
|
"@sveltejs/package": "^2.5.7",
|
|
22
|
-
"@sveltejs/vite-plugin-svelte": "
|
|
23
|
-
"@types/sanitize-html": "^2.16.
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
25
|
-
"@typescript-eslint/parser": "^8.
|
|
26
|
-
"eslint": "^
|
|
22
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
23
|
+
"@types/sanitize-html": "^2.16.1",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.59.4",
|
|
25
|
+
"@typescript-eslint/parser": "^8.59.4",
|
|
26
|
+
"eslint": "^10.4.0",
|
|
27
27
|
"eslint-config-prettier": "^10.1.8",
|
|
28
|
-
"eslint-plugin-svelte": "^3.
|
|
28
|
+
"eslint-plugin-svelte": "^3.17.1",
|
|
29
29
|
"gh-pages": "^6.3.0",
|
|
30
|
-
"globals": "^17.
|
|
30
|
+
"globals": "^17.6.0",
|
|
31
31
|
"highlight.js": "^11.11.1",
|
|
32
|
-
"prettier": "^3.8.
|
|
33
|
-
"prettier-plugin-svelte": "^
|
|
34
|
-
"publint": "^0.3.
|
|
35
|
-
"svelte": "^5.
|
|
36
|
-
"svelte-check": "^4.4.
|
|
37
|
-
"svelte-eslint-parser": "^1.
|
|
32
|
+
"prettier": "^3.8.3",
|
|
33
|
+
"prettier-plugin-svelte": "^4.0.1",
|
|
34
|
+
"publint": "^0.3.21",
|
|
35
|
+
"svelte": "^5.55.9",
|
|
36
|
+
"svelte-check": "^4.4.8",
|
|
37
|
+
"svelte-eslint-parser": "^1.6.1",
|
|
38
38
|
"tslib": "^2.8.1",
|
|
39
|
-
"typescript": "^
|
|
40
|
-
"vite": "^
|
|
39
|
+
"typescript": "^6.0.3",
|
|
40
|
+
"vite": "^8.0.14"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"svelte": "^5.0.0"
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"prosemirror-transform": "^1.11.0",
|
|
82
82
|
"prosemirror-view": "^1.41.6",
|
|
83
83
|
"sanitize-html": "^2.17.1",
|
|
84
|
-
"svelte-awesome-color-picker": "^4.1.
|
|
84
|
+
"svelte-awesome-color-picker": "^4.1.2",
|
|
85
85
|
"svelte-tiptap": "^2",
|
|
86
86
|
"tippy.js": "^6.3.7"
|
|
87
87
|
},
|