@hitachivantara/uikit-react-pentaho 6.0.13 → 6.0.15

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,154 +1,129 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
1
  import { useRef, useState } from "react";
3
- import { useControlled, useEnhancedEffect, HvTypography, createClasses, theme, isKey } from "@hitachivantara/uikit-react-core";
2
+ import { HvTypography, createClasses, isKey, theme, useControlled, useEnhancedEffect } from "@hitachivantara/uikit-react-core";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { Edit } from "@hitachivantara/uikit-react-icons";
5
- const { staticClasses, useClasses } = createClasses(
6
- "HvCanvasToolbarTabsEditor",
7
- {
8
- root: {
9
- position: "relative",
10
- display: "flex",
11
- width: "100%",
12
- overflow: "hidden",
13
- "&:has($label:hover:not($edit))": {
14
- color: theme.colors.textSubtle,
15
- "& $editIcon": { visibility: "visible" }
16
- }
17
- },
18
- edit: {
19
- color: theme.colors.textSubtle,
20
- borderColor: "currentColor",
21
- backgroundColor: theme.colors.bgContainer,
22
- cursor: "text"
23
- },
24
- label: {
25
- width: "100%",
26
- boxSizing: "border-box",
27
- border: "1px solid transparent",
28
- borderRadius: theme.radii.base,
29
- padding: theme.spacing(0, "sm", 0, "xs"),
30
- textAlign: "start",
31
- whiteSpace: "nowrap",
32
- overflow: "hidden",
33
- outline: "none",
34
- "&:not($edit)": {
35
- textOverflow: "ellipsis"
36
- },
37
- "&:hover:not($edit)": {
38
- color: theme.colors.textSubtle,
39
- borderColor: theme.colors.bgHover,
40
- backgroundColor: theme.colors.bgHover
41
- }
42
- },
43
- editIcon: {
44
- position: "absolute",
45
- right: theme.space.xxs,
46
- top: 4,
47
- width: 16,
48
- height: 16,
49
- visibility: "hidden",
50
- pointerEvents: "none"
51
- }
52
- }
53
- );
54
- const sanitize = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
55
- const ToolbarTabEditor = ({
56
- id,
57
- className,
58
- edit: editProp,
59
- value: valueProp,
60
- defaultValue: defaultValueProp = "",
61
- classes: classesProp,
62
- onInput: onInputProp,
63
- onClick: onClickProp,
64
- onBlur: onBlurProp,
65
- onKeyDown: onKeyDownProp,
66
- onChange: onChangeProp,
67
- onEditChange: onEditChangeProp,
68
- ...others
69
- }) => {
70
- const { cx, classes } = useClasses(classesProp);
71
- const contentEditableRef = useRef(null);
72
- const [value, setValue] = useControlled(
73
- valueProp ? sanitize(valueProp) : valueProp,
74
- defaultValueProp ? sanitize(defaultValueProp) : defaultValueProp
75
- );
76
- const [cachedValue, setCachedValue] = useState(value);
77
- const [isEditing, setIsEditing] = useControlled(editProp, false);
78
- const moveCursorToEnd = () => {
79
- if (!contentEditableRef.current) return;
80
- const element = contentEditableRef.current;
81
- const range = document.createRange();
82
- const selection = window.getSelection();
83
- range.selectNodeContents(element);
84
- range.collapse(false);
85
- selection?.removeAllRanges();
86
- selection?.addRange(range);
87
- element.scrollLeft = element.scrollWidth;
88
- };
89
- const scrollContentToStart = () => {
90
- if (!contentEditableRef.current) return;
91
- const element = contentEditableRef.current;
92
- element.scrollLeft = 0;
93
- };
94
- const changeEdit = (edit) => {
95
- setIsEditing(edit);
96
- onEditChangeProp?.(edit);
97
- };
98
- useEnhancedEffect(() => {
99
- if (isEditing) moveCursorToEnd();
100
- }, [isEditing, value]);
101
- const handleInput = (event) => {
102
- const newValue = sanitize(event.target.textContent) || "";
103
- setValue(newValue);
104
- onInputProp?.(event);
105
- onChangeProp?.(event, newValue);
106
- };
107
- const handleClick = (event) => {
108
- setCachedValue(value);
109
- changeEdit(true);
110
- onClickProp?.(event);
111
- };
112
- const handleBlur = (event) => {
113
- changeEdit(false);
114
- scrollContentToStart();
115
- const newValue = value.trim() || cachedValue;
116
- setValue(newValue);
117
- onBlurProp?.(event, newValue);
118
- };
119
- const handleKeyDown = (event) => {
120
- if (isKey(event, "Enter")) {
121
- handleBlur(event);
122
- } else if (isKey(event, "Esc")) {
123
- changeEdit(false);
124
- setValue(cachedValue);
125
- onChangeProp?.(event, cachedValue);
126
- }
127
- onKeyDownProp?.(event);
128
- };
129
- return /* @__PURE__ */ jsxs("div", { id, className: cx(classes.root, className), children: [
130
- /* @__PURE__ */ jsx(
131
- HvTypography,
132
- {
133
- ref: contentEditableRef,
134
- contentEditable: isEditing,
135
- className: cx(classes.label, { [classes.edit]: isEditing }),
136
- variant: "label",
137
- component: "span",
138
- onInput: handleInput,
139
- onClick: handleClick,
140
- onBlur: handleBlur,
141
- onKeyDown: handleKeyDown,
142
- dangerouslySetInnerHTML: {
143
- __html: value
144
- },
145
- ...others
146
- }
147
- ),
148
- /* @__PURE__ */ jsx(Edit, { className: classes.editIcon, iconSize: "XS" })
149
- ] });
150
- };
151
- export {
152
- ToolbarTabEditor,
153
- staticClasses as toolbarTabEditorClasses
5
+ //#region src/Canvas/ToolbarTabs/ToolbarTabEditor.tsx
6
+ var { staticClasses, useClasses } = createClasses("HvCanvasToolbarTabsEditor", {
7
+ root: {
8
+ position: "relative",
9
+ display: "flex",
10
+ width: "100%",
11
+ overflow: "hidden",
12
+ "&:has($label:hover:not($edit))": {
13
+ color: theme.colors.textSubtle,
14
+ "& $editIcon": { visibility: "visible" }
15
+ }
16
+ },
17
+ edit: {
18
+ color: theme.colors.textSubtle,
19
+ borderColor: "currentColor",
20
+ backgroundColor: theme.colors.bgContainer,
21
+ cursor: "text"
22
+ },
23
+ label: {
24
+ width: "100%",
25
+ boxSizing: "border-box",
26
+ border: "1px solid transparent",
27
+ borderRadius: theme.radii.base,
28
+ padding: theme.spacing(0, "sm", 0, "xs"),
29
+ textAlign: "start",
30
+ whiteSpace: "nowrap",
31
+ overflow: "hidden",
32
+ outline: "none",
33
+ "&:not($edit)": { textOverflow: "ellipsis" },
34
+ "&:hover:not($edit)": {
35
+ color: theme.colors.textSubtle,
36
+ borderColor: theme.colors.bgHover,
37
+ backgroundColor: theme.colors.bgHover
38
+ }
39
+ },
40
+ editIcon: {
41
+ position: "absolute",
42
+ right: theme.space.xxs,
43
+ top: 4,
44
+ width: 16,
45
+ height: 16,
46
+ visibility: "hidden",
47
+ pointerEvents: "none"
48
+ }
49
+ });
50
+ var sanitize = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
51
+ var ToolbarTabEditor = ({ id, className, edit: editProp, value: valueProp, defaultValue: defaultValueProp = "", classes: classesProp, onInput: onInputProp, onClick: onClickProp, onBlur: onBlurProp, onKeyDown: onKeyDownProp, onChange: onChangeProp, onEditChange: onEditChangeProp, ...others }) => {
52
+ const { cx, classes } = useClasses(classesProp);
53
+ const contentEditableRef = useRef(null);
54
+ const [value, setValue] = useControlled(valueProp ? sanitize(valueProp) : valueProp, defaultValueProp ? sanitize(defaultValueProp) : defaultValueProp);
55
+ const [cachedValue, setCachedValue] = useState(value);
56
+ const [isEditing, setIsEditing] = useControlled(editProp, false);
57
+ const moveCursorToEnd = () => {
58
+ if (!contentEditableRef.current) return;
59
+ const element = contentEditableRef.current;
60
+ const range = document.createRange();
61
+ const selection = window.getSelection();
62
+ range.selectNodeContents(element);
63
+ range.collapse(false);
64
+ selection?.removeAllRanges();
65
+ selection?.addRange(range);
66
+ element.scrollLeft = element.scrollWidth;
67
+ };
68
+ const scrollContentToStart = () => {
69
+ if (!contentEditableRef.current) return;
70
+ const element = contentEditableRef.current;
71
+ element.scrollLeft = 0;
72
+ };
73
+ const changeEdit = (edit) => {
74
+ setIsEditing(edit);
75
+ onEditChangeProp?.(edit);
76
+ };
77
+ useEnhancedEffect(() => {
78
+ if (isEditing) moveCursorToEnd();
79
+ }, [isEditing, value]);
80
+ const handleInput = (event) => {
81
+ const newValue = sanitize(event.target.textContent) || "";
82
+ setValue(newValue);
83
+ onInputProp?.(event);
84
+ onChangeProp?.(event, newValue);
85
+ };
86
+ const handleClick = (event) => {
87
+ setCachedValue(value);
88
+ changeEdit(true);
89
+ onClickProp?.(event);
90
+ };
91
+ const handleBlur = (event) => {
92
+ changeEdit(false);
93
+ scrollContentToStart();
94
+ const newValue = value.trim() || cachedValue;
95
+ setValue(newValue);
96
+ onBlurProp?.(event, newValue);
97
+ };
98
+ const handleKeyDown = (event) => {
99
+ if (isKey(event, "Enter")) handleBlur(event);
100
+ else if (isKey(event, "Esc")) {
101
+ changeEdit(false);
102
+ setValue(cachedValue);
103
+ onChangeProp?.(event, cachedValue);
104
+ }
105
+ onKeyDownProp?.(event);
106
+ };
107
+ return /* @__PURE__ */ jsxs("div", {
108
+ id,
109
+ className: cx(classes.root, className),
110
+ children: [/* @__PURE__ */ jsx(HvTypography, {
111
+ ref: contentEditableRef,
112
+ contentEditable: isEditing,
113
+ className: cx(classes.label, { [classes.edit]: isEditing }),
114
+ variant: "label",
115
+ component: "span",
116
+ onInput: handleInput,
117
+ onClick: handleClick,
118
+ onBlur: handleBlur,
119
+ onKeyDown: handleKeyDown,
120
+ dangerouslySetInnerHTML: { __html: value },
121
+ ...others
122
+ }), /* @__PURE__ */ jsx(Edit, {
123
+ className: classes.editIcon,
124
+ iconSize: "XS"
125
+ })]
126
+ });
154
127
  };
128
+ //#endregion
129
+ export { ToolbarTabEditor, staticClasses };