@antscorp/antsomi-ui 1.3.7-beta.7 → 1.3.7-beta.8

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.
@@ -17,7 +17,7 @@ import '@yaireo/tagify/dist/tagify.css';
17
17
  // Styled
18
18
  import { TagTextArea, TagifyWrapper, WrapperPlaceHolder } from './styled';
19
19
  // Utils
20
- import { parseTagStringToTagify, convertInputStringToOriginal, emojiManufacturer, getEmojiTag, isPersonalizeTagType, generateTagContent, unescapeString, hasLineBreak, selectRange, isTagClickable, findURLInTextNodes, getAttributesString, isAnchorNodeChildOfElement, isShortLinkTagType, isCustomTagType, sanitizeTagAttributes, getTagAttributes, applyTagAttributes, getTagContentAttributes, isCaretAtEndOfTextNodeWithNextTag, getCurrentSelectionAndCloneRange, handleEnterWithNextTag, handleTextNodeBackspace, } from './utils';
20
+ import { parseTagStringToTagify, convertInputStringToOriginal, emojiManufacturer, getEmojiTag, isPersonalizeTagType, generateTagContent, unescapeString, hasLineBreak, selectRange, isTagClickable, findURLInTextNodes, getAttributesString, isAnchorNodeChildOfElement, isShortLinkTagType, isCustomTagType, sanitizeTagAttributes, getTagAttributes, applyTagAttributes, getTagContentAttributes, isCaretAtEndOfTextNodeWithNextTag, getCurrentSelectionAndCloneRange, handleEnterWithNextTag, handleTextNodeBackspace, extractTagValues, } from './utils';
21
21
  import { acceptablePatternChecking, detectURLRegex, getCachedRegex, getCustomTagId, getPersonalizeTagInfo, getShortLinkTagInfo, patternHandlers, } from './patternHandlers';
22
22
  // Constants
23
23
  import { DETECT_LINK, EMOJI, PERSONALIZE_PTN, SHORT_LINK, SHORT_LINK_PTN, SHORT_LINK_V2, TAG_TYPE, UNSUBSCRIBE_WHATSAPP, defaultCssVariables, tagifyDefaultProps, TAG_CUSTOM_ATTRIBUTES, } from './constants';
@@ -25,7 +25,7 @@ const { CUSTOM_TAG } = TAG_TYPE;
25
25
  const { PREPARING_ST, INVALID_TAG, MESSAGE_TAG, FORCE_SHOW_TOOLTIP } = TAG_CUSTOM_ATTRIBUTES;
