@antscorp/antsomi-ui 1.3.5-beta.979 → 1.3.5-beta.980

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.
@@ -16,11 +16,12 @@ import '@yaireo/tagify/dist/tagify.css';
16
16
  // Styled
17
17
  import { TagTextArea, TagifyWrapper, WrapperPlaceHolder } from './styled';
18
18
  // Utils
19
- import { parseTagStringToTagify, convertInputStringToOriginal, emojiManufacturer, getEmojiTag, isPersonalizeTagType, generateTagContent, unescapeString, hasLineBreak, selectRange, isTagClickable, findURLInTextNodes, getAttributesString, isAnchorNodeChildOfElement, isShortLinkTagType, isCustomTagType, } from './utils';
19
+ import { parseTagStringToTagify, convertInputStringToOriginal, emojiManufacturer, getEmojiTag, isPersonalizeTagType, generateTagContent, unescapeString, hasLineBreak, selectRange, isTagClickable, findURLInTextNodes, getAttributesString, isAnchorNodeChildOfElement, isShortLinkTagType, isCustomTagType, sanitizeTagAttributes, getTagAttributes, applyTagAttributes, getTagContentAttributes, } from './utils';
20
20
  import { acceptablePatternChecking, detectURLRegex, getCachedRegex, getCustomTagId, getPersonalizeTagInfo, getShortLinkTagInfo, patternHandlers, } from './patternHandlers';
21
21
  // Constants
22
- import { DETECT_LINK, EMOJI, ERROR_TAG, FORCE_SHOW_TOOLTIP, INVALID_TAG, MESSAGE_TAG, PERSONALIZE_PTN, PROMOTION_CODE, READONLY_TAG, SHORT_LINK, SHORT_LINK_PTN, SHORT_LINK_V2, WARNING_TAG, TAG_TYPE, defaultCssVariables, tagifyDefaultProps, } from './constants';
22
+ import { DETECT_LINK, EMOJI, PERSONALIZE_PTN, PROMOTION_CODE, SHORT_LINK, SHORT_LINK_PTN, SHORT_LINK_V2, TAG_TYPE, defaultCssVariables, tagifyDefaultProps, TAG_CUSTOM_ATTRIBUTES, } from './constants';
23
23
  const { CUSTOM_TAG } = TAG_TYPE;
