@instructure/ui-editable 8.33.2-snapshot-0 → 8.33.2
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 +1 -5
- package/es/Editable/index.js +12 -42
- package/es/Editable/props.js +1 -0
- package/es/InPlaceEdit/index.js +22 -40
- package/es/InPlaceEdit/props.js +1 -0
- package/es/InPlaceEdit/styles.js +1 -4
- package/es/index.js +1 -0
- package/lib/Editable/index.js +12 -47
- package/lib/Editable/props.js +1 -3
- package/lib/InPlaceEdit/index.js +22 -52
- package/lib/InPlaceEdit/props.js +1 -3
- package/lib/InPlaceEdit/styles.js +1 -5
- package/lib/index.js +0 -2
- package/package.json +13 -13
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
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
|
-
## [8.33.2
|
|
6
|
+
## [8.33.2](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2) (2023-01-25)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-editable
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
10
|
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
15
11
|
|
|
16
12
|
**Note:** Version bump only for package @instructure/ui-editable
|
package/es/Editable/index.js
CHANGED
|
@@ -26,7 +26,6 @@ import { deepEqual } from '@instructure/ui-utils';
|
|
|
26
26
|
import { logWarn as warn } from '@instructure/console';
|
|
27
27
|
import { requestAnimationFrame } from '@instructure/ui-dom-utils';
|
|
28
28
|
import { propTypes, allowedProps } from './props';
|
|
29
|
-
|
|
30
29
|
/**
|
|
31
30
|
---
|
|
32
31
|
category: components
|
|
@@ -36,23 +35,19 @@ category: components
|
|
|
36
35
|
class Editable extends Component {
|
|
37
36
|
constructor(_props) {
|
|
38
37
|
var _this;
|
|
39
|
-
|
|
40
38
|
super(_props);
|
|
41
39
|
_this = this;
|
|
42
40
|
this.state = {
|
|
43
41
|
showModeToggle: false,
|
|
44
42
|
valueOnEdit: null // the value when mode flips from view -> edit
|
|
45
|
-
|
|
46
43
|
};
|
|
47
44
|
this._editorRef = null;
|
|
48
45
|
this._editButtonRef = null;
|
|
49
|
-
|
|
50
46
|
this.handleEditESC = event => {
|
|
51
47
|
if (event.key === 'Escape') {
|
|
52
48
|
this.enterView();
|
|
53
49
|
}
|
|
54
50
|
};
|
|
55
|
-
|
|
56
51
|
this.handleViewMouseOver = event => {
|
|
57
52
|
if (this.props.mode === 'view') {
|
|
58
53
|
// because the mouse event handlers are on the container, not the view
|
|
@@ -62,7 +57,6 @@ class Editable extends Component {
|
|
|
62
57
|
});
|
|
63
58
|
}
|
|
64
59
|
};
|
|
65
|
-
|
|
66
60
|
this.handleViewMouseOut = event => {
|
|
67
61
|
if (this.props.mode === 'view') {
|
|
68
62
|
event.stopPropagation();
|
|
@@ -71,7 +65,6 @@ class Editable extends Component {
|
|
|
71
65
|
});
|
|
72
66
|
}
|
|
73
67
|
};
|
|
74
|
-
|
|
75
68
|
this.handleViewClick = event => {
|
|
76
69
|
if (event.buttons === 1) {
|
|
77
70
|
requestAnimationFrame(() => {
|
|
@@ -79,43 +72,35 @@ class Editable extends Component {
|
|
|
79
72
|
});
|
|
80
73
|
}
|
|
81
74
|
};
|
|
82
|
-
|
|
83
75
|
this.handleEditBlur = () => {
|
|
84
76
|
this.enterView();
|
|
85
77
|
};
|
|
86
|
-
|
|
87
78
|
this.handleEditButtonFocus = () => {
|
|
88
79
|
this.setState({
|
|
89
80
|
showModeToggle: true
|
|
90
81
|
});
|
|
91
82
|
};
|
|
92
|
-
|
|
93
83
|
this.handleEditButtonBlur = () => {
|
|
94
84
|
this.setState({
|
|
95
85
|
showModeToggle: false
|
|
96
86
|
});
|
|
97
87
|
};
|
|
98
|
-
|
|
99
88
|
this.handleEditButtonClick = () => {
|
|
100
89
|
this.enterEdit();
|
|
101
90
|
};
|
|
102
|
-
|
|
103
91
|
this.ref = null;
|
|
104
|
-
|
|
105
92
|
this.handleContainerRef = el => {
|
|
106
93
|
const elementRef = this.props.elementRef;
|
|
107
94
|
this.ref = el;
|
|
108
|
-
|
|
109
95
|
if (typeof elementRef === 'function') {
|
|
110
96
|
elementRef(el);
|
|
111
97
|
}
|
|
112
98
|
};
|
|
113
|
-
|
|
114
99
|
this.getContainerProps = function () {
|
|
115
100
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
116
101
|
const _this$props = _this.props,
|
|
117
|
-
|
|
118
|
-
|
|
102
|
+
mode = _this$props.mode,
|
|
103
|
+
readOnly = _this$props.readOnly;
|
|
119
104
|
return {
|
|
120
105
|
onMouseOver: _this.handleViewMouseOver,
|
|
121
106
|
onMouseOut: _this.handleViewMouseOut,
|
|
@@ -126,7 +111,6 @@ class Editable extends Component {
|
|
|
126
111
|
ref: _this.handleContainerRef
|
|
127
112
|
};
|
|
128
113
|
};
|
|
129
|
-
|
|
130
114
|
this.getViewerProps = function () {
|
|
131
115
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
132
116
|
return {
|
|
@@ -135,7 +119,6 @@ class Editable extends Component {
|
|
|
135
119
|
...props
|
|
136
120
|
};
|
|
137
121
|
};
|
|
138
|
-
|
|
139
122
|
this.getEditorProps = function () {
|
|
140
123
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
141
124
|
return {
|
|
@@ -148,7 +131,6 @@ class Editable extends Component {
|
|
|
148
131
|
...props
|
|
149
132
|
};
|
|
150
133
|
};
|
|
151
|
-
|
|
152
134
|
this.getEditButtonProps = function () {
|
|
153
135
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
154
136
|
return {
|
|
@@ -163,47 +145,41 @@ class Editable extends Component {
|
|
|
163
145
|
...props
|
|
164
146
|
};
|
|
165
147
|
};
|
|
166
|
-
|
|
167
148
|
warn(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
168
149
|
}
|
|
169
|
-
|
|
170
150
|
componentDidMount() {
|
|
171
151
|
if (this.props.mode === 'edit') {
|
|
172
152
|
this.focusEditor();
|
|
173
153
|
}
|
|
174
154
|
}
|
|
175
|
-
|
|
176
155
|
componentDidUpdate(prevProps) {
|
|
177
156
|
const _this$props2 = this.props,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
157
|
+
mode = _this$props2.mode,
|
|
158
|
+
value = _this$props2.value,
|
|
159
|
+
onChange = _this$props2.onChange;
|
|
181
160
|
|
|
161
|
+
// on the switch from view -> edit
|
|
182
162
|
if (prevProps.mode !== 'edit' && mode === 'edit') {
|
|
183
163
|
this.setState({
|
|
184
164
|
valueOnEdit: value
|
|
185
165
|
});
|
|
186
166
|
this.focusEditor();
|
|
187
|
-
}
|
|
188
|
-
|
|
167
|
+
}
|
|
189
168
|
|
|
169
|
+
// on the switch from edit to view
|
|
190
170
|
if (prevProps.mode === 'edit' && mode !== 'edit') {
|
|
191
171
|
this._editButtonRef && this._editButtonRef.focus();
|
|
192
|
-
|
|
193
172
|
if (onChange && !deepEqual(this.state.valueOnEdit, value)) {
|
|
194
173
|
onChange(value);
|
|
195
174
|
}
|
|
196
175
|
}
|
|
197
176
|
}
|
|
198
|
-
|
|
199
177
|
focusEditor() {
|
|
200
178
|
warn(!!this._editorRef && !this.props.readOnly, '[Editable] Did you forget to connect editorRef to your editor component?');
|
|
201
|
-
|
|
202
179
|
if (this._editorRef) {
|
|
203
180
|
this._editorRef.focus();
|
|
204
181
|
}
|
|
205
182
|
}
|
|
206
|
-
|
|
207
183
|
enterView() {
|
|
208
184
|
if (this.props.mode !== 'view') {
|
|
209
185
|
this.setState({
|
|
@@ -212,26 +188,22 @@ class Editable extends Component {
|
|
|
212
188
|
this.props.onChangeMode('view');
|
|
213
189
|
}
|
|
214
190
|
}
|
|
215
|
-
|
|
216
191
|
enterEdit() {
|
|
217
192
|
if (!this.props.readOnly) {
|
|
218
193
|
this.setState({
|
|
219
194
|
showModeToggle: false
|
|
220
195
|
});
|
|
221
|
-
|
|
222
196
|
if (this.props.mode !== 'edit') {
|
|
223
197
|
this.props.onChangeMode('edit');
|
|
224
198
|
}
|
|
225
199
|
}
|
|
226
200
|
}
|
|
227
|
-
|
|
228
201
|
render() {
|
|
229
202
|
const _this$props3 = this.props,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
203
|
+
children = _this$props3.children,
|
|
204
|
+
_this$props3$render = _this$props3.render,
|
|
205
|
+
render = _this$props3$render === void 0 ? children : _this$props3$render,
|
|
206
|
+
mode = _this$props3.mode;
|
|
235
207
|
if (typeof render === 'function') {
|
|
236
208
|
return render({
|
|
237
209
|
mode,
|
|
@@ -244,9 +216,7 @@ class Editable extends Component {
|
|
|
244
216
|
return null;
|
|
245
217
|
}
|
|
246
218
|
}
|
|
247
|
-
|
|
248
219
|
}
|
|
249
|
-
|
|
250
220
|
Editable.displayName = "Editable";
|
|
251
221
|
Editable.propTypes = propTypes;
|
|
252
222
|
Editable.allowedProps = allowedProps;
|
package/es/Editable/props.js
CHANGED
package/es/InPlaceEdit/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
const _excluded = ["buttonRef"],
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
_excluded2 = ["isVisible", "readOnly", "label"];
|
|
5
4
|
var _dec, _class, _class2;
|
|
6
|
-
|
|
7
5
|
/*
|
|
8
6
|
* The MIT License (MIT)
|
|
9
7
|
*
|
|
@@ -40,7 +38,6 @@ import { View } from '@instructure/ui-view';
|
|
|
40
38
|
import { Editable } from '../Editable';
|
|
41
39
|
import generateStyle from './styles';
|
|
42
40
|
import { propTypes, allowedProps } from './props';
|
|
43
|
-
|
|
44
41
|
/**
|
|
45
42
|
---
|
|
46
43
|
category: components
|
|
@@ -52,20 +49,17 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
|
|
|
52
49
|
super(props);
|
|
53
50
|
this.ref = null;
|
|
54
51
|
this._editButtonRef = null;
|
|
55
|
-
|
|
56
52
|
this.handleRef = el => {
|
|
57
53
|
this.ref = el;
|
|
58
54
|
};
|
|
59
|
-
|
|
60
55
|
this.handleEditButtonRef = el => {
|
|
61
56
|
this._editButtonRef = el;
|
|
62
57
|
};
|
|
63
|
-
|
|
64
58
|
this.renderAll = _ref => {
|
|
65
59
|
let getContainerProps = _ref.getContainerProps,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
getViewerProps = _ref.getViewerProps,
|
|
61
|
+
getEditorProps = _ref.getEditorProps,
|
|
62
|
+
getEditButtonProps = _ref.getEditButtonProps;
|
|
69
63
|
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
70
64
|
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
71
65
|
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
@@ -80,32 +74,25 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
|
|
|
80
74
|
margin: buttonMargin
|
|
81
75
|
}, this.renderEditButton(getEditButtonProps())));
|
|
82
76
|
};
|
|
83
|
-
|
|
84
77
|
warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
componentDidMount() {
|
|
88
80
|
var _this$props$makeStyle, _this$props;
|
|
89
|
-
|
|
90
81
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
91
82
|
}
|
|
92
|
-
|
|
93
83
|
componentDidUpdate() {
|
|
94
84
|
var _this$props$makeStyle2, _this$props2;
|
|
95
|
-
|
|
96
85
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
97
86
|
}
|
|
98
|
-
|
|
99
87
|
renderEditor(_ref2) {
|
|
100
88
|
var _this$props$styles;
|
|
101
|
-
|
|
102
89
|
let mode = _ref2.mode,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
90
|
+
onBlur = _ref2.onBlur,
|
|
91
|
+
editorRef = _ref2.editorRef,
|
|
92
|
+
readOnly = _ref2.readOnly;
|
|
106
93
|
const _this$props3 = this.props,
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
showFocusRing = _this$props3.showFocusRing,
|
|
95
|
+
renderEditor = _this$props3.renderEditor;
|
|
109
96
|
const isEditMode = !readOnly && mode === 'edit';
|
|
110
97
|
return isEditMode ? jsx(View, {
|
|
111
98
|
as: "span",
|
|
@@ -120,32 +107,30 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
|
|
|
120
107
|
editorRef
|
|
121
108
|
})) : null;
|
|
122
109
|
}
|
|
123
|
-
|
|
124
110
|
renderViewer(_ref3) {
|
|
125
111
|
let readOnly = _ref3.readOnly,
|
|
126
|
-
|
|
112
|
+
mode = _ref3.mode;
|
|
127
113
|
return readOnly || mode === 'view' ? this.props.renderViewer() : null;
|
|
128
114
|
}
|
|
129
|
-
|
|
130
115
|
renderEditButton(_ref4) {
|
|
131
116
|
let buttonRef = _ref4.buttonRef,
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
rest = _objectWithoutProperties(_ref4, _excluded);
|
|
134
118
|
return this.props.renderEditButton({
|
|
135
119
|
elementRef: createChainedFunction(this.handleEditButtonRef, buttonRef),
|
|
136
120
|
...rest
|
|
137
121
|
});
|
|
138
|
-
}
|
|
139
|
-
// the margin makes room for the focus ring
|
|
122
|
+
}
|
|
140
123
|
|
|
124
|
+
// Render a default edit button, an icon button with the edit icon
|
|
125
|
+
// the margin makes room for the focus ring
|
|
141
126
|
|
|
142
127
|
render() {
|
|
143
128
|
const _this$props4 = this.props,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
129
|
+
mode = _this$props4.mode,
|
|
130
|
+
value = _this$props4.value,
|
|
131
|
+
onChange = _this$props4.onChange,
|
|
132
|
+
onChangeMode = _this$props4.onChangeMode,
|
|
133
|
+
readOnly = _this$props4.readOnly;
|
|
149
134
|
return jsx(Editable, {
|
|
150
135
|
mode: mode,
|
|
151
136
|
onChangeMode: onChangeMode,
|
|
@@ -156,7 +141,6 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
|
|
|
156
141
|
elementRef: this.handleRef
|
|
157
142
|
});
|
|
158
143
|
}
|
|
159
|
-
|
|
160
144
|
}, _class2.displayName = "InPlaceEdit", _class2.componentId = 'InPlaceEdit', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
|
|
161
145
|
readOnly: false,
|
|
162
146
|
showFocusRing: true,
|
|
@@ -164,14 +148,12 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
|
|
|
164
148
|
editButtonPlacement: 'end'
|
|
165
149
|
}, _class2.renderDefaultEditButton = _ref5 => {
|
|
166
150
|
let isVisible = _ref5.isVisible,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
151
|
+
readOnly = _ref5.readOnly,
|
|
152
|
+
label = _ref5.label,
|
|
153
|
+
buttonProps = _objectWithoutProperties(_ref5, _excluded2);
|
|
171
154
|
if (readOnly) {
|
|
172
155
|
return null;
|
|
173
156
|
}
|
|
174
|
-
|
|
175
157
|
return jsx(IconButton, Object.assign({
|
|
176
158
|
size: "small",
|
|
177
159
|
screenReaderLabel: label,
|
package/es/InPlaceEdit/props.js
CHANGED
package/es/InPlaceEdit/styles.js
CHANGED
|
@@ -42,9 +42,7 @@ const generateStyle = () => {
|
|
|
42
42
|
overflow: 'visible',
|
|
43
43
|
direction: 'inherit',
|
|
44
44
|
margin: 0,
|
|
45
|
-
textDecoration: 'none'
|
|
46
|
-
/* for links styled as buttons */
|
|
47
|
-
,
|
|
45
|
+
textDecoration: 'none' /* for links styled as buttons */,
|
|
48
46
|
textAlign: 'inherit',
|
|
49
47
|
userSelect: 'none',
|
|
50
48
|
touchAction: 'manipulation',
|
|
@@ -54,5 +52,4 @@ const generateStyle = () => {
|
|
|
54
52
|
}
|
|
55
53
|
};
|
|
56
54
|
};
|
|
57
|
-
|
|
58
55
|
export default generateStyle;
|
package/es/index.js
CHANGED
package/lib/Editable/index.js
CHANGED
|
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Editable = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
|
|
11
|
-
|
|
12
9
|
var _console = require("@instructure/console");
|
|
13
|
-
|
|
14
10
|
var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
|
|
15
|
-
|
|
16
11
|
var _props2 = require("./props");
|
|
17
|
-
|
|
18
12
|
/*
|
|
19
13
|
* The MIT License (MIT)
|
|
20
14
|
*
|
|
@@ -48,23 +42,19 @@ category: components
|
|
|
48
42
|
class Editable extends _react.Component {
|
|
49
43
|
constructor(_props) {
|
|
50
44
|
var _this;
|
|
51
|
-
|
|
52
45
|
super(_props);
|
|
53
46
|
_this = this;
|
|
54
47
|
this.state = {
|
|
55
48
|
showModeToggle: false,
|
|
56
49
|
valueOnEdit: null // the value when mode flips from view -> edit
|
|
57
|
-
|
|
58
50
|
};
|
|
59
51
|
this._editorRef = null;
|
|
60
52
|
this._editButtonRef = null;
|
|
61
|
-
|
|
62
53
|
this.handleEditESC = event => {
|
|
63
54
|
if (event.key === 'Escape') {
|
|
64
55
|
this.enterView();
|
|
65
56
|
}
|
|
66
57
|
};
|
|
67
|
-
|
|
68
58
|
this.handleViewMouseOver = event => {
|
|
69
59
|
if (this.props.mode === 'view') {
|
|
70
60
|
// because the mouse event handlers are on the container, not the view
|
|
@@ -74,7 +64,6 @@ class Editable extends _react.Component {
|
|
|
74
64
|
});
|
|
75
65
|
}
|
|
76
66
|
};
|
|
77
|
-
|
|
78
67
|
this.handleViewMouseOut = event => {
|
|
79
68
|
if (this.props.mode === 'view') {
|
|
80
69
|
event.stopPropagation();
|
|
@@ -83,7 +72,6 @@ class Editable extends _react.Component {
|
|
|
83
72
|
});
|
|
84
73
|
}
|
|
85
74
|
};
|
|
86
|
-
|
|
87
75
|
this.handleViewClick = event => {
|
|
88
76
|
if (event.buttons === 1) {
|
|
89
77
|
(0, _requestAnimationFrame.requestAnimationFrame)(() => {
|
|
@@ -91,43 +79,35 @@ class Editable extends _react.Component {
|
|
|
91
79
|
});
|
|
92
80
|
}
|
|
93
81
|
};
|
|
94
|
-
|
|
95
82
|
this.handleEditBlur = () => {
|
|
96
83
|
this.enterView();
|
|
97
84
|
};
|
|
98
|
-
|
|
99
85
|
this.handleEditButtonFocus = () => {
|
|
100
86
|
this.setState({
|
|
101
87
|
showModeToggle: true
|
|
102
88
|
});
|
|
103
89
|
};
|
|
104
|
-
|
|
105
90
|
this.handleEditButtonBlur = () => {
|
|
106
91
|
this.setState({
|
|
107
92
|
showModeToggle: false
|
|
108
93
|
});
|
|
109
94
|
};
|
|
110
|
-
|
|
111
95
|
this.handleEditButtonClick = () => {
|
|
112
96
|
this.enterEdit();
|
|
113
97
|
};
|
|
114
|
-
|
|
115
98
|
this.ref = null;
|
|
116
|
-
|
|
117
99
|
this.handleContainerRef = el => {
|
|
118
100
|
const elementRef = this.props.elementRef;
|
|
119
101
|
this.ref = el;
|
|
120
|
-
|
|
121
102
|
if (typeof elementRef === 'function') {
|
|
122
103
|
elementRef(el);
|
|
123
104
|
}
|
|
124
105
|
};
|
|
125
|
-
|
|
126
106
|
this.getContainerProps = function () {
|
|
127
107
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
128
108
|
const _this$props = _this.props,
|
|
129
|
-
|
|
130
|
-
|
|
109
|
+
mode = _this$props.mode,
|
|
110
|
+
readOnly = _this$props.readOnly;
|
|
131
111
|
return {
|
|
132
112
|
onMouseOver: _this.handleViewMouseOver,
|
|
133
113
|
onMouseOut: _this.handleViewMouseOut,
|
|
@@ -138,7 +118,6 @@ class Editable extends _react.Component {
|
|
|
138
118
|
ref: _this.handleContainerRef
|
|
139
119
|
};
|
|
140
120
|
};
|
|
141
|
-
|
|
142
121
|
this.getViewerProps = function () {
|
|
143
122
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
144
123
|
return {
|
|
@@ -147,7 +126,6 @@ class Editable extends _react.Component {
|
|
|
147
126
|
...props
|
|
148
127
|
};
|
|
149
128
|
};
|
|
150
|
-
|
|
151
129
|
this.getEditorProps = function () {
|
|
152
130
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
153
131
|
return {
|
|
@@ -160,7 +138,6 @@ class Editable extends _react.Component {
|
|
|
160
138
|
...props
|
|
161
139
|
};
|
|
162
140
|
};
|
|
163
|
-
|
|
164
141
|
this.getEditButtonProps = function () {
|
|
165
142
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
166
143
|
return {
|
|
@@ -175,47 +152,41 @@ class Editable extends _react.Component {
|
|
|
175
152
|
...props
|
|
176
153
|
};
|
|
177
154
|
};
|
|
178
|
-
|
|
179
155
|
(0, _console.logWarn)(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
180
156
|
}
|
|
181
|
-
|
|
182
157
|
componentDidMount() {
|
|
183
158
|
if (this.props.mode === 'edit') {
|
|
184
159
|
this.focusEditor();
|
|
185
160
|
}
|
|
186
161
|
}
|
|
187
|
-
|
|
188
162
|
componentDidUpdate(prevProps) {
|
|
189
163
|
const _this$props2 = this.props,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
164
|
+
mode = _this$props2.mode,
|
|
165
|
+
value = _this$props2.value,
|
|
166
|
+
onChange = _this$props2.onChange;
|
|
193
167
|
|
|
168
|
+
// on the switch from view -> edit
|
|
194
169
|
if (prevProps.mode !== 'edit' && mode === 'edit') {
|
|
195
170
|
this.setState({
|
|
196
171
|
valueOnEdit: value
|
|
197
172
|
});
|
|
198
173
|
this.focusEditor();
|
|
199
|
-
}
|
|
200
|
-
|
|
174
|
+
}
|
|
201
175
|
|
|
176
|
+
// on the switch from edit to view
|
|
202
177
|
if (prevProps.mode === 'edit' && mode !== 'edit') {
|
|
203
178
|
this._editButtonRef && this._editButtonRef.focus();
|
|
204
|
-
|
|
205
179
|
if (onChange && !(0, _deepEqual.deepEqual)(this.state.valueOnEdit, value)) {
|
|
206
180
|
onChange(value);
|
|
207
181
|
}
|
|
208
182
|
}
|
|
209
183
|
}
|
|
210
|
-
|
|
211
184
|
focusEditor() {
|
|
212
185
|
(0, _console.logWarn)(!!this._editorRef && !this.props.readOnly, '[Editable] Did you forget to connect editorRef to your editor component?');
|
|
213
|
-
|
|
214
186
|
if (this._editorRef) {
|
|
215
187
|
this._editorRef.focus();
|
|
216
188
|
}
|
|
217
189
|
}
|
|
218
|
-
|
|
219
190
|
enterView() {
|
|
220
191
|
if (this.props.mode !== 'view') {
|
|
221
192
|
this.setState({
|
|
@@ -224,26 +195,22 @@ class Editable extends _react.Component {
|
|
|
224
195
|
this.props.onChangeMode('view');
|
|
225
196
|
}
|
|
226
197
|
}
|
|
227
|
-
|
|
228
198
|
enterEdit() {
|
|
229
199
|
if (!this.props.readOnly) {
|
|
230
200
|
this.setState({
|
|
231
201
|
showModeToggle: false
|
|
232
202
|
});
|
|
233
|
-
|
|
234
203
|
if (this.props.mode !== 'edit') {
|
|
235
204
|
this.props.onChangeMode('edit');
|
|
236
205
|
}
|
|
237
206
|
}
|
|
238
207
|
}
|
|
239
|
-
|
|
240
208
|
render() {
|
|
241
209
|
const _this$props3 = this.props,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
210
|
+
children = _this$props3.children,
|
|
211
|
+
_this$props3$render = _this$props3.render,
|
|
212
|
+
render = _this$props3$render === void 0 ? children : _this$props3$render,
|
|
213
|
+
mode = _this$props3.mode;
|
|
247
214
|
if (typeof render === 'function') {
|
|
248
215
|
return render({
|
|
249
216
|
mode,
|
|
@@ -256,9 +223,7 @@ class Editable extends _react.Component {
|
|
|
256
223
|
return null;
|
|
257
224
|
}
|
|
258
225
|
}
|
|
259
|
-
|
|
260
226
|
}
|
|
261
|
-
|
|
262
227
|
exports.Editable = Editable;
|
|
263
228
|
Editable.displayName = "Editable";
|
|
264
229
|
Editable.propTypes = _props2.propTypes;
|
package/lib/Editable/props.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.propTypes = exports.allowedProps = void 0;
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
/*
|
|
13
10
|
* The MIT License (MIT)
|
|
14
11
|
*
|
|
@@ -32,6 +29,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
32
29
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
30
|
* SOFTWARE.
|
|
34
31
|
*/
|
|
32
|
+
|
|
35
33
|
const propTypes = {
|
|
36
34
|
mode: _propTypes.default.oneOf(['view', 'edit']).isRequired,
|
|
37
35
|
onChangeMode: _propTypes.default.func.isRequired,
|