@tiptap/extension-emoji 2.24.2 → 3.0.0-beta.11
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/LICENSE.md +21 -0
- package/dist/index.cjs +19695 -31890
- package/dist/index.cjs.map +1 -1
- package/dist/{emoji.d.ts → index.d.cts} +18 -8
- package/dist/index.d.ts +77 -7
- package/dist/index.js +19662 -31874
- package/dist/index.js.map +1 -1
- package/package.json +15 -13
- package/src/data.ts +3949 -16136
- package/src/emoji.ts +73 -77
- package/src/generate.ts +4 -9
- package/src/helpers/emojiToShortcode.ts +1 -1
- package/src/helpers/removeDuplicates.ts +1 -3
- package/src/helpers/shortcodeToEmoji.ts +1 -1
- package/dist/data.d.ts +0 -5
- package/dist/data.d.ts.map +0 -1
- package/dist/emoji.d.ts.map +0 -1
- package/dist/helpers/emojiToShortcode.d.ts +0 -3
- package/dist/helpers/emojiToShortcode.d.ts.map +0 -1
- package/dist/helpers/removeDuplicates.d.ts +0 -9
- package/dist/helpers/removeDuplicates.d.ts.map +0 -1
- package/dist/helpers/removeVariationSelector.d.ts +0 -2
- package/dist/helpers/removeVariationSelector.d.ts.map +0 -1
- package/dist/helpers/shortcodeToEmoji.d.ts +0 -3
- package/dist/helpers/shortcodeToEmoji.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -31912
- package/dist/index.umd.js.map +0 -1
package/src/emoji.ts
CHANGED
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
nodeInputRule,
|
|
10
10
|
PasteRule,
|
|
11
11
|
} from '@tiptap/core'
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
12
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
13
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
14
|
+
import type { SuggestionOptions } from '@tiptap/suggestion'
|
|
15
|
+
import Suggestion from '@tiptap/suggestion'
|
|
14
16
|
import emojiRegex from 'emoji-regex'
|
|
15
17
|
import { isEmojiSupported } from 'is-emoji-supported'
|
|
16
18
|
|
|
@@ -25,7 +27,7 @@ declare module '@tiptap/core' {
|
|
|
25
27
|
/**
|
|
26
28
|
* Add an emoji
|
|
27
29
|
*/
|
|
28
|
-
setEmoji: (shortcode: string) => ReturnType
|
|
30
|
+
setEmoji: (shortcode: string) => ReturnType
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -34,52 +36,52 @@ export type EmojiItem = {
|
|
|
34
36
|
/**
|
|
35
37
|
* A unique name of the emoji which will be stored as attribute
|
|
36
38
|
*/
|
|
37
|
-
name: string
|
|
39
|
+
name: string
|
|
38
40
|
/**
|
|
39
41
|
* The emoji unicode character
|
|
40
42
|
*/
|
|
41
|
-
emoji?: string
|
|
43
|
+
emoji?: string
|
|
42
44
|
/**
|
|
43
45
|
* A list of unique shortcodes that are used by input rules to find the emoji
|
|
44
46
|
*/
|
|
45
|
-
shortcodes: string[]
|
|
47
|
+
shortcodes: string[]
|
|
46
48
|
/**
|
|
47
49
|
* A list of tags that can help for searching emojis
|
|
48
50
|
*/
|
|
49
|
-
tags: string[]
|
|
51
|
+
tags: string[]
|
|
50
52
|
/**
|
|
51
53
|
* A name that can help to group emojis
|
|
52
54
|
*/
|
|
53
|
-
group?: string
|
|
55
|
+
group?: string
|
|
54
56
|
/**
|
|
55
57
|
* A list of unique emoticons
|
|
56
58
|
*/
|
|
57
|
-
emoticons?: string[]
|
|
59
|
+
emoticons?: string[]
|
|
58
60
|
/**
|
|
59
61
|
* The unicode version the emoji was introduced
|
|
60
62
|
*/
|
|
61
|
-
version?: number
|
|
63
|
+
version?: number
|
|
62
64
|
/**
|
|
63
65
|
* A fallback image if the current system doesn't support the emoji or for custom emojis
|
|
64
66
|
*/
|
|
65
|
-
fallbackImage?: string
|
|
67
|
+
fallbackImage?: string
|
|
66
68
|
/**
|
|
67
69
|
* Store some custom data
|
|
68
70
|
*/
|
|
69
|
-
[key: string]: any
|
|
71
|
+
[key: string]: any
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export type EmojiOptions = {
|
|
73
|
-
HTMLAttributes: Record<string, any
|
|
74
|
-
emojis: EmojiItem[]
|
|
75
|
-
enableEmoticons: boolean
|
|
76
|
-
forceFallbackImages: boolean
|
|
77
|
-
suggestion: Omit<SuggestionOptions, 'editor'
|
|
75
|
+
HTMLAttributes: Record<string, any>
|
|
76
|
+
emojis: EmojiItem[]
|
|
77
|
+
enableEmoticons: boolean
|
|
78
|
+
forceFallbackImages: boolean
|
|
79
|
+
suggestion: Omit<SuggestionOptions, 'editor'>
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
export type EmojiStorage = {
|
|
81
|
-
emojis: EmojiItem[]
|
|
82
|
-
isSupported: (item: EmojiItem) => boolean
|
|
83
|
+
emojis: EmojiItem[]
|
|
84
|
+
isSupported: (item: EmojiItem) => boolean
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
export const EmojiSuggestionPluginKey = new PluginKey('emojiSuggestion')
|
|
@@ -155,18 +157,14 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
155
157
|
|
|
156
158
|
return {
|
|
157
159
|
...versions,
|
|
158
|
-
[version as number]: emoji
|
|
159
|
-
? isEmojiSupported(emoji.emoji as string)
|
|
160
|
-
: false,
|
|
160
|
+
[version as number]: emoji ? isEmojiSupported(emoji.emoji as string) : false,
|
|
161
161
|
}
|
|
162
162
|
}, {})
|
|
163
163
|
|
|
164
164
|
return {
|
|
165
165
|
emojis: this.options.emojis,
|
|
166
166
|
isSupported: emojiItem => {
|
|
167
|
-
return emojiItem.version
|
|
168
|
-
? supportMap[emojiItem.version]
|
|
169
|
-
: false
|
|
167
|
+
return emojiItem.version ? supportMap[emojiItem.version] : false
|
|
170
168
|
},
|
|
171
169
|
}
|
|
172
170
|
},
|
|
@@ -193,43 +191,35 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
193
191
|
|
|
194
192
|
renderHTML({ HTMLAttributes, node }) {
|
|
195
193
|
const emojiItem = shortcodeToEmoji(node.attrs.name, this.options.emojis)
|
|
196
|
-
const attributes = mergeAttributes(
|
|
197
|
-
HTMLAttributes,
|
|
198
|
-
this.options.HTMLAttributes,
|
|
199
|
-
{ 'data-type': this.name },
|
|
200
|
-
)
|
|
194
|
+
const attributes = mergeAttributes(HTMLAttributes, this.options.HTMLAttributes, { 'data-type': this.name })
|
|
201
195
|
|
|
202
196
|
if (!emojiItem) {
|
|
203
|
-
return [
|
|
204
|
-
'span',
|
|
205
|
-
attributes,
|
|
206
|
-
`:${node.attrs.name}:`,
|
|
207
|
-
]
|
|
197
|
+
return ['span', attributes, `:${node.attrs.name}:`]
|
|
208
198
|
}
|
|
209
199
|
|
|
210
200
|
const isSupported = this.storage.isSupported(emojiItem)
|
|
211
201
|
const hasEmoji = !!emojiItem?.emoji
|
|
212
202
|
const hasFallbackImage = !!emojiItem?.fallbackImage
|
|
213
203
|
|
|
214
|
-
const renderFallbackImage =
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
204
|
+
const renderFallbackImage =
|
|
205
|
+
(this.options.forceFallbackImages && !hasEmoji) ||
|
|
206
|
+
(this.options.forceFallbackImages && hasFallbackImage) ||
|
|
207
|
+
(this.options.forceFallbackImages && !isSupported && hasFallbackImage) ||
|
|
208
|
+
((!isSupported || !hasEmoji) && hasFallbackImage)
|
|
218
209
|
|
|
219
210
|
return [
|
|
220
211
|
'span',
|
|
221
212
|
attributes,
|
|
222
213
|
renderFallbackImage
|
|
223
214
|
? [
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
]
|
|
215
|
+
'img',
|
|
216
|
+
{
|
|
217
|
+
src: emojiItem.fallbackImage,
|
|
218
|
+
draggable: 'false',
|
|
219
|
+
loading: 'lazy',
|
|
220
|
+
align: 'absmiddle',
|
|
221
|
+
},
|
|
222
|
+
]
|
|
233
223
|
: emojiItem.emoji || `:${emojiItem.shortcodes[0]}:`,
|
|
234
224
|
]
|
|
235
225
|
},
|
|
@@ -242,27 +232,30 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
242
232
|
|
|
243
233
|
addCommands() {
|
|
244
234
|
return {
|
|
245
|
-
setEmoji:
|
|
246
|
-
|
|
235
|
+
setEmoji:
|
|
236
|
+
shortcode =>
|
|
237
|
+
({ chain }) => {
|
|
238
|
+
const emojiItem = shortcodeToEmoji(shortcode, this.options.emojis)
|
|
247
239
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
240
|
+
if (!emojiItem) {
|
|
241
|
+
return false
|
|
242
|
+
}
|
|
251
243
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
244
|
+
chain()
|
|
245
|
+
.insertContent({
|
|
246
|
+
type: this.name,
|
|
247
|
+
attrs: {
|
|
248
|
+
name: emojiItem.name,
|
|
249
|
+
},
|
|
250
|
+
})
|
|
251
|
+
.command(({ tr, state }) => {
|
|
252
|
+
tr.setStoredMarks(state.doc.resolve(state.selection.to - 1).marks())
|
|
253
|
+
return true
|
|
254
|
+
})
|
|
255
|
+
.run()
|
|
263
256
|
|
|
264
|
-
|
|
265
|
-
|
|
257
|
+
return true
|
|
258
|
+
},
|
|
266
259
|
}
|
|
267
260
|
},
|
|
268
261
|
|
|
@@ -289,7 +282,8 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
289
282
|
.command(({ tr, state }) => {
|
|
290
283
|
tr.setStoredMarks(state.doc.resolve(state.selection.to - 1).marks())
|
|
291
284
|
return true
|
|
292
|
-
})
|
|
285
|
+
})
|
|
286
|
+
.run()
|
|
293
287
|
},
|
|
294
288
|
}),
|
|
295
289
|
)
|
|
@@ -337,14 +331,18 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
337
331
|
}
|
|
338
332
|
|
|
339
333
|
chain()
|
|
340
|
-
.insertContentAt(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
name,
|
|
334
|
+
.insertContentAt(
|
|
335
|
+
range,
|
|
336
|
+
{
|
|
337
|
+
type: this.name,
|
|
338
|
+
attrs: {
|
|
339
|
+
name,
|
|
340
|
+
},
|
|
344
341
|
},
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
342
|
+
{
|
|
343
|
+
updateSelection: false,
|
|
344
|
+
},
|
|
345
|
+
)
|
|
348
346
|
.command(({ tr, state }) => {
|
|
349
347
|
tr.setStoredMarks(state.doc.resolve(state.selection.to - 1).marks())
|
|
350
348
|
return true
|
|
@@ -386,8 +384,7 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
386
384
|
|
|
387
385
|
// replace text emojis with emoji node on any change
|
|
388
386
|
appendTransaction: (transactions, oldState, newState) => {
|
|
389
|
-
const docChanges = transactions.some(transaction => transaction.docChanged)
|
|
390
|
-
&& !oldState.doc.eq(newState.doc)
|
|
387
|
+
const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)
|
|
391
388
|
|
|
392
389
|
if (!docChanges) {
|
|
393
390
|
return
|
|
@@ -444,7 +441,6 @@ export const Emoji = Node.create<EmojiOptions, EmojiStorage>({
|
|
|
444
441
|
tr.replaceRangeWith(from, to, emojiNode)
|
|
445
442
|
|
|
446
443
|
tr.setStoredMarks(newState.doc.resolve(from).marks())
|
|
447
|
-
|
|
448
444
|
})
|
|
449
445
|
})
|
|
450
446
|
})
|
package/src/generate.ts
CHANGED
|
@@ -6,7 +6,7 @@ import gitHubShortcodes from 'emojibase-data/en/shortcodes/github.json'
|
|
|
6
6
|
import fs from 'fs'
|
|
7
7
|
import json5 from 'json5'
|
|
8
8
|
|
|
9
|
-
import { EmojiItem } from './emoji.js'
|
|
9
|
+
import type { EmojiItem } from './emoji.js'
|
|
10
10
|
import { removeVariationSelector } from './helpers/removeVariationSelector.js'
|
|
11
11
|
|
|
12
12
|
const emojis: EmojiItem[] = data
|
|
@@ -16,14 +16,9 @@ const emojis: EmojiItem[] = data
|
|
|
16
16
|
return item.unified === emoji.hexcode || item.non_qualified === emoji.hexcode
|
|
17
17
|
})
|
|
18
18
|
const hasFallbackImage = dataSourceEmoji?.has_img_apple
|
|
19
|
-
const name = [gitHubShortcodes[emoji.hexcode]].flat()[0]
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
? [emojibaseShortcodes[emoji.hexcode]].flat()
|
|
23
|
-
: []
|
|
24
|
-
const emoticons = emoji.emoticon
|
|
25
|
-
? [emoji.emoticon].flat()
|
|
26
|
-
: []
|
|
19
|
+
const name = [gitHubShortcodes[emoji.hexcode]].flat()[0] || [emojibaseShortcodes[emoji.hexcode]].flat()[0]
|
|
20
|
+
const shortcodes = emojibaseShortcodes[emoji.hexcode] ? [emojibaseShortcodes[emoji.hexcode]].flat() : []
|
|
21
|
+
const emoticons = emoji.emoticon ? [emoji.emoticon].flat() : []
|
|
27
22
|
|
|
28
23
|
return {
|
|
29
24
|
emoji: removeVariationSelector(emoji.emoji),
|
|
@@ -8,8 +8,6 @@ export function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {
|
|
|
8
8
|
return array.filter(item => {
|
|
9
9
|
const key = by(item)
|
|
10
10
|
|
|
11
|
-
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
12
|
-
? false
|
|
13
|
-
: (seen[key] = true)
|
|
11
|
+
return Object.prototype.hasOwnProperty.call(seen, key) ? false : (seen[key] = true)
|
|
14
12
|
})
|
|
15
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmojiItem } from '../emoji.js'
|
|
1
|
+
import type { EmojiItem } from '../emoji.js'
|
|
2
2
|
|
|
3
3
|
export function shortcodeToEmoji(shortcode: string, emojis: EmojiItem[]): EmojiItem | undefined {
|
|
4
4
|
return emojis.find(item => shortcode === item.name || item.shortcodes.includes(shortcode))
|
package/dist/data.d.ts
DELETED
package/dist/data.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,eAAO,MAAM,MAAM,EAAE,SAAS,EAmp9B7B,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,SAAS,EA4KzC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,SAAS,EAAuC,CAAA"}
|
package/dist/emoji.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emoji.d.ts","sourceRoot":"","sources":["../src/emoji.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAGL,MAAM,cAAc,CAAA;AACrB,OAAO,EAAU,SAAS,EAAe,MAAM,kBAAkB,CAAA;AACjE,OAAmB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AASlE,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,KAAK,EAAE;YACL;;eAEG;YACH,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC;SAC7C,CAAA;KACF;CACF;AAED,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,UAAU,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;CAC/C,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,WAAW,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC;CAC3C,CAAA;AAED,eAAO,MAAM,wBAAwB,gBAAmC,CAAA;AAExE,eAAO,MAAM,UAAU,QAAyB,CAAA;AAEhD,eAAO,MAAM,UAAU,QAAyB,CAAA;AAEhD,eAAO,MAAM,KAAK,kCAkXhB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emojiToShortcode.d.ts","sourceRoot":"","sources":["../../src/helpers/emojiToShortcode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,GAAG,SAAS,CAEvF"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes duplicated values within an array.
|
|
3
|
-
* Supports numbers, strings and objects.
|
|
4
|
-
*/
|
|
5
|
-
export declare function removeDuplicates<T>(array: T[], by?: {
|
|
6
|
-
(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
7
|
-
(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
|
|
8
|
-
}): T[];
|
|
9
|
-
//# sourceMappingURL=removeDuplicates.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeDuplicates.d.ts","sourceRoot":"","sources":["../../src/helpers/removeDuplicates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE;;;CAAiB,GAAG,CAAC,EAAE,CAUxE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeVariationSelector.d.ts","sourceRoot":"","sources":["../../src/helpers/removeVariationSelector.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shortcodeToEmoji.d.ts","sourceRoot":"","sources":["../../src/helpers/shortcodeToEmoji.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,GAAG,SAAS,CAE9F"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAE7C,eAAe,KAAK,CAAA"}
|