24
+ const { READONLY_TAG, INVALID_TAG, MESSAGE_TAG, FORCE_SHOW_TOOLTIP, ERROR_TAG, WARNING_TAG } = TAG_CUSTOM_ATTRIBUTES;
24
25
  const TagifyInput = forwardRef((props, ref) => {
25
26
  // Props
26
27
  const { initialValue, escapeHTML, status, readonly, readonlyTag, realtime, disabled, maxLength, maxHeight, minWidth, placeholder, minWidthPlaceholder, isSingleLineText, acceptableTagPattern, tagProperties = {}, mapAttributes = {}, mapErrorAttributes = {}, maxPersonalizeTags, name, children, cssTagifyVariables, onTagClick, onTagRemove, onChange, } = props;
@@ -572,12 +573,8 @@ const TagifyInput = forwardRef((props, ref) => {
572
573
  if (!isCustomTag) {
573
574
  tagTextNode.textContent = tagLabel;
574
575
  }
575
- // Clear all previous attributes
576
- tagElement.removeAttribute(INVALID_TAG);
577
- tagElement.removeAttribute(ERROR_TAG);
578
- tagElement.removeAttribute(WARNING_TAG);
579
- tagElement.removeAttribute(READONLY_TAG);
580
- tagElement.removeAttribute(MESSAGE_TAG);
576
+ // Remove all existing attributes
577
+ sanitizeTagAttributes(tagElement);
581
578
  // In case promotion pool has something wrong
582
579
  if (message) {
583
580
  if (isRemoved || isArchived || !isActive || isExpired) {
@@ -618,12 +615,8 @@ const TagifyInput = forwardRef((props, ref) => {
618
615
  */
619
616
  if (tagTextNode) {
620
617
  tagTextNode.textContent = tagLabel;
621
- // Clear all previous attributes
622
- tagElement.removeAttribute(INVALID_TAG);
623
- tagElement.removeAttribute(ERROR_TAG);
624
- tagElement.removeAttribute(WARNING_TAG);
625
- tagElement.removeAttribute(READONLY_TAG);
626
- tagElement.removeAttribute(MESSAGE_TAG);
618
+ // Remove all existing attributes
619
+ sanitizeTagAttributes(tagElement);
627
620
  // In case promotion pool has something wrong
628
621
  if (!isValid && message) {
629
622
  tagElement.setAttribute(ERROR_TAG, 'true');
@@ -645,40 +638,40 @@ const TagifyInput = forwardRef((props, ref) => {
645
638
  const tagElements = tagifyRef.current.getTagElms();
646
639
  const { pattern, name: cachePatternName } = patternHandlers[PERSONALIZE_PTN];
647
640
  tagElements.forEach(tagElement => {
648
- const tagData = tagifyRef.current?.getSetTagData(tagElement);
649
- if (tagData) {
650
- const { type, value } = tagData;
651
- const isCustomTag = type === CUSTOM_TAG;
652
- // Skip if it is not a custom tag
653
- if (!isCustomTag || !value)
654
- return;
655
- // Use the cached regex instead of creating a new one each time
656
- const regex = getCachedRegex(pattern, 'g', cachePatternName);
657
- let match;
658
- // Iterate over matches of the current pattern
659
- // eslint-disable-next-line no-cond-assign
660
- while ((match = regex.exec(value)) !== null) {
661
- const [, contentCode] = match;
662
- const customTagId = getCustomTagId(type, contentCode);
663
- const property = _.get(properties, customTagId);
664
- if (!customTagId || !property)
665
- continue;
666
- /*
667
- * Just only update to the correct text of the tag
668
- * NOTE: Do not actually affect raw data
669
- */
670
- tagData.label = property.displayName;
671
- tagData.bgColorPersonalizeType = property.type;
672
- tagifyRef.current?.replaceTag(tagElement, tagData);
673
- // Mark the tag as changed
674
- isChangeOccurred = true;
641
+ const { __tagifyTagData: tagData } = tagElement;
642
+ if (!tagData || tagData?.type !== CUSTOM_TAG || !tagData?.value)
643
+ return;
644
+ const { type, value } = tagData;
645
+ // Use the cached regex instead of creating a new one each time
646
+ const regex = getCachedRegex(pattern, 'g', cachePatternName);
647
+ let match;
648
+ // Iterate over matches of the current pattern
649
+ // eslint-disable-next-line no-cond-assign
650
+ while ((match = regex.exec(value)) !== null) {
651
+ const [, contentCode] = match;
652
+ const customTagId = getCustomTagId(type, contentCode);
653
+ const property = _.get(properties, customTagId);
654
+ if (!customTagId || !property)
655
+ continue;
656
+ const { displayName } = property;
657
+ // Update tag text (but not raw data)
658
+ tagifyRef.current?.setTagTextNode(tagElement, displayName);
659
+ isChangeOccurred = true;
660
+ // Remove all existing attributes
661
+ sanitizeTagAttributes(tagElement);
662
+ // Update new tag attributes
663
+ const tagAttributes = getTagAttributes(property);
664
+ applyTagAttributes(tagElement, tagAttributes);
665
+ // Update tag content element attributes
666
+ const tagContentEl = tagElement.querySelector('.tagify__tag-content');
667
+ if (tagContentEl) {
668
+ const tagContentAttributes = getTagContentAttributes(property.type);
669
+ applyTagAttributes(tagContentEl, tagContentAttributes);
675
670
  }
676
671
  }
677
672
  });
678
673
  if (isChangeOccurred) {
679
674
  setTooltipRefresher(prev => prev + 1);
680
- // Make silent update -> do not callback data out
681
- tagifyRef.current?.update({ withoutChangeEvent: true });
682
675
  }
683
676
  }
684
677
  }, []);
@@ -833,8 +826,8 @@ const TagifyInput = forwardRef((props, ref) => {
833
826
  * Need to sync label of the tags if any map attribute is changed to make correct label
834
827
  * */
835
828
  useDeepCompareEffect(() => {
836
- makeValidLabelTags(mapAttributes, mapErrorAttributes, tagProperties);
837
- }, [mapAttributes, mapErrorAttributes, tagProperties, makeValidLabelTags]);
829
+ makeValidLabelTags(mapAttributes, mapErrorAttributes, {});
830
+ }, [mapAttributes, mapErrorAttributes, makeValidLabelTags]);
838
831
  useLayoutEffect(() => {
839
832
  if (tagProperties) {
840
833
  executeTagProperties(tagProperties);
@@ -4,6 +4,17 @@ export declare const DIMENSIONS: {
4
4
  readonly TAG_H: 24;
5
5
  };
6
6
  export declare const MIN_H_WRAPPER: 34, TAG_H: 24;
7
+ export declare const TAG_STATUS: {
8
+ readonly REMOVED: "removed";
9
+ readonly ARCHIVED: "archived";
10
+ readonly ACTIVE: "active";
11
+ readonly INACTIVE: "inactive";
12
+ readonly EXPIRED: "expired";
13
+ readonly WARNING: "warning";
14
+ readonly ERROR: "error";
15
+ readonly INVALID: "invalid";
16
+ readonly DO_NOT_VIEW: "do-not-view";
17
+ };
7
18
  export declare const TAG_CUSTOM_ATTRIBUTES: {
8
19
  readonly READONLY_TAG: "readonly-tag";
9
20
  readonly INVALID_TAG: "invalid-tag";
@@ -13,8 +24,11 @@ export declare const TAG_CUSTOM_ATTRIBUTES: {
13
24
  readonly FORCE_SHOW_TOOLTIP: "force-show-tooltip";
14
25
  readonly ERROR_TAG: "error-tag";
15
26
  readonly WARNING_TAG: "warning-tag";
27
+ readonly PRIORITY_COLOR_TYPE: "priority-color-type";
28
+ readonly BG_COLOR_PERSONALIZE_TYPE: "bg-color-personalize-type";
29
+ readonly BG_COLOR_PERSONALIZE_TYPE_V2: "bgColorPersonalizeType";
16
30
  };
17
- export declare const READONLY_TAG: "readonly-tag", INVALID_TAG: "invalid-tag", REMOVED_TAG: "removed-tag", NO_VIEW_TAG: "no-view-tag", MESSAGE_TAG: "message-tag", FORCE_SHOW_TOOLTIP: "force-show-tooltip", ERROR_TAG: "error-tag", WARNING_TAG: "warning-tag";
31
+ export declare const READONLY_TAG: "readonly-tag", INVALID_TAG: "invalid-tag", REMOVED_TAG: "removed-tag", NO_VIEW_TAG: "no-view-tag", MESSAGE_TAG: "message-tag", FORCE_SHOW_TOOLTIP: "force-show-tooltip", ERROR_TAG: "error-tag", WARNING_TAG: "warning-tag", PRIORITY_COLOR_TYPE: "priority-color-type", BG_COLOR_PERSONALIZE_TYPE: "bg-color-personalize-type", BG_COLOR_PERSONALIZE_TYPE_V2: "bgColorPersonalizeType";
18
32
  export declare const defaultCssVariables: {
19
33
  '--input-color': string | undefined;
20
34
  '--input-font-size': string;
@@ -5,6 +5,17 @@ export const DIMENSIONS = {
5
5
  TAG_H: 24,
6
6
  };
7
7
  export const { MIN_H_WRAPPER, TAG_H } = DIMENSIONS;
8
+ export const TAG_STATUS = {
9
+ REMOVED: 'removed',
10
+ ARCHIVED: 'archived',
11
+ ACTIVE: 'active',
12
+ INACTIVE: 'inactive',
13
+ EXPIRED: 'expired',
14
+ WARNING: 'warning',
15
+ ERROR: 'error',
16
+ INVALID: 'invalid',
17
+ DO_NOT_VIEW: 'do-not-view',
18
+ };
8
19
  export const TAG_CUSTOM_ATTRIBUTES = {
9
20
  READONLY_TAG: 'readonly-tag',
10
21
  INVALID_TAG: 'invalid-tag',
@@ -14,8 +25,11 @@ export const TAG_CUSTOM_ATTRIBUTES = {
14
25
  FORCE_SHOW_TOOLTIP: 'force-show-tooltip',
15
26
  ERROR_TAG: 'error-tag',
16
27
  WARNING_TAG: 'warning-tag',
28
+ PRIORITY_COLOR_TYPE: 'priority-color-type',
29
+ BG_COLOR_PERSONALIZE_TYPE: 'bg-color-personalize-type',
30
+ BG_COLOR_PERSONALIZE_TYPE_V2: 'bgColorPersonalizeType',
17
31
  };
18
- export const { READONLY_TAG, INVALID_TAG, REMOVED_TAG, NO_VIEW_TAG, MESSAGE_TAG, FORCE_SHOW_TOOLTIP, ERROR_TAG, WARNING_TAG, } = TAG_CUSTOM_ATTRIBUTES;
32
+ export const { READONLY_TAG, INVALID_TAG, REMOVED_TAG, NO_VIEW_TAG, MESSAGE_TAG, FORCE_SHOW_TOOLTIP, ERROR_TAG, WARNING_TAG, PRIORITY_COLOR_TYPE, BG_COLOR_PERSONALIZE_TYPE, BG_COLOR_PERSONALIZE_TYPE_V2, } = TAG_CUSTOM_ATTRIBUTES;
19
33
  export const defaultCssVariables = {
20
34
  '--input-color': globalToken?.colorText,
21
35
  '--input-font-size': `${globalToken?.fontSize}px`,
@@ -1,14 +1,17 @@
1
1
  /// <reference types="yaireo__tagify" />
2
2
  import { ClassNameSettings, TagData, TagifySettings } from '@yaireo/tagify';
3
- import { EMOJI_COLLECTIONS, PATTERN_CACHE_TYPE, SHORT_LINK_TYPE, TAG_COLOR, TAG_TYPE } from './constants';
3
+ import { EMOJI_COLLECTIONS, PATTERN_CACHE_TYPE, SHORT_LINK_TYPE, TAG_COLOR, TAG_STATUS, TAG_TYPE } from './constants';
4
4
  import { type CSSProperties } from 'react';
5
5
  export type TagType = (typeof TAG_TYPE)[keyof typeof TAG_TYPE];
6
6
  export type TagTypeProperty = Exclude<TagType, 'detect_link' | 'emoji' | 'shortlink'>;
7
- export type TagProperties = Record<string, {
7
+ export type TagProperty = {
8
8
  [key: string]: any;
9
9
  displayName: string;
10
10
  type: TagTypeProperty;
11
- }>;
11
+ };
12
+ export type TagProperties = Record<string, TagProperty>;
13
+ export type TagAttribute = [string, string];
14
+ export type TagStatus = (typeof TAG_STATUS)[keyof typeof TAG_STATUS];
12
15
  export type MapAttributesProps = Record<string, Record<string, any>>;
13
16
  export type StatusType = 'error' | 'success' | 'warning';
14
17
  export type BackgroundColorPersonalizeType = Exclude<keyof typeof TAG_COLOR, 'detect_link' | 'emoji' | 'shortlink'>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="yaireo__tagify" />
2
2
  import Tagify from '@yaireo/tagify';
3
- import { AcceptablePattern, EmojiCollection, EmojiTag, TagDataCustomize, TagType } from './types';
3
+ import { AcceptablePattern, TagAttribute, EmojiCollection, EmojiTag, TagDataCustomize, TagProperty, TagType } 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
@@ -48,6 +48,11 @@ export declare const getEmojiTag: ({ src, emoji, code }: EmojiTag) => string;
48
48
  export declare const isPersonalizeTagType: (type: TagType) => boolean;
49
49
  export declare const isShortLinkTagType: (type: TagType) => boolean;
50
50
  export declare const isCustomTagType: (type: TagType) => boolean;
51
+ export declare const sanitizeTagAttributes: (tagElement: HTMLElement) => void;
52
+ export declare const applyTagAttributes: (element: HTMLElement, attributes: TagAttribute[]) => void;
53
+ export declare const getStatusTagAttributes: (statusMsg: string) => Record<string, TagAttribute[]>;
54
+ export declare const getTagContentAttributes: (propertyType: string) => TagAttribute[];
55
+ export declare const getTagAttributes: (property: TagProperty) => TagAttribute[];
51
56
  export declare const generateTagContent: (params: {
52
57
  tagData: TagDataCustomize;
53
58
  content: string;
@@ -1,11 +1,13 @@
1
1
  // Libraries
2
2
  import stringReplaceToArray from 'string-replace-to-array';
3
3
  // Constants
4
- import { EMOJI_COLLECTIONS, PREFIX_PATTERN_LINE_MESSAGE, READONLY_TAG, SHORT_LINK_V2, TAG_TYPE, } from './constants';
4
+ import { EMOJI_COLLECTIONS, PREFIX_PATTERN_LINE_MESSAGE, SHORT_LINK_V2, TAG_CUSTOM_ATTRIBUTES, TAG_STATUS, TAG_TYPE, } from './constants';
5
5
  import { iconsViber } from './iconsViber';
6
6
  // Utils
7
7
  import { acceptablePatternChecking, detectURLRegex, getCachedRegex, patternHandlers, tagRegexStringPattern, } from './patternHandlers';
8
8
  const { CUSTOMER, VISITOR, EVENT, JOURNEY, CAMPAIGN, VARIANT, PROMOTION_CODE, CUSTOM_FN, OBJECT_WIDGET, CONTENT_SOURCE_GROUP, ALLOCATED_CODE, CUSTOM_TAG, } = TAG_TYPE;
9
+ const { READONLY_TAG, INVALID_TAG, MESSAGE_TAG, ERROR_TAG, WARNING_TAG, PRIORITY_COLOR_TYPE, BG_COLOR_PERSONALIZE_TYPE, BG_COLOR_PERSONALIZE_TYPE_V2, } = TAG_CUSTOM_ATTRIBUTES;
10
+ const { REMOVED, ARCHIVED, INACTIVE, INVALID, EXPIRED, WARNING, DO_NOT_VIEW, ERROR } = TAG_STATUS;
9
11
  /*
10
12
  * Custom error type for JSON parse errors
11
13
  */
@@ -405,13 +407,69 @@ export const isPersonalizeTagType = (type) => [
405
407
  ].includes(type);
406
408
  export const isShortLinkTagType = (type) => [SHORT_LINK_V2].includes(type);
407
409
  export const isCustomTagType = (type) => type === CUSTOM_TAG;
410
+ export const sanitizeTagAttributes = (tagElement) => {
411
+ const attributesToRemove = [INVALID_TAG, ERROR_TAG, WARNING_TAG, READONLY_TAG, MESSAGE_TAG];
412
+ attributesToRemove.forEach(attr => tagElement.removeAttribute(attr));
413
+ };
414
+ export const applyTagAttributes = (element, attributes) => {
415
+ attributes.forEach(([attr, value]) => element.setAttribute(attr, value));
416
+ };
417
+ export const getStatusTagAttributes = (statusMsg) => {
418
+ const statusAttributes = {
419
+ error: [
420
+ [ERROR_TAG, 'true'],
421
+ [MESSAGE_TAG, statusMsg],
422
+ ],
423
+ warning: [
424
+ [WARNING_TAG, 'true'],
425
+ [MESSAGE_TAG, statusMsg],
426
+ ],
427
+ invalid: [
428
+ [READONLY_TAG, 'true'],
429
+ [INVALID_TAG, 'true'],
430
+ [MESSAGE_TAG, statusMsg],
431
+ ],
432
+ };
433
+ return statusAttributes;
434
+ };
435
+ export const getTagContentAttributes = (propertyType) => [
436
+ [`data-${PRIORITY_COLOR_TYPE}`, propertyType],
437
+ [`data-${BG_COLOR_PERSONALIZE_TYPE}`, propertyType],
438
+ ];
439
+ export const getTagAttributes = (property) => {
440
+ const { status, statusMsg, type } = property;
441
+ const attributes = [[BG_COLOR_PERSONALIZE_TYPE_V2, type]];
442
+ if (!statusMsg)
443
+ return attributes;
444
+ const statusAttributes = getStatusTagAttributes(statusMsg);
445
+ switch (status) {
446
+ case REMOVED:
447
+ case ARCHIVED:
448
+ case EXPIRED:
449
+ case ERROR:
450
+ case INACTIVE:
451
+ attributes.push(...statusAttributes.error);
452
+ break;
453
+ case WARNING:
454
+ case DO_NOT_VIEW:
455
+ attributes.push(...statusAttributes.warning);
456
+ break;
457
+ case INVALID:
458
+ attributes.push(...statusAttributes.invalid);
459
+ break;
460
+ default: {
461
+ break;
462
+ }
463
+ }
464
+ return attributes;
465
+ };
408
466
  export const generateTagContent = (params) => {
409
467
  const { tagData, content } = params;
410
468
  let dataAttrsString = '';
411
469
  const dataAttrs = new Map([['tag-type', tagData.type]]);
412
470
  if (tagData.bgColorPersonalizeType) {
413
- dataAttrs.set('priority-color-type', tagData.bgColorPersonalizeType);
414
- dataAttrs.set('bg-color-personalize-type', tagData.bgColorPersonalizeType);
471
+ dataAttrs.set(PRIORITY_COLOR_TYPE, tagData.bgColorPersonalizeType);
472
+ dataAttrs.set(BG_COLOR_PERSONALIZE_TYPE, tagData.bgColorPersonalizeType);
415
473
  }
416
474
  if (tagData.type === TAG_TYPE.SHORT_LINK) {
417
475
  const { shortlinkType } = tagData;
@@ -55,20 +55,19 @@ export const getTagifyInputStyled = ({ $minWidth, $placeholder, $minWidthPlaceho
55
55
 
56
56
  ${$isSingleLineText &&
57
57
  css `
58
- white-space: nowrap;
59
- overflow: auto;
58
+ white-space: nowrap;
59
+ overflow: auto;
60
60
 
61
- br {
62
- display: none;
63
- }
61
+ br {
62
+ display: none;
63
+ }
64
64
 
65
- div, p {
66
- display: inline-block;
67
- white-space: nowrap;
68
- overflow: auto
69
- overflow-y: hidden;
70
- }
71
- `}
65
+ div,
66
+ p {
67
+ display: inline-block;
68
+ white-space: nowrap;
69
+ }
70
+ `}
72
71
  `;
73
72
  const getBackgroundColor = (tag) => {
74
73
  const { type } = tag;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.979",
3
+ "version": "1.3.5-beta.980",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",