@vendorflow/components 2.1.0 → 3.0.4
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/lib/components/index.d.ts +1 -1
- package/lib/components/material-ui/DataTable/Data.d.ts +1 -1
- package/lib/components/material-ui/DataTable/DataTable.d.ts +9 -76
- package/lib/components/material-ui/DataTable/FilterTool/Filters/MultiSelectFilter.d.ts +1 -1
- package/lib/components/material-ui/DataTable/FilterTool/Filters/RangeFilter.d.ts +1 -1
- package/lib/components/material-ui/DataTable/FilterTool/Filters/SingleSelectFilter.d.ts +1 -1
- package/lib/components/material-ui/DataTable/FilterTool/Filters/TextFilter.d.ts +1 -1
- package/lib/components/material-ui/DataTable/FilterTool/index.d.ts +2 -2
- package/lib/components/material-ui/DataTable/TablePieces/BodyRow.d.ts +1 -1
- package/lib/components/material-ui/DataTable/TablePieces/HeaderCell.d.ts +1 -1
- package/lib/components/material-ui/DataTable/TablePieces/Toolbar.d.ts +1 -1
- package/lib/components/material-ui/DataTable/index.d.ts +1 -1
- package/lib/index.js +3 -14
- package/lib/index.js.LICENSE.txt +35 -0
- package/lib/index.js.map +1 -0
- package/lib/types/DataTable.types.d.ts +69 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +20 -99
- package/lib/TempHooks.d.ts +0 -9
- package/lib/TempHooks.js +0 -25
- package/lib/components/InfiniteScroll/InfiniteScroll.d.ts +0 -16
- package/lib/components/InfiniteScroll/InfiniteScroll.js +0 -159
- package/lib/components/InfiniteScroll/index.d.ts +0 -1
- package/lib/components/InfiniteScroll/index.js +0 -8
- package/lib/components/blueprint/InputGroup/InputGroup.d.ts +0 -20
- package/lib/components/blueprint/InputGroup/InputGroup.js +0 -13
- package/lib/components/blueprint/InputGroup/InputGroup.story.d.ts +0 -2
- package/lib/components/blueprint/InputGroup/InputGroup.story.js +0 -11
- package/lib/components/blueprint/InputGroup/index.d.ts +0 -1
- package/lib/components/blueprint/InputGroup/index.js +0 -4
- package/lib/components/blueprint/InputSelect/InputSelect.d.ts +0 -51
- package/lib/components/blueprint/InputSelect/InputSelect.js +0 -98
- package/lib/components/blueprint/InputSelect/InputSelect.story.d.ts +0 -3
- package/lib/components/blueprint/InputSelect/InputSelect.story.js +0 -19
- package/lib/components/blueprint/InputSelect/index.d.ts +0 -1
- package/lib/components/blueprint/InputSelect/index.js +0 -4
- package/lib/components/blueprint/InputTime/InputTime.d.ts +0 -24
- package/lib/components/blueprint/InputTime/InputTime.js +0 -28
- package/lib/components/blueprint/InputTime/InputTime.story.d.ts +0 -2
- package/lib/components/blueprint/InputTime/InputTime.story.js +0 -11
- package/lib/components/blueprint/InputTime/index.d.ts +0 -1
- package/lib/components/blueprint/InputTime/index.js +0 -4
- package/lib/components/index.js +0 -32
- package/lib/components/material-ui/AudioPlayer/AudioPlayer.js +0 -111
- package/lib/components/material-ui/AudioPlayer/AudioPlayer.story.js +0 -9
- package/lib/components/material-ui/AudioPlayer/index.js +0 -8
- package/lib/components/material-ui/Button/Button.js +0 -38
- package/lib/components/material-ui/Button/Button.story.js +0 -9
- package/lib/components/material-ui/Button/index.js +0 -8
- package/lib/components/material-ui/ButtonMenu/ButtonMenu.js +0 -115
- package/lib/components/material-ui/ButtonMenu/ButtonMenu.story.js +0 -79
- package/lib/components/material-ui/ButtonMenu/index.js +0 -8
- package/lib/components/material-ui/ChatInterface/ActionsMenu.d.ts +0 -4
- package/lib/components/material-ui/ChatInterface/ActionsMenu.js +0 -37
- package/lib/components/material-ui/ChatInterface/ChatInterface.d.ts +0 -33
- package/lib/components/material-ui/ChatInterface/ChatInterface.js +0 -109
- package/lib/components/material-ui/ChatInterface/ChatInterface.story.d.ts +0 -1
- package/lib/components/material-ui/ChatInterface/ChatInterface.story.js +0 -134
- package/lib/components/material-ui/ChatInterface/MessageInput.d.ts +0 -9
- package/lib/components/material-ui/ChatInterface/MessageInput.js +0 -53
- package/lib/components/material-ui/ChatInterface/MessageItem.d.ts +0 -8
- package/lib/components/material-ui/ChatInterface/MessageItem.js +0 -71
- package/lib/components/material-ui/ChatInterface/MessageThread.d.ts +0 -6
- package/lib/components/material-ui/ChatInterface/MessageThread.js +0 -119
- package/lib/components/material-ui/ChatInterface/index.d.ts +0 -1
- package/lib/components/material-ui/ChatInterface/index.js +0 -8
- package/lib/components/material-ui/ColorPicker/ColorPicker.js +0 -86
- package/lib/components/material-ui/ColorPicker/ColorPicker.story.js +0 -47
- package/lib/components/material-ui/ColorPicker/index.js +0 -8
- package/lib/components/material-ui/ColorPicker/styles.js +0 -24
- package/lib/components/material-ui/DataTable/AppliedFilters.d.ts +0 -12
- package/lib/components/material-ui/DataTable/AppliedFilters.js +0 -26
- package/lib/components/material-ui/DataTable/Data.js +0 -42
- package/lib/components/material-ui/DataTable/DataTable.js +0 -363
- package/lib/components/material-ui/DataTable/DataTable.story.js +0 -76
- package/lib/components/material-ui/DataTable/FilterTool/Filters/MultiSelectFilter.js +0 -63
- package/lib/components/material-ui/DataTable/FilterTool/Filters/RangeFilter.js +0 -76
- package/lib/components/material-ui/DataTable/FilterTool/Filters/SingleSelectFilter.js +0 -69
- package/lib/components/material-ui/DataTable/FilterTool/Filters/TextFilter.js +0 -52
- package/lib/components/material-ui/DataTable/FilterTool/index.js +0 -78
- package/lib/components/material-ui/DataTable/GlobalSearchFilter.d.ts +0 -10
- package/lib/components/material-ui/DataTable/GlobalSearchFilter.js +0 -49
- package/lib/components/material-ui/DataTable/IndeterminateCheckbox.d.ts +0 -4
- package/lib/components/material-ui/DataTable/IndeterminateCheckbox.js +0 -65
- package/lib/components/material-ui/DataTable/SortIndicator.d.ts +0 -10
- package/lib/components/material-ui/DataTable/SortIndicator.js +0 -33
- package/lib/components/material-ui/DataTable/TablePieces/AppliedFilters.js +0 -26
- package/lib/components/material-ui/DataTable/TablePieces/BodyCell.js +0 -50
- package/lib/components/material-ui/DataTable/TablePieces/BodyRow.js +0 -88
- package/lib/components/material-ui/DataTable/TablePieces/GlobalSearchFilter.js +0 -49
- package/lib/components/material-ui/DataTable/TablePieces/HeaderCell.js +0 -57
- package/lib/components/material-ui/DataTable/TablePieces/IndeterminateCheckbox.js +0 -65
- package/lib/components/material-ui/DataTable/TablePieces/SortIndicator.js +0 -33
- package/lib/components/material-ui/DataTable/TablePieces/Table.js +0 -47
- package/lib/components/material-ui/DataTable/TablePieces/TableBodyContent.js +0 -89
- package/lib/components/material-ui/DataTable/TablePieces/Toolbar.js +0 -59
- package/lib/components/material-ui/DataTable/TablePieces/ViewColumnTool.js +0 -77
- package/lib/components/material-ui/DataTable/Toolbar.d.ts +0 -24
- package/lib/components/material-ui/DataTable/Toolbar.js +0 -63
- package/lib/components/material-ui/DataTable/Utils.d.ts +0 -25
- package/lib/components/material-ui/DataTable/Utils.js +0 -119
- package/lib/components/material-ui/DataTable/ViewColumnTool.d.ts +0 -11
- package/lib/components/material-ui/DataTable/ViewColumnTool.js +0 -76
- package/lib/components/material-ui/DataTable/index.js +0 -8
- package/lib/components/material-ui/ErrorBoundary/ErrorBoundary.d.ts +0 -7
- package/lib/components/material-ui/ErrorBoundary/ErrorBoundary.js +0 -20
- package/lib/components/material-ui/ErrorBoundary/index.d.ts +0 -1
- package/lib/components/material-ui/ErrorBoundary/index.js +0 -8
- package/lib/components/material-ui/InputCheckboxGroup/InputCheckboxGroup.js +0 -99
- package/lib/components/material-ui/InputCheckboxGroup/InputCheckboxGroup.story.js +0 -52
- package/lib/components/material-ui/InputCheckboxGroup/index.js +0 -8
- package/lib/components/material-ui/InputDate/InputDate.js +0 -93
- package/lib/components/material-ui/InputDate/InputDate.story.js +0 -53
- package/lib/components/material-ui/InputDate/index.js +0 -8
- package/lib/components/material-ui/InputDateTime/InputDateTime.js +0 -82
- package/lib/components/material-ui/InputDateTime/InputDateTime.story.js +0 -53
- package/lib/components/material-ui/InputDateTime/index.js +0 -8
- package/lib/components/material-ui/InputGroup/InputGroup.js +0 -91
- package/lib/components/material-ui/InputGroup/InputGroup.story.js +0 -50
- package/lib/components/material-ui/InputGroup/index.js +0 -8
- package/lib/components/material-ui/InputRadioGroup/InputRadioGroup.js +0 -82
- package/lib/components/material-ui/InputRadioGroup/InputRadioGroup.story.js +0 -52
- package/lib/components/material-ui/InputRadioGroup/index.js +0 -8
- package/lib/components/material-ui/InputSearchDropdown/InputSearchDropdown.js +0 -146
- package/lib/components/material-ui/InputSearchDropdown/InputSearchDropdown.story.js +0 -66
- package/lib/components/material-ui/InputSearchDropdown/index.js +0 -8
- package/lib/components/material-ui/InputTime/InputTime.js +0 -82
- package/lib/components/material-ui/InputTime/InputTime.story.js +0 -53
- package/lib/components/material-ui/InputTime/index.js +0 -8
- package/lib/components/material-ui/Modal/Modal.js +0 -57
- package/lib/components/material-ui/Modal/Modal.story.js +0 -83
- package/lib/components/material-ui/Modal/index.js +0 -8
- package/lib/services/Select.service.d.ts +0 -5
- package/lib/services/Select.service.js +0 -67
- package/lib/stories/0-Inputs.stories.d.ts +0 -17
- package/lib/stories/0-Inputs.stories.js +0 -38
- package/lib/types/Component.types.js +0 -2
- package/lib/types/Internal.types.js +0 -2
- package/lib/types/index.js +0 -13
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/** @jsxRuntime classic */
|
|
18
|
-
/** @jsx jsx */
|
|
19
|
-
var react_1 = require("@emotion/react");
|
|
20
|
-
var short_uuid_1 = __importDefault(require("short-uuid"));
|
|
21
|
-
var hooks_1 = require("material-ui-popup-state/hooks");
|
|
22
|
-
var material_1 = require("@mui/material");
|
|
23
|
-
var icons_material_1 = require("@mui/icons-material");
|
|
24
|
-
var react_2 = require("react");
|
|
25
|
-
function ActionsMenu() {
|
|
26
|
-
var popupId = (0, react_2.useRef)(short_uuid_1.default.generate());
|
|
27
|
-
var popupState = (0, hooks_1.usePopupState)({ variant: 'popover', popupId: popupId.current });
|
|
28
|
-
return ((0, react_1.jsx)("div", null,
|
|
29
|
-
(0, react_1.jsx)(material_1.Tooltip, { placement: "top", title: "Actions" },
|
|
30
|
-
(0, react_1.jsx)(material_1.IconButton, __assign({}, (0, hooks_1.bindTrigger)(popupState)),
|
|
31
|
-
(0, react_1.jsx)(icons_material_1.MapsUgc, null))),
|
|
32
|
-
(0, react_1.jsx)(material_1.Menu, __assign({}, (0, hooks_1.bindMenu)(popupState), { anchorOrigin: { vertical: 'top', horizontal: 'left' }, transformOrigin: { vertical: 'bottom', horizontal: 'right' } }),
|
|
33
|
-
(0, react_1.jsx)(material_1.MenuItem, null, "Template 1"),
|
|
34
|
-
(0, react_1.jsx)(material_1.MenuItem, null, "Template 2"),
|
|
35
|
-
(0, react_1.jsx)(material_1.MenuItem, null, "Template 3"))));
|
|
36
|
-
}
|
|
37
|
-
exports.default = ActionsMenu;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ReactNode, Ref } from 'react';
|
|
2
|
-
export interface Message {
|
|
3
|
-
id: string;
|
|
4
|
-
userId: string;
|
|
5
|
-
username: string;
|
|
6
|
-
/** use for building chat icon */
|
|
7
|
-
initials: string;
|
|
8
|
-
timestamp: string;
|
|
9
|
-
content: string;
|
|
10
|
-
}
|
|
11
|
-
export interface ChatInterfaceProps {
|
|
12
|
-
userId: string;
|
|
13
|
-
messages: Message[];
|
|
14
|
-
handleSend: (message: string) => Promise<boolean>;
|
|
15
|
-
className?: string;
|
|
16
|
-
style?: any;
|
|
17
|
-
placeholder?: string;
|
|
18
|
-
hasNextPage?: boolean;
|
|
19
|
-
fetchNextPage?: () => Promise<any> | any;
|
|
20
|
-
/** Determines if the initial load is happening */
|
|
21
|
-
isLoading: boolean;
|
|
22
|
-
/** Determines if a data fetch is happening */
|
|
23
|
-
isFetching: boolean;
|
|
24
|
-
/** Determines if a message submission is happening */
|
|
25
|
-
isSubmitting: boolean;
|
|
26
|
-
colors?: {
|
|
27
|
-
user: string;
|
|
28
|
-
others: string;
|
|
29
|
-
};
|
|
30
|
-
/** Needs to take a ref that is used to determine the height of the input component */
|
|
31
|
-
renderInputComponent?: (ref: Ref<HTMLDivElement>) => ReactNode;
|
|
32
|
-
}
|
|
33
|
-
export default function ChatInterface({ userId, messages, fetchNextPage, handleSend, hasNextPage, className, style, isSubmitting, placeholder, isLoading, isFetching, colors, renderInputComponent, }: ChatInterfaceProps): JSX.Element;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
-
function step(op) {
|
|
20
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
-
while (_) try {
|
|
22
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
-
switch (op[0]) {
|
|
25
|
-
case 0: case 1: t = op; break;
|
|
26
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
-
default:
|
|
30
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
-
if (t[2]) _.ops.pop();
|
|
35
|
-
_.trys.pop(); continue;
|
|
36
|
-
}
|
|
37
|
-
op = body.call(thisArg, _);
|
|
38
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
43
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
44
|
-
if (!m) return o;
|
|
45
|
-
var i = m.call(o), r, ar = [], e;
|
|
46
|
-
try {
|
|
47
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
48
|
-
}
|
|
49
|
-
catch (error) { e = { error: error }; }
|
|
50
|
-
finally {
|
|
51
|
-
try {
|
|
52
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
53
|
-
}
|
|
54
|
-
finally { if (e) throw e.error; }
|
|
55
|
-
}
|
|
56
|
-
return ar;
|
|
57
|
-
};
|
|
58
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
/** @jsxRuntime classic */
|
|
63
|
-
/** @jsx jsx */
|
|
64
|
-
var react_1 = require("@emotion/react");
|
|
65
|
-
var react_2 = require("react");
|
|
66
|
-
var react_measure_1 = __importDefault(require("react-measure"));
|
|
67
|
-
var MessageInput_1 = __importDefault(require("./MessageInput"));
|
|
68
|
-
var MessageThread_1 = __importDefault(require("./MessageThread"));
|
|
69
|
-
function ChatInterface(_a) {
|
|
70
|
-
var userId = _a.userId, messages = _a.messages, fetchNextPage = _a.fetchNextPage, handleSend = _a.handleSend, hasNextPage = _a.hasNextPage, className = _a.className, style = _a.style, isSubmitting = _a.isSubmitting, placeholder = _a.placeholder, isLoading = _a.isLoading, isFetching = _a.isFetching, colors = _a.colors, renderInputComponent = _a.renderInputComponent;
|
|
71
|
-
var _b = __read((0, react_2.useState)(''), 2), message = _b[0], setMessage = _b[1];
|
|
72
|
-
var _c = __read((0, react_2.useState)(-1), 2), inputHeight = _c[0], setInputHeight = _c[1];
|
|
73
|
-
function handleClickSend() {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
-
var success, e_1;
|
|
76
|
-
return __generator(this, function (_a) {
|
|
77
|
-
switch (_a.label) {
|
|
78
|
-
case 0:
|
|
79
|
-
_a.trys.push([0, 2, , 3]);
|
|
80
|
-
return [4 /*yield*/, handleSend(message)];
|
|
81
|
-
case 1:
|
|
82
|
-
success = _a.sent();
|
|
83
|
-
if (success) {
|
|
84
|
-
setMessage('');
|
|
85
|
-
}
|
|
86
|
-
return [3 /*break*/, 3];
|
|
87
|
-
case 2:
|
|
88
|
-
e_1 = _a.sent();
|
|
89
|
-
// tslint:disable-next-line:no-console
|
|
90
|
-
console.error(e_1);
|
|
91
|
-
return [3 /*break*/, 3];
|
|
92
|
-
case 3: return [2 /*return*/];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return ((0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n height: 100%;\n min-height: 15rem;\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',\n 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n "], ["\n width: 100%;\n height: 100%;\n min-height: 15rem;\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',\n 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n "]))), className: className, style: style },
|
|
98
|
-
(0, react_1.jsx)(react_measure_1.default, { bounds: true, onResize: function (_a) {
|
|
99
|
-
var bounds = _a.bounds;
|
|
100
|
-
return setInputHeight((bounds === null || bounds === void 0 ? void 0 : bounds.height) || 0);
|
|
101
|
-
} }, function (_a) {
|
|
102
|
-
var measureRef = _a.measureRef;
|
|
103
|
-
return ((0, react_1.jsx)(react_2.Fragment, null,
|
|
104
|
-
(0, react_1.jsx)(MessageThread_1.default, { userId: userId, messages: messages, inputHeight: inputHeight, hasNextPage: hasNextPage, fetchNextPage: fetchNextPage, isLoading: isLoading, isFetching: isFetching, isSubmitting: isSubmitting, colors: colors }),
|
|
105
|
-
renderInputComponent ? (renderInputComponent(measureRef)) : ((0, react_1.jsx)(MessageInput_1.default, { ref: measureRef, handleClickSend: handleClickSend, message: message, setMessage: setMessage, isSubmitting: isSubmitting, placeholder: placeholder }))));
|
|
106
|
-
})));
|
|
107
|
-
}
|
|
108
|
-
exports.default = ChatInterface;
|
|
109
|
-
var templateObject_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function ChatInterface(): JSX.Element;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
7
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
8
|
-
if (!m) return o;
|
|
9
|
-
var i = m.call(o), r, ar = [], e;
|
|
10
|
-
try {
|
|
11
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
12
|
-
}
|
|
13
|
-
catch (error) { e = { error: error }; }
|
|
14
|
-
finally {
|
|
15
|
-
try {
|
|
16
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
17
|
-
}
|
|
18
|
-
finally { if (e) throw e.error; }
|
|
19
|
-
}
|
|
20
|
-
return ar;
|
|
21
|
-
};
|
|
22
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
23
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
24
|
-
if (ar || !(i in from)) {
|
|
25
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
26
|
-
ar[i] = from[i];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
30
|
-
};
|
|
31
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.ChatInterface = void 0;
|
|
36
|
-
/** @jsxRuntime classic */
|
|
37
|
-
/** @jsx jsx */
|
|
38
|
-
var react_1 = require("@emotion/react");
|
|
39
|
-
var react_2 = require("react");
|
|
40
|
-
var faker_1 = __importDefault(require("faker"));
|
|
41
|
-
var short_uuid_1 = __importDefault(require("short-uuid"));
|
|
42
|
-
var ChatInterface_1 = __importDefault(require("./ChatInterface"));
|
|
43
|
-
var Workspaces_constants_1 = require("@vendorflow/common/lib/constants/Workspaces.constants");
|
|
44
|
-
// tslint:disable-next-line:no-console
|
|
45
|
-
function ChatInterface() {
|
|
46
|
-
var _a = __read((0, react_2.useState)(true), 2), isLoading = _a[0], setLoading = _a[1];
|
|
47
|
-
var _b = __read((0, react_2.useState)(true), 2), isFetching = _b[0], setFetching = _b[1];
|
|
48
|
-
var _c = __read((0, react_2.useState)(false), 2), isSubmitting = _c[0], setSubmitting = _c[1];
|
|
49
|
-
var _d = __read((0, react_2.useState)([]), 2), messages = _d[0], setMessages = _d[1];
|
|
50
|
-
var _e = __read((0, react_2.useState)(true), 2), hasMore = _e[0], setHasMore = _e[1];
|
|
51
|
-
(0, react_2.useEffect)(function () {
|
|
52
|
-
setMessages(new Array(5).fill(null).map(generateMessage).concat([generateSystemMessage()]));
|
|
53
|
-
setLoading(false);
|
|
54
|
-
setFetching(false);
|
|
55
|
-
}, []);
|
|
56
|
-
function generateTimestamp() {
|
|
57
|
-
return new Date().toISOString();
|
|
58
|
-
}
|
|
59
|
-
function generateId() {
|
|
60
|
-
return short_uuid_1.default.generate();
|
|
61
|
-
}
|
|
62
|
-
function generateSystemMessage() {
|
|
63
|
-
return {
|
|
64
|
-
id: generateId(),
|
|
65
|
-
userId: Workspaces_constants_1.SYSTEM_IDENTITY_ID,
|
|
66
|
-
username: 'System',
|
|
67
|
-
initials: 'S',
|
|
68
|
-
timestamp: generateTimestamp(),
|
|
69
|
-
content: faker_1.default.lorem.sentence(5, 2),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function generateMessage() {
|
|
73
|
-
var user = faker_1.default.random.arrayElement([
|
|
74
|
-
{
|
|
75
|
-
id: 'user1',
|
|
76
|
-
name: 'Socorro Aguilar',
|
|
77
|
-
initials: 'SA',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
id: 'user2',
|
|
81
|
-
name: 'Greg Bujak',
|
|
82
|
-
initials: 'GB',
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: 'user3',
|
|
86
|
-
name: 'xinyi@vendorflow.co',
|
|
87
|
-
initials: 'X',
|
|
88
|
-
},
|
|
89
|
-
]);
|
|
90
|
-
return {
|
|
91
|
-
id: generateId(),
|
|
92
|
-
userId: user.id,
|
|
93
|
-
username: user.name,
|
|
94
|
-
initials: user.initials,
|
|
95
|
-
timestamp: generateTimestamp(),
|
|
96
|
-
content: faker_1.default.lorem.sentence(5, 2),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function generateMessagePage() {
|
|
100
|
-
return new Array(10).fill(null).map(generateMessage);
|
|
101
|
-
}
|
|
102
|
-
var fetchNextPage = (0, react_2.useCallback)(function () {
|
|
103
|
-
setFetching(true);
|
|
104
|
-
setTimeout(function () {
|
|
105
|
-
setMessages(__spreadArray(__spreadArray([], __read(messages), false), __read(generateMessagePage()), false));
|
|
106
|
-
setFetching(false);
|
|
107
|
-
}, 100);
|
|
108
|
-
}, [messages, generateMessagePage, setMessages]);
|
|
109
|
-
function handleSend(message) {
|
|
110
|
-
setSubmitting(true);
|
|
111
|
-
setFetching(true);
|
|
112
|
-
return new Promise(function (resolve) {
|
|
113
|
-
setTimeout(function () {
|
|
114
|
-
setMessages(__spreadArray([
|
|
115
|
-
{
|
|
116
|
-
id: generateId(),
|
|
117
|
-
userId: 'user1',
|
|
118
|
-
username: 'Socorro Aguilar',
|
|
119
|
-
initials: 'SA',
|
|
120
|
-
timestamp: generateTimestamp(),
|
|
121
|
-
content: message,
|
|
122
|
-
}
|
|
123
|
-
], __read(messages), false));
|
|
124
|
-
setSubmitting(false);
|
|
125
|
-
setFetching(false);
|
|
126
|
-
resolve(true);
|
|
127
|
-
}, 500);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return ((0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border: 1px solid #ededed;\n height: 30rem;\n "], ["\n border: 1px solid #ededed;\n height: 30rem;\n "]))) },
|
|
131
|
-
(0, react_1.jsx)(ChatInterface_1.default, { userId: "user1", messages: messages, handleSend: handleSend, fetchNextPage: fetchNextPage, hasNextPage: hasMore, isLoading: isLoading, isFetching: isFetching, isSubmitting: isSubmitting })));
|
|
132
|
-
}
|
|
133
|
-
exports.ChatInterface = ChatInterface;
|
|
134
|
-
var templateObject_1;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { ChatInterfaceProps } from './ChatInterface';
|
|
3
|
-
interface Props extends Pick<ChatInterfaceProps, 'isSubmitting' | 'placeholder'> {
|
|
4
|
-
handleClickSend: () => Promise<void>;
|
|
5
|
-
message: string;
|
|
6
|
-
setMessage: Dispatch<SetStateAction<string>>;
|
|
7
|
-
}
|
|
8
|
-
declare const MessageInput: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
|
-
export default MessageInput;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
/** @jsxRuntime classic */
|
|
11
|
-
/** @jsx jsx */
|
|
12
|
-
var react_1 = require("@emotion/react");
|
|
13
|
-
var react_2 = require("react");
|
|
14
|
-
var react_textarea_autosize_1 = __importDefault(require("react-textarea-autosize"));
|
|
15
|
-
var material_1 = require("@mui/material");
|
|
16
|
-
var icons_material_1 = require("@mui/icons-material");
|
|
17
|
-
var ActionsMenu_1 = __importDefault(require("./ActionsMenu"));
|
|
18
|
-
var MessageInput = (0, react_2.forwardRef)(function (_a, ref) {
|
|
19
|
-
var handleClickSend = _a.handleClickSend, message = _a.message, placeholder = _a.placeholder, setMessage = _a.setMessage, isSubmitting = _a.isSubmitting;
|
|
20
|
-
function handleOnChange(_a) {
|
|
21
|
-
var value = _a.target.value;
|
|
22
|
-
setMessage(value);
|
|
23
|
-
}
|
|
24
|
-
function handleOnKeyDown(evt) {
|
|
25
|
-
if (evt.key === 'Enter') {
|
|
26
|
-
evt.stopPropagation();
|
|
27
|
-
evt.preventDefault();
|
|
28
|
-
if (!evt.metaKey && message.trim().length) {
|
|
29
|
-
handleClickSend().then();
|
|
30
|
-
}
|
|
31
|
-
else if (evt.metaKey) {
|
|
32
|
-
setMessage(message + '\n');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function handleOnClickSend() {
|
|
37
|
-
if (message.trim().length) {
|
|
38
|
-
handleClickSend().then();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return ((0, react_1.jsx)("div", { ref: ref, css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n background-color: white;\n bottom: 0;\n left: 0;\n position: absolute;\n display: flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: center;\n "], ["\n width: 100%;\n background-color: white;\n bottom: 0;\n left: 0;\n position: absolute;\n display: flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: center;\n "]))) },
|
|
42
|
-
(0, react_1.jsx)(react_textarea_autosize_1.default, { css: function (theme) {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
return (0, react_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',\n 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n resize: none;\n width: calc(100% - 3.5rem);\n outline: 0 none transparent;\n font-size: 16px;\n margin: 0.5rem;\n padding: 0.5rem;\n box-sizing: border-box;\n border-radius: 5px;\n border-color: ", ";\n "], ["\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',\n 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n resize: none;\n width: calc(100% - 3.5rem);\n outline: 0 none transparent;\n font-size: 16px;\n margin: 0.5rem;\n padding: 0.5rem;\n box-sizing: border-box;\n border-radius: 5px;\n border-color: ", ";\n "])), ((_b = (_a = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b.main) || 'hsl(0, 0%, 89%)');
|
|
45
|
-
}, placeholder: placeholder || 'Type your message here...', value: message, onChange: handleOnChange, onKeyDown: handleOnKeyDown, minRows: 3, maxRows: 8 }),
|
|
46
|
-
(0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n padding-right: 0.5rem;\n overflow: hidden;\n "], ["\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n padding-right: 0.5rem;\n overflow: hidden;\n "]))) },
|
|
47
|
-
(0, react_1.jsx)(ActionsMenu_1.default, null),
|
|
48
|
-
isSubmitting ? ((0, react_1.jsx)(material_1.CircularProgress, { css: (0, react_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n margin: 8px;\n "], ["\n margin: 8px;\n "]))), size: "1.5rem" })) : ((0, react_1.jsx)(material_1.Tooltip, { title: "Send Now", placement: "bottom" },
|
|
49
|
-
(0, react_1.jsx)(material_1.IconButton, { onClick: handleOnClickSend, disabled: isSubmitting },
|
|
50
|
-
(0, react_1.jsx)(icons_material_1.Send, null)))))));
|
|
51
|
-
});
|
|
52
|
-
exports.default = MessageInput;
|
|
53
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
7
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
8
|
-
if (!m) return o;
|
|
9
|
-
var i = m.call(o), r, ar = [], e;
|
|
10
|
-
try {
|
|
11
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
12
|
-
}
|
|
13
|
-
catch (error) { e = { error: error }; }
|
|
14
|
-
finally {
|
|
15
|
-
try {
|
|
16
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
17
|
-
}
|
|
18
|
-
finally { if (e) throw e.error; }
|
|
19
|
-
}
|
|
20
|
-
return ar;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
/** @jsxRuntime classic */
|
|
24
|
-
/** @jsx jsx */
|
|
25
|
-
var react_1 = require("@emotion/react");
|
|
26
|
-
var date_fns_1 = require("date-fns");
|
|
27
|
-
var icons_material_1 = require("@mui/icons-material");
|
|
28
|
-
var material_1 = require("@mui/material");
|
|
29
|
-
var react_2 = require("react");
|
|
30
|
-
var Workspaces_constants_1 = require("@vendorflow/common/lib/constants/Workspaces.constants");
|
|
31
|
-
function MessageItem(_a) {
|
|
32
|
-
var userId = _a.userId, message = _a.message, colors = _a.colors;
|
|
33
|
-
var _b = __read((0, react_2.useState)(getUnixTimestamp()), 2), displayUpdateAt = _b[0], setDisplayUpdateAt = _b[1];
|
|
34
|
-
(0, react_2.useEffect)(function () {
|
|
35
|
-
var interval = setInterval(function () { return setDisplayUpdateAt(getUnixTimestamp()); }, 60 * 1000);
|
|
36
|
-
return function () { return clearInterval(interval); };
|
|
37
|
-
}, []);
|
|
38
|
-
function getUnixTimestamp() {
|
|
39
|
-
return Math.floor(new Date().getTime() / 1000);
|
|
40
|
-
}
|
|
41
|
-
var timeDisplay = (0, react_2.useMemo)(function () {
|
|
42
|
-
var now = new Date();
|
|
43
|
-
var timestamp = new Date(message.timestamp);
|
|
44
|
-
if ((0, date_fns_1.isToday)(timestamp)) {
|
|
45
|
-
var hours = (0, date_fns_1.differenceInHours)(now, timestamp);
|
|
46
|
-
if (hours > 0) {
|
|
47
|
-
return hours + " hour" + (hours === 1 ? '' : 's') + " ago";
|
|
48
|
-
}
|
|
49
|
-
var minutes = (0, date_fns_1.differenceInMinutes)(now, timestamp);
|
|
50
|
-
if (minutes > 0) {
|
|
51
|
-
return minutes + " minute" + (minutes === 1 ? '' : 's') + " ago";
|
|
52
|
-
}
|
|
53
|
-
return "now";
|
|
54
|
-
}
|
|
55
|
-
return (0, date_fns_1.format)(new Date(message.timestamp), 'H:mm MM/dd/yyyy');
|
|
56
|
-
}, [message.timestamp, displayUpdateAt]);
|
|
57
|
-
return ((0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n background: white;\n margin-top: 0.5rem;\n border-radius: 4px;\n display: flex;\n flex-direction: row;\n "], ["\n width: 100%;\n background: white;\n margin-top: 0.5rem;\n border-radius: 4px;\n display: flex;\n flex-direction: row;\n "]))) },
|
|
58
|
-
(0, react_1.jsx)(material_1.Avatar, { css: function (theme) {
|
|
59
|
-
var _a, _b, _c, _d, _e;
|
|
60
|
-
return (0, react_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n && {\n font-size: 1rem;\n height: 2rem;\n width: 2rem;\n margin-right: 0.5rem;\n visibility: ", ";\n background-color: ", ";\n }\n "], ["\n && {\n font-size: 1rem;\n height: 2rem;\n width: 2rem;\n margin-right: 0.5rem;\n visibility: ", ";\n background-color: ", ";\n }\n "])), message.userId === Workspaces_constants_1.SYSTEM_IDENTITY_ID ? 'hidden' : 'visible', userId === message.userId
|
|
61
|
-
? (colors === null || colors === void 0 ? void 0 : colors.user) || ((_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.custom) === null || _a === void 0 ? void 0 : _a.palette) === null || _b === void 0 ? void 0 : _b.tertiary) === null || _c === void 0 ? void 0 : _c.main) || 'hsl(0, 0%, 89%)'
|
|
62
|
-
: (colors === null || colors === void 0 ? void 0 : colors.others) || ((_e = (_d = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _d === void 0 ? void 0 : _d.primary) === null || _e === void 0 ? void 0 : _e.main) || 'hsl(0, 0%, 47%)');
|
|
63
|
-
} }, message.initials === '' ? (0, react_1.jsx)(icons_material_1.Person, null) : message.initials),
|
|
64
|
-
(0, react_1.jsx)("div", null,
|
|
65
|
-
(0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: flex-start;\n "], ["\n display: flex;\n flex-direction: row;\n justify-content: flex-start;\n align-items: flex-start;\n "]))) },
|
|
66
|
-
(0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n font-weight: 700;\n font-size: 0.75rem;\n display: inline-block;\n margin-right: 0.25rem;\n "], ["\n font-weight: 700;\n font-size: 0.75rem;\n display: inline-block;\n margin-right: 0.25rem;\n "]))) }, message.username),
|
|
67
|
-
(0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n font-size: 0.75rem;\n display: inline-block;\n "], ["\n font-size: 0.75rem;\n display: inline-block;\n "]))) }, timeDisplay)),
|
|
68
|
-
(0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n color: ", ";\n font-size: 0.875rem;\n white-space: break-spaces;\n "], ["\n color: ", ";\n font-size: 0.875rem;\n white-space: break-spaces;\n "])), message.userId === Workspaces_constants_1.SYSTEM_IDENTITY_ID ? 'hsl(0, 0%, 65%)' : 'inherit') }, message.content))));
|
|
69
|
-
}
|
|
70
|
-
exports.default = MessageItem;
|
|
71
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ChatInterfaceProps } from './ChatInterface';
|
|
2
|
-
interface Props extends Pick<ChatInterfaceProps, 'userId' | 'messages' | 'hasNextPage' | 'fetchNextPage' | 'isLoading' | 'isFetching' | 'isSubmitting' | 'colors'> {
|
|
3
|
-
inputHeight: number;
|
|
4
|
-
}
|
|
5
|
-
export default function MessageThread({ userId, messages, inputHeight, hasNextPage, fetchNextPage, isLoading, isFetching, isSubmitting, colors, }: Props): JSX.Element;
|
|
6
|
-
export {};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
/** @jsxRuntime classic */
|
|
11
|
-
/** @jsx jsx */
|
|
12
|
-
var react_1 = require("@emotion/react");
|
|
13
|
-
var react_2 = require("react");
|
|
14
|
-
var MessageItem_1 = __importDefault(require("./MessageItem"));
|
|
15
|
-
var lodash_1 = require("lodash");
|
|
16
|
-
var material_1 = require("@mui/material");
|
|
17
|
-
function MessageThread(_a) {
|
|
18
|
-
var _b;
|
|
19
|
-
var userId = _a.userId, messages = _a.messages, inputHeight = _a.inputHeight, hasNextPage = _a.hasNextPage, fetchNextPage = _a.fetchNextPage, isLoading = _a.isLoading, isFetching = _a.isFetching, isSubmitting = _a.isSubmitting, colors = _a.colors;
|
|
20
|
-
var isInitialized = (0, react_2.useRef)(false);
|
|
21
|
-
var isScrollLoad = (0, react_2.useRef)(false);
|
|
22
|
-
var hasSubmitted = (0, react_2.useRef)(false);
|
|
23
|
-
var prevScrollTop = (0, react_2.useRef)(null);
|
|
24
|
-
var prevScrollHeight = (0, react_2.useRef)(null);
|
|
25
|
-
var shouldScrollToPrevPosition = (0, react_2.useRef)(false);
|
|
26
|
-
var scrollParent = (0, react_2.useRef)(null);
|
|
27
|
-
var handleScrollEvent = (0, react_2.useCallback)((0, lodash_1.debounce)(function (evt) {
|
|
28
|
-
var parent = evt.target;
|
|
29
|
-
if (parent.scrollTop === 0 && hasNextPage && fetchNextPage && !isLoading && !isFetching) {
|
|
30
|
-
isScrollLoad.current = true;
|
|
31
|
-
prevScrollHeight.current = parent.scrollHeight;
|
|
32
|
-
fetchNextPage();
|
|
33
|
-
}
|
|
34
|
-
}, 300), [hasNextPage, fetchNextPage, isLoading, isFetching]);
|
|
35
|
-
(0, react_2.useEffect)(function () {
|
|
36
|
-
if (isSubmitting) {
|
|
37
|
-
hasSubmitted.current = true;
|
|
38
|
-
}
|
|
39
|
-
}, [isSubmitting]);
|
|
40
|
-
// This will handle the initial loading of messages, then scroll to bottom
|
|
41
|
-
(0, react_2.useEffect)(function () {
|
|
42
|
-
if (!isInitialized.current && !isFetching && scrollParent.current) {
|
|
43
|
-
var _a = scrollParent.current, clientHeight = _a.clientHeight, scrollHeight = _a.scrollHeight;
|
|
44
|
-
if (clientHeight >= scrollHeight && hasNextPage && fetchNextPage) {
|
|
45
|
-
fetchNextPage();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
isInitialized.current = true;
|
|
49
|
-
scrollParent.current.scrollTo(0, scrollHeight - clientHeight);
|
|
50
|
-
}
|
|
51
|
-
}, [isFetching, isInitialized.current, hasNextPage, fetchNextPage]);
|
|
52
|
-
// Sets up the scroll event listener
|
|
53
|
-
(0, react_2.useEffect)(function () {
|
|
54
|
-
if (scrollParent.current) {
|
|
55
|
-
scrollParent.current.addEventListener('scroll', handleScrollEvent);
|
|
56
|
-
}
|
|
57
|
-
return function () {
|
|
58
|
-
if (scrollParent.current) {
|
|
59
|
-
scrollParent.current.removeEventListener('scroll', handleScrollEvent);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}, [scrollParent.current, hasNextPage, fetchNextPage, isLoading, isFetching]);
|
|
63
|
-
// Handles the scroll position adjustment after fetching the next page
|
|
64
|
-
(0, react_2.useEffect)(function () {
|
|
65
|
-
if (!isFetching &&
|
|
66
|
-
isInitialized.current &&
|
|
67
|
-
scrollParent.current &&
|
|
68
|
-
isScrollLoad.current &&
|
|
69
|
-
prevScrollHeight.current &&
|
|
70
|
-
scrollParent.current.scrollHeight !== prevScrollHeight.current) {
|
|
71
|
-
var delta = scrollParent.current.scrollHeight - prevScrollHeight.current;
|
|
72
|
-
scrollParent.current.scrollTo(0, delta);
|
|
73
|
-
isScrollLoad.current = false;
|
|
74
|
-
prevScrollHeight.current = 0;
|
|
75
|
-
}
|
|
76
|
-
}, [isFetching, prevScrollHeight.current]);
|
|
77
|
-
// Manages scroll position for data changes that are triggered from anything other than the scroll event
|
|
78
|
-
(0, react_2.useEffect)(function () {
|
|
79
|
-
var _a;
|
|
80
|
-
if (scrollParent.current && !isScrollLoad.current && isInitialized.current) {
|
|
81
|
-
var _b = scrollParent.current, scrollHeight = _b.scrollHeight, scrollTop = _b.scrollTop, clientHeight = _b.clientHeight;
|
|
82
|
-
if (isFetching) {
|
|
83
|
-
// track the current position
|
|
84
|
-
prevScrollHeight.current = scrollHeight;
|
|
85
|
-
prevScrollTop.current = scrollTop;
|
|
86
|
-
var distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
|
87
|
-
if (!isSubmitting && distanceFromBottom > 200) {
|
|
88
|
-
shouldScrollToPrevPosition.current = true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
// init to scroll to bottom delta
|
|
93
|
-
var delta = scrollHeight - clientHeight;
|
|
94
|
-
if (hasSubmitted.current) {
|
|
95
|
-
// scroll to bottom if this was triggered by the current user's sent message
|
|
96
|
-
(_a = scrollParent.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, delta);
|
|
97
|
-
}
|
|
98
|
-
else if (!isFetching && prevScrollHeight.current !== null && prevScrollTop.current !== null) {
|
|
99
|
-
if (shouldScrollToPrevPosition.current) {
|
|
100
|
-
delta = prevScrollTop.current;
|
|
101
|
-
}
|
|
102
|
-
scrollParent.current.scrollTo(0, delta);
|
|
103
|
-
}
|
|
104
|
-
// clean up
|
|
105
|
-
prevScrollHeight.current = null;
|
|
106
|
-
prevScrollTop.current = null;
|
|
107
|
-
hasSubmitted.current = false;
|
|
108
|
-
shouldScrollToPrevPosition.current = false;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}, [isFetching, (_b = scrollParent.current) === null || _b === void 0 ? void 0 : _b.scrollHeight]);
|
|
112
|
-
return ((0, react_1.jsx)("div", { ref: scrollParent, css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n box-sizing: border-box;\n height: calc(100% - ", "px);\n width: 100%;\n padding: 0.5rem 1rem;\n overflow-y: auto;\n "], ["\n box-sizing: border-box;\n height: calc(100% - ", "px);\n width: 100%;\n padding: 0.5rem 1rem;\n overflow-y: auto;\n "])), inputHeight) },
|
|
113
|
-
(0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n flex-direction: column-reverse;\n justify-content: flex-start;\n align-items: flex-start;\n "], ["\n display: flex;\n flex-direction: column-reverse;\n justify-content: flex-start;\n align-items: flex-start;\n "]))) },
|
|
114
|
-
messages.map(function (message) { return ((0, react_1.jsx)(MessageItem_1.default, { key: "" + message.id, message: message, userId: userId, colors: colors })); }),
|
|
115
|
-
hasNextPage && ((0, react_1.jsx)("div", { key: "loader", css: (0, react_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 100%;\n margin: 0.5rem 0;\n height: auto;\n display: flex;\n justify-content: center;\n align-items: center;\n\n && {\n visibility: ", ";\n }\n "], ["\n width: 100%;\n margin: 0.5rem 0;\n height: auto;\n display: flex;\n justify-content: center;\n align-items: center;\n\n && {\n visibility: ", ";\n }\n "])), isFetching && isScrollLoad ? 'visible' : 'hidden') },
|
|
116
|
-
(0, react_1.jsx)(material_1.CircularProgress, { size: "1.5rem", disableShrink: true }))))));
|
|
117
|
-
}
|
|
118
|
-
exports.default = MessageThread;
|
|
119
|
-
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './ChatInterface';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var ChatInterface_1 = require("./ChatInterface");
|
|
8
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(ChatInterface_1).default; } });
|