@fluentui-copilot/react-prompt-listbox 0.0.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +95 -1
- package/CHANGELOG.md +30 -1
- package/dist/index.d.ts +18 -63
- package/lib/components/PromptListbox/usePromptListboxStyles.styles.js +9 -6
- package/lib/components/PromptListbox/usePromptListboxStyles.styles.js.map +1 -1
- package/lib/components/PromptOption/usePromptOption.js +0 -5
- package/lib/components/PromptOption/usePromptOption.js.map +1 -1
- package/lib/components/PromptOption/usePromptOptionStyles.styles.js +22 -13
- package/lib/components/PromptOption/usePromptOptionStyles.styles.js.map +1 -1
- package/lib/components/utils/PromptListboxFunctionality.types.js.map +1 -1
- package/lib/components/utils/dropdownKeyActions.js +21 -5
- package/lib/components/utils/dropdownKeyActions.js.map +1 -1
- package/lib/components/utils/{useComboboxPositioning.js → useListboxPositioning.js} +3 -2
- package/lib/components/utils/useListboxPositioning.js.map +1 -0
- package/lib/components/utils/usePromptListboxFunctionality.js +28 -36
- package/lib/components/utils/usePromptListboxFunctionality.js.map +1 -1
- package/lib/components/utils/useTriggerKeyDown.js +31 -11
- package/lib/components/utils/useTriggerKeyDown.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/CursorPositionPlugin.js +43 -0
- package/lib/plugins/CursorPositionPlugin.js.map +1 -0
- package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.js +11 -20
- package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.js.map +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOption.js +0 -3
- package/lib-commonjs/components/PromptOption/usePromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.js +33 -54
- package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.js.map +1 -1
- package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js.map +1 -1
- package/lib-commonjs/components/utils/dropdownKeyActions.js +19 -5
- package/lib-commonjs/components/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/components/utils/{useComboboxPositioning.js → useListboxPositioning.js} +5 -4
- package/lib-commonjs/components/utils/useListboxPositioning.js.map +1 -0
- package/lib-commonjs/components/utils/usePromptListboxFunctionality.js +30 -34
- package/lib-commonjs/components/utils/usePromptListboxFunctionality.js.map +1 -1
- package/lib-commonjs/components/utils/useTriggerKeyDown.js +27 -10
- package/lib-commonjs/components/utils/useTriggerKeyDown.js.map +1 -1
- package/lib-commonjs/index.js +0 -4
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/plugins/CursorPositionPlugin.js +54 -0
- package/lib-commonjs/plugins/CursorPositionPlugin.js.map +1 -0
- package/package.json +17 -18
- package/lib/components/utils/useComboboxPositioning.js.map +0 -1
- package/lib/plugins/TextCursorPositionPlugin.js +0 -44
- package/lib/plugins/TextCursorPositionPlugin.js.map +0 -1
- package/lib-commonjs/components/utils/useComboboxPositioning.js.map +0 -1
- package/lib-commonjs/plugins/TextCursorPositionPlugin.js +0 -52
- package/lib-commonjs/plugins/TextCursorPositionPlugin.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export type { PromptListboxProps, PromptListboxSlots, PromptListboxState } from './PromptListbox';\nexport {\n PromptListbox,\n promptListboxClassNames,\n renderPromptListbox_unstable,\n usePromptListboxStyles_unstable,\n usePromptListbox_unstable,\n} from './PromptListbox';\n\nexport { usePromptListboxFunctionality } from './components/utils/usePromptListboxFunctionality';\nexport type {\n OnOpenChangeData,\n ProcessedPromptListboxProps,\n UsePromptListboxFunctionality,\n UsePromptListboxFunctionalityParams,\n} from './components/utils/PromptListboxFunctionality.types';\n\nexport type {
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export type { PromptListboxProps, PromptListboxSlots, PromptListboxState } from './PromptListbox';\nexport {\n PromptListbox,\n promptListboxClassNames,\n renderPromptListbox_unstable,\n usePromptListboxStyles_unstable,\n usePromptListbox_unstable,\n} from './PromptListbox';\n\nexport { usePromptListboxFunctionality } from './components/utils/usePromptListboxFunctionality';\nexport type {\n OnOpenChangeData,\n ProcessedPromptListboxProps,\n UsePromptListboxFunctionality,\n UsePromptListboxFunctionalityParams,\n} from './components/utils/PromptListboxFunctionality.types';\n\nexport type { PromptOptionProps, PromptOptionSlots, PromptOptionState } from './PromptOption';\nexport {\n PromptOption,\n promptOptionClassNames,\n renderPromptOption_unstable,\n usePromptOptionStyles_unstable,\n usePromptOption_unstable,\n} from './PromptOption';\n"],"names":["PromptListbox","PromptOption","promptListboxClassNames","promptOptionClassNames","renderPromptListbox_unstable","renderPromptOption_unstable","usePromptListboxFunctionality","usePromptListboxStyles_unstable","usePromptListbox_unstable","usePromptOptionStyles_unstable","usePromptOption_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAEEA,aAAa;eAAbA,4BAAa;;IAiBbC,YAAY;eAAZA,0BAAY;;IAhBZC,uBAAuB;eAAvBA,sCAAuB;;IAiBvBC,sBAAsB;eAAtBA,oCAAsB;;IAhBtBC,4BAA4B;eAA5BA,2CAA4B;;IAiB5BC,2BAA2B;eAA3BA,yCAA2B;;IAZpBC,6BAA6B;eAA7BA,4DAA6B;;IAJpCC,+BAA+B;eAA/BA,8CAA+B;;IAC/BC,yBAAyB;eAAzBA,wCAAyB;;IAgBzBC,8BAA8B;eAA9BA,4CAA8B;;IAC9BC,wBAAwB;eAAxBA,sCAAwB;;;+BAhBnB;+CAEuC;8BAevC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "CursorPositionPlugin", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return CursorPositionPlugin;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
|
|
13
|
+
const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
|
|
14
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
15
|
+
const CursorPositionPlugin = ({ setCursorPosition })=>{
|
|
16
|
+
const [editor] = (0, _reacttexteditor.useLexicalComposerContext)();
|
|
17
|
+
_react.useEffect(()=>{
|
|
18
|
+
const $selectionChangeHandler = ()=>{
|
|
19
|
+
const selection = (0, _reacttexteditor.$getSelection)();
|
|
20
|
+
// If selection is null, the cursor is not active in the editor and we should just noop
|
|
21
|
+
if (selection === null || !(0, _reacttexteditor.$isRangeSelection)(selection) || !selection.isCollapsed()) {
|
|
22
|
+
setCursorPosition('between-text');
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// Should only be one node in the selection because the selection is collapsed
|
|
26
|
+
const selectedNode = selection.getNodes().at(0);
|
|
27
|
+
// If there's no selected node, focus isn't in the editor
|
|
28
|
+
if (!selectedNode) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// If there are no leaf nodes, the paragraph node will be selected
|
|
32
|
+
if ((0, _reacttexteditor.$isElementNode)(selectedNode)) {
|
|
33
|
+
setCursorPosition('start-end');
|
|
34
|
+
return false;
|
|
35
|
+
} else if ((0, _chatinputplugins.$isSentinelNode)(selectedNode) && !selectedNode.getNextSibling()) {
|
|
36
|
+
setCursorPosition('end');
|
|
37
|
+
return false;
|
|
38
|
+
} else if ((0, _chatinputplugins.$isSentinelNode)(selectedNode.getNextSibling()) && selection.focus.offset === selectedNode.getTextContentSize()) {
|
|
39
|
+
setCursorPosition('end');
|
|
40
|
+
return false;
|
|
41
|
+
} else if (selectedNode.getPreviousSibling() === null && selection.focus.offset === 0) {
|
|
42
|
+
setCursorPosition('start');
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
setCursorPosition('between-text');
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
return editor.registerCommand(_reacttexteditor.SELECTION_CHANGE_COMMAND, $selectionChangeHandler, _reacttexteditor.COMMAND_PRIORITY_HIGH);
|
|
49
|
+
}, [
|
|
50
|
+
editor,
|
|
51
|
+
setCursorPosition
|
|
52
|
+
]);
|
|
53
|
+
return null;
|
|
54
|
+
}; //# sourceMappingURL=CursorPositionPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["CursorPositionPlugin.ts"],"sourcesContent":["import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport {\n SELECTION_CHANGE_COMMAND,\n $getSelection,\n useLexicalComposerContext,\n $isRangeSelection,\n $isElementNode,\n COMMAND_PRIORITY_HIGH,\n} from '@fluentui-copilot/react-text-editor';\nimport * as React from 'react';\n\n/**\n * Position the cursor is in based on it's content. The goal\n * is to track whether the cursor is at the end of the input\n * or between text.\n */\nexport type CursorPosition = 'start' | 'between-text' | 'end' | 'start-end';\n\nexport type CursorPositionPluginProps = {\n setCursorPosition: (position: CursorPosition) => void;\n};\n\nexport const CursorPositionPlugin: React.FunctionComponent<CursorPositionPluginProps> = ({ setCursorPosition }) => {\n const [editor] = useLexicalComposerContext();\n\n React.useEffect(() => {\n const $selectionChangeHandler = () => {\n const selection = $getSelection();\n // If selection is null, the cursor is not active in the editor and we should just noop\n if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {\n setCursorPosition('between-text');\n return false;\n }\n\n // Should only be one node in the selection because the selection is collapsed\n const selectedNode = selection.getNodes().at(0);\n // If there's no selected node, focus isn't in the editor\n if (!selectedNode) {\n return false;\n }\n\n // If there are no leaf nodes, the paragraph node will be selected\n if ($isElementNode(selectedNode)) {\n setCursorPosition('start-end');\n return false;\n }\n\n // if the selection node is a sentinel and it matches the sentinel at the end\n else if ($isSentinelNode(selectedNode) && !selectedNode.getNextSibling()) {\n setCursorPosition('end');\n return false;\n }\n\n // else if the selection node is not a sentinel, check that the next sibling node is a sentinel\n // and check if the focus offset is in the last position of the node.\n else if (\n $isSentinelNode(selectedNode.getNextSibling()) &&\n selection.focus.offset === selectedNode.getTextContentSize()\n ) {\n setCursorPosition('end');\n return false;\n }\n\n // else if the selection node is not at the end and is not a sentinel, check if there's a previous\n // sibling and that we are at the start. If that's the case we are at the start.\n else if (selectedNode.getPreviousSibling() === null && selection.focus.offset === 0) {\n setCursorPosition('start');\n return false;\n }\n\n setCursorPosition('between-text');\n return false;\n };\n\n return editor.registerCommand(SELECTION_CHANGE_COMMAND, $selectionChangeHandler, COMMAND_PRIORITY_HIGH);\n }, [editor, setCursorPosition]);\n\n return null;\n};\n"],"names":["CursorPositionPlugin","editor","$selectionChangeHandler","selection","$isRangeSelection","isCollapsed","selectedNode","getNodes","at","$isSentinelNode","getNextSibling","focus","offset","getTextContentSize","getPreviousSibling","setCursorPosition"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAsBaA;;;eAAAA;;;;kCAtBmB;iCAQzB;iEACgB;AAahB,MAAMA,uBAA2E,CAAC,mBACzE;UAGZ,CAAAC,OAAMC,GAAAA,IAAAA,0CAA0B;oBAC9B,CAAMC;wCACN;kBACAA,YAAIA,IAAAA,8BAAc;mGACE;8BACX,QAAA,CAAAC,IAAAA,kCAAA,EAAAD,cAAA,CAAAA,UAAAE,WAAA,IAAA;kCACT;uBAEA;;0FAEyD;kBACzDC,eAAKA,UAAcC,QAAA,GAAAC,EAAA,CAAA;qEACV;+BACT;uBAEA;;8EAEoB;mDACX,EAAAF,eAAA;kCAIAG;;uBAEPA,IAAAA,iCAAO,EAAAH,iBAAA,CAAAA,aAAAI,cAAA,IAAA;kCAMPD;;uBAIAA,IAAAA,iCAAO,EAAAH,aAAAI,cAAA,OAAAP,UAAAQ,KAAA,CAAAC,MAAA,KAAAN,aAAAO,kBAAA,IAAA;kCAKAP;;uBAEPA,aAAOQ,kBAAA,OAAA,QAAAX,UAAAQ,KAAA,CAAAC,MAAA,KAAA,GAAA;kCACT;uBAEAG;;8BAEF;mBAEA;QACF;eAAId,OAAAA,eAAAA,CAAAA,yCAAAA,EAAAA,yBAAAA,sCAAAA;;;QAAQc;KAAAA;WAAkB;GAGhC,gDAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-copilot/react-prompt-listbox",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "PromptListbox for input components using EditorInput.",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -12,26 +12,26 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@fluentui-copilot/chat-input-plugins": "^0.
|
|
16
|
-
"@fluentui-copilot/react-chat-input-plugins": "^0.
|
|
17
|
-
"@fluentui-copilot/react-editor-input": "^0.
|
|
18
|
-
"@fluentui-copilot/react-prompt-input": "^0.
|
|
19
|
-
"@fluentui-copilot/react-provider": "^0.
|
|
20
|
-
"@fluentui-copilot/react-text-editor": "^0.
|
|
21
|
-
"@fluentui-copilot/text-editor": "^0.0
|
|
15
|
+
"@fluentui-copilot/chat-input-plugins": "^0.2.0",
|
|
16
|
+
"@fluentui-copilot/react-chat-input-plugins": "^0.2.0",
|
|
17
|
+
"@fluentui-copilot/react-editor-input": "^0.2.0",
|
|
18
|
+
"@fluentui-copilot/react-prompt-input": "^0.3.0",
|
|
19
|
+
"@fluentui-copilot/react-provider": "^0.9.0",
|
|
20
|
+
"@fluentui-copilot/react-text-editor": "^0.2.0",
|
|
21
|
+
"@fluentui-copilot/text-editor": "^0.1.0",
|
|
22
22
|
"@swc/helpers": "^0.5.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@fluentui/keyboard-keys": ">=9.0.7 <10.0.0",
|
|
26
|
-
"@fluentui/react-aria": ">=9.13.
|
|
27
|
-
"@fluentui/react-combobox": ">=9.13.
|
|
28
|
-
"@fluentui/react-components": ">=9.54.
|
|
26
|
+
"@fluentui/react-aria": ">=9.13.2 <10.0.0",
|
|
27
|
+
"@fluentui/react-combobox": ">=9.13.3 <10.0.0",
|
|
28
|
+
"@fluentui/react-components": ">=9.54.10 <10.0.0",
|
|
29
29
|
"@fluentui/react-icons": ">=2.0.247 <3.0.0",
|
|
30
|
-
"@fluentui/react-jsx-runtime": ">=9.0.
|
|
31
|
-
"@fluentui/react-positioning": ">=9.15.
|
|
32
|
-
"@fluentui/react-shared-contexts": ">=9.
|
|
33
|
-
"@fluentui/react-tabster": ">=9.22.
|
|
34
|
-
"@fluentui/react-utilities": ">=9.18.
|
|
30
|
+
"@fluentui/react-jsx-runtime": ">=9.0.42 <10.0.0",
|
|
31
|
+
"@fluentui/react-positioning": ">=9.15.7 <10.0.0",
|
|
32
|
+
"@fluentui/react-shared-contexts": ">=9.20.0 <10.0.0",
|
|
33
|
+
"@fluentui/react-tabster": ">=9.22.3 <10.0.0",
|
|
34
|
+
"@fluentui/react-utilities": ">=9.18.13 <10.0.0",
|
|
35
35
|
"@types/react": ">=16.14.0 <19.0.0",
|
|
36
36
|
"@types/react-dom": ">=16.9.8 <19.0.0",
|
|
37
37
|
"react": ">=16.14.0 <19.0.0",
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"beachball": {
|
|
41
41
|
"disallowedChangeTypes": [
|
|
42
|
-
"major"
|
|
43
|
-
"minor"
|
|
42
|
+
"major"
|
|
44
43
|
]
|
|
45
44
|
},
|
|
46
45
|
"exports": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useComboboxPositioning.ts"],"sourcesContent":["// Brought from Fluent UI\n\nimport { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport type * as React from 'react';\nimport type { ComboboxBaseProps } from '@fluentui/react-combobox';\nimport type { UsePromptListboxFunctionalityParams } from './PromptListboxFunctionality.types';\nimport type { PositioningShorthandValue } from '@fluentui/react-positioning';\n\nexport function useComboboxPositioning(\n props: ComboboxBaseProps & Required<Pick<UsePromptListboxFunctionalityParams, 'fluid'>>,\n): [\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n listboxRef: React.MutableRefObject<any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerRef: React.MutableRefObject<any>,\n] {\n const { positioning, fluid } = props;\n\n const fallbackPositions: PositioningShorthandValue[] = ['below'];\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n fallbackPositions: fallbackPositions,\n matchTargetSize: fluid ? ('width' as const) : undefined,\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n return [containerRef, targetRef];\n}\n"],"names":["resolvePositioningShorthand","usePositioning","useComboboxPositioning","props","positioning","fluid","fallbackPositions","popperOptions","position","align","offset","crossAxis","mainAxis","matchTargetSize","undefined","targetRef","containerRef"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yBAAyB;AAEzB,SAASA,2BAA2B,EAAEC,cAAc,QAAQ,8BAA8B;AAM1F,OAAO,SAASC,uBACdC,KAAuF;IAOvF,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE,GAAGF;IAE/B,MAAMG,oBAAiD;QAAC;KAAQ;IAEhE,iBAAiB;IACjB,MAAMC,gBAAgB;QACpBC,UAAU;QACVC,OAAO;QACPC,QAAQ;YAAEC,WAAW;YAAGC,UAAU;QAAE;QACpCN,mBAAmBA;QACnBO,iBAAiBR,QAAS,UAAoBS;QAC9C,GAAGd,4BAA4BI,YAAY;IAC7C;IAEA,MAAM,EAAEW,SAAS,EAAEC,YAAY,EAAE,GAAGf,eAAeM;IAEnD,OAAO;QAACS;QAAcD;KAAU;AAClC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';
|
|
2
|
-
import { COMMAND_PRIORITY_CRITICAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, $getSelection, useLexicalComposerContext, $getLeafNodes, $getRoot, $isRangeSelection, mergeRegister } from '@fluentui-copilot/react-text-editor';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
export const TextCursorPositionPlugin = ({
|
|
5
|
-
setIsInLastPosition
|
|
6
|
-
}) => {
|
|
7
|
-
const [editor] = useLexicalComposerContext();
|
|
8
|
-
const keypressHandler = _ev => {
|
|
9
|
-
const root = $getRoot();
|
|
10
|
-
const leafNodes = $getLeafNodes(root);
|
|
11
|
-
const lastLeafNode = leafNodes.length === 0 ? undefined : leafNodes[leafNodes.length - 1];
|
|
12
|
-
const selection = $getSelection();
|
|
13
|
-
if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
14
|
-
setIsInLastPosition(false);
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const selectionNodes = selection.getNodes();
|
|
18
|
-
// if we don't have a lead node, then we don't have any nodes, so we are in the last position
|
|
19
|
-
if (selectionNodes.length === 0 || !lastLeafNode) {
|
|
20
|
-
setIsInLastPosition(true);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
const lastSelectionNode = selectionNodes[selectionNodes.length - 1];
|
|
24
|
-
// if the selection node is a sentinel and it matches the sentinel at the end
|
|
25
|
-
if ($isSentinelNode(lastSelectionNode) && lastSelectionNode.is(lastLeafNode)) {
|
|
26
|
-
setIsInLastPosition(true);
|
|
27
|
-
return false;
|
|
28
|
-
} else if ($isSentinelNode(lastSelectionNode.getNextSibling()) && selection.focus.offset === lastSelectionNode.getTextContentSize()) {
|
|
29
|
-
setIsInLastPosition(true);
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
setIsInLastPosition(false);
|
|
33
|
-
return false;
|
|
34
|
-
};
|
|
35
|
-
React.useEffect(() => {
|
|
36
|
-
return mergeRegister(editor.registerCommand(KEY_ARROW_DOWN_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(KEY_ARROW_UP_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL));
|
|
37
|
-
// We are disabling exhaustive-deps because we only want to register the command once on mount and the
|
|
38
|
-
// the teardown function when unmounting
|
|
39
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
40
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
-
}, []);
|
|
42
|
-
return null;
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=TextCursorPositionPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["TextCursorPositionPlugin.ts"],"sourcesContent":["import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport {\n COMMAND_PRIORITY_CRITICAL,\n KEY_ARROW_DOWN_COMMAND,\n KEY_ARROW_UP_COMMAND,\n $getSelection,\n useLexicalComposerContext,\n $getLeafNodes,\n $getRoot,\n $isRangeSelection,\n mergeRegister,\n} from '@fluentui-copilot/react-text-editor';\nimport * as React from 'react';\n\nexport type TextCursorPositionPluginProps = {\n setIsInLastPosition: (isInLastPosition: boolean) => void;\n};\n\nexport const TextCursorPositionPlugin: React.FunctionComponent<TextCursorPositionPluginProps> = ({\n setIsInLastPosition,\n}) => {\n const [editor] = useLexicalComposerContext();\n\n const keypressHandler = (_ev: KeyboardEvent) => {\n const root = $getRoot();\n const leafNodes = $getLeafNodes(root);\n const lastLeafNode = leafNodes.length === 0 ? undefined : leafNodes[leafNodes.length - 1];\n const selection = $getSelection();\n if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {\n setIsInLastPosition(false);\n return false;\n }\n\n const selectionNodes = selection.getNodes();\n // if we don't have a lead node, then we don't have any nodes, so we are in the last position\n if (selectionNodes.length === 0 || !lastLeafNode) {\n setIsInLastPosition(true);\n return false;\n }\n const lastSelectionNode = selectionNodes[selectionNodes.length - 1];\n\n // if the selection node is a sentinel and it matches the sentinel at the end\n if ($isSentinelNode(lastSelectionNode) && lastSelectionNode.is(lastLeafNode)) {\n setIsInLastPosition(true);\n return false;\n }\n // else if the selection node is not a sentinel, check that the next sibling node is a sentinel\n // and check if the focus offset is in the last position of the node.\n else if (\n $isSentinelNode(lastSelectionNode.getNextSibling()) &&\n selection.focus.offset === lastSelectionNode.getTextContentSize()\n ) {\n setIsInLastPosition(true);\n return false;\n }\n\n setIsInLastPosition(false);\n return false;\n };\n\n React.useEffect(() => {\n return mergeRegister(\n editor.registerCommand(KEY_ARROW_DOWN_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL),\n editor.registerCommand(KEY_ARROW_UP_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL),\n );\n // We are disabling exhaustive-deps because we only want to register the command once on mount and the\n // the teardown function when unmounting\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return null;\n};\n"],"names":["$isSentinelNode","COMMAND_PRIORITY_CRITICAL","KEY_ARROW_DOWN_COMMAND","KEY_ARROW_UP_COMMAND","$getSelection","useLexicalComposerContext","$getLeafNodes","$getRoot","$isRangeSelection","mergeRegister","React","TextCursorPositionPlugin","setIsInLastPosition","editor","keypressHandler","_ev","root","leafNodes","lastLeafNode","length","undefined","selection","isCollapsed","selectionNodes","getNodes","lastSelectionNode","is","getNextSibling","focus","offset","getTextContentSize","useEffect","registerCommand"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,eAAe,QAAQ,uCAAuC;AACvE,SACEC,yBAAyB,EACzBC,sBAAsB,EACtBC,oBAAoB,EACpBC,aAAa,EACbC,yBAAyB,EAC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":3,"sources":["useComboboxPositioning.ts"],"sourcesContent":["// Brought from Fluent UI\n\nimport { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport type * as React from 'react';\nimport type { ComboboxBaseProps } from '@fluentui/react-combobox';\nimport type { UsePromptListboxFunctionalityParams } from './PromptListboxFunctionality.types';\nimport type { PositioningShorthandValue } from '@fluentui/react-positioning';\n\nexport function useComboboxPositioning(\n props: ComboboxBaseProps & Required<Pick<UsePromptListboxFunctionalityParams, 'fluid'>>,\n): [\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n listboxRef: React.MutableRefObject<any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerRef: React.MutableRefObject<any>,\n] {\n const { positioning, fluid } = props;\n\n const fallbackPositions: PositioningShorthandValue[] = ['below'];\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n fallbackPositions: fallbackPositions,\n matchTargetSize: fluid ? ('width' as const) : undefined,\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n return [containerRef, targetRef];\n}\n"],"names":["useComboboxPositioning","props","positioning","fallbackPositions","popperOptions","position","align","offset","crossAxis","mainAxis","matchTargetSize","resolvePositioningShorthand","containerRef","targetRef","usePositioning"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yBAAyB;;;;;+BAQTA;;;eAAAA;;;kCAN4C;AAMrD,SAASA,uBACdC,KAAuF;UAOvF,EAEAC,WAAMC,OAAkD,KAAQF;UAEhEE,oBAAiB;QAAA;KAAA;qBACXC;UACJC,gBAAU;kBACVC;eACAC;gBAAUC;uBAAcC;sBAAY;;2BAEpCC;yBACGC,QAAAA,UAA4BT;QACjC,GAAAS,IAAAA,6CAAA,EAAAT,YAAA;;UAIA,WAAQU,cAAcC,KAAUC,IAAAA,gCAAA,EAAAV;IAClC,OAAA;QAAAQ;QAAAC;KAAA"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "TextCursorPositionPlugin", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TextCursorPositionPlugin;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
-
const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
|
|
13
|
-
const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
|
|
14
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
15
|
-
const TextCursorPositionPlugin = ({ setIsInLastPosition })=>{
|
|
16
|
-
const [editor] = (0, _reacttexteditor.useLexicalComposerContext)();
|
|
17
|
-
const keypressHandler = (_ev)=>{
|
|
18
|
-
const root = (0, _reacttexteditor.$getRoot)();
|
|
19
|
-
const leafNodes = (0, _reacttexteditor.$getLeafNodes)(root);
|
|
20
|
-
const lastLeafNode = leafNodes.length === 0 ? undefined : leafNodes[leafNodes.length - 1];
|
|
21
|
-
const selection = (0, _reacttexteditor.$getSelection)();
|
|
22
|
-
if (selection === null || !(0, _reacttexteditor.$isRangeSelection)(selection) || !selection.isCollapsed()) {
|
|
23
|
-
setIsInLastPosition(false);
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
const selectionNodes = selection.getNodes();
|
|
27
|
-
// if we don't have a lead node, then we don't have any nodes, so we are in the last position
|
|
28
|
-
if (selectionNodes.length === 0 || !lastLeafNode) {
|
|
29
|
-
setIsInLastPosition(true);
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
const lastSelectionNode = selectionNodes[selectionNodes.length - 1];
|
|
33
|
-
// if the selection node is a sentinel and it matches the sentinel at the end
|
|
34
|
-
if ((0, _chatinputplugins.$isSentinelNode)(lastSelectionNode) && lastSelectionNode.is(lastLeafNode)) {
|
|
35
|
-
setIsInLastPosition(true);
|
|
36
|
-
return false;
|
|
37
|
-
} else if ((0, _chatinputplugins.$isSentinelNode)(lastSelectionNode.getNextSibling()) && selection.focus.offset === lastSelectionNode.getTextContentSize()) {
|
|
38
|
-
setIsInLastPosition(true);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
setIsInLastPosition(false);
|
|
42
|
-
return false;
|
|
43
|
-
};
|
|
44
|
-
_react.useEffect(()=>{
|
|
45
|
-
return (0, _reacttexteditor.mergeRegister)(editor.registerCommand(_reacttexteditor.KEY_ARROW_DOWN_COMMAND, keypressHandler, _reacttexteditor.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(_reacttexteditor.KEY_ARROW_UP_COMMAND, keypressHandler, _reacttexteditor.COMMAND_PRIORITY_CRITICAL));
|
|
46
|
-
// We are disabling exhaustive-deps because we only want to register the command once on mount and the
|
|
47
|
-
// the teardown function when unmounting
|
|
48
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
49
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
-
}, []);
|
|
51
|
-
return null;
|
|
52
|
-
}; //# sourceMappingURL=TextCursorPositionPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["TextCursorPositionPlugin.ts"],"sourcesContent":["import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport {\n COMMAND_PRIORITY_CRITICAL,\n KEY_ARROW_DOWN_COMMAND,\n KEY_ARROW_UP_COMMAND,\n $getSelection,\n useLexicalComposerContext,\n $getLeafNodes,\n $getRoot,\n $isRangeSelection,\n mergeRegister,\n} from '@fluentui-copilot/react-text-editor';\nimport * as React from 'react';\n\nexport type TextCursorPositionPluginProps = {\n setIsInLastPosition: (isInLastPosition: boolean) => void;\n};\n\nexport const TextCursorPositionPlugin: React.FunctionComponent<TextCursorPositionPluginProps> = ({\n setIsInLastPosition,\n}) => {\n const [editor] = useLexicalComposerContext();\n\n const keypressHandler = (_ev: KeyboardEvent) => {\n const root = $getRoot();\n const leafNodes = $getLeafNodes(root);\n const lastLeafNode = leafNodes.length === 0 ? undefined : leafNodes[leafNodes.length - 1];\n const selection = $getSelection();\n if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {\n setIsInLastPosition(false);\n return false;\n }\n\n const selectionNodes = selection.getNodes();\n // if we don't have a lead node, then we don't have any nodes, so we are in the last position\n if (selectionNodes.length === 0 || !lastLeafNode) {\n setIsInLastPosition(true);\n return false;\n }\n const lastSelectionNode = selectionNodes[selectionNodes.length - 1];\n\n // if the selection node is a sentinel and it matches the sentinel at the end\n if ($isSentinelNode(lastSelectionNode) && lastSelectionNode.is(lastLeafNode)) {\n setIsInLastPosition(true);\n return false;\n }\n // else if the selection node is not a sentinel, check that the next sibling node is a sentinel\n // and check if the focus offset is in the last position of the node.\n else if (\n $isSentinelNode(lastSelectionNode.getNextSibling()) &&\n selection.focus.offset === lastSelectionNode.getTextContentSize()\n ) {\n setIsInLastPosition(true);\n return false;\n }\n\n setIsInLastPosition(false);\n return false;\n };\n\n React.useEffect(() => {\n return mergeRegister(\n editor.registerCommand(KEY_ARROW_DOWN_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL),\n editor.registerCommand(KEY_ARROW_UP_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL),\n );\n // We are disabling exhaustive-deps because we only want to register the command once on mount and the\n // the teardown function when unmounting\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return null;\n};\n"],"names":["TextCursorPositionPlugin","useLexicalComposerContext","editor","root","$getRoot","keypressHandler","$getLeafNodes","lastLeafNode","leafNodes","selection","$getSelection","$isRangeSelection","isCollapsed","setIsInLastPosition","selectionNodes","length","getNodes","lastSelectionNode","is","$isSentinelNode","getNextSibling","focus","offset","getTextContentSize","React","useEffect","merge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