tiptapify 0.4.0 → 0.4.1
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/tiptapify.css +1 -1
- package/dist/tiptapify.mjs +2 -2
- package/dist/tiptapify.umd.js +1 -1
- package/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/extensions/components/media/image/imageDialog.test.ts +10 -0
- package/src/extensions/components/media/image/imageDialog.ts +6 -3
- package/src/index.ts +2 -0
package/index.d.ts
CHANGED
|
@@ -360,6 +360,9 @@ export type {
|
|
|
360
360
|
|
|
361
361
|
export type { TiptapifyConfig }
|
|
362
362
|
|
|
363
|
+
/** The logic of the image dialog, for a host that replaces the dialog with its own */
|
|
364
|
+
export * as imageDialog from './src/extensions/components/media/image/imageDialog'
|
|
365
|
+
|
|
363
366
|
declare module '@vue/runtime-core' {
|
|
364
367
|
interface GlobalComponents {
|
|
365
368
|
Tiptapify: typeof Tiptapify
|
package/package.json
CHANGED
|
@@ -140,6 +140,16 @@ describe('image dialog apply', () => {
|
|
|
140
140
|
expect(selectedImageAttrs(editor!.state)).toMatchObject({ src: 'https://example.com/a.png', width: 640 })
|
|
141
141
|
})
|
|
142
142
|
|
|
143
|
+
it('reads a node selection made by another copy of prosemirror-state', () => {
|
|
144
|
+
createEditor('<p>Text</p><img src="https://example.com/a.png" width="640">')
|
|
145
|
+
const { from, to } = editor!.state.selection
|
|
146
|
+
const node = editor!.state.doc.nodeAt(6)
|
|
147
|
+
const foreignSelection = { from, to, node }
|
|
148
|
+
const state = { ...editor!.state, selection: foreignSelection } as unknown as Parameters<typeof selectedImageAttrs>[0]
|
|
149
|
+
|
|
150
|
+
expect(selectedImageAttrs(state)).toMatchObject({ src: 'https://example.com/a.png', width: 640 })
|
|
151
|
+
})
|
|
152
|
+
|
|
143
153
|
it('sends the selected image to the dialog, or none to insert one', () => {
|
|
144
154
|
createEditor('<p>Text</p><img src="https://example.com/a.png">')
|
|
145
155
|
const details: Array<{ image: Record<string, unknown> | null }> = []
|
|
@@ -5,6 +5,8 @@ import { ImageAlign } from '@tiptapify/extensions/components/media/image/caption
|
|
|
5
5
|
|
|
6
6
|
export { resizeSide, toSize }
|
|
7
7
|
|
|
8
|
+
export type { ImageAlign }
|
|
9
|
+
|
|
8
10
|
export type ImageSizeMode = 'original' | 'text' | 'custom'
|
|
9
11
|
|
|
10
12
|
export type ImageSize = MediaSize
|
|
@@ -27,12 +29,13 @@ const typeName = 'image'
|
|
|
27
29
|
* The attributes of the image selected as a node, or null when no image is selected (the dialog inserts one).
|
|
28
30
|
*/
|
|
29
31
|
export function selectedImageAttrs(state: EditorState): Record<string, unknown> | null {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
// Not instanceof: a host that imports this module from the source runs another copy of prosemirror-state than the editor
|
|
33
|
+
const { node } = state.selection as Partial<NodeSelection>
|
|
34
|
+
if (node?.type.name !== typeName) {
|
|
32
35
|
return null
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
return { ...
|
|
38
|
+
return { ...node.attrs }
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
/**
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { TiptapifyFooterAlignment } from '@tiptapify/types/editor'
|
|
|
6
6
|
import { createAiBackendProvider } from '@tiptapify/extensions/components/ai/backend'
|
|
7
7
|
import { registerSkin, defineSkin } from '@tiptapify/skins/registry'
|
|
8
8
|
import { contentCss, inlineContentStyles } from '@tiptapify/utils/contentStyles'
|
|
9
|
+
import * as imageDialog from '@tiptapify/extensions/components/media/image/imageDialog'
|
|
9
10
|
|
|
10
11
|
import { Editor as TipTapEditor, nodeViewProps, NodeViewWrapper, VueNodeViewRenderer } from '@tiptap/vue-3'
|
|
11
12
|
import { Node, Mark, markInputRule, markPasteRule, mergeAttributes } from '@tiptap/core'
|
|
@@ -55,6 +56,7 @@ export {
|
|
|
55
56
|
defineSkin,
|
|
56
57
|
contentCss,
|
|
57
58
|
inlineContentStyles,
|
|
59
|
+
imageDialog,
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export type { TiptapifyConfig } from '@tiptapify/composables/useTiptapifyConfig'
|