@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/lib/Editable/v1/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var _react = require("react");
|
|
|
8
8
|
var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
|
|
9
9
|
var _console = require("@instructure/console");
|
|
10
10
|
var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
|
|
11
|
-
var
|
|
11
|
+
var _props = require("./props");
|
|
12
12
|
/*
|
|
13
13
|
* The MIT License (MIT)
|
|
14
14
|
*
|
|
@@ -39,115 +39,21 @@ category: components
|
|
|
39
39
|
---
|
|
40
40
|
**/
|
|
41
41
|
class Editable extends _react.Component {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (this.props.mode === 'view') {
|
|
58
|
-
// because the mouse event handlers are on the container, not the view
|
|
59
|
-
event.stopPropagation();
|
|
60
|
-
this.setState({
|
|
61
|
-
showModeToggle: true
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
this.handleViewMouseOut = event => {
|
|
66
|
-
if (this.props.mode === 'view') {
|
|
67
|
-
event.stopPropagation();
|
|
68
|
-
this.setState({
|
|
69
|
-
showModeToggle: document.activeElement === this._editButtonRef
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
this.handleViewClick = event => {
|
|
74
|
-
if (event.buttons === 1) {
|
|
75
|
-
(0, _requestAnimationFrame.requestAnimationFrame)(() => {
|
|
76
|
-
this.enterEdit();
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
this.handleEditBlur = () => {
|
|
81
|
-
this.enterView();
|
|
82
|
-
};
|
|
83
|
-
this.handleEditButtonFocus = () => {
|
|
84
|
-
this.setState({
|
|
85
|
-
showModeToggle: true
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
this.handleEditButtonBlur = () => {
|
|
89
|
-
this.setState({
|
|
90
|
-
showModeToggle: false
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
this.handleEditButtonClick = () => {
|
|
94
|
-
this.enterEdit();
|
|
95
|
-
};
|
|
96
|
-
this.ref = null;
|
|
97
|
-
this.handleContainerRef = el => {
|
|
98
|
-
const elementRef = this.props.elementRef;
|
|
99
|
-
this.ref = el;
|
|
100
|
-
if (typeof elementRef === 'function') {
|
|
101
|
-
elementRef(el);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
// ------- prop getters ------
|
|
105
|
-
this.getContainerProps = (props = {}) => {
|
|
106
|
-
const _this$props = this.props,
|
|
107
|
-
mode = _this$props.mode,
|
|
108
|
-
readOnly = _this$props.readOnly;
|
|
109
|
-
return {
|
|
110
|
-
onMouseOver: this.handleViewMouseOver,
|
|
111
|
-
onMouseOut: this.handleViewMouseOut,
|
|
112
|
-
onMouseDown: mode !== 'edit' ? this.handleViewClick : void 0,
|
|
113
|
-
onKeyUp: mode === 'edit' ? this.handleEditESC : void 0,
|
|
114
|
-
readOnly,
|
|
115
|
-
...props,
|
|
116
|
-
ref: this.handleContainerRef
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
this.getViewerProps = (props = {}) => {
|
|
120
|
-
return {
|
|
121
|
-
mode: this.props.mode,
|
|
122
|
-
readOnly: this.props.readOnly,
|
|
123
|
-
...props
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
this.getEditorProps = (props = {}) => {
|
|
127
|
-
return {
|
|
128
|
-
mode: this.props.mode,
|
|
129
|
-
onBlur: this.handleEditBlur,
|
|
130
|
-
editorRef: el => {
|
|
131
|
-
this._editorRef = el;
|
|
132
|
-
},
|
|
133
|
-
readOnly: this.props.readOnly,
|
|
134
|
-
...props
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
this.getEditButtonProps = (props = {}) => {
|
|
138
|
-
return {
|
|
139
|
-
onClick: this.handleEditButtonClick,
|
|
140
|
-
onFocus: this.handleEditButtonFocus,
|
|
141
|
-
onBlur: this.handleEditButtonBlur,
|
|
142
|
-
isVisible: this.state.showModeToggle,
|
|
143
|
-
buttonRef: el => {
|
|
144
|
-
this._editButtonRef = el;
|
|
145
|
-
},
|
|
146
|
-
readOnly: this.props.readOnly,
|
|
147
|
-
...props
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
(0, _console.logWarn)(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
42
|
+
static displayName = "Editable";
|
|
43
|
+
static allowedProps = _props.allowedProps;
|
|
44
|
+
static defaultProps = {
|
|
45
|
+
readOnly: false,
|
|
46
|
+
children: null
|
|
47
|
+
};
|
|
48
|
+
state = {
|
|
49
|
+
showModeToggle: false,
|
|
50
|
+
valueOnEdit: null // the value when mode flips from view -> edit
|
|
51
|
+
};
|
|
52
|
+
_editorRef = null;
|
|
53
|
+
_editButtonRef = null;
|
|
54
|
+
constructor(props) {
|
|
55
|
+
super(props);
|
|
56
|
+
(0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
151
57
|
}
|
|
152
58
|
componentDidMount() {
|
|
153
59
|
if (this.props.mode === 'edit') {
|
|
@@ -155,10 +61,11 @@ class Editable extends _react.Component {
|
|
|
155
61
|
}
|
|
156
62
|
}
|
|
157
63
|
componentDidUpdate(prevProps) {
|
|
158
|
-
const
|
|
159
|
-
mode
|
|
160
|
-
value
|
|
161
|
-
onChange
|
|
64
|
+
const {
|
|
65
|
+
mode,
|
|
66
|
+
value,
|
|
67
|
+
onChange
|
|
68
|
+
} = this.props;
|
|
162
69
|
|
|
163
70
|
// on the switch from view -> edit
|
|
164
71
|
if (prevProps.mode !== 'edit' && mode === 'edit') {
|
|
@@ -200,12 +107,116 @@ class Editable extends _react.Component {
|
|
|
200
107
|
}
|
|
201
108
|
}
|
|
202
109
|
}
|
|
110
|
+
handleEditESC = event => {
|
|
111
|
+
if (event.key === 'Escape') {
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
this.enterView();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
handleViewMouseOver = event => {
|
|
117
|
+
if (this.props.mode === 'view') {
|
|
118
|
+
// because the mouse event handlers are on the container, not the view
|
|
119
|
+
event.stopPropagation();
|
|
120
|
+
this.setState({
|
|
121
|
+
showModeToggle: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
handleViewMouseOut = event => {
|
|
126
|
+
if (this.props.mode === 'view') {
|
|
127
|
+
event.stopPropagation();
|
|
128
|
+
this.setState({
|
|
129
|
+
showModeToggle: document.activeElement === this._editButtonRef
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
handleViewClick = event => {
|
|
134
|
+
if (event.buttons === 1) {
|
|
135
|
+
(0, _requestAnimationFrame.requestAnimationFrame)(() => {
|
|
136
|
+
this.enterEdit();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
handleEditBlur = () => {
|
|
141
|
+
this.enterView();
|
|
142
|
+
};
|
|
143
|
+
handleEditButtonFocus = () => {
|
|
144
|
+
this.setState({
|
|
145
|
+
showModeToggle: true
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
handleEditButtonBlur = () => {
|
|
149
|
+
this.setState({
|
|
150
|
+
showModeToggle: false
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
handleEditButtonClick = () => {
|
|
154
|
+
this.enterEdit();
|
|
155
|
+
};
|
|
156
|
+
ref = null;
|
|
157
|
+
handleContainerRef = el => {
|
|
158
|
+
const {
|
|
159
|
+
elementRef
|
|
160
|
+
} = this.props;
|
|
161
|
+
this.ref = el;
|
|
162
|
+
if (typeof elementRef === 'function') {
|
|
163
|
+
elementRef(el);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// ------- prop getters ------
|
|
168
|
+
getContainerProps = (props = {}) => {
|
|
169
|
+
const {
|
|
170
|
+
mode,
|
|
171
|
+
readOnly
|
|
172
|
+
} = this.props;
|
|
173
|
+
return {
|
|
174
|
+
onMouseOver: this.handleViewMouseOver,
|
|
175
|
+
onMouseOut: this.handleViewMouseOut,
|
|
176
|
+
onMouseDown: mode !== 'edit' ? this.handleViewClick : undefined,
|
|
177
|
+
onKeyUp: mode === 'edit' ? this.handleEditESC : undefined,
|
|
178
|
+
readOnly,
|
|
179
|
+
...props,
|
|
180
|
+
ref: this.handleContainerRef
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
getViewerProps = (props = {}) => {
|
|
184
|
+
return {
|
|
185
|
+
mode: this.props.mode,
|
|
186
|
+
readOnly: this.props.readOnly,
|
|
187
|
+
...props
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
getEditorProps = (props = {}) => {
|
|
191
|
+
return {
|
|
192
|
+
mode: this.props.mode,
|
|
193
|
+
onBlur: this.handleEditBlur,
|
|
194
|
+
editorRef: el => {
|
|
195
|
+
this._editorRef = el;
|
|
196
|
+
},
|
|
197
|
+
readOnly: this.props.readOnly,
|
|
198
|
+
...props
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
getEditButtonProps = (props = {}) => {
|
|
202
|
+
return {
|
|
203
|
+
onClick: this.handleEditButtonClick,
|
|
204
|
+
onFocus: this.handleEditButtonFocus,
|
|
205
|
+
onBlur: this.handleEditButtonBlur,
|
|
206
|
+
isVisible: this.state.showModeToggle,
|
|
207
|
+
buttonRef: el => {
|
|
208
|
+
this._editButtonRef = el;
|
|
209
|
+
},
|
|
210
|
+
readOnly: this.props.readOnly,
|
|
211
|
+
...props
|
|
212
|
+
};
|
|
213
|
+
};
|
|
203
214
|
render() {
|
|
204
|
-
const
|
|
205
|
-
children
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
const {
|
|
216
|
+
children,
|
|
217
|
+
render = children,
|
|
218
|
+
mode
|
|
219
|
+
} = this.props;
|
|
209
220
|
if (typeof render === 'function') {
|
|
210
221
|
return render({
|
|
211
222
|
mode,
|
|
@@ -220,10 +231,4 @@ class Editable extends _react.Component {
|
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
233
|
exports.Editable = Editable;
|
|
223
|
-
Editable.displayName = "Editable";
|
|
224
|
-
Editable.allowedProps = _props2.allowedProps;
|
|
225
|
-
Editable.defaultProps = {
|
|
226
|
-
readOnly: false,
|
|
227
|
-
children: null
|
|
228
|
-
};
|
|
229
234
|
var _default = exports.default = Editable;
|
|
@@ -17,7 +17,7 @@ var _v = require("../../Editable/v1");
|
|
|
17
17
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
18
18
|
var _props = require("./props");
|
|
19
19
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
20
|
-
var _dec, _class
|
|
20
|
+
var _dec, _class;
|
|
21
21
|
/*
|
|
22
22
|
* The MIT License (MIT)
|
|
23
23
|
*
|
|
@@ -46,68 +46,51 @@ var _dec, _class, _InPlaceEdit;
|
|
|
46
46
|
category: components
|
|
47
47
|
---
|
|
48
48
|
**/
|
|
49
|
-
let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, null), _dec(_class =
|
|
49
|
+
let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, null), _dec(_class = class InPlaceEdit extends _react.Component {
|
|
50
|
+
static displayName = "InPlaceEdit";
|
|
51
|
+
static componentId = 'InPlaceEdit';
|
|
52
|
+
static allowedProps = _props.allowedProps;
|
|
53
|
+
static defaultProps = {
|
|
54
|
+
readOnly: false,
|
|
55
|
+
showFocusRing: true,
|
|
56
|
+
inline: true,
|
|
57
|
+
editButtonPlacement: 'end'
|
|
58
|
+
};
|
|
59
|
+
ref = null;
|
|
60
|
+
_editButtonRef = null;
|
|
61
|
+
handleRef = el => {
|
|
62
|
+
this.ref = el;
|
|
63
|
+
};
|
|
50
64
|
constructor(props) {
|
|
51
65
|
super(props);
|
|
52
|
-
this.ref = null;
|
|
53
|
-
this._editButtonRef = null;
|
|
54
|
-
this.handleRef = el => {
|
|
55
|
-
this.ref = el;
|
|
56
|
-
};
|
|
57
|
-
this.handleEditButtonRef = el => {
|
|
58
|
-
this._editButtonRef = el;
|
|
59
|
-
};
|
|
60
|
-
this.renderAll = ({
|
|
61
|
-
getContainerProps,
|
|
62
|
-
getViewerProps,
|
|
63
|
-
getEditorProps,
|
|
64
|
-
getEditButtonProps
|
|
65
|
-
}) => {
|
|
66
|
-
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
67
|
-
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
68
|
-
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
69
|
-
return (0, _jsxRuntime.jsxs)(_v11_.Flex, {
|
|
70
|
-
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
71
|
-
direction: flexDir,
|
|
72
|
-
justifyItems: justifyItems,
|
|
73
|
-
...getContainerProps(),
|
|
74
|
-
children: [(0, _jsxRuntime.jsxs)(_v11_.Flex.Item, {
|
|
75
|
-
shouldGrow: true,
|
|
76
|
-
shouldShrink: true,
|
|
77
|
-
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
78
|
-
}), (0, _jsxRuntime.jsx)(_v11_.Flex.Item, {
|
|
79
|
-
margin: buttonMargin,
|
|
80
|
-
children: this.renderEditButton(getEditButtonProps())
|
|
81
|
-
})]
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
66
|
(0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
85
67
|
}
|
|
86
68
|
componentDidMount() {
|
|
87
|
-
|
|
88
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
69
|
+
this.props.makeStyles?.();
|
|
89
70
|
}
|
|
90
71
|
componentDidUpdate() {
|
|
91
|
-
|
|
92
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
72
|
+
this.props.makeStyles?.();
|
|
93
73
|
}
|
|
74
|
+
handleEditButtonRef = el => {
|
|
75
|
+
this._editButtonRef = el;
|
|
76
|
+
};
|
|
94
77
|
renderEditor({
|
|
95
78
|
mode,
|
|
96
79
|
onBlur,
|
|
97
80
|
editorRef,
|
|
98
81
|
readOnly
|
|
99
82
|
}) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
83
|
+
const {
|
|
84
|
+
showFocusRing,
|
|
85
|
+
renderEditor
|
|
86
|
+
} = this.props;
|
|
104
87
|
const isEditMode = !readOnly && mode === 'edit';
|
|
105
88
|
return isEditMode ? (0, _jsxRuntime.jsx)(_v11_3.View, {
|
|
106
89
|
as: "span",
|
|
107
90
|
display: "block",
|
|
108
91
|
withFocusOutline: showFocusRing,
|
|
109
92
|
position: "relative",
|
|
110
|
-
css:
|
|
93
|
+
css: this.props.styles?.inPlaceEdit,
|
|
111
94
|
borderRadius: "medium",
|
|
112
95
|
margin: "auto",
|
|
113
96
|
children: renderEditor({
|
|
@@ -134,14 +117,56 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyleLegacy)(_s
|
|
|
134
117
|
|
|
135
118
|
// Render a default edit button, an icon button with the edit icon
|
|
136
119
|
// the margin makes room for the focus ring
|
|
137
|
-
|
|
120
|
+
static renderDefaultEditButton = ({
|
|
121
|
+
isVisible,
|
|
122
|
+
readOnly,
|
|
123
|
+
label,
|
|
124
|
+
...buttonProps
|
|
125
|
+
}) => {
|
|
126
|
+
if (readOnly) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
|
|
130
|
+
size: "small",
|
|
131
|
+
screenReaderLabel: label,
|
|
132
|
+
withBackground: false,
|
|
133
|
+
withBorder: false,
|
|
134
|
+
...buttonProps,
|
|
135
|
+
children: isVisible ? _IconEditLine.IconEditLine : null
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
renderAll = ({
|
|
139
|
+
getContainerProps,
|
|
140
|
+
getViewerProps,
|
|
141
|
+
getEditorProps,
|
|
142
|
+
getEditButtonProps
|
|
143
|
+
}) => {
|
|
144
|
+
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
145
|
+
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
146
|
+
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
147
|
+
return (0, _jsxRuntime.jsxs)(_v11_.Flex, {
|
|
148
|
+
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
149
|
+
direction: flexDir,
|
|
150
|
+
justifyItems: justifyItems,
|
|
151
|
+
...getContainerProps(),
|
|
152
|
+
children: [(0, _jsxRuntime.jsxs)(_v11_.Flex.Item, {
|
|
153
|
+
shouldGrow: true,
|
|
154
|
+
shouldShrink: true,
|
|
155
|
+
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
156
|
+
}), (0, _jsxRuntime.jsx)(_v11_.Flex.Item, {
|
|
157
|
+
margin: buttonMargin,
|
|
158
|
+
children: this.renderEditButton(getEditButtonProps())
|
|
159
|
+
})]
|
|
160
|
+
});
|
|
161
|
+
};
|
|
138
162
|
render() {
|
|
139
|
-
const
|
|
140
|
-
mode
|
|
141
|
-
value
|
|
142
|
-
onChange
|
|
143
|
-
onChangeMode
|
|
144
|
-
readOnly
|
|
163
|
+
const {
|
|
164
|
+
mode,
|
|
165
|
+
value,
|
|
166
|
+
onChange,
|
|
167
|
+
onChangeMode,
|
|
168
|
+
readOnly
|
|
169
|
+
} = this.props;
|
|
145
170
|
return (0, _jsxRuntime.jsx)(_v.Editable, {
|
|
146
171
|
mode: mode,
|
|
147
172
|
onChangeMode: onChangeMode,
|
|
@@ -152,27 +177,5 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyleLegacy)(_s
|
|
|
152
177
|
elementRef: this.handleRef
|
|
153
178
|
});
|
|
154
179
|
}
|
|
155
|
-
}
|
|
156
|
-
readOnly: false,
|
|
157
|
-
showFocusRing: true,
|
|
158
|
-
inline: true,
|
|
159
|
-
editButtonPlacement: 'end'
|
|
160
|
-
}, _InPlaceEdit.renderDefaultEditButton = ({
|
|
161
|
-
isVisible,
|
|
162
|
-
readOnly,
|
|
163
|
-
label,
|
|
164
|
-
...buttonProps
|
|
165
|
-
}) => {
|
|
166
|
-
if (readOnly) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
return (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
|
|
170
|
-
size: "small",
|
|
171
|
-
screenReaderLabel: label,
|
|
172
|
-
withBackground: false,
|
|
173
|
-
withBorder: false,
|
|
174
|
-
...buttonProps,
|
|
175
|
-
children: isVisible ? _IconEditLine.IconEditLine : null
|
|
176
|
-
});
|
|
177
|
-
}, _InPlaceEdit)) || _class);
|
|
180
|
+
}) || _class);
|
|
178
181
|
var _default = exports.default = InPlaceEdit;
|
|
@@ -17,7 +17,7 @@ var _v = require("../../Editable/v1");
|
|
|
17
17
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
18
18
|
var _props = require("./props");
|
|
19
19
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
20
|
-
var _dec, _class
|
|
20
|
+
var _dec, _class;
|
|
21
21
|
/*
|
|
22
22
|
* The MIT License (MIT)
|
|
23
23
|
*
|
|
@@ -46,68 +46,51 @@ var _dec, _class, _InPlaceEdit;
|
|
|
46
46
|
category: components
|
|
47
47
|
---
|
|
48
48
|
**/
|
|
49
|
-
let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class =
|
|
49
|
+
let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = class InPlaceEdit extends _react.Component {
|
|
50
|
+
static displayName = "InPlaceEdit";
|
|
51
|
+
static componentId = 'InPlaceEdit';
|
|
52
|
+
static allowedProps = _props.allowedProps;
|
|
53
|
+
static defaultProps = {
|
|
54
|
+
readOnly: false,
|
|
55
|
+
showFocusRing: true,
|
|
56
|
+
inline: true,
|
|
57
|
+
editButtonPlacement: 'end'
|
|
58
|
+
};
|
|
59
|
+
ref = null;
|
|
60
|
+
_editButtonRef = null;
|
|
61
|
+
handleRef = el => {
|
|
62
|
+
this.ref = el;
|
|
63
|
+
};
|
|
50
64
|
constructor(props) {
|
|
51
65
|
super(props);
|
|
52
|
-
this.ref = null;
|
|
53
|
-
this._editButtonRef = null;
|
|
54
|
-
this.handleRef = el => {
|
|
55
|
-
this.ref = el;
|
|
56
|
-
};
|
|
57
|
-
this.handleEditButtonRef = el => {
|
|
58
|
-
this._editButtonRef = el;
|
|
59
|
-
};
|
|
60
|
-
this.renderAll = ({
|
|
61
|
-
getContainerProps,
|
|
62
|
-
getViewerProps,
|
|
63
|
-
getEditorProps,
|
|
64
|
-
getEditButtonProps
|
|
65
|
-
}) => {
|
|
66
|
-
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
67
|
-
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
68
|
-
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
69
|
-
return (0, _jsxRuntime.jsxs)(_latest.Flex, {
|
|
70
|
-
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
71
|
-
direction: flexDir,
|
|
72
|
-
justifyItems: justifyItems,
|
|
73
|
-
...getContainerProps(),
|
|
74
|
-
children: [(0, _jsxRuntime.jsxs)(_latest.Flex.Item, {
|
|
75
|
-
shouldGrow: true,
|
|
76
|
-
shouldShrink: true,
|
|
77
|
-
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
78
|
-
}), (0, _jsxRuntime.jsx)(_latest.Flex.Item, {
|
|
79
|
-
margin: buttonMargin,
|
|
80
|
-
children: this.renderEditButton(getEditButtonProps())
|
|
81
|
-
})]
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
66
|
(0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
85
67
|
}
|
|
86
68
|
componentDidMount() {
|
|
87
|
-
|
|
88
|
-
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
69
|
+
this.props.makeStyles?.();
|
|
89
70
|
}
|
|
90
71
|
componentDidUpdate() {
|
|
91
|
-
|
|
92
|
-
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
72
|
+
this.props.makeStyles?.();
|
|
93
73
|
}
|
|
74
|
+
handleEditButtonRef = el => {
|
|
75
|
+
this._editButtonRef = el;
|
|
76
|
+
};
|
|
94
77
|
renderEditor({
|
|
95
78
|
mode,
|
|
96
79
|
onBlur,
|
|
97
80
|
editorRef,
|
|
98
81
|
readOnly
|
|
99
82
|
}) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
83
|
+
const {
|
|
84
|
+
showFocusRing,
|
|
85
|
+
renderEditor
|
|
86
|
+
} = this.props;
|
|
104
87
|
const isEditMode = !readOnly && mode === 'edit';
|
|
105
88
|
return isEditMode ? (0, _jsxRuntime.jsx)(_latest3.View, {
|
|
106
89
|
as: "span",
|
|
107
90
|
display: "block",
|
|
108
91
|
withFocusOutline: showFocusRing,
|
|
109
92
|
position: "relative",
|
|
110
|
-
css:
|
|
93
|
+
css: this.props.styles?.inPlaceEdit,
|
|
111
94
|
borderRadius: "medium",
|
|
112
95
|
margin: "auto",
|
|
113
96
|
children: renderEditor({
|
|
@@ -134,14 +117,56 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
134
117
|
|
|
135
118
|
// Render a default edit button, an icon button with the edit icon
|
|
136
119
|
// the margin makes room for the focus ring
|
|
137
|
-
|
|
120
|
+
static renderDefaultEditButton = ({
|
|
121
|
+
isVisible,
|
|
122
|
+
readOnly,
|
|
123
|
+
label,
|
|
124
|
+
...buttonProps
|
|
125
|
+
}) => {
|
|
126
|
+
if (readOnly) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return (0, _jsxRuntime.jsx)(_latest2.IconButton, {
|
|
130
|
+
size: "small",
|
|
131
|
+
screenReaderLabel: label,
|
|
132
|
+
withBackground: false,
|
|
133
|
+
withBorder: false,
|
|
134
|
+
...buttonProps,
|
|
135
|
+
children: isVisible ? _uiIcons.PencilInstUIIcon : null
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
renderAll = ({
|
|
139
|
+
getContainerProps,
|
|
140
|
+
getViewerProps,
|
|
141
|
+
getEditorProps,
|
|
142
|
+
getEditButtonProps
|
|
143
|
+
}) => {
|
|
144
|
+
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
145
|
+
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
146
|
+
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
147
|
+
return (0, _jsxRuntime.jsxs)(_latest.Flex, {
|
|
148
|
+
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
149
|
+
direction: flexDir,
|
|
150
|
+
justifyItems: justifyItems,
|
|
151
|
+
...getContainerProps(),
|
|
152
|
+
children: [(0, _jsxRuntime.jsxs)(_latest.Flex.Item, {
|
|
153
|
+
shouldGrow: true,
|
|
154
|
+
shouldShrink: true,
|
|
155
|
+
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
156
|
+
}), (0, _jsxRuntime.jsx)(_latest.Flex.Item, {
|
|
157
|
+
margin: buttonMargin,
|
|
158
|
+
children: this.renderEditButton(getEditButtonProps())
|
|
159
|
+
})]
|
|
160
|
+
});
|
|
161
|
+
};
|
|
138
162
|
render() {
|
|
139
|
-
const
|
|
140
|
-
mode
|
|
141
|
-
value
|
|
142
|
-
onChange
|
|
143
|
-
onChangeMode
|
|
144
|
-
readOnly
|
|
163
|
+
const {
|
|
164
|
+
mode,
|
|
165
|
+
value,
|
|
166
|
+
onChange,
|
|
167
|
+
onChangeMode,
|
|
168
|
+
readOnly
|
|
169
|
+
} = this.props;
|
|
145
170
|
return (0, _jsxRuntime.jsx)(_v.Editable, {
|
|
146
171
|
mode: mode,
|
|
147
172
|
onChangeMode: onChangeMode,
|
|
@@ -152,27 +177,5 @@ let InPlaceEdit = exports.InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.
|
|
|
152
177
|
elementRef: this.handleRef
|
|
153
178
|
});
|
|
154
179
|
}
|
|
155
|
-
}
|
|
156
|
-
readOnly: false,
|
|
157
|
-
showFocusRing: true,
|
|
158
|
-
inline: true,
|
|
159
|
-
editButtonPlacement: 'end'
|
|
160
|
-
}, _InPlaceEdit.renderDefaultEditButton = ({
|
|
161
|
-
isVisible,
|
|
162
|
-
readOnly,
|
|
163
|
-
label,
|
|
164
|
-
...buttonProps
|
|
165
|
-
}) => {
|
|
166
|
-
if (readOnly) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
return (0, _jsxRuntime.jsx)(_latest2.IconButton, {
|
|
170
|
-
size: "small",
|
|
171
|
-
screenReaderLabel: label,
|
|
172
|
-
withBackground: false,
|
|
173
|
-
withBorder: false,
|
|
174
|
-
...buttonProps,
|
|
175
|
-
children: isVisible ? _uiIcons.PencilInstUIIcon : null
|
|
176
|
-
});
|
|
177
|
-
}, _InPlaceEdit)) || _class);
|
|
180
|
+
}) || _class);
|
|
178
181
|
var _default = exports.default = InPlaceEdit;
|