@instructure/ui-editable 11.7.3-snapshot-7 → 11.7.3-snapshot-26
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.
- package/CHANGELOG.md +5 -2
- package/es/Editable/v1/index.js +129 -124
- package/es/InPlaceEdit/v1/index.js +77 -74
- package/es/InPlaceEdit/v2/index.js +77 -74
- package/lib/Editable/v1/index.js +130 -125
- package/lib/InPlaceEdit/v1/index.js +76 -73
- package/lib/InPlaceEdit/v2/index.js +76 -73
- package/package.json +15 -15
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [11.7.3-snapshot-
|
|
6
|
+
## [11.7.3-snapshot-26](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-26) (2026-05-05)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **many:** update dependencies, remove lots of Babel plugins, remove Webpack 4 support ([f916fca](https://github.com/instructure/instructure-ui/commit/f916fcafdddcb2d7de401f93e8ff92cfdfa47bba))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
package/es/Editable/v1/index.js
CHANGED
|
@@ -32,115 +32,21 @@ category: components
|
|
|
32
32
|
---
|
|
33
33
|
**/
|
|
34
34
|
class Editable extends Component {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (this.props.mode === 'view') {
|
|
51
|
-
// because the mouse event handlers are on the container, not the view
|
|
52
|
-
event.stopPropagation();
|
|
53
|
-
this.setState({
|
|
54
|
-
showModeToggle: true
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
this.handleViewMouseOut = event => {
|
|
59
|
-
if (this.props.mode === 'view') {
|
|
60
|
-
event.stopPropagation();
|
|
61
|
-
this.setState({
|
|
62
|
-
showModeToggle: document.activeElement === this._editButtonRef
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
this.handleViewClick = event => {
|
|
67
|
-
if (event.buttons === 1) {
|
|
68
|
-
requestAnimationFrame(() => {
|
|
69
|
-
this.enterEdit();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
this.handleEditBlur = () => {
|
|
74
|
-
this.enterView();
|
|
75
|
-
};
|
|
76
|
-
this.handleEditButtonFocus = () => {
|
|
77
|
-
this.setState({
|
|
78
|
-
showModeToggle: true
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
this.handleEditButtonBlur = () => {
|
|
82
|
-
this.setState({
|
|
83
|
-
showModeToggle: false
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
this.handleEditButtonClick = () => {
|
|
87
|
-
this.enterEdit();
|
|
88
|
-
};
|
|
89
|
-
this.ref = null;
|
|
90
|
-
this.handleContainerRef = el => {
|
|
91
|
-
const elementRef = this.props.elementRef;
|
|
92
|
-
this.ref = el;
|
|
93
|
-
if (typeof elementRef === 'function') {
|
|
94
|
-
elementRef(el);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
// ------- prop getters ------
|
|
98
|
-
this.getContainerProps = (props = {}) => {
|
|
99
|
-
const _this$props = this.props,
|
|
100
|
-
mode = _this$props.mode,
|
|
101
|
-
readOnly = _this$props.readOnly;
|
|
102
|
-
return {
|
|
103
|
-
onMouseOver: this.handleViewMouseOver,
|
|
104
|
-
onMouseOut: this.handleViewMouseOut,
|
|
105
|
-
onMouseDown: mode !== 'edit' ? this.handleViewClick : void 0,
|
|
106
|
-
onKeyUp: mode === 'edit' ? this.handleEditESC : void 0,
|
|
107
|
-
readOnly,
|
|
108
|
-
...props,
|
|
109
|
-
ref: this.handleContainerRef
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
this.getViewerProps = (props = {}) => {
|
|
113
|
-
return {
|
|
114
|
-
mode: this.props.mode,
|
|
115
|
-
readOnly: this.props.readOnly,
|
|
116
|
-
...props
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
this.getEditorProps = (props = {}) => {
|
|
120
|
-
return {
|
|
121
|
-
mode: this.props.mode,
|
|
122
|
-
onBlur: this.handleEditBlur,
|
|
123
|
-
editorRef: el => {
|
|
124
|
-
this._editorRef = el;
|
|
125
|
-
},
|
|
126
|
-
readOnly: this.props.readOnly,
|
|
127
|
-
...props
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
this.getEditButtonProps = (props = {}) => {
|
|
131
|
-
return {
|
|
132
|
-
onClick: this.handleEditButtonClick,
|
|
133
|
-
onFocus: this.handleEditButtonFocus,
|
|
134
|
-
onBlur: this.handleEditButtonBlur,
|
|
135
|
-
isVisible: this.state.showModeToggle,
|
|
136
|
-
buttonRef: el => {
|
|
137
|
-
this._editButtonRef = el;
|
|
138
|
-
},
|
|
139
|
-
readOnly: this.props.readOnly,
|
|
140
|
-
...props
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
warn(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
35
|
+
static displayName = "Editable";
|
|
36
|
+
static allowedProps = allowedProps;
|
|
37
|
+
static defaultProps = {
|
|
38
|
+
readOnly: false,
|
|
39
|
+
children: null
|
|
40
|
+
};
|
|
41
|
+
state = {
|
|
42
|
+
showModeToggle: false,
|
|
43
|
+
valueOnEdit: null // the value when mode flips from view -> edit
|
|
44
|
+
};
|
|
45
|
+
_editorRef = null;
|
|
46
|
+
_editButtonRef = null;
|
|
47
|
+
constructor(props) {
|
|
48
|
+
super(props);
|
|
49
|
+
warn(props.readOnly ? props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
144
50
|
}
|
|
145
51
|
componentDidMount() {
|
|
146
52
|
if (this.props.mode === 'edit') {
|
|
@@ -148,10 +54,11 @@ class Editable extends Component {
|
|
|
148
54
|
}
|
|
149
55
|
}
|
|
150
56
|
componentDidUpdate(prevProps) {
|
|
151
|
-
const
|
|
152
|
-
mode
|
|
153
|
-
value
|
|
154
|
-
onChange
|
|
57
|
+
const {
|
|
58
|
+
mode,
|
|
59
|
+
value,
|
|
60
|
+
onChange
|
|
61
|
+
} = this.props;
|
|
155
62
|
|
|
156
63
|
// on the switch from view -> edit
|
|
157
64
|
if (prevProps.mode !== 'edit' && mode === 'edit') {
|
|
@@ -193,12 +100,116 @@ class Editable extends Component {
|
|
|
193
100
|
}
|
|
194
101
|
}
|
|
195
102
|
}
|
|
103
|
+
handleEditESC = event => {
|
|
104
|
+
if (event.key === 'Escape') {
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
this.enterView();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
handleViewMouseOver = event => {
|
|
110
|
+
if (this.props.mode === 'view') {
|
|
111
|
+
// because the mouse event handlers are on the container, not the view
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
this.setState({
|
|
114
|
+
showModeToggle: true
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
handleViewMouseOut = event => {
|
|
119
|
+
if (this.props.mode === 'view') {
|
|
120
|
+
event.stopPropagation();
|
|
121
|
+
this.setState({
|
|
122
|
+
showModeToggle: document.activeElement === this._editButtonRef
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
handleViewClick = event => {
|
|
127
|
+
if (event.buttons === 1) {
|
|
128
|
+
requestAnimationFrame(() => {
|
|
129
|
+
this.enterEdit();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
handleEditBlur = () => {
|
|
134
|
+
this.enterView();
|
|
135
|
+
};
|
|
136
|
+
handleEditButtonFocus = () => {
|
|
137
|
+
this.setState({
|
|
138
|
+
showModeToggle: true
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
handleEditButtonBlur = () => {
|
|
142
|
+
this.setState({
|
|
143
|
+
showModeToggle: false
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
handleEditButtonClick = () => {
|
|
147
|
+
this.enterEdit();
|
|
148
|
+
};
|
|
149
|
+
ref = null;
|
|
150
|
+
handleContainerRef = el => {
|
|
151
|
+
const {
|
|
152
|
+
elementRef
|
|
153
|
+
} = this.props;
|
|
154
|
+
this.ref = el;
|
|
155
|
+
if (typeof elementRef === 'function') {
|
|
156
|
+
elementRef(el);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// ------- prop getters ------
|
|
161
|
+
getContainerProps = (props = {}) => {
|
|
162
|
+
const {
|
|
163
|
+
mode,
|
|
164
|
+
readOnly
|
|
165
|
+
} = this.props;
|
|
166
|
+
return {
|
|
167
|
+
onMouseOver: this.handleViewMouseOver,
|
|
168
|
+
onMouseOut: this.handleViewMouseOut,
|
|
169
|
+
onMouseDown: mode !== 'edit' ? this.handleViewClick : undefined,
|
|
170
|
+
onKeyUp: mode === 'edit' ? this.handleEditESC : undefined,
|
|
171
|
+
readOnly,
|
|
172
|
+
...props,
|
|
173
|
+
ref: this.handleContainerRef
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
getViewerProps = (props = {}) => {
|
|
177
|
+
return {
|
|
178
|
+
mode: this.props.mode,
|
|
179
|
+
readOnly: this.props.readOnly,
|
|
180
|
+
...props
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
getEditorProps = (props = {}) => {
|
|
184
|
+
return {
|
|
185
|
+
mode: this.props.mode,
|
|
186
|
+
onBlur: this.handleEditBlur,
|
|
187
|
+
editorRef: el => {
|
|
188
|
+
this._editorRef = el;
|
|
189
|
+
},
|
|
190
|
+
readOnly: this.props.readOnly,
|
|
191
|
+
...props
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
getEditButtonProps = (props = {}) => {
|
|
195
|
+
return {
|
|
196
|
+
onClick: this.handleEditButtonClick,
|
|
197
|
+
onFocus: this.handleEditButtonFocus,
|
|
198
|
+
onBlur: this.handleEditButtonBlur,
|
|
199
|
+
isVisible: this.state.showModeToggle,
|
|
200
|
+
buttonRef: el => {
|
|
201
|
+
this._editButtonRef = el;
|
|
202
|
+
},
|
|
203
|
+
readOnly: this.props.readOnly,
|
|
204
|
+
...props
|
|
205
|
+
};
|
|
206
|
+
};
|
|
196
207
|
render() {
|
|
197
|
-
const
|
|
198
|
-
children
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
const {
|
|
209
|
+
children,
|
|
210
|
+
render = children,
|
|
211
|
+
mode
|
|
212
|
+
} = this.props;
|
|
202
213
|
if (typeof render === 'function') {
|
|
203
214
|
return render({
|
|
204
215
|
mode,
|
|
@@ -212,11 +223,5 @@ class Editable extends Component {
|
|
|
212
223
|
}
|
|
213
224
|
}
|
|
214
225
|
}
|
|
215
|
-
Editable.displayName = "Editable";
|
|
216
|
-
Editable.allowedProps = allowedProps;
|
|
217
|
-
Editable.defaultProps = {
|
|
218
|
-
readOnly: false,
|
|
219
|
-
children: null
|
|
220
|
-
};
|
|
221
226
|
export default Editable;
|
|
222
227
|
export { Editable };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _dec, _class
|
|
1
|
+
var _dec, _class;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -34,74 +34,57 @@ import { View } from '@instructure/ui-view/v11_6';
|
|
|
34
34
|
import { Editable } from "../../Editable/v1/index.js";
|
|
35
35
|
import generateStyle from "./styles.js";
|
|
36
36
|
import { allowedProps } from "./props.js";
|
|
37
|
-
import {
|
|
37
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
38
38
|
/**
|
|
39
39
|
---
|
|
40
40
|
category: components
|
|
41
41
|
---
|
|
42
42
|
**/
|
|
43
|
-
let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class =
|
|
43
|
+
let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class InPlaceEdit extends Component {
|
|
44
|
+
static displayName = "InPlaceEdit";
|
|
45
|
+
static componentId = 'InPlaceEdit';
|
|
46
|
+
static allowedProps = allowedProps;
|
|
47
|
+
static defaultProps = {
|
|
48
|
+
readOnly: false,
|
|
49
|
+
showFocusRing: true,
|
|
50
|
+
inline: true,
|
|
51
|
+
editButtonPlacement: 'end'
|
|
52
|
+
};
|
|
53
|
+
ref = null;
|
|
54
|
+
_editButtonRef = null;
|
|
55
|
+
handleRef = el => {
|
|
56
|
+
this.ref = el;
|
|
57
|
+
};
|
|
44
58
|
constructor(props) {
|
|
45
59
|
super(props);
|
|
46
|
-
this.ref = null;
|
|
47
|
-
this._editButtonRef = null;
|
|
48
|
-
this.handleRef = el => {
|
|
49
|
-
this.ref = el;
|
|
50
|
-
};
|
|
51
|
-
this.handleEditButtonRef = el => {
|
|
52
|
-
this._editButtonRef = el;
|
|
53
|
-
};
|
|
54
|
-
this.renderAll = ({
|
|
55
|
-
getContainerProps,
|
|
56
|
-
getViewerProps,
|
|
57
|
-
getEditorProps,
|
|
58
|
-
getEditButtonProps
|
|
59
|
-
}) => {
|
|
60
|
-
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
61
|
-
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
62
|
-
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
63
|
-
return _jsxs(Flex, {
|
|
64
|
-
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
65
|
-
direction: flexDir,
|
|
66
|
-
justifyItems: justifyItems,
|
|
67
|
-
...getContainerProps(),
|
|
68
|
-
children: [_jsxs(Flex.Item, {
|
|
69
|
-
shouldGrow: true,
|
|
70
|
-
shouldShrink: true,
|
|
71
|
-
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
72
|
-
}), _jsx(Flex.Item, {
|
|
73
|
-
margin: buttonMargin,
|
|
74
|
-
children: this.renderEditButton(getEditButtonProps())
|
|
75
|
-
})]
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
60
|
warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
79
61
|
}
|
|
80
62
|
componentDidMount() {
|
|
81
|
-
|
|
82
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
63
|
+
this.props.makeStyles?.();
|
|
83
64
|
}
|
|
84
65
|
componentDidUpdate() {
|
|
85
|
-
|
|
86
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
66
|
+
this.props.makeStyles?.();
|
|
87
67
|
}
|
|
68
|
+
handleEditButtonRef = el => {
|
|
69
|
+
this._editButtonRef = el;
|
|
70
|
+
};
|
|
88
71
|
renderEditor({
|
|
89
72
|
mode,
|
|
90
73
|
onBlur,
|
|
91
74
|
editorRef,
|
|
92
75
|
readOnly
|
|
93
76
|
}) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
const {
|
|
78
|
+
showFocusRing,
|
|
79
|
+
renderEditor
|
|
80
|
+
} = this.props;
|
|
98
81
|
const isEditMode = !readOnly && mode === 'edit';
|
|
99
82
|
return isEditMode ? _jsx(View, {
|
|
100
83
|
as: "span",
|
|
101
84
|
display: "block",
|
|
102
85
|
withFocusOutline: showFocusRing,
|
|
103
86
|
position: "relative",
|
|
104
|
-
css:
|
|
87
|
+
css: this.props.styles?.inPlaceEdit,
|
|
105
88
|
borderRadius: "medium",
|
|
106
89
|
margin: "auto",
|
|
107
90
|
children: renderEditor({
|
|
@@ -128,14 +111,56 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_InPlac
|
|
|
128
111
|
|
|
129
112
|
// Render a default edit button, an icon button with the edit icon
|
|
130
113
|
// the margin makes room for the focus ring
|
|
131
|
-
|
|
114
|
+
static renderDefaultEditButton = ({
|
|
115
|
+
isVisible,
|
|
116
|
+
readOnly,
|
|
117
|
+
label,
|
|
118
|
+
...buttonProps
|
|
119
|
+
}) => {
|
|
120
|
+
if (readOnly) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return _jsx(IconButton, {
|
|
124
|
+
size: "small",
|
|
125
|
+
screenReaderLabel: label,
|
|
126
|
+
withBackground: false,
|
|
127
|
+
withBorder: false,
|
|
128
|
+
...buttonProps,
|
|
129
|
+
children: isVisible ? IconEditLine : null
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
renderAll = ({
|
|
133
|
+
getContainerProps,
|
|
134
|
+
getViewerProps,
|
|
135
|
+
getEditorProps,
|
|
136
|
+
getEditButtonProps
|
|
137
|
+
}) => {
|
|
138
|
+
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
139
|
+
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
140
|
+
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
141
|
+
return _jsxs(Flex, {
|
|
142
|
+
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
143
|
+
direction: flexDir,
|
|
144
|
+
justifyItems: justifyItems,
|
|
145
|
+
...getContainerProps(),
|
|
146
|
+
children: [_jsxs(Flex.Item, {
|
|
147
|
+
shouldGrow: true,
|
|
148
|
+
shouldShrink: true,
|
|
149
|
+
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
150
|
+
}), _jsx(Flex.Item, {
|
|
151
|
+
margin: buttonMargin,
|
|
152
|
+
children: this.renderEditButton(getEditButtonProps())
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
};
|
|
132
156
|
render() {
|
|
133
|
-
const
|
|
134
|
-
mode
|
|
135
|
-
value
|
|
136
|
-
onChange
|
|
137
|
-
onChangeMode
|
|
138
|
-
readOnly
|
|
157
|
+
const {
|
|
158
|
+
mode,
|
|
159
|
+
value,
|
|
160
|
+
onChange,
|
|
161
|
+
onChangeMode,
|
|
162
|
+
readOnly
|
|
163
|
+
} = this.props;
|
|
139
164
|
return _jsx(Editable, {
|
|
140
165
|
mode: mode,
|
|
141
166
|
onChangeMode: onChangeMode,
|
|
@@ -146,28 +171,6 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_InPlac
|
|
|
146
171
|
elementRef: this.handleRef
|
|
147
172
|
});
|
|
148
173
|
}
|
|
149
|
-
}
|
|
150
|
-
readOnly: false,
|
|
151
|
-
showFocusRing: true,
|
|
152
|
-
inline: true,
|
|
153
|
-
editButtonPlacement: 'end'
|
|
154
|
-
}, _InPlaceEdit.renderDefaultEditButton = ({
|
|
155
|
-
isVisible,
|
|
156
|
-
readOnly,
|
|
157
|
-
label,
|
|
158
|
-
...buttonProps
|
|
159
|
-
}) => {
|
|
160
|
-
if (readOnly) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
return _jsx(IconButton, {
|
|
164
|
-
size: "small",
|
|
165
|
-
screenReaderLabel: label,
|
|
166
|
-
withBackground: false,
|
|
167
|
-
withBorder: false,
|
|
168
|
-
...buttonProps,
|
|
169
|
-
children: isVisible ? IconEditLine : null
|
|
170
|
-
});
|
|
171
|
-
}, _InPlaceEdit)) || _class);
|
|
174
|
+
}) || _class);
|
|
172
175
|
export default InPlaceEdit;
|
|
173
176
|
export { InPlaceEdit };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _dec, _class
|
|
1
|
+
var _dec, _class;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -34,74 +34,57 @@ import { View } from '@instructure/ui-view/latest';
|
|
|
34
34
|
import { Editable } from "../../Editable/v1/index.js";
|
|
35
35
|
import generateStyle from "./styles.js";
|
|
36
36
|
import { allowedProps } from "./props.js";
|
|
37
|
-
import {
|
|
37
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
38
38
|
/**
|
|
39
39
|
---
|
|
40
40
|
category: components
|
|
41
41
|
---
|
|
42
42
|
**/
|
|
43
|
-
let InPlaceEdit = (_dec = withStyle(generateStyle), _dec(_class =
|
|
43
|
+
let InPlaceEdit = (_dec = withStyle(generateStyle), _dec(_class = class InPlaceEdit extends Component {
|
|
44
|
+
static displayName = "InPlaceEdit";
|
|
45
|
+
static componentId = 'InPlaceEdit';
|
|
46
|
+
static allowedProps = allowedProps;
|
|
47
|
+
static defaultProps = {
|
|
48
|
+
readOnly: false,
|
|
49
|
+
showFocusRing: true,
|
|
50
|
+
inline: true,
|
|
51
|
+
editButtonPlacement: 'end'
|
|
52
|
+
};
|
|
53
|
+
ref = null;
|
|
54
|
+
_editButtonRef = null;
|
|
55
|
+
handleRef = el => {
|
|
56
|
+
this.ref = el;
|
|
57
|
+
};
|
|
44
58
|
constructor(props) {
|
|
45
59
|
super(props);
|
|
46
|
-
this.ref = null;
|
|
47
|
-
this._editButtonRef = null;
|
|
48
|
-
this.handleRef = el => {
|
|
49
|
-
this.ref = el;
|
|
50
|
-
};
|
|
51
|
-
this.handleEditButtonRef = el => {
|
|
52
|
-
this._editButtonRef = el;
|
|
53
|
-
};
|
|
54
|
-
this.renderAll = ({
|
|
55
|
-
getContainerProps,
|
|
56
|
-
getViewerProps,
|
|
57
|
-
getEditorProps,
|
|
58
|
-
getEditButtonProps
|
|
59
|
-
}) => {
|
|
60
|
-
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
61
|
-
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
62
|
-
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
63
|
-
return _jsxs(Flex, {
|
|
64
|
-
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
65
|
-
direction: flexDir,
|
|
66
|
-
justifyItems: justifyItems,
|
|
67
|
-
...getContainerProps(),
|
|
68
|
-
children: [_jsxs(Flex.Item, {
|
|
69
|
-
shouldGrow: true,
|
|
70
|
-
shouldShrink: true,
|
|
71
|
-
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
72
|
-
}), _jsx(Flex.Item, {
|
|
73
|
-
margin: buttonMargin,
|
|
74
|
-
children: this.renderEditButton(getEditButtonProps())
|
|
75
|
-
})]
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
60
|
warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
79
61
|
}
|
|
80
62
|
componentDidMount() {
|
|
81
|
-
|
|
82
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
63
|
+
this.props.makeStyles?.();
|
|
83
64
|
}
|
|
84
65
|
componentDidUpdate() {
|
|
85
|
-
|
|
86
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
66
|
+
this.props.makeStyles?.();
|
|
87
67
|
}
|
|
68
|
+
handleEditButtonRef = el => {
|
|
69
|
+
this._editButtonRef = el;
|
|
70
|
+
};
|
|
88
71
|
renderEditor({
|
|
89
72
|
mode,
|
|
90
73
|
onBlur,
|
|
91
74
|
editorRef,
|
|
92
75
|
readOnly
|
|
93
76
|
}) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
const {
|
|
78
|
+
showFocusRing,
|
|
79
|
+
renderEditor
|
|
80
|
+
} = this.props;
|
|
98
81
|
const isEditMode = !readOnly && mode === 'edit';
|
|
99
82
|
return isEditMode ? _jsx(View, {
|
|
100
83
|
as: "span",
|
|
101
84
|
display: "block",
|
|
102
85
|
withFocusOutline: showFocusRing,
|
|
103
86
|
position: "relative",
|
|
104
|
-
css:
|
|
87
|
+
css: this.props.styles?.inPlaceEdit,
|
|
105
88
|
borderRadius: "medium",
|
|
106
89
|
margin: "auto",
|
|
107
90
|
children: renderEditor({
|
|
@@ -128,14 +111,56 @@ let InPlaceEdit = (_dec = withStyle(generateStyle), _dec(_class = (_InPlaceEdit
|
|
|
128
111
|
|
|
129
112
|
// Render a default edit button, an icon button with the edit icon
|
|
130
113
|
// the margin makes room for the focus ring
|
|
131
|
-
|
|
114
|
+
static renderDefaultEditButton = ({
|
|
115
|
+
isVisible,
|
|
116
|
+
readOnly,
|
|
117
|
+
label,
|
|
118
|
+
...buttonProps
|
|
119
|
+
}) => {
|
|
120
|
+
if (readOnly) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return _jsx(IconButton, {
|
|
124
|
+
size: "small",
|
|
125
|
+
screenReaderLabel: label,
|
|
126
|
+
withBackground: false,
|
|
127
|
+
withBorder: false,
|
|
128
|
+
...buttonProps,
|
|
129
|
+
children: isVisible ? PencilInstUIIcon : null
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
renderAll = ({
|
|
133
|
+
getContainerProps,
|
|
134
|
+
getViewerProps,
|
|
135
|
+
getEditorProps,
|
|
136
|
+
getEditButtonProps
|
|
137
|
+
}) => {
|
|
138
|
+
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
139
|
+
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
140
|
+
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
141
|
+
return _jsxs(Flex, {
|
|
142
|
+
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
143
|
+
direction: flexDir,
|
|
144
|
+
justifyItems: justifyItems,
|
|
145
|
+
...getContainerProps(),
|
|
146
|
+
children: [_jsxs(Flex.Item, {
|
|
147
|
+
shouldGrow: true,
|
|
148
|
+
shouldShrink: true,
|
|
149
|
+
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
150
|
+
}), _jsx(Flex.Item, {
|
|
151
|
+
margin: buttonMargin,
|
|
152
|
+
children: this.renderEditButton(getEditButtonProps())
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
};
|
|
132
156
|
render() {
|
|
133
|
-
const
|
|
134
|
-
mode
|
|
135
|
-
value
|
|
136
|
-
onChange
|
|
137
|
-
onChangeMode
|
|
138
|
-
readOnly
|
|
157
|
+
const {
|
|
158
|
+
mode,
|
|
159
|
+
value,
|
|
160
|
+
onChange,
|
|
161
|
+
onChangeMode,
|
|
162
|
+
readOnly
|
|
163
|
+
} = this.props;
|
|
139
164
|
return _jsx(Editable, {
|
|
140
165
|
mode: mode,
|
|
141
166
|
onChangeMode: onChangeMode,
|
|
@@ -146,28 +171,6 @@ let InPlaceEdit = (_dec = withStyle(generateStyle), _dec(_class = (_InPlaceEdit
|
|
|
146
171
|
elementRef: this.handleRef
|
|
147
172
|
});
|
|
148
173
|
}
|
|
149
|
-
}
|
|
150
|
-
readOnly: false,
|
|
151
|
-
showFocusRing: true,
|
|
152
|
-
inline: true,
|
|
153
|
-
editButtonPlacement: 'end'
|
|
154
|
-
}, _InPlaceEdit.renderDefaultEditButton = ({
|
|
155
|
-
isVisible,
|
|
156
|
-
readOnly,
|
|
157
|
-
label,
|
|
158
|
-
...buttonProps
|
|
159
|
-
}) => {
|
|
160
|
-
if (readOnly) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
return _jsx(IconButton, {
|
|
164
|
-
size: "small",
|
|
165
|
-
screenReaderLabel: label,
|
|
166
|
-
withBackground: false,
|
|
167
|
-
withBorder: false,
|
|
168
|
-
...buttonProps,
|
|
169
|
-
children: isVisible ? PencilInstUIIcon : null
|
|
170
|
-
});
|
|
171
|
-
}, _InPlaceEdit)) || _class);
|
|
174
|
+
}) || _class);
|
|
172
175
|
export default InPlaceEdit;
|
|
173
176
|
export { InPlaceEdit };
|