26
26
  const TagifyInput = forwardRef((props, ref) => {
27
27
  // Props
28
- const { initialValue, escapeHTML, status, readonly, readonlyTag, readonlyText, readonlyWhenNotEmpty, realtime, disabled, maxLength, maxHeight, minWidth, placeholder, minWidthPlaceholder, isSingleLineText, acceptableTagPattern, tagProperties, mapAttributes = {}, mapErrorAttributes = {}, maxPersonalizeTags, name, children, cssTagifyVariables, onTagClick, onTagRemove, onChange, onRestoreTagProperty, onBlur, } = props;
28
+ const { initialValue, escapeHTML, status, readonly, readonlyTag, readonlyText, readonlyWhenNotEmpty, realtime, disabled, maxLength, maxHeight, minWidth, placeholder, minWidthPlaceholder, isSingleLineText, acceptableTagPattern, tagProperties, mapAttributes = {}, mapErrorAttributes = {}, maxPersonalizeTags, name, children, cssTagifyVariables, onTagClick, onAddTag, onTagRemove, onChange, onRestoreTagProperty, onBlur, } = props;
29
29
  // States
30
30
  const [isLineBreak, setIsLineBreak] = useState(hasLineBreak(initialValue));
31
31
  const [tooltipRefresher, setTooltipRefresher] = useState(1);
@@ -471,7 +471,7 @@ const TagifyInput = forwardRef((props, ref) => {
471
471
  }, [onTagClick]);
472
472
  const onTagifyRemoveTag = useCallback((event) => {
473
473
  if (event.detail && onTagRemove) {
474
- onTagRemove(event.detail);
474
+ onTagRemove(event.detail, extractTagValues(event.detail.tagify));
475
475
  }
476
476
  }, [onTagRemove]);
477
477
  // Used to trigger replace URL detection and line break
@@ -780,14 +780,10 @@ const TagifyInput = forwardRef((props, ref) => {
780
780
  const hasContent = cleanValue.length > 0;
781
781
  inputEl.setAttribute('contenteditable', hasContent ? 'false' : 'true');
782
782
  }
783
- else if (typeof readonlyText === 'function') {
784
- const isReadonlyText = readonlyText(tagifyRef.current.getCleanValue());
785
- inputEl.setAttribute('contenteditable', isReadonlyText ? 'false' : 'true');
786
- }
787
783
  else if (typeof readonlyText !== 'undefined') {
788
784
  inputEl.setAttribute('contenteditable', readonlyText ? 'false' : 'true');
789
785
  }
790
- }, [readonlyText, readonlyWhenNotEmpty, tagLength]);
786
+ }, [readonlyText, readonlyWhenNotEmpty]);
791
787
  const onTagifyWrapperClick = useCallback(event => {
792
788
  event.preventDefault();
793
789
  event.stopPropagation();
@@ -874,8 +870,11 @@ const TagifyInput = forwardRef((props, ref) => {
874
870
  try {
875
871
  node.dataset.__removed_by_mutation = 'true';
876
872
  const tagData = tagifyRef.current?.getSetTagData(node);
877
- if (tagData && tagData.type === CUSTOM_TAG && !tagData?.__removed) {
878
- onTagRemove({ data: tagData });
873
+ if (tagifyRef.current &&
874
+ tagData &&
875
+ tagData.type === CUSTOM_TAG &&
876
+ !tagData?.__removed) {
877
+ onTagRemove({ data: tagData }, extractTagValues(tagifyRef.current));
879
878
  }
880
879
  }
881
880
  catch (error) {
@@ -987,6 +986,8 @@ const TagifyInput = forwardRef((props, ref) => {
987
986
  tagifyInstance.on('change', onTagifyChangedDebounce);
988
987
  tagifyInstance.on('remove', onTagifyRemoveTag);
989
988
  tagifyInstance.on('keydown', onKeyDown);
989
+ if (onAddTag)
990
+ tagifyInstance.on('add', onAddTag);
990
991
  if (onBlur)
991
992
  tagifyInstance.on('blur', onBlur);
992
993
  }
@@ -998,11 +999,14 @@ const TagifyInput = forwardRef((props, ref) => {
998
999
  tagifyInstance.off('change', onTagifyChangedDebounce);
999
1000
  tagifyInstance.off('remove', onTagifyRemoveTag);
1000
1001
  tagifyInstance.off('keydown', onKeyDown);
1002
+ if (onAddTag)
1003
+ tagifyInstance.off('add', onAddTag);
1001
1004
  if (onBlur)
1002
1005
  tagifyInstance.off('blur', onBlur);
1003
1006
  }
1004
1007
  };
1005
1008
  }, [
1009
+ onAddTag,
1006
1010
  onBlur,
1007
1011
  onTagItemClick,
1008
1012
  onInputTagifyDebounce,
@@ -15,6 +15,10 @@ export type TagStatus = (typeof TAG_STATUS)[keyof typeof TAG_STATUS];
15
15
  export type MapAttributesProps = Record<string, Record<string, any>>;
16
16
  export type StatusType = 'error' | 'success' | 'warning';
17
17
  export type BackgroundColorPersonalizeType = Exclude<keyof typeof TAG_COLOR, 'detect_link' | 'emoji' | 'shortlink'>;
18
+ export interface TagValues {
19
+ listTags: TagDataCustomize[];
20
+ value: string;
21
+ }
18
22
  /**
19
23
  * Interface defining the properties for the Tagify input component.
20
24
  * Provides configuration options and event handlers to manage Tagify's behavior and appearance.
@@ -134,11 +138,16 @@ export interface TagifyInputProps {
134
138
  * Receives the tag detail as parameter, allowing custom actions on tag click.
135
139
  */
136
140
  onTagClick?: (tagDetail: Tagify.ClickEventData<TagDataCustomize>) => void;
141
+ /**
142
+ * Event handler triggered when a tag is added.
143
+ * Receives the tag detail as parameter, allowing custom actions on tag addition.
144
+ */
145
+ onAddTag?: (event: CustomEvent<Tagify.AddEventData<TagDataCustomize>>) => void;
137
146
  /**
138
147
  * Event handler triggered when a tag is removed.
139
148
  * Receives the tag detail as parameter, allowing custom actions on tag removal.
140
149
  */
141
- onTagRemove?: (tagDetail: Tagify.RemoveEventData<TagDataCustomize>) => void;
150
+ onTagRemove?: (tagDetail: Tagify.RemoveEventData<TagDataCustomize>, values: TagValues) => void;
142
151
  /**
143
152
  * Event handler triggered when the input value changes.
144
153
  * Receives the updated input value as a string, allowing for controlled component updates.
@@ -159,7 +168,7 @@ export interface TagifyInputProps {
159
168
  /**
160
169
  * Defines whether the input text is read but not the whole tags.
161
170
  */
162
- readonlyText?: boolean | ((listTags: TagDataCustomize[]) => boolean);
171
+ readonlyText?: boolean;
163
172
  /**
164
173
  * When true, automatically sets the input text to readonly (contenteditable='false')
165
174
  * when the input is not empty (has tags or content).
@@ -1,6 +1,6 @@
1
1
  /// <reference types="yaireo__tagify" />
2
2
  import Tagify from '@yaireo/tagify';
3
- import { AcceptablePattern, TagAttribute, EmojiCollection, EmojiTag, TagDataCustomize, TagProperty, TagType } from './types';
3
+ import { AcceptablePattern, TagAttribute, EmojiCollection, EmojiTag, TagDataCustomize, TagProperty, TagType, TagValues } from './types';
4
4
  /**
5
5
  * Parses the input string and replaces matching patterns with processed tags.
6
6
  * This function iterates over predefined regex patterns and replaces each match
@@ -202,3 +202,4 @@ export declare const getCurrentSelectionAndCloneRange: () => {
202
202
  };
203
203
  export declare const handleTextNodeBackspace: (range: Range) => void;
204
204
  export declare const handleEnterWithNextTag: (range: Range) => void;
205
+ export declare const extractTagValues: (tagify: Tagify<TagDataCustomize>) => TagValues;
@@ -796,3 +796,11 @@ export const handleEnterWithNextTag = (range) => {
796
796
  return;
797
797
  insertZeroWidthSpaceBeforeTag(currentNode);
798
798
  };
799
+ export const extractTagValues = (tagify) => {
800
+ if (!tagify)
801
+ return { listTags: [], value: '' };
802
+ return {
803
+ listTags: tagify.getCleanValue(),
804
+ value: tagify.getInputValue(),
805
+ };
806
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.7-beta.7",
3
+ "version": "1.3.7-beta.8",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",
@@ -14,6 +14,9 @@
14
14
  "es",
15
15
  "dist"
16
16
  ],
17
+ "engines": {
18
+ "node": "20.x"
19
+ },
17
20
  "main": "es/index.js",
18
21
  "module": "es/index.js",
19
22
  "unpkg": "dist/index.js",