@homecode/ui 5.3.9 → 5.3.11

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.
@@ -59,6 +59,7 @@ import '../PromptComposer/PromptComposer.js';
59
59
  import '@tiptap/extensions';
60
60
  import '@tiptap/react';
61
61
  import '@tiptap/starter-kit';
62
+ import '../PromptComposer/PromptComposer.styl.js';
62
63
  import '../RadioGroup/RadioGroupContext.js';
63
64
  import '../RadioButton/RadioButton.styl.js';
64
65
  import '../RadioGroup/RadioGroup.styl.js';
@@ -58,6 +58,7 @@ import '../PromptComposer/PromptComposer.js';
58
58
  import '@tiptap/extensions';
59
59
  import '@tiptap/react';
60
60
  import '@tiptap/starter-kit';
61
+ import '../PromptComposer/PromptComposer.styl.js';
61
62
  import '../../tiptap/slash-mention/createSlashMentionExtension.js';
62
63
  import '../RadioGroup/RadioGroupContext.js';
63
64
  import '../RadioButton/RadioButton.styl.js';
@@ -1,4 +1,4 @@
1
- import { createElement, Component } from 'react';
1
+ import { createElement, Component, createRef } from 'react';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import cn from 'classnames';
4
4
  import { useStore } from 'justorm/react';
@@ -19,8 +19,69 @@ function getDeltaPos(p1, p2) {
19
19
  };
20
20
  }
21
21
  const TOUCH_MOVE_TRESHOLD = 50;
