hanbiro-react16-sdk 1.0.23 → 1.0.24

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.
@@ -1,381 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- var __async = (__this, __arguments, generator) => {
5
- return new Promise((resolve, reject) => {
6
- var fulfilled = (value) => {
7
- try {
8
- step(generator.next(value));
9
- } catch (e) {
10
- reject(e);
11
- }
12
- };
13
- var rejected = (value) => {
14
- try {
15
- step(generator.throw(value));
16
- } catch (e) {
17
- reject(e);
18
- }
19
- };
20
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
21
- step((generator = generator.apply(__this, __arguments)).next());
22
- });
23
- };
24
- import * as React from "react";
25
- import * as ReactDOM from "react-dom";
26
- import { apiGet } from "../../utils/api.js";
27
- import { AI_LANG_FLAGS } from "../../constants/index.js";
28
- import CountryFlag from "../CountryFlag/index.js";
29
- import { TONE_OPTIONS, LENGTH_OPTIONS } from "./constants.js";
30
- import Settings from "../../node_modules/react-feather/dist/icons/settings.js";
31
- import ChevronDown from "../../node_modules/react-feather/dist/icons/chevron-down.js";
32
- import Frown from "../../node_modules/react-feather/dist/icons/frown.js";
33
- import ThumbsUp from "../../node_modules/react-feather/dist/icons/thumbs-up.js";
34
- import Smile from "../../node_modules/react-feather/dist/icons/smile.js";
35
- import Compass from "../../node_modules/react-feather/dist/icons/compass.js";
36
- import Heart from "../../node_modules/react-feather/dist/icons/heart.js";
37
- import Award from "../../node_modules/react-feather/dist/icons/award.js";
38
- import Zap from "../../node_modules/react-feather/dist/icons/zap.js";
39
- import FileText from "../../node_modules/react-feather/dist/icons/file-text.js";
40
- import AlignJustify from "../../node_modules/react-feather/dist/icons/align-justify.js";
41
- import Scissors from "../../node_modules/react-feather/dist/icons/scissors.js";
42
- const getFlagCode = (value) => {
43
- var _a;
44
- return (_a = AI_LANG_FLAGS.find((l) => l.value === value)) == null ? void 0 : _a.flagCode;
45
- };
46
- class LanguageSelect extends React.Component {
47
- constructor(props) {
48
- super(props);
49
- __publicField(this, "ref");
50
- __publicField(this, "handleClickOutside", (e) => {
51
- if (this.ref.current && !this.ref.current.contains(e.target)) {
52
- this.setState({ open: false });
53
- }
54
- });
55
- __publicField(this, "toggle", () => {
56
- this.setState((s) => ({ open: !s.open }));
57
- });
58
- __publicField(this, "pick", (opt) => {
59
- this.props.onChange(opt);
60
- this.setState({ open: false });
61
- });
62
- this.state = { open: false };
63
- this.ref = React.createRef();
64
- }
65
- componentDidMount() {
66
- document.addEventListener("mousedown", this.handleClickOutside);
67
- }
68
- componentWillUnmount() {
69
- document.removeEventListener("mousedown", this.handleClickOutside);
70
- }
71
- render() {
72
- const { value, options } = this.props;
73
- const { open } = this.state;
74
- const selectedFlag = getFlagCode(value == null ? void 0 : value.value);
75
- return /* @__PURE__ */ React.createElement("div", { ref: this.ref, style: { position: "relative", width: "100%" } }, /* @__PURE__ */ React.createElement(
76
- "button",
77
- {
78
- type: "button",
79
- onClick: this.toggle,
80
- style: {
81
- width: "100%",
82
- display: "flex",
83
- alignItems: "center",
84
- gap: 8,
85
- padding: "8px 10px",
86
- border: "1px solid var(--border-main)",
87
- borderRadius: 4,
88
- background: "#fff",
89
- cursor: "pointer",
90
- fontFamily: "inherit",
91
- fontSize: 13,
92
- color: "var(--text-primary)"
93
- }
94
- },
95
- selectedFlag && /* @__PURE__ */ React.createElement(
96
- CountryFlag,
97
- {
98
- flagCode: selectedFlag,
99
- style: { width: 18, height: 14, flexShrink: 0 }
100
- }
101
- ),
102
- /* @__PURE__ */ React.createElement("span", { style: { flex: 1, textAlign: "left" } }, (value == null ? void 0 : value.label) || "Select Language"),
103
- /* @__PURE__ */ React.createElement(
104
- ChevronDown,
105
- {
106
- size: 14,
107
- style: {
108
- transform: open ? "rotate(180deg)" : "none",
109
- transition: "transform 0.15s"
110
- }
111
- }
112
- )
113
- ), open && /* @__PURE__ */ React.createElement(
114
- "div",
115
- {
116
- style: {
117
- position: "absolute",
118
- top: "calc(100% + 4px)",
119
- left: 0,
120
- right: 0,
121
- maxHeight: 220,
122
- overflowY: "auto",
123
- border: "1px solid var(--border-main)",
124
- borderRadius: 4,
125
- background: "#fff",
126
- boxShadow: "0 4px 12px rgba(0, 0, 0, 0.08)",
127
- zIndex: 2
128
- }
129
- },
130
- options.map((opt) => {
131
- const fc = getFlagCode(opt.value);
132
- const isActive = (value == null ? void 0 : value.value) === opt.value;
133
- return /* @__PURE__ */ React.createElement(
134
- "button",
135
- {
136
- key: opt.value,
137
- type: "button",
138
- onClick: () => this.pick(opt),
139
- className: "chat-ai-lang-option" + (isActive ? " is-active" : ""),
140
- style: {
141
- width: "100%",
142
- display: "flex",
143
- alignItems: "center",
144
- gap: 8,
145
- padding: "8px 10px",
146
- border: "none",
147
- background: isActive ? "var(--primary-lighter)" : void 0,
148
- cursor: "pointer",
149
- fontFamily: "inherit",
150
- fontSize: 13,
151
- textAlign: "left",
152
- color: "var(--text-primary)",
153
- fontWeight: 400
154
- }
155
- },
156
- fc && /* @__PURE__ */ React.createElement(
157
- CountryFlag,
158
- {
159
- flagCode: fc,
160
- style: { width: 18, height: 14, flexShrink: 0 }
161
- }
162
- ),
163
- /* @__PURE__ */ React.createElement("span", null, opt.label)
164
- );
165
- })
166
- ));
167
- }
168
- }
169
- const ICON_SIZE = 14;
170
- const TONE_ICONS = {
171
- formal: /* @__PURE__ */ React.createElement(Award, { size: ICON_SIZE }),
172
- polite: /* @__PURE__ */ React.createElement(Heart, { size: ICON_SIZE }),
173
- neutral: /* @__PURE__ */ React.createElement(Compass, { size: ICON_SIZE }),
174
- friendly: /* @__PURE__ */ React.createElement(Smile, { size: ICON_SIZE }),
175
- firm: /* @__PURE__ */ React.createElement(ThumbsUp, { size: ICON_SIZE }),
176
- apologetic: /* @__PURE__ */ React.createElement(Frown, { size: ICON_SIZE })
177
- };
178
- const LENGTH_ICONS = {
179
- short: /* @__PURE__ */ React.createElement(Scissors, { size: ICON_SIZE }),
180
- medium: /* @__PURE__ */ React.createElement(AlignJustify, { size: ICON_SIZE }),
181
- long: /* @__PURE__ */ React.createElement(FileText, { size: ICON_SIZE }),
182
- one_liner: /* @__PURE__ */ React.createElement(Zap, { size: ICON_SIZE })
183
- };
184
- class SettingPopper extends React.Component {
185
- constructor(props) {
186
- super(props);
187
- __publicField(this, "containerRef");
188
- __publicField(this, "popperRef");
189
- __publicField(this, "getLanguageOptions", () => __async(this, null, function* () {
190
- var _a;
191
- const { data } = yield apiGet("/email/ai/langlist");
192
- if (data == null ? void 0 : data.list) {
193
- const langs = (_a = Object.keys(data == null ? void 0 : data.list)) == null ? void 0 : _a.map((_key, i) => {
194
- var _a2;
195
- const _item = (_a2 = data == null ? void 0 : data.list) == null ? void 0 : _a2[_key];
196
- return {
197
- value: _key,
198
- label: _item == null ? void 0 : _item.name
199
- };
200
- });
201
- this.setState({ languageOptions: langs });
202
- }
203
- }));
204
- __publicField(this, "handleClickOutside", (event) => {
205
- const target = event.target;
206
- if (this.containerRef.current && !this.containerRef.current.contains(target) && (!this.popperRef.current || !this.popperRef.current.contains(target))) {
207
- this.setState({ open: false });
208
- }
209
- });
210
- __publicField(this, "togglePopper", () => {
211
- this.setState((prevState) => ({ open: !prevState.open }));
212
- });
213
- __publicField(this, "renderChipGroup", (options, selected, onSelect, iconMap, columns = 3) => /* @__PURE__ */ React.createElement(
214
- "div",
215
- {
216
- style: {
217
- display: "grid",
218
- gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
219
- gap: 6
220
- }
221
- },
222
- options.map((opt) => {
223
- const isActive = (selected == null ? void 0 : selected.value) === opt.value;
224
- return /* @__PURE__ */ React.createElement(
225
- "button",
226
- {
227
- key: opt.value,
228
- type: "button",
229
- onClick: () => onSelect(opt),
230
- style: {
231
- display: "flex",
232
- alignItems: "center",
233
- justifyContent: "center",
234
- gap: 6,
235
- padding: "8px 10px",
236
- borderRadius: 4,
237
- border: isActive ? "1px solid var(--primary-main)" : "1px solid var(--border-main)",
238
- background: isActive ? "var(--primary-lighter)" : "#fff",
239
- color: isActive ? "var(--primary-main)" : "var(--text-primary)",
240
- fontWeight: isActive ? 600 : 400,
241
- fontSize: 13,
242
- cursor: "pointer",
243
- fontFamily: "inherit",
244
- transition: "background 0.15s, border-color 0.15s",
245
- minWidth: 0
246
- }
247
- },
248
- /* @__PURE__ */ React.createElement(
249
- "span",
250
- {
251
- style: {
252
- display: "inline-flex",
253
- alignItems: "center",
254
- flexShrink: 0
255
- }
256
- },
257
- iconMap[opt.value]
258
- ),
259
- /* @__PURE__ */ React.createElement("span", { style: { whiteSpace: "nowrap" } }, opt.label)
260
- );
261
- })
262
- ));
263
- this.state = { open: false, languageOptions: [] };
264
- this.containerRef = React.createRef();
265
- this.popperRef = React.createRef();
266
- }
267
- componentDidMount() {
268
- document.addEventListener("mousedown", this.handleClickOutside);
269
- this.getLanguageOptions();
270
- }
271
- componentWillUnmount() {
272
- document.removeEventListener("mousedown", this.handleClickOutside);
273
- }
274
- render() {
275
- const { lang, tone, length, parentRef } = this.props;
276
- const { open, languageOptions } = this.state;
277
- let popperTop = 0;
278
- let popperLeft = 0;
279
- let popperWidth = 320;
280
- if (open && this.containerRef.current) {
281
- const rect = this.containerRef.current.getBoundingClientRect();
282
- popperTop = rect.top + (window.scrollY || document.documentElement.scrollTop) - 8;
283
- popperLeft = rect.left + (window.scrollX || document.documentElement.scrollLeft);
284
- if (parentRef && parentRef.current) {
285
- const parentRect = parentRef.current.getBoundingClientRect();
286
- popperWidth = parentRect.width - 16;
287
- popperLeft = parentRect.left + 8;
288
- }
289
- }
290
- return /* @__PURE__ */ React.createElement(
291
- "div",
292
- {
293
- ref: this.containerRef,
294
- style: { position: "relative", display: "inline-block" }
295
- },
296
- /* @__PURE__ */ React.createElement(
297
- "button",
298
- {
299
- type: "button",
300
- onClick: this.togglePopper,
301
- className: "icon-button small"
302
- },
303
- /* @__PURE__ */ React.createElement(Settings, { size: 16 })
304
- ),
305
- open && this.containerRef.current && ReactDOM.createPortal(
306
- /* @__PURE__ */ React.createElement(
307
- "div",
308
- {
309
- ref: this.popperRef,
310
- style: {
311
- position: "absolute",
312
- top: popperTop,
313
- left: popperLeft,
314
- transform: "translateY(-100%)",
315
- zIndex: 1051,
316
- background: "#fff",
317
- border: "1px solid #ddd",
318
- boxShadow: "0px 4px 12px rgba(0, 0, 0, 0.1)",
319
- borderRadius: 8,
320
- padding: 16,
321
- width: popperWidth,
322
- boxSizing: "border-box"
323
- }
324
- },
325
- /* @__PURE__ */ React.createElement(
326
- "div",
327
- {
328
- style: { display: "flex", flexDirection: "column", gap: 12 }
329
- },
330
- /* @__PURE__ */ React.createElement(
331
- "div",
332
- {
333
- style: { display: "flex", flexDirection: "column", gap: 6 }
334
- },
335
- /* @__PURE__ */ React.createElement("span", { style: { fontSize: 12, fontWeight: 600 } }, "Language"),
336
- /* @__PURE__ */ React.createElement(
337
- LanguageSelect,
338
- {
339
- value: lang,
340
- options: languageOptions,
341
- onChange: (opt) => this.props.setLang(opt)
342
- }
343
- )
344
- ),
345
- /* @__PURE__ */ React.createElement(
346
- "div",
347
- {
348
- style: { display: "flex", flexDirection: "column", gap: 6 }
349
- },
350
- /* @__PURE__ */ React.createElement("span", { style: { fontSize: 12, fontWeight: 600 } }, "Tone"),
351
- this.renderChipGroup(
352
- TONE_OPTIONS,
353
- tone,
354
- (opt) => this.props.setTone(opt),
355
- TONE_ICONS
356
- )
357
- ),
358
- /* @__PURE__ */ React.createElement(
359
- "div",
360
- {
361
- style: { display: "flex", flexDirection: "column", gap: 6 }
362
- },
363
- /* @__PURE__ */ React.createElement("span", { style: { fontSize: 12, fontWeight: 600 } }, "Length"),
364
- this.renderChipGroup(
365
- LENGTH_OPTIONS,
366
- length,
367
- (opt) => this.props.setLength(opt),
368
- LENGTH_ICONS,
369
- 4
370
- )
371
- )
372
- )
373
- ),
374
- document.body
375
- )
376
- );
377
- }
378
- }
379
- export {
380
- SettingPopper as default
381
- };