@fluentui-copilot/chat-input-plugins 0.4.2-hotfix.1 → 0.4.2-hotfix.3
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/CHANGELOG.json +20 -5
- package/CHANGELOG.md +5 -5
- package/lib/BasicFunctionality/BasicFunctionality.base.js +92 -92
- package/lib/BasicFunctionality/SentinelNode.js +30 -29
- package/lib/BasicFunctionality/SentinelNodeHandlers.js +78 -73
- package/lib/BasicFunctionality/index.js +1 -0
- package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js +114 -109
- package/lib/ChatInputEntity/ChatInputEntityPlugin.types.js +2 -1
- package/lib/ChatInputEntity/index.js +1 -0
- package/lib/GhostText/GhostText.base.js +145 -142
- package/lib/GhostText/index.js +1 -0
- package/lib/ImperativeControl/ImperativeControl.base.js +83 -82
- package/lib/ImperativeControl/index.js +1 -0
- package/lib/ManualGhostText/ManualGhostText.base.js +67 -68
- package/lib/ManualGhostText/index.js +1 -0
- package/lib/PasteUnfurling/PasteUnfurling.base.js +57 -52
- package/lib/PasteUnfurling/PasteUnfurling.types.js +2 -1
- package/lib/PasteUnfurling/PasteUnfurlingTestUtils.js +139 -138
- package/lib/PasteUnfurling/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +3 -2
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNode.js +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNode.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js +5 -3
- package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/index.js +1 -0
- package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js +5 -3
- package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js.map +1 -1
- package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.types.js +1 -0
- package/lib-commonjs/ChatInputEntity/index.js +1 -0
- package/lib-commonjs/GhostText/GhostText.base.js +3 -2
- package/lib-commonjs/GhostText/GhostText.base.js.map +1 -1
- package/lib-commonjs/GhostText/index.js +1 -0
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +1 -1
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/lib-commonjs/ImperativeControl/index.js +1 -0
- package/lib-commonjs/ManualGhostText/ManualGhostText.base.js +1 -1
- package/lib-commonjs/ManualGhostText/ManualGhostText.base.js.map +1 -1
- package/lib-commonjs/ManualGhostText/index.js +1 -0
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js.map +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.types.js +1 -0
- package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js.map +1 -1
- package/lib-commonjs/PasteUnfurling/index.js +1 -0
- package/lib-commonjs/index.js +1 -0
- package/package.json +2 -2
|
@@ -1,162 +1,163 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { TextNode } from '@fluentui-copilot/text-editor';
|
|
3
3
|
export class MockClipboardEvent extends Event {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
constructor(...args) {
|
|
5
|
+
super(...args);
|
|
6
|
+
_define_property(this, "clipboardData", null);
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
export function createPasteEvent(data) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
const event = new MockClipboardEvent('paste');
|
|
11
|
+
event.clipboardData = {
|
|
12
|
+
types: [data.map(({
|
|
13
|
+
mimeType
|
|
14
|
+
}) => mimeType)],
|
|
15
|
+
getData: format => {
|
|
16
|
+
const item = data.find(({
|
|
17
|
+
mimeType
|
|
18
|
+
}) => mimeType === format);
|
|
19
|
+
if (item) {
|
|
20
|
+
return item.value;
|
|
21
|
+
}
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return event;
|
|
24
26
|
}
|
|
25
27
|
export class MockEntityNode extends TextNode {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
static getType() {
|
|
29
|
+
return 'mockEntity';
|
|
30
|
+
}
|
|
31
|
+
constructor(text, url) {
|
|
32
|
+
super(text);
|
|
33
|
+
_define_property(this, "url", void 0);
|
|
34
|
+
this.url = url;
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
export function $createMockEntityNode(text, url) {
|
|
36
|
-
|
|
38
|
+
return new MockEntityNode(text, url);
|
|
37
39
|
}
|
|
38
40
|
export function $isMockEntityNode(node) {
|
|
39
|
-
|
|
41
|
+
return node instanceof MockEntityNode;
|
|
40
42
|
}
|
|
41
|
-
export const parseLinkPreview =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
previewData = JSON.parse(previewDataString);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return {
|
|
54
|
-
handled: false
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const title = previewData.title;
|
|
58
|
-
const url = previewData.url;
|
|
59
|
-
if (!title || !url) {
|
|
60
|
-
return {
|
|
61
|
-
handled: false
|
|
62
|
-
};
|
|
43
|
+
export const parseLinkPreview = event => {
|
|
44
|
+
let previewData;
|
|
45
|
+
try {
|
|
46
|
+
var _event_clipboardData;
|
|
47
|
+
const previewDataString = (_event_clipboardData = event.clipboardData) === null || _event_clipboardData === void 0 ? void 0 : _event_clipboardData.getData('text/link-preview');
|
|
48
|
+
if (previewDataString === undefined || previewDataString === '') {
|
|
49
|
+
return {
|
|
50
|
+
handled: false
|
|
51
|
+
};
|
|
63
52
|
}
|
|
53
|
+
previewData = JSON.parse(previewDataString);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return {
|
|
56
|
+
handled: false
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const title = previewData.title;
|
|
60
|
+
const url = previewData.url;
|
|
61
|
+
if (!title || !url) {
|
|
64
62
|
return {
|
|
65
|
-
|
|
66
|
-
transformedParts: [
|
|
67
|
-
{
|
|
68
|
-
type: 'entity',
|
|
69
|
-
value: {
|
|
70
|
-
text: title,
|
|
71
|
-
data: {
|
|
72
|
-
url
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
]
|
|
63
|
+
handled: false
|
|
77
64
|
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
handled: true,
|
|
68
|
+
transformedParts: [{
|
|
69
|
+
type: 'entity',
|
|
70
|
+
value: {
|
|
71
|
+
text: title,
|
|
72
|
+
data: {
|
|
73
|
+
url
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}]
|
|
77
|
+
};
|
|
78
78
|
};
|
|
79
79
|
const urlRegex = /(\b(?:https?):\/\/[^\s]+)/gi;
|
|
80
|
-
export const parseLink =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
handled: false
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const transformedParts = parts.map((str, i)=>{
|
|
96
|
-
if (i % 2 === 0) {
|
|
97
|
-
return {
|
|
98
|
-
type: 'text',
|
|
99
|
-
value: str
|
|
100
|
-
};
|
|
101
|
-
} else {
|
|
102
|
-
return {
|
|
103
|
-
type: 'entity',
|
|
104
|
-
value: {
|
|
105
|
-
text: str,
|
|
106
|
-
data: {
|
|
107
|
-
url: str
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
})// Filter out all the nulls for empty strings
|
|
113
|
-
.filter((node)=>node !== null);
|
|
80
|
+
export const parseLink = event => {
|
|
81
|
+
var _event_clipboardData;
|
|
82
|
+
const text = (_event_clipboardData = event.clipboardData) === null || _event_clipboardData === void 0 ? void 0 : _event_clipboardData.getData('text/plain');
|
|
83
|
+
if (!text) {
|
|
84
|
+
return {
|
|
85
|
+
handled: false
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const parts = text.split(urlRegex);
|
|
89
|
+
// If an entity was found, parts will be at least 3 elements long
|
|
90
|
+
if (parts.length < 3) {
|
|
114
91
|
return {
|
|
115
|
-
|
|
116
|
-
transformedParts
|
|
92
|
+
handled: false
|
|
117
93
|
};
|
|
94
|
+
}
|
|
95
|
+
const transformedParts = parts.map((str, i) => {
|
|
96
|
+
if (i % 2 === 0) {
|
|
97
|
+
return {
|
|
98
|
+
type: 'text',
|
|
99
|
+
value: str
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
return {
|
|
103
|
+
type: 'entity',
|
|
104
|
+
value: {
|
|
105
|
+
text: str,
|
|
106
|
+
data: {
|
|
107
|
+
url: str
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}) // Filter out all the nulls for empty strings
|
|
113
|
+
.filter(node => node !== null);
|
|
114
|
+
return {
|
|
115
|
+
handled: true,
|
|
116
|
+
transformedParts
|
|
117
|
+
};
|
|
118
118
|
};
|
|
119
119
|
// A transform can be async in case it needs to fetch data from a server.
|
|
120
|
-
export const parseEntity = async
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
handled: false
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
// Assume entities come in the syntax <entity>title</entity>
|
|
129
|
-
const re = /<entity[^>]*>([^<]*)<\/entity>/g;
|
|
130
|
-
const parts = text.split(re);
|
|
131
|
-
// If an entity was found, parts will be at least 3 elements long
|
|
132
|
-
if (parts.length < 3) {
|
|
133
|
-
return {
|
|
134
|
-
handled: false
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
// Even elements are text, odd elements are entities
|
|
138
|
-
// ["", entity, "", entity, "", ...]
|
|
139
|
-
const transformedParts = parts.map((str, i)=>{
|
|
140
|
-
if (i % 2 === 0) {
|
|
141
|
-
return {
|
|
142
|
-
type: 'text',
|
|
143
|
-
value: str
|
|
144
|
-
};
|
|
145
|
-
} else {
|
|
146
|
-
return {
|
|
147
|
-
type: 'entity',
|
|
148
|
-
value: {
|
|
149
|
-
text: str,
|
|
150
|
-
data: {
|
|
151
|
-
url: str
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
})// Filter out all the nulls for empty strings
|
|
157
|
-
.filter((node)=>node !== null);
|
|
120
|
+
export const parseEntity = async event => {
|
|
121
|
+
var _event_clipboardData;
|
|
122
|
+
const text = (_event_clipboardData = event.clipboardData) === null || _event_clipboardData === void 0 ? void 0 : _event_clipboardData.getData('text/plain');
|
|
123
|
+
if (!text) {
|
|
158
124
|
return {
|
|
159
|
-
|
|
160
|
-
transformedParts
|
|
125
|
+
handled: false
|
|
161
126
|
};
|
|
127
|
+
}
|
|
128
|
+
// Assume entities come in the syntax <entity>title</entity>
|
|
129
|
+
const re = /<entity[^>]*>([^<]*)<\/entity>/g;
|
|
130
|
+
const parts = text.split(re);
|
|
131
|
+
// If an entity was found, parts will be at least 3 elements long
|
|
132
|
+
if (parts.length < 3) {
|
|
133
|
+
return {
|
|
134
|
+
handled: false
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// Even elements are text, odd elements are entities
|
|
138
|
+
// ["", entity, "", entity, "", ...]
|
|
139
|
+
const transformedParts = parts.map((str, i) => {
|
|
140
|
+
if (i % 2 === 0) {
|
|
141
|
+
return {
|
|
142
|
+
type: 'text',
|
|
143
|
+
value: str
|
|
144
|
+
};
|
|
145
|
+
} else {
|
|
146
|
+
return {
|
|
147
|
+
type: 'entity',
|
|
148
|
+
value: {
|
|
149
|
+
text: str,
|
|
150
|
+
data: {
|
|
151
|
+
url: str
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}) // Filter out all the nulls for empty strings
|
|
157
|
+
.filter(node => node !== null);
|
|
158
|
+
return {
|
|
159
|
+
handled: true,
|
|
160
|
+
transformedParts
|
|
161
|
+
};
|
|
162
162
|
};
|
|
163
|
+
//# sourceMappingURL=PasteUnfurlingTestUtils.js.map
|
package/lib/index.js
CHANGED
|
@@ -79,7 +79,8 @@ class BasicFunctionalityBase {
|
|
|
79
79
|
(0, _texteditor.$getRoot)().getAllTextNodes().forEach((node)=>{
|
|
80
80
|
node.remove();
|
|
81
81
|
});
|
|
82
|
-
},
|
|
82
|
+
}, // Don't allow undoing this action
|
|
83
|
+
{
|
|
83
84
|
tag: 'historic'
|
|
84
85
|
});
|
|
85
86
|
}
|
|
@@ -113,4 +114,4 @@ class BasicFunctionalityBase {
|
|
|
113
114
|
}
|
|
114
115
|
function noop() {
|
|
115
116
|
return;
|
|
116
|
-
}
|
|
117
|
+
} //# sourceMappingURL=BasicFunctionality.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getRoot,\n $getSelection,\n $insertNodes,\n $isRangeSelection,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n PASTE_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { SENTINEL_VALUE } from './SentinelNode';\nimport { registerSentinelNodeHandlers } from './SentinelNodeHandlers';\n\nfunction isClipboardEvent(event: ClipboardEvent | KeyboardEvent | InputEvent): event is ClipboardEvent {\n return event.type === 'paste';\n}\n\nexport interface IBasicFunctionalityBase {\n insertDefaultValue: (defaultValue: string) => void;\n setIsDisabled: (isDisabled: boolean) => void;\n activateContentCallbacks(onContentChange?: (value: string) => void, onCountChanged?: (count: number) => void): void;\n deactivateContentCallbacks(): void;\n activateTrimWhitespace(): void;\n deactivateTrimWhitespace(): void;\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void;\n deactivatePasteCallback(): void;\n cleanup(): void;\n}\n\nexport class BasicFunctionalityBase implements IBasicFunctionalityBase {\n private __editor: LexicalEditor;\n private __contentChangeCleanup?: () => void;\n private __trimWhitespaceCleanup?: () => void;\n private __baseHandlersCleanup?: () => void;\n private __pasteHandlerCleanup?: () => void;\n\n private __enterHandler(event: KeyboardEvent) {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n if (event === null) {\n return false;\n }\n\n event.preventDefault();\n\n if (event.shiftKey) {\n return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);\n }\n\n // Mark event handled to override default behavior\n return true;\n }\n\n constructor(editor: LexicalEditor, isSentinelNodeEnabled = true) {\n this.__editor = editor;\n\n this.__baseHandlersCleanup = mergeRegister(\n this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH),\n isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop,\n );\n }\n\n insertDefaultValue(defaultValue: string) {\n if (defaultValue) {\n this.__editor.update(() => {\n $insertNodes([$createTextNode(defaultValue)]);\n });\n }\n }\n\n activateContentCallbacks(\n onContentChange?: ((value: string) => void) | undefined,\n onCountChanged?: ((count: number) => void) | undefined,\n ) {\n this.deactivateContentCallbacks();\n this.__contentChangeCleanup = this.__editor.registerTextContentListener(text => {\n // Remove the sentinel node\n const processed = text.replace(SENTINEL_VALUE, '');\n onContentChange?.(processed);\n onCountChanged?.(processed.length);\n });\n }\n\n deactivateContentCallbacks() {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = undefined;\n }\n\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void) {\n this.__pasteHandlerCleanup = this.__editor.registerCommand(\n PASTE_COMMAND,\n (event: ClipboardEvent | KeyboardEvent | InputEvent) => {\n if (!isClipboardEvent(event)) {\n return false;\n }\n\n onPaste(event);\n\n if (event.defaultPrevented) {\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_HIGH,\n );\n }\n\n deactivatePasteCallback() {\n this.__pasteHandlerCleanup?.();\n this.__pasteHandlerCleanup = undefined;\n }\n\n activateTrimWhitespace() {\n this.deactivateTrimWhitespace();\n this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {\n if (text.trim() === '') {\n this.__editor.update(\n () => {\n $getRoot()\n .getAllTextNodes()\n .forEach(node => {\n node.remove();\n });\n },\n // Don't allow undoing this action\n { tag: 'historic' },\n );\n }\n });\n }\n\n deactivateTrimWhitespace() {\n this.__trimWhitespaceCleanup?.();\n this.__trimWhitespaceCleanup = undefined;\n }\n\n setIsDisabled(isDisabled: boolean) {\n this.__editor.setEditable(!isDisabled);\n }\n\n cleanup() {\n this.deactivateContentCallbacks();\n this.deactivateTrimWhitespace();\n this.deactivatePasteCallback();\n this.__baseHandlersCleanup?.();\n this.__baseHandlersCleanup = undefined;\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["BasicFunctionalityBase","isClipboardEvent","event","type","__enterHandler","selection","$getSelection","$isRangeSelection","preventDefault","shiftKey","__editor","dispatchCommand","INSERT_PARAGRAPH_COMMAND","
|
|
1
|
+
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getRoot,\n $getSelection,\n $insertNodes,\n $isRangeSelection,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n PASTE_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { SENTINEL_VALUE } from './SentinelNode';\nimport { registerSentinelNodeHandlers } from './SentinelNodeHandlers';\n\nfunction isClipboardEvent(event: ClipboardEvent | KeyboardEvent | InputEvent): event is ClipboardEvent {\n return event.type === 'paste';\n}\n\nexport interface IBasicFunctionalityBase {\n insertDefaultValue: (defaultValue: string) => void;\n setIsDisabled: (isDisabled: boolean) => void;\n activateContentCallbacks(onContentChange?: (value: string) => void, onCountChanged?: (count: number) => void): void;\n deactivateContentCallbacks(): void;\n activateTrimWhitespace(): void;\n deactivateTrimWhitespace(): void;\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void;\n deactivatePasteCallback(): void;\n cleanup(): void;\n}\n\nexport class BasicFunctionalityBase implements IBasicFunctionalityBase {\n private __editor: LexicalEditor;\n private __contentChangeCleanup?: () => void;\n private __trimWhitespaceCleanup?: () => void;\n private __baseHandlersCleanup?: () => void;\n private __pasteHandlerCleanup?: () => void;\n\n private __enterHandler(event: KeyboardEvent) {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n if (event === null) {\n return false;\n }\n\n event.preventDefault();\n\n if (event.shiftKey) {\n return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);\n }\n\n // Mark event handled to override default behavior\n return true;\n }\n\n constructor(editor: LexicalEditor, isSentinelNodeEnabled = true) {\n this.__editor = editor;\n\n this.__baseHandlersCleanup = mergeRegister(\n this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH),\n isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop,\n );\n }\n\n insertDefaultValue(defaultValue: string) {\n if (defaultValue) {\n this.__editor.update(() => {\n $insertNodes([$createTextNode(defaultValue)]);\n });\n }\n }\n\n activateContentCallbacks(\n onContentChange?: ((value: string) => void) | undefined,\n onCountChanged?: ((count: number) => void) | undefined,\n ) {\n this.deactivateContentCallbacks();\n this.__contentChangeCleanup = this.__editor.registerTextContentListener(text => {\n // Remove the sentinel node\n const processed = text.replace(SENTINEL_VALUE, '');\n onContentChange?.(processed);\n onCountChanged?.(processed.length);\n });\n }\n\n deactivateContentCallbacks() {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = undefined;\n }\n\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void) {\n this.__pasteHandlerCleanup = this.__editor.registerCommand(\n PASTE_COMMAND,\n (event: ClipboardEvent | KeyboardEvent | InputEvent) => {\n if (!isClipboardEvent(event)) {\n return false;\n }\n\n onPaste(event);\n\n if (event.defaultPrevented) {\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_HIGH,\n );\n }\n\n deactivatePasteCallback() {\n this.__pasteHandlerCleanup?.();\n this.__pasteHandlerCleanup = undefined;\n }\n\n activateTrimWhitespace() {\n this.deactivateTrimWhitespace();\n this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {\n if (text.trim() === '') {\n this.__editor.update(\n () => {\n $getRoot()\n .getAllTextNodes()\n .forEach(node => {\n node.remove();\n });\n },\n // Don't allow undoing this action\n { tag: 'historic' },\n );\n }\n });\n }\n\n deactivateTrimWhitespace() {\n this.__trimWhitespaceCleanup?.();\n this.__trimWhitespaceCleanup = undefined;\n }\n\n setIsDisabled(isDisabled: boolean) {\n this.__editor.setEditable(!isDisabled);\n }\n\n cleanup() {\n this.deactivateContentCallbacks();\n this.deactivateTrimWhitespace();\n this.deactivatePasteCallback();\n this.__baseHandlersCleanup?.();\n this.__baseHandlersCleanup = undefined;\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["BasicFunctionalityBase","isClipboardEvent","event","type","__enterHandler","selection","$getSelection","$isRangeSelection","preventDefault","shiftKey","__editor","dispatchCommand","INSERT_PARAGRAPH_COMMAND","insertDefaultValue","defaultValue","update","$insertNodes","onContentChange","onCountChanged","deactivateContentCallbacks","activateContentCallbacks","text","processed","__contentChangeCleanup","SENTINEL_VALUE","registerTextContentListener","length","_this___contentChangeCleanup","_this","call","undefined","__pasteHandlerCleanup","registerCommand","PASTE_COMMAND","activatePasteCallback","onPaste","defaultPrevented","COMMAND_PRIORITY_HIGH","_this___pasteHandlerCleanup","deactivatePasteCallback","deactivateTrimWhitespace","activateTrimWhitespace","__trimWhitespaceCleanup","trim","forEach","node","remove","_this___trimWhitespaceCleanup","isDisabled","setIsDisabled","cleanup","__baseHandlersCleanup","_this___baseHandlersCleanup","editor","isSentinelNodeEnabled","constructor","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAgCaA;;;eAAAA;;;;4BA/ByB;8BAYP;sCACc;AAE7C,SAASC,iBAAiBC,KAAkD;WAC1EA,MAAOA,IAAMC,KAAI;AACnB;AAcO,MAAMH;mBAOHI,KAAeF,EAAoB;cACzCG,YAAMA,IAAAA,yBAAYC;YAClB,CAAAC,IAAAA,6BAAKA,EAAAA,YAAkBF;mBACrB;;YAGFH,UAAIA,MAAU;mBACZ;;cAGFA,cAAMM;YAENN,MAAIA,QAAMO,EAAAA;mBACR,IAAA,CAAAC,QAAYA,CAAAA,eAASC,CAAAA,oCAAgBC,EAAAA;;0DAGvC;eACA;;uBAYFC,YAAmBC,EAAoB;YACrCA,cAAIA;yBACGJ,CAAAA,MAASK,CAAAA;4CACZC,EAAAA;oBAAAA,IAAAA,2BAAa,EAAAF;iBAAA;;;;6BAEjBG,eAAA,EAAAC,cAAA,EAAA;QACF,I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AA,MAAA,QAAAK,kCAAA,KAAA,IAAA,KAAA,IAAAA,8BAAAlB,IAAA,CAAAD;aAAAc,uBAAA,GAAAZ;;kBAEFkB,UAAA,EAAA;QAEAC,IAAAA,CAAAA,QAAAA,CAAcD,WAAmB,CAAE,CAAAA;;cAEnC;QAEAE,IAAAA,6BAAUtB;uCAIR;YAHA,CAAAY,wBAAKrB;YACL,CAAAoB,uBAAKC;uCACAD,AAAuBX,CAAAA,QAAA,IAAA,EAAAuB,qBAAA,MAAA,QAAAC,gCAAA,KAAA,IAAA,KAAA,IAAAA,4BAAAvB,IAAA,CAAAD;aAC5BuB,qBAAA,GAAArB;;gBAEFuB,MAAA,EAAAC,wBAAA,IAAA,CAAA;QA9FAC,IAAAA,kBAAYF,EAAAA,IAAuBC,EAAAA,YAAAA,KAAAA;8BA1BnC,EAAA,IAAA,EAAA,0BAAA,KAAA;8BACA,EAAA,IAAA,EAAA,2BAAQ/B,KAAR;8BACA,EAAA,IAAA,EAAA,yBAAQmB,KAAAA;8BACR,EAAA,IAAA,EAAA,yBAAQS,KAAR;YACA,CAAAzC,QAAA,GAAA2C;YAuBE,CAAAF,qBAAgBE,GAAAA,IAAAA,yBAAAA,EAAAA,IAAAA,CAAAA,QAAAA,CAAAA,eAAAA,CAAAA,6BAAAA,EAAAA,IAAAA,CAAAA,cAAAA,CAAAA,IAAAA,CAAAA,IAAAA,GAAAA,iCAAAA,GAAAA,wBAAAA,IAAAA,kDAAAA,EAAAA,UAAAA;;;AA8FpB,SAAAG;IAEA;EAEA,mDAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, NodeKey, SerializedTextNode } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\n// 2 zero width characters will not be visible in the editor.\n// \\u200b is the zero width space character which can allow line wrapping in a word\n// \\u200c is the zero width non-joiner character which prevents ligatures from connecting the two surrounding characters\n// These two characters together are a no-op and should not be present together in any legitimate user input.\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n element.ariaHidden = 'true';\n return element;\n }\n\n isToken() {\n return true;\n }\n\n exportJSON(): SerializedTextNode {\n return {\n ...super.exportJSON(),\n type: 'sentinel',\n version: 1,\n };\n }\n\n static importJSON(serializedNode: SerializedTextNode): SentinelNode {\n return $createSentinelNode();\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["$createSentinelNode","$isSentinelNode","SENTINEL_VALUE","SentinelNode","TextNode","getType","clone","node","__key","createDOM","config","element","ariaHidden","isToken","exportJSON","type","version","importJSON","serializedNode","constructor","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IA4CgBA,mBAAAA;eAAAA;;IAIAC,eAAAA;eAAAA;;IAzCHC,cAAAA;eAAAA;;IAEAC,YAAAA;eAAAA;;;4BARY;AAMlB,MAAMD,iBAAiB;AAEvB,MAAMC,qBAAqBC,oBAAAA;
|
|
1
|
+
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, NodeKey, SerializedTextNode } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\n// 2 zero width characters will not be visible in the editor.\n// \\u200b is the zero width space character which can allow line wrapping in a word\n// \\u200c is the zero width non-joiner character which prevents ligatures from connecting the two surrounding characters\n// These two characters together are a no-op and should not be present together in any legitimate user input.\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n element.ariaHidden = 'true';\n return element;\n }\n\n isToken() {\n return true;\n }\n\n exportJSON(): SerializedTextNode {\n return {\n ...super.exportJSON(),\n type: 'sentinel',\n version: 1,\n };\n }\n\n static importJSON(serializedNode: SerializedTextNode): SentinelNode {\n return $createSentinelNode();\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["$createSentinelNode","$isSentinelNode","SENTINEL_VALUE","SentinelNode","TextNode","getType","clone","node","__key","createDOM","config","element","ariaHidden","isToken","exportJSON","type","version","importJSON","serializedNode","constructor","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IA4CgBA,mBAAAA;eAAAA;;IAIAC,eAAAA;eAAAA;;IAzCHC,cAAAA;eAAAA;;IAEAC,YAAAA;eAAAA;;;4BARY;AAMlB,MAAMD,iBAAiB;AAEvB,MAAMC,qBAAqBC,oBAAAA;WAKhCC,UAAOA;eACL;;WAEFC,MAAOA,IAAMC,EAAkB;eAC7B,IAAOJ,aAAIA,KAAaI,KAAKC;;cAG/BC,MAAUC,EAAoB;cAC5BC,UAAMA,KAAU,CAAAF,UAAMA;gBACtBE,UAAQC,GAAAA;eACRD;;cAGFE;eACE;;iBAGFC;eACE;oBACE,CAAGA,YAAMA;kBACTC;qBACAC;;;WAIJC,WAAOA,cAAWC,EAAkC;eAClDlB;;gBA9BFmB,GAAYC,CAAa;aACvB,CAAAlB,gBAAMA;;AA+BV;AAEO,SAASF,oBAAoBoB,GAAa;WAC/C,IAAOjB,aAAIA;AACb;AAEO,SAASF,gBAAgBM,IAAwB;WACtDA,gBAAOA;AACT"}
|
|
@@ -29,9 +29,11 @@ function registerSentinelNodeHandlers(editor) {
|
|
|
29
29
|
// If the last node isn't a sentinel, add one
|
|
30
30
|
if (!(0, _SentinelNode.$isSentinelNode)(lastNode)) {
|
|
31
31
|
editor.update(()=>{
|
|
32
|
-
var
|
|
32
|
+
var // We find the node by its key again in case the node was removed before this update runs
|
|
33
|
+
_$getNodeByKey;
|
|
33
34
|
(_$getNodeByKey = (0, _texteditor.$getNodeByKey)(lastNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.insertAfter((0, _SentinelNode.$createSentinelNode)());
|
|
34
|
-
},
|
|
35
|
+
}, // historic tag prevents every sentinel node addition from being added to LexicalHistoryPlugin undo stack
|
|
36
|
+
{
|
|
35
37
|
discrete: true,
|
|
36
38
|
tag: 'historic'
|
|
37
39
|
});
|
|
@@ -84,4 +86,4 @@ function registerSentinelNodeHandlers(editor) {
|
|
|
84
86
|
return;
|
|
85
87
|
}
|
|
86
88
|
}));
|
|
87
|
-
}
|
|
89
|
+
} //# sourceMappingURL=SentinelNodeHandlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SentinelNodeHandlers.ts"],"sourcesContent":["import type {\n LexicalEditor,\n UpdateListener} from '@fluentui-copilot/text-editor';\nimport {\n $getLeafNodes,\n $getNodeByKey,\n $getRoot,\n $getSelection,\n $isRangeSelection,\n $normalizeSelection__EXPERIMENTAL,\n $setSelection,\n mergeRegister\n} from '@fluentui-copilot/text-editor';\nimport { $isSentinelNode, $createSentinelNode, SentinelNode } from './SentinelNode';\n\nexport function registerSentinelNodeHandlers(editor: LexicalEditor) {\n // Add a sentinel node at the end of the input when there is content.\n // This sentinel node fixes a number of issues.\n // In Safari, Lexical's behaviour of adding <br /> tags to the end of the input when it ends\n // in a decorator node causes cursor location issues: https://github.com/facebook/lexical/issues/4487\n // Otherwise, when a decorator node is the last node in the input, the cursor can't move past it.\n // Adding an invisible text node that doesn't contribute to the content and can't be selected to the end of the input\n // mitigates these issues.\n const sentinelNodeUpdateHandler: UpdateListener = ({ editorState }) => {\n editorState.read(() => {\n const leaves = $getLeafNodes($getRoot());\n if (leaves.length === 0) {\n return;\n }\n\n const lastNode = leaves[leaves.length - 1];\n const lastNodeKey = lastNode.getKey();\n\n // If the last node isn't a sentinel, add one\n if (!$isSentinelNode(lastNode)) {\n editor.update(\n () => {\n // We find the node by its key again in case the node was removed before this update runs\n $getNodeByKey(lastNodeKey)?.insertAfter($createSentinelNode());\n },\n // historic tag prevents every sentinel node addition from being added to LexicalHistoryPlugin undo stack\n { discrete: true, tag: 'historic' },\n );\n return;\n }\n\n // If the sentinel node is not selected, we're done\n const previous = lastNode.getPreviousSibling();\n if (!previous || !lastNode.isSelected()) {\n return;\n }\n\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n // If the cursor is inside the sentinel node, move it out (next to the beginning)\n // We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node\n // where selection is ill-defined.\n if (selection.isCollapsed() && selection.anchor.offset > 0) {\n editor.update(() => {\n $getNodeByKey(lastNodeKey)?.selectStart();\n });\n return;\n }\n\n // If the selection is a range which includes the sentinel, modify the range to exclude it\n if (!selection.isCollapsed()) {\n let selectionChanged = false;\n const newSelection = selection.clone();\n\n if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {\n newSelection.anchor.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {\n newSelection.focus.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n\n if (selectionChanged) {\n editor.update(() => {\n if ($getNodeByKey(lastNodeKey) !== null) {\n $setSelection($normalizeSelection__EXPERIMENTAL(newSelection));\n }\n });\n }\n }\n });\n };\n\n return mergeRegister(\n editor.registerUpdateListener(sentinelNodeUpdateHandler),\n editor.registerNodeTransform(SentinelNode, node => {\n if (!node.getPreviousSibling() || node.getNextSibling()) {\n node.remove();\n return;\n }\n }),\n );\n}\n"],"names":["registerSentinelNodeHandlers","editor","sentinelNodeUpdateHandler","editorState","
|
|
1
|
+
{"version":3,"sources":["SentinelNodeHandlers.ts"],"sourcesContent":["import type {\n LexicalEditor,\n UpdateListener} from '@fluentui-copilot/text-editor';\nimport {\n $getLeafNodes,\n $getNodeByKey,\n $getRoot,\n $getSelection,\n $isRangeSelection,\n $normalizeSelection__EXPERIMENTAL,\n $setSelection,\n mergeRegister\n} from '@fluentui-copilot/text-editor';\nimport { $isSentinelNode, $createSentinelNode, SentinelNode } from './SentinelNode';\n\nexport function registerSentinelNodeHandlers(editor: LexicalEditor) {\n // Add a sentinel node at the end of the input when there is content.\n // This sentinel node fixes a number of issues.\n // In Safari, Lexical's behaviour of adding <br /> tags to the end of the input when it ends\n // in a decorator node causes cursor location issues: https://github.com/facebook/lexical/issues/4487\n // Otherwise, when a decorator node is the last node in the input, the cursor can't move past it.\n // Adding an invisible text node that doesn't contribute to the content and can't be selected to the end of the input\n // mitigates these issues.\n const sentinelNodeUpdateHandler: UpdateListener = ({ editorState }) => {\n editorState.read(() => {\n const leaves = $getLeafNodes($getRoot());\n if (leaves.length === 0) {\n return;\n }\n\n const lastNode = leaves[leaves.length - 1];\n const lastNodeKey = lastNode.getKey();\n\n // If the last node isn't a sentinel, add one\n if (!$isSentinelNode(lastNode)) {\n editor.update(\n () => {\n // We find the node by its key again in case the node was removed before this update runs\n $getNodeByKey(lastNodeKey)?.insertAfter($createSentinelNode());\n },\n // historic tag prevents every sentinel node addition from being added to LexicalHistoryPlugin undo stack\n { discrete: true, tag: 'historic' },\n );\n return;\n }\n\n // If the sentinel node is not selected, we're done\n const previous = lastNode.getPreviousSibling();\n if (!previous || !lastNode.isSelected()) {\n return;\n }\n\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n // If the cursor is inside the sentinel node, move it out (next to the beginning)\n // We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node\n // where selection is ill-defined.\n if (selection.isCollapsed() && selection.anchor.offset > 0) {\n editor.update(() => {\n $getNodeByKey(lastNodeKey)?.selectStart();\n });\n return;\n }\n\n // If the selection is a range which includes the sentinel, modify the range to exclude it\n if (!selection.isCollapsed()) {\n let selectionChanged = false;\n const newSelection = selection.clone();\n\n if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {\n newSelection.anchor.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {\n newSelection.focus.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n\n if (selectionChanged) {\n editor.update(() => {\n if ($getNodeByKey(lastNodeKey) !== null) {\n $setSelection($normalizeSelection__EXPERIMENTAL(newSelection));\n }\n });\n }\n }\n });\n };\n\n return mergeRegister(\n editor.registerUpdateListener(sentinelNodeUpdateHandler),\n editor.registerNodeTransform(SentinelNode, node => {\n if (!node.getPreviousSibling() || node.getNextSibling()) {\n node.remove();\n return;\n }\n }),\n );\n}\n"],"names":["registerSentinelNodeHandlers","editor","sentinelNodeUpdateHandler","editorState","leaves","$getLeafNodes","$getRoot","length","lastNode","lastNodeKey","$isSentinelNode","$getNodeByKey","discrete","_$getNodeByKey","insertAfter","$createSentinelNode","previous","selection","$getSelection","$isRangeSelection","isCollapsed","anchor","offset","selectStart","newSelection","selectionChanged","clone","getNode","focus","update","$setSelection","$normalizeSelection__EXPERIMENTAL","mergeRegister","registerUpdateListener","registerNodeTransform","SentinelNode","node","getPreviousSibling","getNextSibling","remove"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAegBA;;;eAAAA;;;4BAHT;8BAC4D;AAE5D,SAASA,6BAA6BC,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C,IAAAA,6CAAA,EAAAP;wBACF;oBACF;gBAEA;;;;WAMIQ,IAAAA,yBAAA,EAAA/B,OAAAgC,sBAAA,CAAA/B,4BAAAD,OAAAiC,qBAAA,CAAAC,0BAAA,EAAAC,CAAAA;QACF,IAAA,CAAAA,KAAAC,kBAAA,MAAAD,KAAAE,cAAA,IAAA;YAEJF,KAAAG,MAAA"}
|
|
@@ -72,10 +72,12 @@ class ChatInputEntityPluginBase {
|
|
|
72
72
|
this.__editor = editor;
|
|
73
73
|
this.__id = id;
|
|
74
74
|
this.__nodeClass = nodeClass;
|
|
75
|
-
this._cleanup = (0, _texteditor.mergeRegister)(
|
|
75
|
+
this._cleanup = (0, _texteditor.mergeRegister)(// Keep track of delete direction so we know where to put the selection after adding back a space
|
|
76
|
+
editor.registerCommand(_texteditor.DELETE_CHARACTER_COMMAND, (isBackward)=>{
|
|
76
77
|
this.__deleteDirection = isBackward ? 'backward' : 'forward';
|
|
77
78
|
return false;
|
|
78
|
-
}, _texteditor.COMMAND_PRIORITY_CRITICAL),
|
|
79
|
+
}, _texteditor.COMMAND_PRIORITY_CRITICAL), // Always maintain a space before, after, and between entities in order for selection to work properly
|
|
80
|
+
editor.registerNodeTransform(this.__nodeClass, (node)=>{
|
|
79
81
|
const nextSibling = node.getNextSibling();
|
|
80
82
|
if (!nextSibling || (0, _texteditor.$isDecoratorNode)(nextSibling)) {
|
|
81
83
|
const selection = (0, _texteditor.$getSelection)();
|
|
@@ -122,4 +124,4 @@ class ChatInputEntityPluginBase {
|
|
|
122
124
|
}
|
|
123
125
|
function noop() {
|
|
124
126
|
return;
|
|
125
|
-
}
|
|
127
|
+
} //# sourceMappingURL=ChatInputEntityPlugin.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ChatInputEntityPlugin.base.ts"],"sourcesContent":["import type { LexicalEditor, LexicalNode, NodeKey, Klass } from '@fluentui-copilot/text-editor';\nimport {\n $createParagraphNode,\n $createTextNode,\n $getNodeByKey,\n $getSelection,\n $insertNodes,\n $isDecoratorNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n $nodesOfType,\n $wrapNodeInElement,\n COMMAND_PRIORITY_CRITICAL,\n DELETE_CHARACTER_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport type {\n ChatInputEntityData,\n ChatInputEntityPluginProps,\n IChatInputEntityPluginBase,\n IEntityNode,\n} from './ChatInputEntityPlugin.types';\n\nexport class ChatInputEntityPluginBase<\n ExtraDataType,\n NodePropsType,\n NodeType extends IEntityNode<ExtraDataType, NodePropsType>,\n> implements IChatInputEntityPluginBase<ExtraDataType, NodePropsType>\n{\n private __nodeClass: Klass<NodeType>;\n private __editor: LexicalEditor;\n private __id: string;\n\n private __deleteDirection: 'forward' | 'backward' | null = null;\n private __$createNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => NodeType;\n\n private _cleanup: () => void;\n\n cleanup() {\n this._cleanup();\n }\n\n constructor(\n editor: LexicalEditor,\n id: string,\n nodeClass: Klass<NodeType>,\n $createNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => NodeType,\n $isChatInputEntityNode: (node: LexicalNode | null) => node is NodeType,\n onChatInputEntityAdded?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityAdded'],\n onChatInputEntityDeleted?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityDeleted'],\n ) {\n this.__$createNode = $createNode;\n this.__editor = editor;\n this.__id = id;\n this.__nodeClass = nodeClass;\n\n this._cleanup = mergeRegister(\n // Keep track of delete direction so we know where to put the selection after adding back a space\n editor.registerCommand(\n DELETE_CHARACTER_COMMAND,\n isBackward => {\n this.__deleteDirection = isBackward ? 'backward' : 'forward';\n return false;\n },\n COMMAND_PRIORITY_CRITICAL,\n ),\n // Always maintain a space before, after, and between entities in order for selection to work properly\n editor.registerNodeTransform(this.__nodeClass, node => {\n const nextSibling = node.getNextSibling();\n if (!nextSibling || $isDecoratorNode(nextSibling)) {\n const selection = $getSelection();\n\n // If selection is between the two nodes, that means the user is trying to delete the space\n // If they deleted to the left, we should move the cursor to the end of the entity\n // If they delete to the right, we should move the cursor to the end of the newly added space\n // This mimics changing the delete into a cursor move action\n const shouldMoveSelection =\n selection &&\n $isRangeSelection(selection) &&\n selection.isCollapsed() &&\n selection.anchor.offset === node.getIndexWithinParent() + 1;\n const text = $createTextNode(' ');\n node.insertAfter(text);\n if (shouldMoveSelection) {\n if (this.__deleteDirection === 'forward') {\n text.selectEnd();\n } else {\n node.selectEnd();\n }\n }\n }\n\n // In the case the entity is the first node, we need a space before it.\n if (!node.getPreviousSibling()) {\n const text = $createTextNode(' ');\n node.insertBefore(text);\n }\n }),\n onChatInputEntityAdded || onChatInputEntityDeleted\n ? editor.registerMutationListener(this.__nodeClass, (nodes, payload) => {\n for (const [nodeKey, mutation] of nodes) {\n if (onChatInputEntityDeleted && mutation === 'destroyed') {\n payload.prevEditorState.read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityDeleted(node.getEntityData(), nodeKey);\n }\n });\n } else if (onChatInputEntityAdded && mutation === 'created') {\n editor.getEditorState().read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityAdded(node.getEntityData(), nodeKey);\n }\n });\n }\n }\n })\n : noop,\n );\n }\n insertChatInputEntity(props: ChatInputEntityData<ExtraDataType, NodePropsType>): string | undefined {\n let key: string | undefined = undefined;\n this.__editor.update(() => {\n const { text, data, entityProps } = props;\n\n const entityNode = this.__$createNode(this.__id, text, data, entityProps);\n\n $insertNodes([entityNode]);\n entityNode.selectEnd();\n if ($isRootOrShadowRoot(entityNode.getParentOrThrow())) {\n $wrapNodeInElement(entityNode, $createParagraphNode).selectEnd();\n }\n\n key = entityNode.getKey();\n });\n\n return key;\n }\n removeChatInputEntity(\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n ) {\n this.__editor.update(() => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass)\n .filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i))\n .forEach(node => node.remove());\n } else {\n $getNodeByKey(keyOrPredicate)?.remove();\n }\n });\n }\n updateChatInputEntityProps(\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n props:\n | ChatInputEntityData<ExtraDataType, NodePropsType>\n | ((\n oldProps: ChatInputEntityData<ExtraDataType, NodePropsType>,\n ) => ChatInputEntityData<ExtraDataType, NodePropsType>),\n ) {\n const updateNode = (node: NodeType) => {\n const newProps = typeof props === 'function' ? props(node.getEntityData()) : props;\n node.updateEntityData(newProps);\n };\n\n this.__editor.update(\n () => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass)\n .filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i))\n .forEach(updateNode);\n } else {\n const node = $getNodeByKey<NodeType>(keyOrPredicate);\n if (node) {\n updateNode(node);\n }\n }\n },\n { tag: 'historic' },\n );\n }\n\n getActiveEntities(): ChatInputEntityData<ExtraDataType, NodePropsType>[] {\n return this.__editor.getEditorState().read(() =>\n $nodesOfType(this.__nodeClass)\n .filter(node => node.__pluginId === this.__id)\n .map(node => node.getEntityData()),\n );\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["ChatInputEntityPluginBase","cleanup","_cleanup","insertChatInputEntity","props","key","undefined","__editor","update","text","data","entityProps","entityNode","__$createNode","__id","$insertNodes","selectEnd","$isRootOrShadowRoot","getParentOrThrow","$wrapNodeInElement","$createParagraphNode","getKey","removeChatInputEntity","keyOrPredicate","$nodesOfType","__nodeClass","filter","node","i","__pluginId","getEntityData","forEach","remove","$getNodeByKey","updateChatInputEntityProps","updateNode","newProps","updateEntityData","tag","getActiveEntities","getEditorState","read","map","constructor","editor","id","nodeClass","$createNode","$isChatInputEntityNode","onChatInputEntityAdded","onChatInputEntityDeleted","_define_property","__deleteDirection","mergeRegister","registerCommand","DELETE_CHARACTER_COMMAND","isBackward","COMMAND_PRIORITY_CRITICAL","registerNodeTransform","nextSibling","getNextSibling","$isDecoratorNode","selection","$getSelection","shouldMoveSelection","$isRangeSelection","isCollapsed","anchor","offset","getIndexWithinParent","$createTextNode","insertAfter","getPreviousSibling","insertBefore","registerMutationListener","nodes","payload","nodeKey","mutation","prevEditorState","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAuBaA;;;eAAAA;;;;4BARN;AAQA,MAAMA;IAqBXC,UAAU;QACR,IAAI,CAACC,QAAQ;IACf;IAuFAC,sBAAsBC,KAAwD,EAAsB;QAClG,IAAIC,MAA0BC;QAC9B,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;YACnB,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGP;YAEpC,MAAMQ,aAAa,IAAI,CAACC,aAAa,CAAC,IAAI,CAACC,IAAI,EAAEL,MAAMC,MAAMC;YAE7DI,IAAAA,wBAAAA,EAAa;gBAACH;aAAW;YACzBA,WAAWI,SAAS;YACpB,IAAIC,IAAAA,+BAAAA,EAAoBL,WAAWM,gBAAgB,KAAK;gBACtDC,IAAAA,8BAAAA,EAAmBP,YAAYQ,gCAAAA,EAAsBJ,SAAS;YAChE;YAEAX,MAAMO,WAAWS,MAAM;QACzB;QAEA,OAAOhB;IACT;IACAiB,sBACEC,cAA4G,EAC5G;QACA,IAAI,CAAChB,QAAQ,CAACC,MAAM,CAAC;YACnB,IAAI,OAAOe,mBAA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AAqB;oBACvB,IAAI,IAAI,CAACZ,iBAAiB,KAAK,WAAW;wBACxC3C,KAAKO,SAAS;oBAChB,OAAO;wBACLW,KAAKX,SAAS;oBAChB;gBACF;YACF;YAEA,uEAAuE;YACvE,IAAI,CAACW,KAAK6C,kBAAkB,IAAI;gBAC9B,MAAM/D,OAAO6D,IAAAA,2BAAAA,EAAgB;gBAC7B3C,KAAK8C,YAAY,CAAChE;YACpB;QACF,IACAwC,0BAA0BC,2BACtBN,OAAO8B,wBAAwB,CAAC,IAAI,CAACjD,WAAW,EAAE,CAACkD,OAAOC;YACxD,KAAK,MAAM,CAACC,SAASC,SAAS,IAAIH,MAAO;gBACvC,IAAIzB,4BAA4B4B,aAAa,aAAa;oBACxDF,QAAQG,eAAe,CAACtC,IAAI,CAAC;wBAC3B,MAAMd,OAAOM,IAAAA,yBAAAA,EAAc4C;wBAC3B,IAAI7B,uBAAuBrB,SAASA,KAAKE,UAAU,KAAKgB,IAAI;4BAC1DK,yBAAyBvB,KAAKG,aAAa,IAAI+C;wBACjD;oBACF;gBACF,OAAO,IAAI5B,0BAA0B6B,aAAa,WAAW;oBAC3DlC,OAAOJ,cAAc,GAAGC,IAAI,CAAC;wBAC3B,MAAMd,OAAOM,IAAAA,yBAAAA,EAAc4C;wBAC3B,IAAI7B,uBAAuBrB,SAASA,KAAKE,UAAU,KAAKgB,IAAI;4BAC1DI,uBAAuBtB,KAAKG,aAAa,IAAI+C;wBAC/C;oBACF;gBACF;YACF;QACF,KACAG;IAER;AAqEF;AAEA,SAASA;IACP;AACF"}
|
|
1
|
+
{"version":3,"sources":["ChatInputEntityPlugin.base.ts"],"sourcesContent":["import type { LexicalEditor, LexicalNode, NodeKey, Klass } from '@fluentui-copilot/text-editor';\nimport {\n $createParagraphNode,\n $createTextNode,\n $getNodeByKey,\n $getSelection,\n $insertNodes,\n $isDecoratorNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n $nodesOfType,\n $wrapNodeInElement,\n COMMAND_PRIORITY_CRITICAL,\n DELETE_CHARACTER_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport type {\n ChatInputEntityData,\n ChatInputEntityPluginProps,\n IChatInputEntityPluginBase,\n IEntityNode,\n} from './ChatInputEntityPlugin.types';\n\nexport class ChatInputEntityPluginBase<\n ExtraDataType,\n NodePropsType,\n NodeType extends IEntityNode<ExtraDataType, NodePropsType>,\n> implements IChatInputEntityPluginBase<ExtraDataType, NodePropsType>\n{\n private __nodeClass: Klass<NodeType>;\n private __editor: LexicalEditor;\n private __id: string;\n\n private __deleteDirection: 'forward' | 'backward' | null = null;\n private __$createNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => NodeType;\n\n private _cleanup: () => void;\n\n cleanup() {\n this._cleanup();\n }\n\n constructor(\n editor: LexicalEditor,\n id: string,\n nodeClass: Klass<NodeType>,\n $createNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => NodeType,\n $isChatInputEntityNode: (node: LexicalNode | null) => node is NodeType,\n onChatInputEntityAdded?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityAdded'],\n onChatInputEntityDeleted?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityDeleted'],\n ) {\n this.__$createNode = $createNode;\n this.__editor = editor;\n this.__id = id;\n this.__nodeClass = nodeClass;\n\n this._cleanup = mergeRegister(\n // Keep track of delete direction so we know where to put the selection after adding back a space\n editor.registerCommand(\n DELETE_CHARACTER_COMMAND,\n isBackward => {\n this.__deleteDirection = isBackward ? 'backward' : 'forward';\n return false;\n },\n COMMAND_PRIORITY_CRITICAL,\n ),\n // Always maintain a space before, after, and between entities in order for selection to work properly\n editor.registerNodeTransform(this.__nodeClass, node => {\n const nextSibling = node.getNextSibling();\n if (!nextSibling || $isDecoratorNode(nextSibling)) {\n const selection = $getSelection();\n\n // If selection is between the two nodes, that means the user is trying to delete the space\n // If they deleted to the left, we should move the cursor to the end of the entity\n // If they delete to the right, we should move the cursor to the end of the newly added space\n // This mimics changing the delete into a cursor move action\n const shouldMoveSelection =\n selection &&\n $isRangeSelection(selection) &&\n selection.isCollapsed() &&\n selection.anchor.offset === node.getIndexWithinParent() + 1;\n const text = $createTextNode(' ');\n node.insertAfter(text);\n if (shouldMoveSelection) {\n if (this.__deleteDirection === 'forward') {\n text.selectEnd();\n } else {\n node.selectEnd();\n }\n }\n }\n\n // In the case the entity is the first node, we need a space before it.\n if (!node.getPreviousSibling()) {\n const text = $createTextNode(' ');\n node.insertBefore(text);\n }\n }),\n onChatInputEntityAdded || onChatInputEntityDeleted\n ? editor.registerMutationListener(this.__nodeClass, (nodes, payload) => {\n for (const [nodeKey, mutation] of nodes) {\n if (onChatInputEntityDeleted && mutation === 'destroyed') {\n payload.prevEditorState.read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityDeleted(node.getEntityData(), nodeKey);\n }\n });\n } else if (onChatInputEntityAdded && mutation === 'created') {\n editor.getEditorState().read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityAdded(node.getEntityData(), nodeKey);\n }\n });\n }\n }\n })\n : noop,\n );\n }\n insertChatInputEntity(props: ChatInputEntityData<ExtraDataType, NodePropsType>): string | undefined {\n let key: string | undefined = undefined;\n this.__editor.update(() => {\n const { text, data, entityProps } = props;\n\n const entityNode = this.__$createNode(this.__id, text, data, entityProps);\n\n $insertNodes([entityNode]);\n entityNode.selectEnd();\n if ($isRootOrShadowRoot(entityNode.getParentOrThrow())) {\n $wrapNodeInElement(entityNode, $createParagraphNode).selectEnd();\n }\n\n key = entityNode.getKey();\n });\n\n return key;\n }\n removeChatInputEntity(\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n ) {\n this.__editor.update(() => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass)\n .filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i))\n .forEach(node => node.remove());\n } else {\n $getNodeByKey(keyOrPredicate)?.remove();\n }\n });\n }\n updateChatInputEntityProps(\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n props:\n | ChatInputEntityData<ExtraDataType, NodePropsType>\n | ((\n oldProps: ChatInputEntityData<ExtraDataType, NodePropsType>,\n ) => ChatInputEntityData<ExtraDataType, NodePropsType>),\n ) {\n const updateNode = (node: NodeType) => {\n const newProps = typeof props === 'function' ? props(node.getEntityData()) : props;\n node.updateEntityData(newProps);\n };\n\n this.__editor.update(\n () => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass)\n .filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i))\n .forEach(updateNode);\n } else {\n const node = $getNodeByKey<NodeType>(keyOrPredicate);\n if (node) {\n updateNode(node);\n }\n }\n },\n { tag: 'historic' },\n );\n }\n\n getActiveEntities(): ChatInputEntityData<ExtraDataType, NodePropsType>[] {\n return this.__editor.getEditorState().read(() =>\n $nodesOfType(this.__nodeClass)\n .filter(node => node.__pluginId === this.__id)\n .map(node => node.getEntityData()),\n );\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["ChatInputEntityPluginBase","cleanup","_cleanup","insertChatInputEntity","props","key","__editor","update","$insertNodes","entityNode","selectEnd","__id","text","data","entityProps","$isRootOrShadowRoot","$wrapNodeInElement","getParentOrThrow","$createParagraphNode","removeChatInputEntity","keyOrPredicate","$nodesOfType","$getNodeByKey","_$getNodeByKey","remove","updateChatInputEntityProps","updateEntityData","newProps","node","getEntityData","updateNode","tag","getActiveEntities","constructor","editor","id","$createNode","$isChatInputEntityNode","onChatInputEntityAdded","onChatInputEntityDeleted","map","nodeClass","__deleteDirection","__$createNode","__nodeClass","registerCommand","COMMAND_PRIORITY_CRITICAL","isBackward","registerNodeTransform","$isDecoratorNode","$getSelection","getNextSibling","nextSibling","isCollapsed","$isRangeSelection","selection","anchor","offset","getIndexWithinParent","$createTextNode","mutation","nodeKey","read","getEditorState","__pluginId","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAuBaA;;;eAAAA;;;;4BARN;AAQA,MAAMA;cAqBXC;YACE,CAAAC,QAAKA;;0BAwFPC,KAAsBC,EAAwD;YAC5EC,MAAIA;YACJ,CAAAC,QAAKA,CAAAA,MAASC,CAAAA;kBACZ,MAEA,MAEAC,aAAcC;kBACdA,aAAWC,IAAAA,CAAAA,aAAS,CAAA,IAAA,CAAAC,IAAA,EAAAC,MAAAC,MAAAC;wCAChBC,EAAAA;gBAAAA;aAAAA;uBACFC,SAAAA;mDACF,EAAAP,WAAAQ,gBAAA,KAAA;kDAEMR,EAAAA,YAAiBS,gCAAA,EAAAR,SAAA;;kBAGzBD,WAAOJ,MAAAA;QACT;QACAc,OAAAA;;0BAIeC,cAAAA,EAAAA;qBACTC,CAAAA,MAAAA,CAAAA;uBAGFD,mBAAO,YAAA;4CACLE,EAAAA,IAAAA,CAAAA,WAAAA,EAAAA,MAAAA,CAAAA,CAAAA,MAAAA,IAAAA,KAAAA,UAAAA,KAAAA,IAAAA,CAAAA,IAAAA,IAAAA,eAAAA,KAAAA,aAAAA,IAAAA,IAAAA,OAAAA,CAAAA,CAAAA,OAAAA,KAAAA,MAAAA;;oBACFC;gBACFA,CAAAA,iBAAAD,IAAAA,yBAAA,EAAAF,eAAA,MAAA,QAAAG,mBAAA,KAAA,IAAA,KAAA,IAAAA,eAAAC,MAAA;YACF;QACAC;;+BASqBL,cAAOhB,EAAAA,KAAU,EAAA;2BAC7BsB,CAAAA;k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GAAAA,aAA2BJ,aAAahB;mBAC7C;gDACoBqB,yGACAC;oCAElB,CAAA,IAAA,CAAAN,WAAA,EAAAhB,CAAAA;gCACAA,KAAAuB,cAAA;gCACAF,IAAAA,4BAAA,EAAAG,cAAA;kCACAF,IAAAA,yBAAA;2GAIYG;kGAEiB;6GACZzC;4EACQ;4CACd8B,aAAiBY,IAAAA,6BAAgB,EAAAC,cAAAA,UAAAF,WAAA,MAAAE,UAAAC,MAAA,CAAAC,MAAA,KAAA7B,KAAA8B,oBAAA,KAAA;4DACnChD,EAAAA;gCACP,CAAAE;yCACOF;8CACP,KAAA,WAAA;6BACFA,SAAA;2BACF;wBAEAkB,KAAAlB,SAAA;;;;mFAIA;gBACF,CAAAkB,KACAU,kBAAAA,IAA0BC;sBAEpB3B,OAAK+C,IAAAA,2BAAgBC,EAAAA;iCACfrB,CAAAA;;sCAEMX,2BAAqBiC,OAAAA,wBAAAA,CAAAA,IAAAA,CAAAA,WAAAA,EAAAA,CAAAA,OAAAA;iCAC3BD,SAAIvB,IAAAA,MAAAA;gDACFE,aAAyBX,aAAKC;2CAChC,CAAAiC,IAAA,CAAA;qCACFxC,IAAAA,yBAAA,EAAAuC;4BACFxB,uBAAWC,SAAAA,KAA0BsB,UAAAA,KAAazB,IAAA;qDACzC4B,KAAiBD,aAAK,IAAAD;;;qDAGzBvB,aAA4BT,WAAa;yCAC3C,GAAAiC,IAAA,CAAA;qCACFxC,IAAAA,yBAAA,EAAAuC;4BACFxB,uBAAAT,SAAAA,KAAAoC,UAAA,KAAA7B,IAAA;4BACFG,uBAAAV,KAAAC,aAAA,IAAAgC;wBACF;oBAGR;gBAqEF;YAEA;QACE,KAAAI;IACF"}
|
|
@@ -28,7 +28,8 @@ class GhostTextPluginBase {
|
|
|
28
28
|
setAllowCompletion(allowCompletion) {
|
|
29
29
|
this.__allowCompletion = allowCompletion;
|
|
30
30
|
}
|
|
31
|
-
constructor(editor, id, $getGhostText, nodeClass, createNode, componentProps,
|
|
31
|
+
constructor(editor, id, $getGhostText, nodeClass, createNode, componentProps, // Whether or not the ghost text should count as text inside the input for submitting and character count
|
|
32
|
+
exposeText, allowCompletion){
|
|
32
33
|
(0, _define_property._)(this, "__id", void 0);
|
|
33
34
|
(0, _define_property._)(this, "__$getGhostText", void 0);
|
|
34
35
|
(0, _define_property._)(this, "__componentProps", void 0);
|
|
@@ -164,4 +165,4 @@ class GhostTextPluginBase {
|
|
|
164
165
|
}
|
|
165
166
|
function noop() {
|
|
166
167
|
return;
|
|
167
|
-
}
|
|
168
|
+
} //# sourceMappingURL=GhostText.base.js.map
|