@seorii/tiptap 0.3.0-next.8 → 0.3.0

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.
Files changed (45) hide show
  1. package/dist/i18n/index.d.ts +106 -6
  2. package/dist/i18n/index.js +56 -11
  3. package/dist/plugin/command/emoji.d.ts +3 -17
  4. package/dist/plugin/command/emoji.js +51 -24
  5. package/dist/plugin/command/stores.svelte.d.ts +52 -0
  6. package/dist/plugin/command/stores.svelte.js +69 -0
  7. package/dist/plugin/command/suggest.d.ts +6 -19
  8. package/dist/plugin/command/suggest.js +133 -51
  9. package/dist/plugin/embed.d.ts +2 -2
  10. package/dist/plugin/embed.js +5 -1
  11. package/dist/plugin/image/dragdrop.d.ts +2 -0
  12. package/dist/plugin/image/dragdrop.js +66 -2
  13. package/dist/plugin/image/index.js +3 -2
  14. package/dist/plugin/indent.js +0 -1
  15. package/dist/plugin/orderedlist/index.d.ts +1 -1
  16. package/dist/plugin/orderedlist/index.js +1 -1
  17. package/dist/plugin/orderedlist/{korean.scss → korean.css} +2 -2
  18. package/dist/plugin/table/index.d.ts +1 -1
  19. package/dist/plugin/table/index.js +19 -11
  20. package/dist/plugin/table/style/{cell.scss → cell.css} +6 -5
  21. package/dist/plugin/table/style/{grip.scss → grip.css} +14 -19
  22. package/dist/plugin/table/style/resize.css +28 -0
  23. package/dist/plugin/table/style/{table.scss → table.css} +15 -17
  24. package/dist/plugin/table/style.css +4 -0
  25. package/dist/plugin/table/tableCell/index.js +2 -4
  26. package/dist/plugin/table/tableHeader/index.js +1 -2
  27. package/dist/tiptap/Bubble.svelte +106 -71
  28. package/dist/tiptap/Bubble.svelte.d.ts +8 -6
  29. package/dist/tiptap/Command.svelte +160 -158
  30. package/dist/tiptap/Command.svelte.d.ts +2 -3
  31. package/dist/tiptap/Floating.svelte +51 -24
  32. package/dist/tiptap/Floating.svelte.d.ts +1 -0
  33. package/dist/tiptap/TipTap.svelte +215 -135
  34. package/dist/tiptap/TipTap.svelte.d.ts +7 -3
  35. package/dist/tiptap/ToolbarButton.svelte +30 -10
  36. package/dist/tiptap/ToolbarButton.svelte.d.ts +10 -6
  37. package/dist/tiptap/setMath.d.ts +2 -1
  38. package/dist/tiptap/setMath.js +74 -12
  39. package/dist/tiptap/tiptap.d.ts +9 -1
  40. package/dist/tiptap/tiptap.js +170 -16
  41. package/package.json +63 -57
  42. package/dist/plugin/command/stores.d.ts +0 -13
  43. package/dist/plugin/command/stores.js +0 -7
  44. package/dist/plugin/table/style/resize.scss +0 -26
  45. package/dist/plugin/table/style.scss +0 -4
