@lofcz/platejs-mention 52.0.15
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 +24 -0
- package/README.md +12 -0
- package/dist/BaseMentionPlugin-uPSCCRSr.js +43 -0
- package/dist/BaseMentionPlugin-uPSCCRSr.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +10 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Ziad Beyens, Dylan Schiemann, Joe Anderson, Felix Feng
|
|
4
|
+
|
|
5
|
+
Unless otherwise specified in a LICENSE file within an individual package directory,
|
|
6
|
+
this license applies to all files in this repository outside of those package directories.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { withTriggerCombobox } from "@platejs/combobox";
|
|
2
|
+
import { KEYS, createSlatePlugin, createTSlatePlugin } from "platejs";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/BaseMentionPlugin.ts
|
|
5
|
+
const BaseMentionInputPlugin = createSlatePlugin({
|
|
6
|
+
key: KEYS.mentionInput,
|
|
7
|
+
node: {
|
|
8
|
+
isElement: true,
|
|
9
|
+
isInline: true,
|
|
10
|
+
isVoid: true
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
/** Enables support for autocompleting @mentions. */
|
|
14
|
+
const BaseMentionPlugin = createTSlatePlugin({
|
|
15
|
+
key: KEYS.mention,
|
|
16
|
+
node: {
|
|
17
|
+
isElement: true,
|
|
18
|
+
isInline: true,
|
|
19
|
+
isMarkableVoid: true,
|
|
20
|
+
isVoid: true
|
|
21
|
+
},
|
|
22
|
+
options: {
|
|
23
|
+
trigger: "@",
|
|
24
|
+
triggerPreviousCharPattern: /^\s?$/,
|
|
25
|
+
createComboboxInput: (trigger) => ({
|
|
26
|
+
children: [{ text: "" }],
|
|
27
|
+
trigger,
|
|
28
|
+
type: KEYS.mentionInput
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
plugins: [BaseMentionInputPlugin]
|
|
32
|
+
}).extendEditorTransforms(({ editor, type }) => ({ insert: { mention: ({ key, value }) => {
|
|
33
|
+
editor.tf.insertNodes({
|
|
34
|
+
key,
|
|
35
|
+
children: [{ text: "" }],
|
|
36
|
+
type,
|
|
37
|
+
value
|
|
38
|
+
});
|
|
39
|
+
} } })).overrideEditor(withTriggerCombobox);
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { BaseMentionPlugin as n, BaseMentionInputPlugin as t };
|
|
43
|
+
//# sourceMappingURL=BaseMentionPlugin-uPSCCRSr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseMentionPlugin-uPSCCRSr.js","names":["TriggerComboboxPluginOptions","withTriggerCombobox","PluginConfig","TMentionElement","createSlatePlugin","createTSlatePlugin","KEYS","MentionConfig","insertSpaceAfterMention","insert","mention","options","search","value","key","BaseMentionInputPlugin","mentionInput","node","isElement","isInline","isVoid","BaseMentionPlugin","isMarkableVoid","trigger","triggerPreviousCharPattern","createComboboxInput","children","text","type","plugins","extendEditorTransforms","editor","tf","insertNodes","overrideEditor"],"sources":["../src/lib/BaseMentionPlugin.ts"],"sourcesContent":["import {\n type TriggerComboboxPluginOptions,\n withTriggerCombobox,\n} from '@platejs/combobox';\nimport {\n type PluginConfig,\n type TMentionElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nexport type MentionConfig = PluginConfig<\n 'mention',\n {\n insertSpaceAfterMention?: boolean;\n } & TriggerComboboxPluginOptions,\n {},\n {\n insert: {\n mention: (options: { search: string; value: any; key?: any }) => void;\n };\n }\n>;\n\nexport const BaseMentionInputPlugin = createSlatePlugin({\n key: KEYS.mentionInput,\n node: { isElement: true, isInline: true, isVoid: true },\n});\n\n/** Enables support for autocompleting @mentions. */\nexport const BaseMentionPlugin = createTSlatePlugin<MentionConfig>({\n key: KEYS.mention,\n node: { isElement: true, isInline: true, isMarkableVoid: true, isVoid: true },\n options: {\n trigger: '@',\n triggerPreviousCharPattern: /^\\s?$/,\n createComboboxInput: (trigger) => ({\n children: [{ text: '' }],\n trigger,\n type: KEYS.mentionInput,\n }),\n },\n plugins: [BaseMentionInputPlugin],\n})\n .extendEditorTransforms<MentionConfig['transforms']>(({ editor, type }) => ({\n insert: {\n mention: ({ key, value }) => {\n editor.tf.insertNodes<TMentionElement>({\n key,\n children: [{ text: '' }],\n type,\n value,\n });\n },\n },\n }))\n .overrideEditor(withTriggerCombobox as any);\n"],"mappings":";;;;AAyBA,MAAae,yBAAyBX,kBAAkB;CACtDU,KAAKR,KAAKU;CACVC,MAAM;EAAEC,WAAW;EAAMC,UAAU;EAAMC,QAAQ;EAAK;CACvD,CAAC;;AAGF,MAAaC,oBAAoBhB,mBAAkC;CACjES,KAAKR,KAAKI;CACVO,MAAM;EAAEC,WAAW;EAAMC,UAAU;EAAMG,gBAAgB;EAAMF,QAAQ;EAAM;CAC7ET,SAAS;EACPY,SAAS;EACTC,4BAA4B;EAC5BC,sBAAsBF,aAAa;GACjCG,UAAU,CAAC,EAAEC,MAAM,IAAI,CAAC;GACxBJ;GACAK,MAAMtB,KAAKU;GACZ;EACF;CACDa,SAAS,CAACd,uBAAsB;CACjC,CAAC,CACCe,wBAAqD,EAAEC,QAAQH,YAAY,EAC1EnB,QAAQ,EACNC,UAAU,EAAEI,KAAKD,YAAY;AAC3BkB,QAAOC,GAAGC,YAA6B;EACrCnB;EACAY,UAAU,CAAC,EAAEC,MAAM,IAAI,CAAC;EACxBC;EACAf;EACD,CAAC;GAEN,EACD,EAAE,CACFqB,eAAejC,oBAA2B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TriggerComboboxPluginOptions } from "@platejs/combobox";
|
|
2
|
+
import { PluginConfig, SlateEditor } from "platejs";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/BaseMentionPlugin.d.ts
|
|
5
|
+
type MentionConfig = PluginConfig<'mention', {
|
|
6
|
+
insertSpaceAfterMention?: boolean;
|
|
7
|
+
} & TriggerComboboxPluginOptions, {}, {
|
|
8
|
+
insert: {
|
|
9
|
+
mention: (options: {
|
|
10
|
+
search: string;
|
|
11
|
+
value: any;
|
|
12
|
+
key?: any;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
declare const BaseMentionInputPlugin: any;
|
|
17
|
+
/** Enables support for autocompleting @mentions. */
|
|
18
|
+
declare const BaseMentionPlugin: any;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/lib/types.d.ts
|
|
21
|
+
type TMentionItemBase = {
|
|
22
|
+
text: string;
|
|
23
|
+
key?: any;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/lib/getMentionOnSelectItem.d.ts
|
|
27
|
+
type MentionOnSelectItem<TItem extends TMentionItemBase = TMentionItemBase> = (editor: SlateEditor, item: TItem, search?: string) => void;
|
|
28
|
+
declare const getMentionOnSelectItem: <TItem extends TMentionItemBase = TMentionItemBase>({
|
|
29
|
+
key
|
|
30
|
+
}?: {
|
|
31
|
+
key?: string;
|
|
32
|
+
}) => MentionOnSelectItem<TItem>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { BaseMentionInputPlugin, BaseMentionPlugin, MentionConfig, MentionOnSelectItem, TMentionItemBase, getMentionOnSelectItem };
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib/BaseMentionPlugin.ts","../src/lib/types.ts","../src/lib/getMentionOnSelectItem.ts"],"sourcesContent":[],"mappings":";;;;KAYY,aAAA,GAAgB;;AAA5B,CAAA,GAIM,4BAAA,EAAA,CAAA,CAAA,EAAA;EASO,MAAA,EAAA;IAMA,OAAA,EAAA,CAAA,OA0BgC,EAAA;;;;ICzDjC,CAAA,EAAA,GAAA,IAAA;;;cDyBC;AEpBb;AACgB,cFyBH,iBEzBG,EAAA,GAAA;;;KDNJ,gBAAA;;;;;;KCKA,kCACI,mBAAmB,6BACtB,mBAAmB;cAEnB,uCACI,mBAAmB;;AFepC,CAAA;EAbY,GAAA,CAAA,EAAA,MAAA;AAaZ,CAAA,EAAA,GEXW,mBFWE,CEXkB,KFc7B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { n as BaseMentionPlugin, t as BaseMentionInputPlugin } from "./BaseMentionPlugin-uPSCCRSr.js";
|
|
2
|
+
import { KEYS, getEditorPlugin } from "platejs";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/getMentionOnSelectItem.ts
|
|
5
|
+
const getMentionOnSelectItem = ({ key = KEYS.mention } = {}) => (editor, item, search = "") => {
|
|
6
|
+
const { getOptions, tf } = getEditorPlugin(editor, { key });
|
|
7
|
+
const { insertSpaceAfterMention } = getOptions();
|
|
8
|
+
tf.insert.mention({
|
|
9
|
+
key: item.key,
|
|
10
|
+
search,
|
|
11
|
+
value: item.text
|
|
12
|
+
});
|
|
13
|
+
editor.tf.move({ unit: "offset" });
|
|
14
|
+
const pathAbove = editor.api.block()?.[1];
|
|
15
|
+
if (editor.selection && pathAbove && editor.api.isEnd(editor.selection.anchor, pathAbove) && insertSpaceAfterMention) editor.tf.insertText(" ");
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { BaseMentionInputPlugin, BaseMentionPlugin, getMentionOnSelectItem };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["SlateEditor","getEditorPlugin","KEYS","MentionConfig","TMentionItemBase","MentionOnSelectItem","editor","item","TItem","search","getMentionOnSelectItem","key","mention","getOptions","tf","insertSpaceAfterMention","insert","value","text","move","unit","pathAbove","api","block","isBlockEnd","selection","isEnd","anchor","insertText"],"sources":["../src/lib/getMentionOnSelectItem.ts"],"sourcesContent":["import { type SlateEditor, getEditorPlugin, KEYS } from 'platejs';\n\nimport type { MentionConfig } from './BaseMentionPlugin';\nimport type { TMentionItemBase } from './types';\n\nexport type MentionOnSelectItem<\n TItem extends TMentionItemBase = TMentionItemBase,\n> = (editor: SlateEditor, item: TItem, search?: string) => void;\n\nexport const getMentionOnSelectItem =\n <TItem extends TMentionItemBase = TMentionItemBase>({\n key = KEYS.mention,\n }: {\n key?: string;\n } = {}): MentionOnSelectItem<TItem> =>\n (editor, item, search = '') => {\n const { getOptions, tf } = getEditorPlugin<MentionConfig>(editor, {\n key: key as any,\n });\n const { insertSpaceAfterMention } = getOptions();\n\n tf.insert.mention({ key: item.key, search, value: item.text });\n\n // move the selection after the element\n editor.tf.move({ unit: 'offset' });\n\n const pathAbove = editor.api.block()?.[1];\n\n const isBlockEnd =\n editor.selection &&\n pathAbove &&\n editor.api.isEnd(editor.selection.anchor, pathAbove);\n\n if (isBlockEnd && insertSpaceAfterMention) {\n editor.tf.insertText(' ');\n }\n };\n"],"mappings":";;;;AASA,MAAaU,0BACyC,EAClDC,MAAMT,KAAKU,YAGT,EAAE,MACLN,QAAQC,MAAME,SAAS,OAAO;CAC7B,MAAM,EAAEI,YAAYC,OAAOb,gBAA+BK,QAAQ,EAC3DK,KACN,CAAC;CACF,MAAM,EAAEI,4BAA4BF,YAAY;AAEhDC,IAAGE,OAAOJ,QAAQ;EAAED,KAAKJ,KAAKI;EAAKF;EAAQQ,OAAOV,KAAKW;EAAM,CAAC;AAG9DZ,QAAOQ,GAAGK,KAAK,EAAEC,MAAM,UAAU,CAAC;CAElC,MAAMC,YAAYf,OAAOgB,IAAIC,OAAO,GAAG;AAOvC,KAJEjB,OAAOmB,aACPJ,aACAf,OAAOgB,IAAII,MAAMpB,OAAOmB,UAAUE,QAAQN,UAAU,IAEpCN,wBAChBT,QAAOQ,GAAGc,WAAW,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/MentionPlugin.tsx"],"sourcesContent":[],"mappings":";cAIa;AAAA,cAEA,kBAFgD,EAAA,GAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as BaseMentionPlugin, t as BaseMentionInputPlugin } from "../BaseMentionPlugin-uPSCCRSr.js";
|
|
2
|
+
import { toPlatePlugin } from "platejs/react";
|
|
3
|
+
|
|
4
|
+
//#region src/react/MentionPlugin.tsx
|
|
5
|
+
const MentionPlugin = toPlatePlugin(BaseMentionPlugin);
|
|
6
|
+
const MentionInputPlugin = toPlatePlugin(BaseMentionInputPlugin);
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { MentionInputPlugin, MentionPlugin };
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["toPlatePlugin","BaseMentionInputPlugin","BaseMentionPlugin","MentionPlugin","MentionInputPlugin"],"sources":["../../src/react/MentionPlugin.tsx"],"sourcesContent":["import { toPlatePlugin } from 'platejs/react';\n\nimport { BaseMentionInputPlugin, BaseMentionPlugin } from '../lib';\n\nexport const MentionPlugin = toPlatePlugin(BaseMentionPlugin);\n\nexport const MentionInputPlugin = toPlatePlugin(BaseMentionInputPlugin);\n"],"mappings":";;;;AAIA,MAAaG,gBAAgBH,cAAcE,kBAAkB;AAE7D,MAAaE,qBAAqBJ,cAAcC,uBAAuB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lofcz/platejs-mention",
|
|
3
|
+
"version": "52.0.15",
|
|
4
|
+
"description": "Mention plugin for Plate",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"plate",
|
|
7
|
+
"plugin",
|
|
8
|
+
"slate"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://platejs.org",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/udecode/plate/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/lofcz/plate.git",
|
|
17
|
+
"directory": "packages/mention"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js",
|
|
23
|
+
"./react": "./dist/react/index.js",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/**/*"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"react-compiler-runtime": "^1.0.0",
|
|
33
|
+
"@platejs/combobox": "npm:@lofcz/platejs-combobox@52.0.15"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@plate/scripts": "1.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"platejs": ">=52.0.15",
|
|
40
|
+
"react": ">=18.0.0",
|
|
41
|
+
"react-dom": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"type": "module",
|
|
47
|
+
"module": "./dist/index.js",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"brl": "plate-pkg p:brl",
|
|
50
|
+
"build": "plate-pkg p:build",
|
|
51
|
+
"build:watch": "plate-pkg p:build:watch",
|
|
52
|
+
"clean": "plate-pkg p:clean",
|
|
53
|
+
"lint": "plate-pkg p:lint",
|
|
54
|
+
"lint:fix": "plate-pkg p:lint:fix",
|
|
55
|
+
"test": "plate-pkg p:test",
|
|
56
|
+
"test:watch": "plate-pkg p:test:watch",
|
|
57
|
+
"typecheck": "plate-pkg p:typecheck"
|
|
58
|
+
}
|
|
59
|
+
}
|