@seorii/tiptap 0.4.5 → 0.4.7

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.
@@ -10,5 +10,7 @@ declare module '@tiptap/core' {
10
10
  };
11
11
  }
12
12
  }
13
- declare const _default: Node<any, any>[];
13
+ declare const _default: Node<{
14
+ HTMLAttributes: {};
15
+ }, any>[];
14
16
  export default _default;
@@ -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
- declare const _default: (crossorigin?: string) => import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any>;
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;
@@ -1,4 +1,4 @@
1
- import Image from '@tiptap/extension-image';
1
+ import Image, {} from '@tiptap/extension-image';
2
2
  import { mergeAttributes } from '@tiptap/core';
3
3
  import { dropImagePlugin } from './dragdrop';
4
4
  export default (crossorigin = 'anonymous') => Image.extend({
@@ -0,0 +1,3 @@
1
+ import { Extension } from '@tiptap/core';
2
+ declare const _default: Extension<any, any>;
3
+ export default _default;
@@ -0,0 +1,147 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import { Fragment, Slice } from '@tiptap/pm/model';
3
+ import { Plugin, PluginKey } from '@tiptap/pm/state';
4
+ export default Extension.create({
5
+ name: 'mathPaste',
6
+ addProseMirrorPlugins() {
7
+ return [
8
+ new Plugin({
9
+ key: new PluginKey('mathPaste'),
10
+ props: {
11
+ transformPasted: (slice, view) => {
12
+ const { schema } = view.state;
13
+ const mathInline = schema.nodes.math_inline;
14
+ const mathDisplay = schema.nodes.math_display;
15
+ if (!mathInline && !mathDisplay)
16
+ return slice;
17
+ let changed = false;
18
+ let blockChanged = false;
19
+ const transformFragment = (fragment, parent) => {
20
+ const nodes = [];
21
+ for (let index = 0; index < fragment.childCount; index++) {
22
+ const node = fragment.child(index);
23
+ if (parent?.type.spec.code ||
24
+ node.type.spec.code ||
25
+ node.type.name.startsWith('math_')) {
26
+ nodes.push(node);
27
+ continue;
28
+ }
29
+ if (mathDisplay && node.isTextblock && node.textContent.trim() === '$$') {
30
+ const source = [];
31
+ let endIndex = -1;
32
+ for (let offset = index + 1; offset < fragment.childCount; offset++) {
33
+ const candidate = fragment.child(offset);
34
+ if (candidate.type.spec.code ||
35
+ candidate.type.name.startsWith('math_') ||
36
+ !candidate.isTextblock) {
37
+ break;
38
+ }
39
+ const text = candidate.textContent;
40
+ if (text.trim() === '$$') {
41
+ endIndex = offset;
42
+ break;
43
+ }
44
+ source.push(text);
45
+ }
46
+ const text = source.join('\n').trim();
47
+ if (endIndex > -1 && text.length) {
48
+ nodes.push(mathDisplay.create(null, schema.text(text)));
49
+ index = endIndex;
50
+ changed = true;
51
+ blockChanged = true;
52
+ continue;
53
+ }
54
+ }
55
+ if (mathDisplay && node.isTextblock) {
56
+ const match = /^\s*\$\$([\s\S]*?)\$\$\s*$/.exec(node.textContent);
57
+ const text = match?.[1]?.trim();
58
+ if (text) {
59
+ nodes.push(mathDisplay.create(null, schema.text(text)));
60
+ changed = true;
61
+ blockChanged = true;
62
+ continue;
63
+ }
64
+ }
65
+ if (node.isText) {
66
+ if (!mathInline || node.marks.some((mark) => mark.type.spec.code)) {
67
+ nodes.push(node);
68
+ continue;
69
+ }
70
+ const text = node.text || '';
71
+ const inlineNodes = [];
72
+ let cursor = 0;
73
+ let searchFrom = 0;
74
+ while (searchFrom < text.length) {
75
+ const open = text.indexOf('$', searchFrom);
76
+ if (open === -1)
77
+ break;
78
+ const beforeOpen = text[open - 1];
79
+ const afterOpen = text[open + 1];
80
+ if (beforeOpen === '\\' ||
81
+ beforeOpen === '$' ||
82
+ afterOpen === '$' ||
83
+ !afterOpen ||
84
+ /\s/.test(afterOpen)) {
85
+ searchFrom = open + 1;
86
+ continue;
87
+ }
88
+ let close = open + 1;
89
+ while (close < text.length) {
90
+ close = text.indexOf('$', close);
91
+ if (close === -1)
92
+ break;
93
+ const beforeClose = text[close - 1];
94
+ const afterClose = text[close + 1];
95
+ if (beforeClose === '\\' ||
96
+ beforeClose === '$' ||
97
+ afterClose === '$' ||
98
+ /\s/.test(beforeClose)) {
99
+ close++;
100
+ continue;
101
+ }
102
+ break;
103
+ }
104
+ if (close === -1)
105
+ break;
106
+ const source = text.slice(open + 1, close);
107
+ if (!source.trim()) {
108
+ searchFrom = close + 1;
109
+ continue;
110
+ }
111
+ if (open > cursor)
112
+ inlineNodes.push(schema.text(text.slice(cursor, open), node.marks));
113
+ inlineNodes.push(mathInline.create(null, schema.text(source), node.marks));
114
+ cursor = close + 1;
115
+ searchFrom = cursor;
116
+ }
117
+ if (!inlineNodes.length) {
118
+ nodes.push(node);
119
+ continue;
120
+ }
121
+ if (cursor < text.length)
122
+ inlineNodes.push(schema.text(text.slice(cursor), node.marks));
123
+ nodes.push(...inlineNodes);
124
+ changed = true;
125
+ continue;
126
+ }
127
+ if (!node.content.size) {
128
+ nodes.push(node);
129
+ continue;
130
+ }
131
+ const content = transformFragment(node.content, node);
132
+ nodes.push(content.eq(node.content) ? node : node.copy(content));
133
+ }
134
+ return Fragment.fromArray(nodes);
135
+ };
136
+ const content = transformFragment(slice.content, null);
137
+ if (!changed)
138
+ return slice;
139
+ return blockChanged
140
+ ? new Slice(content, 0, 0)
141
+ : new Slice(content, slice.openStart, slice.openEnd);
142
+ }
143
+ }
144
+ })
145
+ ];
146
+ }
147
+ });
@@ -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 = resizeMeta.kind !== 'image' && Boolean(targetParent);
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(105deg, transparent 20%, rgba(255, 255, 255, 0.36), transparent 80%);
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 = [
@@ -92,6 +94,7 @@
92
94
  allowedTags: sanitizeHtml.defaults.allowedTags.concat([
93
95
  'img',
94
96
  'math-inline',
97
+ 'math-display',
95
98
  'math-node',
96
99
  'iframe',
97
100
  'lite-youtube',
@@ -154,6 +157,9 @@
154
157
  Promise.all([import('./tiptap'), import('@justinribeiro/lite-youtube')]).then(
155
158
  ([{ default: tt }]) => {
156
159
  if (!untrack(() => mounted)) return;
160
+ const initialBody = untrack(() => san(body));
161
+ body = initialBody;
162
+ last = initialBody;
157
163
  const editorPlaceholder = placeholder ?? scopedI18n('placeholder');
158
164
  const optionPlugins = Array.isArray(options.plugins)
159
165
  ? [...options.plugins]
@@ -164,7 +170,7 @@
164
170
  const resizeOptions = typeof resize === 'object' ? resize : {};
165
171
  optionPlugins.unshift(MediaResize.configure(resizeOptions));
166
172
  }
167
- tiptap.v = ref = tt(element, r, {
173
+ tiptap.v = ref = tt(element, initialBody, {
168
174
  placeholder: editorPlaceholder,
169
175
  editable,
170
176
  onTransaction: () => {
@@ -24,6 +24,7 @@ import Embed from '../plugin/embed';
24
24
  import UploadSkeleton from '../plugin/upload/skeleton';
25
25
  // @ts-ignore
26
26
  import { MathInline, MathBlock } from '@seorii/prosemirror-math/tiptap';
27
+ import MathPaste from '../plugin/mathPaste';
27
28
  import Youtube from '../plugin/youtube';
28
29
  import Placeholder from '@tiptap/extension-placeholder';
29
30
  import columns from '../plugin/columns';
@@ -240,6 +241,7 @@ const extensions = (placeholder, plugins, crossorigin, codeBlockLanguageLabels)
240
241
  orderedlist,
241
242
  MathInline,
242
243
  MathBlock,
244
+ MathPaste,
243
245
  ...columns,
244
246
  table,
245
247
  tableHeader,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seorii/tiptap",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
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": "^9.39.3",
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.53.0",
20
+ "@sveltejs/kit": "^2.61.0",
21
21
  "@sveltejs/package": "^2.5.7",
22
- "@sveltejs/vite-plugin-svelte": "6.2.4",
23
- "@types/sanitize-html": "^2.16.0",
24
- "@typescript-eslint/eslint-plugin": "^8.56.0",
25
- "@typescript-eslint/parser": "^8.56.0",
26
- "eslint": "^9.39.3",
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.15.0",
28
+ "eslint-plugin-svelte": "^3.17.1",
29
29
  "gh-pages": "^6.3.0",
30
- "globals": "^17.3.0",
30
+ "globals": "^17.6.0",
31
31
  "highlight.js": "^11.11.1",
32
- "prettier": "^3.8.1",
33
- "prettier-plugin-svelte": "^3.5.0",
34
- "publint": "^0.3.17",
35
- "svelte": "^5.53.2",
36
- "svelte-check": "^4.4.3",
37
- "svelte-eslint-parser": "^1.4.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": "^5.9.3",
40
- "vite": "^7.3.1"
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.1",
84
+ "svelte-awesome-color-picker": "^4.1.2",
85
85
  "svelte-tiptap": "^2",
86
86
  "tippy.js": "^6.3.7"
87
87
  },