@@ -1,19 +1,16 @@
1
- $grip-margin: 3px;
2
-
3
1
  .ProseMirror table {
4
- .grip-column {
2
+ & .grip-column {
5
3
  position: absolute;
6
4
  top: -0.7em;
7
5
  left: 0;
8
6
  z-index: 10;
9
7
  display: block;
10
- width: calc(100% - 2 * #{$grip-margin});
8
+ width: calc(100% - 6px);
11
9
  height: 0.4em;
12
- margin: 0 $grip-margin 3px $grip-margin;
10
+ margin: 0 3px 3px 3px;
13
11
  background: var(--primary-light3);
14
12
  opacity: 0;
15
13
  border-radius: 10px;
16
-
17
14
  transition: all 0.1s ease-in-out;
18
15
 
19
16
  &:hover,
@@ -22,19 +19,18 @@ $grip-margin: 3px;
22
19
  }
23
20
  }
24
21
 
25
- .grip-row {
22
+ & .grip-row {
26
23
  position: absolute;
27
24
  top: 0;
28
25
  left: -0.7em;
29
26
  z-index: 10;
30
27
  display: block;
31
28
  width: 0.4em;
32
- height: calc(100% - 2 * #{$grip-margin});
33
- margin: $grip-margin 3px $grip-margin 0;
29
+ height: calc(100% - 6px);
30
+ margin: 3px 3px 3px 0;
34
31
  background: var(--primary-light3);
35
32
  opacity: 0;
36
33
  border-radius: 10px;
37
-
38
34
  transition: all 0.1s ease-in-out;
39
35
 
40
36
  &:hover,
@@ -43,7 +39,7 @@ $grip-margin: 3px;
43
39
  }
44
40
  }
45
41
 
46
- .grip-table {
42
+ & .grip-table {
47
43
  position: absolute;
48
44
  top: -0.8em;
49
45
  left: -0.8em;
@@ -54,7 +50,6 @@ $grip-margin: 3px;
54
50
  background: var(--primary-light3);
55
51
  border-radius: 50%;
56
52
  opacity: 0;
57
-
58
53
  transition: all 0.1s ease-in-out;
59
54
 
60
55
  &:hover,
@@ -62,13 +57,13 @@ $grip-margin: 3px;
62
57
  background: var(--primary-light6);
63
58
  }
64
59
  }
60
+ }
65
61
 
66
- .editable & {
67
- .grip-column,
68
- .grip-row,
69
- .grip-table {
70
- opacity: 1;
71
- cursor: pointer;
72
- }
62
+ .editable .ProseMirror table {
63
+ & .grip-column,
64
+ & .grip-row,
65
+ & .grip-table {
66
+ opacity: 1;
67
+ cursor: pointer;
73
68
  }
74
69
  }
@@ -0,0 +1,28 @@
1
+ .ProseMirror {
2
+ & table .column-resize-handle {
3
+ position: absolute;
4
+ top: 0;
5
+ right: -2px;
6
+ bottom: -2px;
7
+ width: 4px;
8
+ pointer-events: none;
9
+ background-color: var(--primary-light6);
10
+ opacity: 0;
11
+ }
12
+
13
+ &.resize-cursor {
14
+ pointer-events: none;
15
+ }
16
+ }
17
+
18
+ .editable .ProseMirror {
19
+ & table .column-resize-handle {
20
+ opacity: 1;
21
+ }
22
+
23
+ &.resize-cursor {
24
+ pointer-events: initial;
25
+ cursor: ew-resize;
26
+ cursor: col-resize; /* stylelint-disable declaration-block-no-duplicate-properties */
27
+ }
28
+ }
@@ -1,5 +1,5 @@
1
1
  .ProseMirror {
2
- .tableWrapper {
2
+ & .tableWrapper {
3
3
  position: relative;
4
4
  margin-top: 0.75em;
5
5
  scrollbar-width: thin;
@@ -7,7 +7,7 @@
7
7
  transition: all 0.1s ease-in-out;
8
8
  }
9
9
 
10
- .scrollable {
10
+ & .scrollable {
11
11
  padding-left: 1em;
12
12
  margin-left: -1em;
13
13
  overflow: auto hidden;
@@ -16,7 +16,7 @@
16
16
  transition: border 250ms ease-in-out 0s;
17
17
  }
18
18
 
19
- .scrollable-shadow {
19
+ & .scrollable-shadow {
20
20
  position: absolute;
21
21
  top: 0;
22
22
  bottom: 0;
@@ -52,17 +52,17 @@
52
52
  }
53
53
  }
54
54
 
55
- table {
55
+ & table {
56
56
  margin-top: 1em;
57
57
  border-radius: 4px;
58
58
  border-collapse: collapse;
59
59
  box-sizing: border-box;
60
60
  width: 100% !important;
61
61
 
62
- h1,
63
- h2,
64
- h3,
65
- p {
62
+ & h1,
63
+ & h2,
64
+ & h3,
65
+ & p {
66
66
  margin: 0;
67
67
  }
68
68
 
@@ -72,15 +72,13 @@
72
72
  }
73
73
  }
74
74
 
75
- .editable {
76
- .ProseMirror {
77
- .tableWrapper {
78
- padding: 10px;
79
- }
75
+ .editable .ProseMirror {
76
+ & .tableWrapper {
77
+ padding: 10px;
78
+ }
80
79
 
81
- .selectedCell {
82
- border-style: double;
83
- background: var(--primary-light3);
84
- }
80
+ & .selectedCell {
81
+ border-style: double;
82
+ background: var(--primary-light3);
85
83
  }
86
84
  }
@@ -0,0 +1,4 @@
1
+ @import './style/grip.css';
2
+ @import './style/table.css';
3
+ @import './style/cell.css';
4
+ @import './style/resize.css';
@@ -18,14 +18,12 @@ export default BuiltInTableCell.extend({
18
18
  };
19
19
  },
20
20
  addProseMirrorPlugins() {
21
- const { isEditable } = this.editor;
22
21
  return [
23
22
  new Plugin({
24
23
  props: {
25
24
  decorations: (state) => {
26
- if (!isEditable) {
27
- //return DecorationSet.empty;
28
- }
25
+ if (!this.editor.isEditable)
26
+ return DecorationSet.empty;
29
27
  const { doc, selection } = state;
30
28
  const decorations = [];
31
29
  const cells = getCellsInColumn(0)(selection);
@@ -18,12 +18,11 @@ export default BuiltInTableHeader.extend({
18
18
  };
19
19
  },
20
20
  addProseMirrorPlugins() {
21
- const { isEditable } = this.editor;
22
21
  return [
23
22
  new Plugin({
24
23
  props: {
25
24
  decorations: (state) => {
26
- if (!isEditable)
25
+ if (!this.editor.isEditable)
27
26
  return DecorationSet.empty;
28
27
  const { doc, selection } = state;
29
28
  const decorations = [];
@@ -1,29 +1,43 @@
1
1
  <script lang="ts">
2
2
  import { BubbleMenu } from 'svelte-tiptap';
3
- import { getContext, tick } from 'svelte';
3
+ import { flushSync, getContext, tick, untrack } from 'svelte';
4
4
  import 'tippy.js/animations/shift-away-subtle.css';
5
5
  import ToolbarButton from './ToolbarButton.svelte';
6
6
  import { isTableAnySelected } from '../plugin/table/util';
7
7
  import deleteTable from '../plugin/table/deleteTable';
8
8
  import setMath from './setMath';
9
9
  import { Button, Icon, IconButton, Input, List, OneLine, Paper, Render } from 'nunui';
10
- import i18n from '../i18n';
10
+ import defaultI18n, { I18N_CONTEXT, type I18nTranslate } from '../i18n';
11
11
  import ColorPicker from 'svelte-awesome-color-picker';
12
12
  import { isTextSelection } from '@tiptap/core';
13
+ import type { EditorState, Selection } from '@tiptap/pm/state';
14
+ import type { EditorView } from '@tiptap/pm/view';
13
15
 
14
- let { colors = [], editable, override, children } = $props();
16
+ type Props = {
17
+ colors?: string[];
18
+ editable?: boolean;
19
+ override?: any;
20
+ children?: any;
21
+ };
22
+
23
+ let { colors = [], editable, override, children }: Props = $props();
15
24
 
16
- const editor = getContext<{ v: any }>('editor');
25
+ const editor = getContext<{ v: any; c: number }>('editor');
26
+ const i18nFromContext = getContext<I18nTranslate | undefined>(I18N_CONTEXT);
27
+ const i18n: I18nTranslate = (...args) =>
28
+ i18nFromContext ? i18nFromContext(...args) : defaultI18n(...args);
17
29
  const tiptap = $derived(editor.v);
18
30
 
19
- let selection = $state(null);
20
- let table = $state(false);
31
+ let selection = $state<Selection | null>(null);
32
+ let table = $state<number[] | false>(false);
21
33
  let sel = $state('');
22
34
  let _sel = $state('');
23
35
  let link = $state(false);
24
36
  let href = $state('');
25
37
 
26
38
  $effect(() => {
39
+ let _ = editor.c;
40
+ flushSync();
27
41
  selection = tiptap?.state?.selection;
28
42
  });
29
43
 
@@ -44,16 +58,30 @@
44
58
  });
45
59
 
46
60
  $effect(() => {
47
- if (tiptap && link) {
48
- if (href) {
49
- tiptap.chain().setLink({ href }).run();
50
- } else if (tiptap.getAttributes('link').href) {
51
- tiptap.chain().unsetLink().run();
61
+ const _href = href;
62
+ untrack(() => {
63
+ if (tiptap && link) {
64
+ if (href) {
65
+ tiptap.chain().setLink({ href: _href }).run();
66
+ } else if (tiptap.getAttributes('link').href) {
67
+ tiptap.chain().unsetLink().run();
68
+ }
52
69
  }
53
- }
70
+ });
54
71
  });
55
72
 
56
- const shouldShow = ({ view, state, from, to }) => {
73
+ const shouldShow = ({
74
+ state,
75
+ from,
76
+ to
77
+ }: {
78
+ view: EditorView;
79
+ state: EditorState;
80
+ from: number;
81
+ to: number;
82
+ }) => {
83
+ if (!tiptap?.isEditable) return false;
84
+
57
85
  const { doc, selection } = state;
58
86
  const { empty } = selection;
59
87
 
@@ -86,10 +114,10 @@
86
114
  <Icon icon="link" />
87
115
  {i18n('link')}
88
116
  </p>
89
- <Input placeholder="url" fullWidth bind:value={href} autofocus />
117
+ <Input placeholder="url" bind:value={href} autofocus />
90
118
  <div>
91
119
  <Button
92
- tabindex="0"
120
+ tabindex={0}
93
121
  transparent
94
122
  small
95
123
  onclick={() => {
@@ -99,7 +127,7 @@
99
127
  }}
100
128
  >{i18n('delete')}
101
129
  </Button>
102
- <Button tabindex="0" transparent small onclick={() => (link = false)}
130
+ <Button tabindex={0} transparent small onclick={() => (link = false)}
103
131
  >{i18n('close')}</Button
104
132
  >
105
133
  </div>
@@ -171,7 +199,7 @@
171
199
  <ToolbarButton icon="subscript" prop="subscript" />
172
200
  <ToolbarButton icon="border_color" prop="highlight" />
173
201
  {#if editable}
174
- <ToolbarButton icon="functions" handler={() => setMath(tiptap)} />
202
+ <ToolbarButton icon="functions" prop="math_inline" handler={() => setMath(tiptap)} />
175
203
  {/if}
176
204
  <Paper bl block>
177
205
  {#snippet target()}
@@ -190,10 +218,13 @@
190
218
  outlined
191
219
  onclick={() => tiptap.chain().focus().unsetColor().run()}
192
220
  >
193
- <Icon colorize />
221
+ <Icon icon="palette" />
194
222
  </Button>
195
223
  {/snippet}
196
- <div onclick={(event) => event.stopPropagation()} onmousedown={(event) => event.stopPropagation()}>
224
+ <div
225
+ onclick={(event) => event.stopPropagation()}
226
+ onmousedown={(event) => event.stopPropagation()}
227
+ >
197
228
  <ColorPicker
198
229
  isDialog={false}
199
230
  onInput={(event) => {
@@ -208,10 +239,7 @@
208
239
  outlined
209
240
  onclick={() => tiptap.chain().focus().setColor(color).run()}
210
241
  >
211
- <span
212
- style:background={color}
213
- class="pal"
214
- ></span>
242
+ <span style:background={color} class="pal"></span>
215
243
  </Button>
216
244
  {/each}
217
245
  </div>
@@ -228,54 +256,61 @@
228
256
  </BubbleMenu>
229
257
  {/if}
230
258
 
231
- <style>main {
232
- box-shadow: var(--shadow);
233
- background: var(--surface, #fff);
234
- color: var(--on-surface, #000);
235
- padding: 8px;
236
- border-radius: 4px;
237
- display: flex;
238
- align-items: center;
239
- justify-content: center;
240
- font-size: 1.2em;
241
- }
242
- main > :global(*) {
243
- margin: 0 2px;
244
- }
245
- main > :global(*):first-child {
246
- margin-left: 0;
247
- }
248
- main > :global(*):last-child {
249
- margin-right: 0;
250
- }
259
+ <style>
260
+ main {
261
+ box-shadow: var(--shadow);
262
+ background: var(--surface, #fff);
263
+ color: var(--on-surface, #000);
264
+ padding: 8px;
265
+ border-radius: 4px;
266
+ display: flex;
267
+ align-items: center;
268
+ justify-content: center;
269
+ font-size: 1.2em;
270
+ & > :global(*) {
271
+ margin: 0 2px;
272
+ }
273
+
274
+ & > :global(*:first-child) {
275
+ margin-left: 0;
276
+ }
277
+
278
+ & > :global(*:last-child) {
279
+ margin-right: 0;
280
+ }
281
+ }
282
+
283
+ .link {
284
+ display: flex;
285
+ flex-direction: column;
286
+ font-size: 0.7em;
287
+
288
+ & p {
289
+ margin: 0 0 0.6em 0;
290
+ }
291
+
292
+ & div {
293
+ margin-top: 0.6em;
294
+ display: flex;
295
+ justify-content: flex-end;
296
+ }
297
+ }
251
298
 
252
- .link {
253
- display: flex;
254
- flex-direction: column;
255
- font-size: 0.7em;
256
- }
257
- .link p {
258
- margin: 0 0 0.6em 0;
259
- }
260
- .link div {
261
- margin-top: 0.6em;
262
- display: flex;
263
- justify-content: flex-end;
264
- }
299
+ .colors {
300
+ display: grid;
301
+ grid-template-columns: 1fr 1fr 1fr;
302
+ gap: 4px;
265
303
 
266
- .colors {
267
- display: grid;
268
- grid-template-columns: 1fr 1fr 1fr;
269
- gap: 4px;
270
- }
271
- .colors > :global(:first-child) {
272
- grid-column: 1/3;
273
- }
304
+ & > :global(:first-child) {
305
+ grid-column: 1/3;
306
+ }
307
+ }
274
308
 
275
- .pal {
276
- width: 20px;
277
- height: 16px;
278
- border-radius: 4px;
279
- display: inline-block;
280
- margin-bottom: -2px;
281
- }</style>
309
+ .pal {
310
+ width: 20px;
311
+ height: 16px;
312
+ border-radius: 4px;
313
+ display: inline-block;
314
+ margin-bottom: -2px;
315
+ }
316
+ </style>
@@ -1,8 +1,10 @@
1
1
  import 'tippy.js/animations/shift-away-subtle.css';
2
- declare const Bubble: import("svelte").Component<{
3
- colors?: unknown;
4
- editable: unknown;
5
- override: unknown;
6
- children: unknown;
7
- }, {}, "">;
2
+ type Props = {
3
+ colors?: string[];
4
+ editable?: boolean;
5
+ override?: any;
6
+ children?: any;
7
+ };
8
+ declare const Bubble: import("svelte").Component<Props, {}, "">;
9
+ type Bubble = ReturnType<typeof Bubble>;
8
10
  export default Bubble;