22
+ const WHEEL_MOVE_THRESHOLD = 20;
23
+ const WHEEL_RESET_MS = 150;
24
+ const wheelGesture = {
25
+ itemId: null,
26
+ deltaX: 0,
27
+ deltaY: 0,
28
+ resetTimer: null,
29
+ };
30
+ function resetWheelGesture() {
31
+ wheelGesture.itemId = null;
32
+ wheelGesture.deltaX = 0;
33
+ wheelGesture.deltaY = 0;
34
+ if (wheelGesture.resetTimer) {
35
+ clearTimeout(wheelGesture.resetTimer);
36
+ wheelGesture.resetTimer = null;
37
+ }
38
+ }
39
+ function scheduleWheelGestureReset() {
40
+ if (wheelGesture.resetTimer) {
41
+ clearTimeout(wheelGesture.resetTimer);
42
+ }
43
+ wheelGesture.resetTimer = setTimeout(resetWheelGesture, WHEEL_RESET_MS);
44
+ }
45
+ function isHorizontalWheel(e, id) {
46
+ const absX = Math.abs(e.deltaX);
47
+ const absY = Math.abs(e.deltaY);
48
+ if (absX > absY)
49
+ return true;
50
+ return (wheelGesture.itemId === id && wheelGesture.deltaX >= wheelGesture.deltaY);
51
+ }
52
+ function handleNotificationWheel(id, e, unpause, close) {
53
+ scheduleWheelGestureReset();
54
+ if (wheelGesture.itemId !== null && wheelGesture.itemId !== id) {
55
+ return;
56
+ }
57
+ if (wheelGesture.itemId === null) {
58
+ wheelGesture.itemId = id;
59
+ }
60
+ wheelGesture.deltaX += Math.abs(e.deltaX);
61
+ wheelGesture.deltaY += Math.abs(e.deltaY);
62
+ if (wheelGesture.deltaX > wheelGesture.deltaY &&
63
+ wheelGesture.deltaX > WHEEL_MOVE_THRESHOLD) {
64
+ const closingId = wheelGesture.itemId;
65
+ unpause();
66
+ wheelGesture.deltaX = 0;
67
+ wheelGesture.deltaY = 0;
68
+ close(closingId);
69
+ }
70
+ }
22
71
  class Item extends Component {
23
72
  startPos = null;
73
+ itemRef = createRef();
74
+ componentDidMount() {
75
+ this.itemRef.current?.addEventListener('wheel', this.onWheelNative, {
76
+ passive: false,
77
+ capture: true,
78
+ });
79
+ }
80
+ componentWillUnmount() {
81
+ this.itemRef.current?.removeEventListener('wheel', this.onWheelNative, {
82
+ capture: true,
83
+ });
84
+ }
24
85
  onTouchStart = e => {
25
86
  this.startPos = getTouchPos(e);
26
87
  };
@@ -43,6 +104,14 @@ class Item extends Component {
43
104
  this.startPos = null;
44
105
  };
45
106
  onTouchCancel = () => (this.startPos = null);
107
+ onWheelNative = (e) => {
108
+ const { id, unpause, close } = this.props;
109
+ if (isHorizontalWheel(e, id)) {
110
+ e.preventDefault();
111
+ e.stopPropagation();
112
+ }
113
+ handleNotificationWheel(id, e, unpause, close);
114
+ };
46
115
  closeMe = () => {
47
116
  const { id, close } = this.props;
48
117
  close(id);
@@ -50,7 +119,7 @@ class Item extends Component {
50
119
  render() {
51
120
  const { type = 'default', title, content, visible, pause, unpause, } = this.props;
52
121
  const classes = cn(S.item, S[`type-${type}`], visible && S.visible);
53
- return (jsx("div", { className: classes, onMouseOver: pause, onFocus: pause, onTouchStart: this.onTouchStart, onTouchMove: this.onTouchMove, onMouseOut: unpause, onBlur: unpause, onTouchEnd: this.onTouchEnd, onTouchCancel: this.onTouchCancel, children: jsxs("div", { className: S.itemInner, children: [(title || content) && (jsxs("div", { className: S.text, children: [title && jsx("div", { className: S.title, children: title }), content != null && (jsx("div", { className: S.content, children: typeof content === 'function' ? content() : content }))] })), jsx(Button, { className: S.close, variant: "clear", square: true, onClick: this.closeMe, children: jsx(Icon, { type: "close", size: "s" }) })] }) }));
122
+ return (jsx("div", { ref: this.itemRef, className: classes, onMouseOver: pause, onFocus: pause, onTouchStart: this.onTouchStart, onTouchMove: this.onTouchMove, onMouseOut: unpause, onBlur: unpause, onTouchEnd: this.onTouchEnd, onTouchCancel: this.onTouchCancel, children: jsxs("div", { className: S.itemInner, children: [(title || content) && (jsxs("div", { className: S.text, children: [title && jsx("div", { className: S.title, children: title }), content != null && (jsx("div", { className: S.content, children: typeof content === 'function' ? content() : content }))] })), jsx(Button, { className: S.close, variant: "clear", square: true, onClick: this.closeMe, children: jsx(Icon, { type: "close", size: "s" }) })] }) }));
54
123
  }
55
124
  }
56
125
  const NotificationsStore = STORE;
@@ -1,6 +1,6 @@
1
1
  import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
2
2
 
3
- var css_248z = ".Notifications_root__S3ujN{max-height:calc(var(--vh)*100);overflow:hidden;position:fixed;right:0;top:0;transform:translateZ(0);transition:right .3s ease-out;width:320px;z-index:20}.Notifications_inner__6v9e3{padding:var(--p-5);padding-right:var(--p-3)}.Notifications_empty__zCpOA{pointer-events:none}.Notifications_itemInner__nEYAl,.Notifications_item__I3Up4{border-radius:var(--p-4)}.Notifications_item__I3Up4{-webkit-backface-visibility:hidden;backface-visibility:hidden;left:100%;max-height:0;max-width:100%;opacity:0;position:relative;transition:all .3s ease-out;width:300px}.Notifications_item__I3Up4:first-child{margin-top:calc(var(--p-2)*-1)}.Notifications_item__I3Up4+.Notifications_item__I3Up4{padding-top:var(--p-2)}.Notifications_item__I3Up4:hover{transform:translateX(-2px)}.Notifications_visible__ln4-n{left:0;max-height:500px;opacity:1}.Notifications_itemInner__nEYAl{align-items:center;-webkit-backdrop-filter:blur(30px);backdrop-filter:blur(30px);background-color:var(--decent-color-alpha-500);box-shadow:inset 0 0 1px var(--accent-color-alpha-300),0 0 20px var(--decent-color);box-sizing:border-box;display:flex;padding:var(--p-3);padding-right:var(--p-6);position:relative;transition:.3s ease-out;transition-property:transform}.Notifications_type-warning__Nxg6C .Notifications_itemInner__nEYAl{background-color:var(--warning-color-alpha-300)}.Notifications_type-danger__zeIMt .Notifications_itemInner__nEYAl{background-color:var(--danger-color-alpha-300)}.Notifications_itemInner__nEYAl button{margin-bottom:calc(var(--p-2)*-1);margin-top:calc(var(--p-2)*-1)}.Notifications_icon__nKs-X{background:no-repeat 50%;height:24px;margin-right:10px;min-width:24px;width:24px}.Notifications_type-loading__N4EE5 .Notifications_icon__nKs-X{transform:translateY(-20px)}.Notifications_text__7QZL6{display:flex;flex-direction:column;flex-grow:1;z-index:1}.Notifications_title__Gu9bs{font-size:16px;font-weight:700}.Notifications_content__Zrvw2{font-size:12px;margin-top:calc(var(--p-3)/2)}.Notifications_content__Zrvw2:first-child{margin-top:0}.Notifications_close__-IUH3{background-color:transparent;border-radius:50%;cursor:pointer;height:40px!important;max-height:40px!important;max-width:40px!important;opacity:0;position:absolute;right:-5px;top:2px;transform:scale(.8);transition:.1s ease-out;transition-property:opacity,transform;width:40px!important}.Notifications_close__-IUH3:before{background-color:var(--decent-color-alpha-400);border-radius:inherit;bottom:var(--p-2);content:\"\";left:var(--p-2);pointer-events:none;position:absolute;right:var(--p-2);top:var(--p-2);transition:background-color .1s ease-out}.Notifications_close__-IUH3 svg{transform:scale(.6)}.Notifications_item__I3Up4:hover .Notifications_close__-IUH3{opacity:.8}.Notifications_close__-IUH3:hover{background-color:transparent;background-color:initial;opacity:1}.Notifications_close__-IUH3:hover:before{background-color:var(--decent-color-alpha-800)}@media (max-width:700px){.Notifications_item__I3Up4,.Notifications_root__S3ujN{width:100%}.Notifications_title__Gu9bs{font-size:20px}.Notifications_content__Zrvw2{font-size:16px}.Notifications_close__-IUH3{transform:scale(1.2)}}";
3
+ var css_248z = ".Notifications_root__S3ujN{max-height:calc(var(--vh)*100);overflow:hidden;position:fixed;right:0;top:0;transform:translateZ(0);transition:right .3s ease-out;width:320px;z-index:20}.Notifications_inner__6v9e3{padding:var(--p-5);padding-right:var(--p-3)}.Notifications_empty__zCpOA{pointer-events:none}.Notifications_itemInner__nEYAl,.Notifications_item__I3Up4{border-radius:var(--p-4)}.Notifications_item__I3Up4{-webkit-backface-visibility:hidden;backface-visibility:hidden;left:100%;max-height:0;max-width:100%;opacity:0;overscroll-behavior-x:none;position:relative;touch-action:pan-y;transition:all .3s ease-out;width:300px}.Notifications_item__I3Up4:first-child{margin-top:calc(var(--p-2)*-1)}.Notifications_item__I3Up4+.Notifications_item__I3Up4{padding-top:var(--p-2)}.Notifications_item__I3Up4:hover{transform:translateX(-2px)}.Notifications_visible__ln4-n{left:0;max-height:500px;opacity:1}.Notifications_itemInner__nEYAl{align-items:center;-webkit-backdrop-filter:blur(30px);backdrop-filter:blur(30px);background-color:var(--decent-color-alpha-500);box-shadow:inset 0 0 1px var(--accent-color-alpha-300),0 0 20px var(--decent-color);box-sizing:border-box;display:flex;padding:var(--p-3);padding-right:var(--p-6);position:relative;transition:.3s ease-out;transition-property:transform}.Notifications_type-warning__Nxg6C .Notifications_itemInner__nEYAl{background-color:var(--warning-color-alpha-300)}.Notifications_type-danger__zeIMt .Notifications_itemInner__nEYAl{background-color:var(--danger-color-alpha-300)}.Notifications_itemInner__nEYAl button{margin-bottom:calc(var(--p-2)*-1);margin-top:calc(var(--p-2)*-1)}.Notifications_icon__nKs-X{background:no-repeat 50%;height:24px;margin-right:10px;min-width:24px;width:24px}.Notifications_type-loading__N4EE5 .Notifications_icon__nKs-X{transform:translateY(-20px)}.Notifications_text__7QZL6{display:flex;flex-direction:column;flex-grow:1;z-index:1}.Notifications_title__Gu9bs{font-size:16px;font-weight:700}.Notifications_content__Zrvw2{font-size:12px;margin-top:calc(var(--p-3)/2)}.Notifications_content__Zrvw2:first-child{margin-top:0}.Notifications_close__-IUH3{background-color:transparent;border-radius:50%;cursor:pointer;height:40px!important;max-height:40px!important;max-width:40px!important;opacity:0;position:absolute;right:-5px;top:2px;transform:scale(.8);transition:.1s ease-out;transition-property:opacity,transform;width:40px!important}.Notifications_close__-IUH3:before{background-color:var(--decent-color-alpha-400);border-radius:inherit;bottom:var(--p-2);content:\"\";left:var(--p-2);pointer-events:none;position:absolute;right:var(--p-2);top:var(--p-2);transition:background-color .1s ease-out}.Notifications_close__-IUH3 svg{transform:scale(.6)}.Notifications_item__I3Up4:hover .Notifications_close__-IUH3{opacity:.8}.Notifications_close__-IUH3:hover{background-color:transparent;background-color:initial;opacity:1}.Notifications_close__-IUH3:hover:before{background-color:var(--decent-color-alpha-800)}@media (max-width:700px){.Notifications_item__I3Up4,.Notifications_root__S3ujN{width:100%}.Notifications_title__Gu9bs{font-size:20px}.Notifications_content__Zrvw2{font-size:16px}.Notifications_close__-IUH3{transform:scale(1.2)}}";
4
4
  var S = {"root":"Notifications_root__S3ujN","inner":"Notifications_inner__6v9e3","empty":"Notifications_empty__zCpOA","item":"Notifications_item__I3Up4","itemInner":"Notifications_itemInner__nEYAl","visible":"Notifications_visible__ln4-n","type-warning":"Notifications_type-warning__Nxg6C","type-danger":"Notifications_type-danger__zeIMt","icon":"Notifications_icon__nKs-X","type-loading":"Notifications_type-loading__N4EE5","text":"Notifications_text__7QZL6","title":"Notifications_title__Gu9bs","content":"Notifications_content__Zrvw2","close":"Notifications_close__-IUH3"};
5
5
  styleInject(css_248z);
6
6
 
@@ -1,7 +1,7 @@
1
1
  import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
2
2
 
3
- var css_248z = ".PromptComposer_root__gfdXN{width:100%}.PromptComposer_scroller__Sueif{flex:1;max-height:200px;min-height:40px;width:100%}.PromptComposer_editorMount__B9G-o{background:transparent;border:none;border-radius:0!important;box-shadow:none!important;display:flex;flex:1;flex-direction:column;min-height:40px;min-width:0;padding:0!important}.PromptComposer_editorMount__B9G-o:focus-within{box-shadow:none!important}.PromptComposer_editorMount__B9G-o .promptComposerEditor{border:none!important;box-shadow:none!important;flex:1;margin:0;min-height:40px!important;outline:none!important;overflow:hidden!important;padding:var(--p-2) 0 0!important;resize:none!important;white-space:pre-wrap;word-break:break-word}.PromptComposer_editorMount__B9G-o .promptComposerEmptyEditor .promptComposerEmptyNode:before{color:var(--muted-foreground);content:attr(data-placeholder);float:left;height:0;pointer-events:none}";
4
- var S = {"root":"PromptComposer_root__gfdXN","scroller":"PromptComposer_scroller__Sueif","editorMount":"PromptComposer_editorMount__B9G-o"};
3
+ var css_248z = ".PromptComposer_root__gfdXN{width:100%}.PromptComposer_scroller__Sueif{flex:1;max-height:200px;min-height:40px;width:100%}.PromptComposer_editorMount__B9G-o{background:transparent;border:none;border-radius:0!important;box-shadow:none!important;display:flex;flex:1;flex-direction:column;min-height:40px;min-width:0;padding:0!important}.PromptComposer_editorMount__B9G-o:focus-within{box-shadow:none!important}.PromptComposer_editorMount__B9G-o .PromptComposer_promptComposerEditor__yQIpq{border:none!important;box-shadow:none!important;flex:1;margin:0;min-height:40px!important;outline:none!important;overflow:hidden!important;padding:var(--p-2) 0 0!important;resize:none!important;transition:opacity .1s ease-out;white-space:pre-wrap;word-break:break-word}.PromptComposer_editorMount__B9G-o .PromptComposer_promptComposerEditor__yQIpq a{color:var(--link-color)}.PromptComposer_editorMount__B9G-o .PromptComposer_promptComposerEditor__yQIpq a:hover{cursor:pointer;opacity:.8}.PromptComposer_editorMount__B9G-o .PromptComposer_promptComposerEmptyEditor__VrwNe .PromptComposer_promptComposerEmptyNode__62Ylm:before{color:var(--muted-foreground);content:attr(data-placeholder);float:left;height:0;pointer-events:none}";
4
+ var S = {"root":"PromptComposer_root__gfdXN","scroller":"PromptComposer_scroller__Sueif","editorMount":"PromptComposer_editorMount__B9G-o","promptComposerEditor":"PromptComposer_promptComposerEditor__yQIpq","promptComposerEmptyEditor":"PromptComposer_promptComposerEmptyEditor__VrwNe","promptComposerEmptyNode":"PromptComposer_promptComposerEmptyNode__62Ylm"};
5
5
  styleInject(css_248z);
6
6
 
7
7
  export { S as default };
@@ -2,14 +2,12 @@ import { useRef, useCallback, useMemo, useState, useEffect, useLayoutEffect } fr
2
2
  import { Placeholder } from '@tiptap/extensions';
3
3
  import { useEditor } from '@tiptap/react';
4
4
  import StarterKit from '@tiptap/starter-kit';
5
+ import S from './PromptComposer.styl.js';
5
6
  import { DEFAULT_CHAT_SLASH_ITEMS } from '../../tiptap/slash-mention/defaultChatSlashItems.js';
6
7
  import { createSlashMentionExtension } from '../../tiptap/slash-mention/createSlashMentionExtension.js';
7
8
  import { safePromptComposerEditorText, promptComposerSafeEditorDom, syncPromptComposerHeight } from './PromptComposer.helpers.js';
8
9
  import { PROMPT_COMPOSER_EMPTY_DOC, promptComposerParagraphDoc } from './promptComposerDoc.js';
9
10
 
10
- const PROMPT_COMPOSER_EDITOR_CLASS = 'promptComposerEditor';
11
- const PROMPT_COMPOSER_EMPTY_EDITOR_CLASS = 'promptComposerEmptyEditor';
12
- const PROMPT_COMPOSER_EMPTY_NODE_CLASS = 'promptComposerEmptyNode';
13
11
  function usePromptComposerEditor({ disabled, placeholder, slashCommandItems, slashSuggestionPlacement = 'above', onSlashItemCommand, prefillMessage, attachmentsCount = 0, allowEnterSubmit, onSubmit, onChange, }) {
14
12
  const slashOpenRef = useRef(false);
15
13
  const onSlashItemCommandRef = useRef(onSlashItemCommand);
@@ -50,8 +48,7 @@ function usePromptComposerEditor({ disabled, placeholder, slashCommandItems, sla
50
48
  Placeholder.configure({
51
49
  placeholder: placeholderText,
52
50
  showOnlyWhenEditable: true,
53
- emptyEditorClass: PROMPT_COMPOSER_EMPTY_EDITOR_CLASS,
54
- emptyNodeClass: PROMPT_COMPOSER_EMPTY_NODE_CLASS,
51
+ emptyNodeClass: S.promptComposerEmptyNode,
55
52
  }),
56
53
  ];
57
54
  if (slashItemsStable.length > 0) {
@@ -121,7 +118,7 @@ function usePromptComposerEditor({ disabled, placeholder, slashCommandItems, sla
121
118
  attributes: {
122
119
  spellcheck: 'true',
123
120
  'aria-label': ariaLabelComposer,
124
- class: PROMPT_COMPOSER_EDITOR_CLASS,
121
+ class: S.promptComposerEditor,
125
122
  },
126
123
  handleKeyDown: handleEditorKeyDown,
127
124
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "5.3.9",
3
+ "version": "5.3.11",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "tests": "jest",