@antscorp/antsomi-ui 1.3.5-beta.927 → 1.3.5-beta.929

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,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { IconProps as OriginIconProps } from '../../icons/types';
3
2
  export interface IconProps extends OriginIconProps {
4
3
  size?: number;
@@ -1,3 +1,13 @@
1
- /// <reference types="react" />
2
- export declare const Switch: import("react").ForwardRefExoticComponent<import("antd").SwitchProps & import("react").RefAttributes<HTMLElement>>;
3
- export type { SwitchProps } from 'antd';
1
+ import React from 'react';
2
+ import { type SwitchProps as AntdSwitchProps } from 'antd';
3
+ import { DataType } from 'csstype';
4
+ declare module 'react' {
5
+ interface CSSProperties {
6
+ '--switch-color'?: DataType.Color;
7
+ }
8
+ }
9
+ type SwitchProps = AntdSwitchProps & {
10
+ color?: string;
11
+ };
12
+ declare const Switch: React.FC<SwitchProps>;
13
+ export { Switch, type SwitchProps };
@@ -1,3 +1,8 @@
1
- import { Switch as AntdSwitch } from 'antd';
2
- export const Switch = AntdSwitch;
3
- Switch.defaultProps = {};
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { THEME } from '@antscorp/antsomi-ui/es/constants';
3
+ import { StyledSwitch } from './styled';
4
+ const Switch = props => {
5
+ const { color = THEME.token?.colorPrimary || '#005eb8', ...rest } = props;
6
+ return _jsx(StyledSwitch, { style: { '--switch-color': color }, ...rest });
7
+ };
8
+ export { Switch };
@@ -1,2 +1 @@
1
- export { Switch } from './Switch';
2
- export type { SwitchProps } from 'antd';
1
+ export { Switch, type SwitchProps } from './Switch';
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const StyledSwitch: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd").SwitchProps & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
@@ -0,0 +1,60 @@
1
+ import { THEME } from '@antscorp/antsomi-ui/es/constants';
2
+ import { Switch } from 'antd';
3
+ import styled from 'styled-components';
4
+ export const StyledSwitch = styled(Switch) `
5
+ &.antsomi-switch {
6
+ border: 2px solid var(--switch-color);
7
+
8
+ &.antsomi-switch-checked {
9
+ background: var(--switch-color);
10
+
11
+ > .antsomi-switch-handle {
12
+ &::before {
13
+ background-color: ${THEME.token?.bw0};
14
+ }
15
+ }
16
+
17
+ .antsomi-switch-inner {
18
+ padding-inline-start: 4px;
19
+ padding-inline-end: 18px;
20
+ }
21
+
22
+ &:hover:not(.antsomi-switch-disabled) {
23
+ background-color: var(--switch-color);
24
+ }
25
+ }
26
+
27
+ &.antsomi-switch-disabled {
28
+ background: ${THEME.token?.bw0};
29
+ border-color: ${THEME.token?.colorTextPlaceholder};
30
+
31
+ > .antsomi-switch-handle {
32
+ &::before {
33
+ background-color: ${THEME.token?.colorTextPlaceholder};
34
+ }
35
+ }
36
+
37
+ &.antsomi-switch-checked {
38
+ background: ${THEME.token?.colorTextPlaceholder};
39
+ border-color: ${THEME.token?.colorTextPlaceholder};
40
+
41
+ > .antsomi-switch-handle {
42
+ &::before {
43
+ background-color: ${THEME.token?.bw0};
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ .antsomi-switch-handle {
50
+ &::before {
51
+ background-color: var(--switch-color);
52
+ }
53
+ }
54
+
55
+ .antsomi-switch-inner {
56
+ padding-inline-start: 4px;
57
+ padding-inline-end: 18px;
58
+ }
59
+ }
60
+ `;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
2
3
  export type TDisplayFormat = 'number' | 'percentage' | 'currency' | 'datetime';
3
4
  type DisplayFormatProps = {
@@ -85,7 +85,8 @@ const TagifyInput = forwardRef((props, ref) => {
85
85
  throw new Error('Tagify instance is not initialized');
86
86
  }
87
87
  const { scope } = tagifyRef.current?.DOM;
88
- const isValidSelection = isAnchorNodeChildOfElement(scope);
88
+ const anchorNodeInstance = _.get(tagifyRef.current, 'state.selection.anchorNode', null);
89
+ const isValidSelection = isAnchorNodeChildOfElement(scope, anchorNodeInstance);
89
90
  if (isValidSelection) {
90
91
  const selection = window.getSelection();
91
92
  if (!selection?.rangeCount)
@@ -114,17 +115,20 @@ const TagifyInput = forwardRef((props, ref) => {
114
115
  }
115
116
  const { settings, DOM } = tagifyRef.current;
116
117
  const rangeInstance = _.get(tagifyRef.current, 'state.selection.range', null);
118
+ const anchorNodeInstance = _.get(tagifyRef.current, 'state.selection.anchorNode', null);
117
119
  const { empty } = settings.classNames;
118
- const isValidSelection = isAnchorNodeChildOfElement(DOM.scope);
120
+ const isValidAnchor = isAnchorNodeChildOfElement(DOM.scope, anchorNodeInstance);
119
121
  const selection = window.getSelection();
122
+ const isValidRange = selection?.rangeCount && rangeInstance;
123
+ const hasValidSelection = isValidRange && isValidAnchor;
120
124
  // In case not have the selection yet or lost the selection,
121
- if (!selection?.rangeCount || !isValidSelection || !rangeInstance) {
125
+ if (!hasValidSelection) {
122
126
  // need to restore the last range before inject a new tag if the last range exists
123
127
  if (lastRange.current) {
124
128
  selection?.removeAllRanges();
125
129
  selection?.addRange(lastRange.current);
126
130
  }
127
- else {
131
+ else if (!isValidRange) {
128
132
  // If the last range is lost, need to select the last text node of the input
129
133
  const { input: inputElement } = tagifyRef.current.DOM;
130
134
  if (inputElement) {
@@ -180,6 +180,7 @@ export declare const getAttributesString: (map: Map<string, string | boolean | n
180
180
  * is a child of a specific DOM element.
181
181
  *
182
182
  * @param {HTMLElement} element - The parent element to check against
183
+ * @param {HTMLElement} anchorNodeInstance - The anchor node of the Tagify instance
183
184
  * @returns {boolean} True if the anchor node is a child of the element, false otherwise
184
185
  */
185
- export declare const isAnchorNodeChildOfElement: (element: Node) => boolean;
186
+ export declare const isAnchorNodeChildOfElement: (element: Node, anchorNodeInstance: Node | null) => boolean;
@@ -628,9 +628,10 @@ export const getAttributesString = (map) => Array.from(map.entries())
628
628
  * is a child of a specific DOM element.
629
629
  *
630
630
  * @param {HTMLElement} element - The parent element to check against
631
+ * @param {HTMLElement} anchorNodeInstance - The anchor node of the Tagify instance
631
632
  * @returns {boolean} True if the anchor node is a child of the element, false otherwise
632
633
  */
633
- export const isAnchorNodeChildOfElement = (element) => {
634
+ export const isAnchorNodeChildOfElement = (element, anchorNodeInstance) => {
634
635
  // Get the current selection
635
636
  const selection = window.getSelection();
636
637
  // Check if there's an active selection
@@ -644,5 +645,5 @@ export const isAnchorNodeChildOfElement = (element) => {
644
645
  return false;
645
646
  }
646
647
  // Use Node.contains() to check if the element contains the anchor node
647
- return element.contains(anchorNode);
648
+ return element.contains(anchorNode) && element.contains(anchorNodeInstance);
648
649
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { TFeatureMenu } from '@antscorp/antsomi-ui/es/models/LeftMenu';
3
2
  export type TMenuItem = Omit<Partial<TFeatureMenu>, 'children' | keyof TRequireMenuItemKey> & {
4
3
  key: string;
@@ -3,4 +3,5 @@
3
3
  * Asynchronously loads the component for TemplateListing
4
4
  *
5
5
  */
6
+ /// <reference types="react" />
6
7
  export declare const TemplateListing: (props: import("./types").TemplateListingProps<{}>) => JSX.Element;
@@ -999,46 +999,6 @@ export const GlobalStyle = () => (_jsx(Global, { styles: css `
999
999
  }
1000
1000
  }
1001
1001
 
1002
- /* Switch */
1003
- .antsomi-switch {
1004
- border: 2px solid ${THEME.token?.colorPrimary} !important;
1005
-
1006
- &.antsomi-switch-checked {
1007
- > .antsomi-switch-handle {
1008
- &::before {
1009
- background-color: ${THEME.token?.bw0} !important;
1010
- }
1011
- }
1012
- }
1013
-
1014
- &.antsomi-switch-disabled[aria-checked='true'] {
1015
- background-color: ${THEME.token?.colorTextPlaceholder} !important;
1016
- border: 2px solid ${THEME.token?.colorTextPlaceholder} !important;
1017
-
1018
- > .antsomi-switch-handle {
1019
- &::before {
1020
- background-color: ${THEME.token?.bw0} !important;
1021
- }
1022
- }
1023
- }
1024
-
1025
- &.antsomi-switch-disabled[aria-checked='false'] {
1026
- background-color: ${THEME.token?.bw0} !important;
1027
- border: 2px solid ${THEME.token?.colorTextPlaceholder} !important;
1028
-
1029
- > .antsomi-switch-handle {
1030
- &::before {
1031
- background-color: ${THEME.token?.colorTextPlaceholder} !important;
1032
- }
1033
- }
1034
- }
1035
-
1036
- .antsomi-switch-inner {
1037
- padding-inline-start: 4px !important;
1038
- padding-inline-end: 18px !important;
1039
- }
1040
- }
1041
-
1042
1002
  /* Tabs */
1043
1003
  .antsomi-tabs {
1044
1004
  .antsomi-tabs-tab {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { AREA_LAYOUT_KEYS, BLOCK_KEYS } from '../constants';
3
2
  import { TAlign } from './variables';
4
3
  export type TImageStyles = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.927",
3
+ "version": "1.3.5-beta.929",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",
@@ -256,4 +256,3 @@
256
256
  "react-router-dom": ">= 5.1.0"
257
257
  }
258
258
  }
259
-