@instructure/ui-editable 8.25.1-snapshot-10 → 8.25.1-snapshot-13

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 CHANGED
@@ -3,7 +3,7 @@
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.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
6
+ ## [8.25.1-snapshot-13](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-13) (2022-06-22)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-editable
9
9
 
@@ -34,24 +34,136 @@ experimental: true
34
34
  ---
35
35
  **/
36
36
  class Editable extends Component {
37
- static displayName = "Editable";
38
- static propTypes = propTypes;
39
- static allowedProps = allowedProps;
40
- static defaultProps = {
41
- readOnly: false,
42
- children: null
43
- };
44
- state = {
45
- showModeToggle: false,
46
- valueOnEdit: null // the value when mode flips from view -> edit
47
-
48
- };
49
- _editorRef = null;
50
- _editButtonRef = null;
51
-
52
- constructor(props) {
53
- super(props);
54
- warn(props.readOnly ? props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
37
+ constructor(_props) {
38
+ var _this;
39
+
40
+ super(_props);
41
+ _this = this;
42
+ this.state = {
43
+ showModeToggle: false,
44
+ valueOnEdit: null // the value when mode flips from view -> edit
45
+
46
+ };
47
+ this._editorRef = null;
48
+ this._editButtonRef = null;
49
+
50
+ this.handleEditESC = event => {
51
+ if (event.key === 'Escape') {
52
+ this.enterView();
53
+ }
54
+ };
55
+
56
+ this.handleViewMouseOver = event => {
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
+
66
+ this.handleViewMouseOut = event => {
67
+ if (this.props.mode === 'view') {
68
+ event.stopPropagation();
69
+ this.setState({
70
+ showModeToggle: document.activeElement === this._editButtonRef
71
+ });
72
+ }
73
+ };
74
+
75
+ this.handleViewClick = event => {
76
+ if (event.buttons === 1) {
77
+ requestAnimationFrame(() => {
78
+ this.enterEdit();
79
+ });
80
+ }
81
+ };
82
+
83
+ this.handleEditBlur = event => {
84
+ this.enterView();
85
+ };
86
+
87
+ this.handleEditButtonFocus = event => {
88
+ this.setState({
89
+ showModeToggle: true
90
+ });
91
+ };
92
+
93
+ this.handleEditButtonBlur = event => {
94
+ this.setState({
95
+ showModeToggle: false
96
+ });
97
+ };
98
+
99
+ this.handleEditButtonClick = event => {
100
+ this.enterEdit();
101
+ };
102
+
103
+ this.ref = null;
104
+
105
+ this.handleContainerRef = el => {
106
+ const elementRef = this.props.elementRef;
107
+ this.ref = el;
108
+
109
+ if (typeof elementRef === 'function') {
110
+ elementRef(el);
111
+ }
112
+ };
113
+
114
+ this.getContainerProps = function () {
115
+ let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
116
+ const _this$props = _this.props,
117
+ mode = _this$props.mode,
118
+ readOnly = _this$props.readOnly;
119
+ return {
120
+ onMouseOver: _this.handleViewMouseOver,
121
+ onMouseOut: _this.handleViewMouseOut,
122
+ onMouseDown: mode !== 'edit' ? _this.handleViewClick : null,
123
+ onKeyUp: mode === 'edit' ? _this.handleEditESC : null,
124
+ readOnly,
125
+ ...props,
126
+ ref: _this.handleContainerRef
127
+ };
128
+ };
129
+
130
+ this.getViewerProps = function () {
131
+ let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
132
+ return {
133
+ mode: _this.props.mode,
134
+ readOnly: _this.props.readOnly,
135
+ ...props
136
+ };
137
+ };
138
+
139
+ this.getEditorProps = props => {
140
+ return {
141
+ mode: this.props.mode,
142
+ onBlur: this.handleEditBlur,
143
+ editorRef: el => {
144
+ this._editorRef = el;
145
+ },
146
+ readOnly: this.props.readOnly,
147
+ ...props
148
+ };
149
+ };
150
+
151
+ this.getEditButtonProps = function () {
152
+ let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
153
+ return {
154
+ onClick: _this.handleEditButtonClick,
155
+ onFocus: _this.handleEditButtonFocus,
156
+ onBlur: _this.handleEditButtonBlur,
157
+ isVisible: _this.state.showModeToggle,
158
+ buttonRef: el => {
159
+ _this._editButtonRef = el;
160
+ },
161
+ readOnly: _this.props.readOnly,
162
+ ...props
163
+ };
164
+ };
165
+
166
+ warn(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
55
167
  }
56
168
 
57
169
  componentDidMount() {
@@ -63,10 +175,10 @@ class Editable extends Component {
63
175
  componentWillUnmount() {}
64
176
 
65
177
  componentDidUpdate(prevProps) {
66
- const _this$props = this.props,
67
- mode = _this$props.mode,
68
- value = _this$props.value,
69
- onChange = _this$props.onChange; // on the switch from view -> edit
178
+ const _this$props2 = this.props,
179
+ mode = _this$props2.mode,
180
+ value = _this$props2.value,
181
+ onChange = _this$props2.onChange; // on the switch from view -> edit
70
182
 
71
183
  if (prevProps.mode !== 'edit' && mode === 'edit') {
72
184
  this.setState({
@@ -114,122 +226,6 @@ class Editable extends Component {
114
226
  }
115
227
  }
116
228
 
117
- handleEditESC = event => {
118
- if (event.key === 'Escape') {
119
- this.enterView();
120
- }
121
- };
122
- handleViewMouseOver = event => {
123
- if (this.props.mode === 'view') {
124
- // because the mouse event handlers are on the container, not the view
125
- event.stopPropagation();
126
- this.setState({
127
- showModeToggle: true
128
- });
129
- }
130
- };
131
- handleViewMouseOut = event => {
132
- if (this.props.mode === 'view') {
133
- event.stopPropagation();
134
- this.setState({
135
- showModeToggle: document.activeElement === this._editButtonRef
136
- });
137
- }
138
- };
139
- handleViewClick = event => {
140
- if (event.buttons === 1) {
141
- requestAnimationFrame(() => {
142
- this.enterEdit();
143
- });
144
- }
145
- };
146
- handleEditBlur = event => {
147
- this.enterView();
148
- };
149
- handleEditButtonFocus = event => {
150
- this.setState({
151
- showModeToggle: true
152
- });
153
- };
154
- handleEditButtonBlur = event => {
155
- this.setState({
156
- showModeToggle: false
157
- });
158
- };
159
- handleEditButtonClick = event => {
160
- this.enterEdit();
161
- };
162
- ref = null;
163
- handleContainerRef = el => {
164
- const elementRef = this.props.elementRef;
165
- this.ref = el;
166
-
167
- if (typeof elementRef === 'function') {
168
- elementRef(el);
169
- }
170
- }; // ------- prop getters ------
171
-
172
- getContainerProps = (() => {
173
- var _this = this;
174
-
175
- return function () {
176
- let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
177
- const _this$props2 = _this.props,
178
- mode = _this$props2.mode,
179
- readOnly = _this$props2.readOnly;
180
- return {
181
- onMouseOver: _this.handleViewMouseOver,
182
- onMouseOut: _this.handleViewMouseOut,
183
- onMouseDown: mode !== 'edit' ? _this.handleViewClick : null,
184
- onKeyUp: mode === 'edit' ? _this.handleEditESC : null,
185
- readOnly,
186
- ...props,
187
- ref: _this.handleContainerRef
188
- };
189
- };
190
- })();
191
- getViewerProps = (() => {
192
- var _this2 = this;
193
-
194
- return function () {
195
- let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
196
- return {
197
- mode: _this2.props.mode,
198
- readOnly: _this2.props.readOnly,
199
- ...props
200
- };
201
- };
202
- })();
203
- getEditorProps = props => {
204
- return {
205
- mode: this.props.mode,
206
- onBlur: this.handleEditBlur,
207
- editorRef: el => {
208
- this._editorRef = el;
209
- },
210
- readOnly: this.props.readOnly,
211
- ...props
212
- };
213
- };
214
- getEditButtonProps = (() => {
215
- var _this3 = this;
216
-
217
- return function () {
218
- let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
219
- return {
220
- onClick: _this3.handleEditButtonClick,
221
- onFocus: _this3.handleEditButtonFocus,
222
- onBlur: _this3.handleEditButtonBlur,
223
- isVisible: _this3.state.showModeToggle,
224
- buttonRef: el => {
225
- _this3._editButtonRef = el;
226
- },
227
- readOnly: _this3.props.readOnly,
228
- ...props
229
- };
230
- };
231
- })();
232
-
233
229
  render() {
234
230
  const _this$props3 = this.props,
235
231
  children = _this$props3.children,
@@ -252,5 +248,12 @@ class Editable extends Component {
252
248
 
253
249
  }
254
250
 
251
+ Editable.displayName = "Editable";
252
+ Editable.propTypes = propTypes;
253
+ Editable.allowedProps = allowedProps;
254
+ Editable.defaultProps = {
255
+ readOnly: false,
256
+ children: null
257
+ };
255
258
  export default Editable;
256
259
  export { Editable };
@@ -2,7 +2,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
2
2
  const _excluded = ["buttonRef"],
3
3
  _excluded2 = ["isVisible", "readOnly", "label"];
4
4
 
5
- var _dec, _class;
5
+ var _dec, _class, _class2;
6
6
 
7
7
  /*
8
8
  * The MIT License (MIT)
@@ -46,24 +46,39 @@ import { propTypes, allowedProps } from './props';
46
46
  category: components
47
47
  ---
48
48
  **/
49
- let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class InPlaceEdit extends Component {
50
- static displayName = "InPlaceEdit";
51
- static componentId = 'InPlaceEdit';
52
- static propTypes = propTypes;
53
- static allowedProps = allowedProps;
54
- static defaultProps = {
55
- readOnly: false,
56
- showFocusRing: true,
57
- inline: true,
58
- editButtonPlacement: 'end'
59
- };
60
- ref = null;
61
- handleRef = el => {
62
- this.ref = el;
63
- };
64
-
49
+ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2 = class InPlaceEdit extends Component {
65
50
  constructor(props) {
66
51
  super(props);
52
+ this.ref = null;
53
+
54
+ this.handleRef = el => {
55
+ this.ref = el;
56
+ };
57
+
58
+ this.handleEditButtonRef = el => {
59
+ this._editButtonRef = el;
60
+ };
61
+
62
+ this.renderAll = _ref => {
63
+ let getContainerProps = _ref.getContainerProps,
64
+ getViewerProps = _ref.getViewerProps,
65
+ getEditorProps = _ref.getEditorProps,
66
+ getEditButtonProps = _ref.getEditButtonProps;
67
+ const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
68
+ const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
69
+ const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
70
+ return jsx(Flex, Object.assign({
71
+ display: this.props.inline ? 'inline-flex' : 'flex',
72
+ direction: flexDir,
73
+ justifyItems: justifyItems
74
+ }, getContainerProps()), jsx(Flex.Item, {
75
+ shouldGrow: true,
76
+ shouldShrink: true
77
+ }, this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())), jsx(Flex.Item, {
78
+ margin: buttonMargin
79
+ }, this.renderEditButton(getEditButtonProps())));
80
+ };
81
+
67
82
  warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
68
83
  }
69
84
 
@@ -75,17 +90,13 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
75
90
  this.props.makeStyles();
76
91
  }
77
92
 
78
- handleEditButtonRef = el => {
79
- this._editButtonRef = el;
80
- };
81
-
82
- renderEditor(_ref) {
93
+ renderEditor(_ref2) {
83
94
  var _this$props$styles;
84
95
 
85
- let mode = _ref.mode,
86
- onBlur = _ref.onBlur,
87
- editorRef = _ref.editorRef,
88
- readOnly = _ref.readOnly;
96
+ let mode = _ref2.mode,
97
+ onBlur = _ref2.onBlur,
98
+ editorRef = _ref2.editorRef,
99
+ readOnly = _ref2.readOnly;
89
100
  const _this$props = this.props,
90
101
  showFocusRing = _this$props.showFocusRing,
91
102
  renderEditor = _this$props.renderEditor;
@@ -104,15 +115,15 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
104
115
  })) : null;
105
116
  }
106
117
 
107
- renderViewer(_ref2) {
108
- let readOnly = _ref2.readOnly,
109
- mode = _ref2.mode;
118
+ renderViewer(_ref3) {
119
+ let readOnly = _ref3.readOnly,
120
+ mode = _ref3.mode;
110
121
  return readOnly || mode === 'view' ? this.props.renderViewer() : null;
111
122
  }
112
123
 
113
- renderEditButton(_ref3) {
114
- let buttonRef = _ref3.buttonRef,
115
- rest = _objectWithoutProperties(_ref3, _excluded);
124
+ renderEditButton(_ref4) {
125
+ let buttonRef = _ref4.buttonRef,
126
+ rest = _objectWithoutProperties(_ref4, _excluded);
116
127
 
117
128
  return this.props.renderEditButton({
118
129
  elementRef: createChainedFunction(this.handleEditButtonRef, buttonRef),
@@ -122,43 +133,6 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
122
133
  // the margin makes room for the focus ring
123
134
 
124
135
 
125
- static renderDefaultEditButton = _ref4 => {
126
- let isVisible = _ref4.isVisible,
127
- readOnly = _ref4.readOnly,
128
- label = _ref4.label,
129
- buttonProps = _objectWithoutProperties(_ref4, _excluded2);
130
-
131
- if (readOnly) {
132
- return null;
133
- }
134
-
135
- return jsx(IconButton, Object.assign({
136
- size: "small",
137
- screenReaderLabel: label,
138
- withBackground: false,
139
- withBorder: false
140
- }, buttonProps), isVisible ? IconEditLine : null);
141
- };
142
- renderAll = _ref5 => {
143
- let getContainerProps = _ref5.getContainerProps,
144
- getViewerProps = _ref5.getViewerProps,
145
- getEditorProps = _ref5.getEditorProps,
146
- getEditButtonProps = _ref5.getEditButtonProps;
147
- const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
148
- const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
149
- const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
150
- return jsx(Flex, Object.assign({
151
- display: this.props.inline ? 'inline-flex' : 'flex',
152
- direction: flexDir,
153
- justifyItems: justifyItems
154
- }, getContainerProps()), jsx(Flex.Item, {
155
- shouldGrow: true,
156
- shouldShrink: true
157
- }, this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())), jsx(Flex.Item, {
158
- margin: buttonMargin
159
- }, this.renderEditButton(getEditButtonProps())));
160
- };
161
-
162
136
  render() {
163
137
  const _this$props2 = this.props,
164
138
  mode = _this$props2.mode,
@@ -177,6 +151,27 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
177
151
  });
178
152
  }
179
153
 
180
- }) || _class);
154
+ }, _class2.displayName = "InPlaceEdit", _class2.componentId = 'InPlaceEdit', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
155
+ readOnly: false,
156
+ showFocusRing: true,
157
+ inline: true,
158
+ editButtonPlacement: 'end'
159
+ }, _class2.renderDefaultEditButton = _ref5 => {
160
+ let isVisible = _ref5.isVisible,
161
+ readOnly = _ref5.readOnly,
162
+ label = _ref5.label,
163
+ buttonProps = _objectWithoutProperties(_ref5, _excluded2);
164
+
165
+ if (readOnly) {
166
+ return null;
167
+ }
168
+
169
+ return jsx(IconButton, Object.assign({
170
+ size: "small",
171
+ screenReaderLabel: label,
172
+ withBackground: false,
173
+ withBorder: false
174
+ }, buttonProps), isVisible ? IconEditLine : null);
175
+ }, _class2)) || _class);
181
176
  export default InPlaceEdit;
182
177
  export { InPlaceEdit };
@@ -13,7 +13,7 @@ var _console = require("@instructure/console");
13
13
 
14
14
  var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
15
15
 
16
- var _props = require("./props");
16
+ var _props2 = require("./props");
17
17
 
18
18
  /*
19
19
  * The MIT License (MIT)
@@ -46,24 +46,136 @@ experimental: true
46
46
  ---
47
47
  **/
48
48
  class Editable extends _react.Component {
49
- static displayName = "Editable";
50
- static propTypes = _props.propTypes;
51
- static allowedProps = _props.allowedProps;
52
- static defaultProps = {
53
- readOnly: false,
54
- children: null
55
- };
56
- state = {
57
- showModeToggle: false,
58
- valueOnEdit: null // the value when mode flips from view -> edit
59
-
60
- };
61
- _editorRef = null;
62
- _editButtonRef = null;
63
-
64
- constructor(props) {
65
- super(props);
66
- (0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
49
+ constructor(_props) {
50
+ var _this;
51
+
52
+ super(_props);
53
+ _this = this;
54
+ this.state = {
55
+ showModeToggle: false,
56
+ valueOnEdit: null // the value when mode flips from view -> edit
57
+
58
+ };
59
+ this._editorRef = null;
60
+ this._editButtonRef = null;
61
+
62
+ this.handleEditESC = event => {
63
+ if (event.key === 'Escape') {
64
+ this.enterView();
65
+ }
66
+ };
67
+
68
+ this.handleViewMouseOver = event => {
69
+ if (this.props.mode === 'view') {
70
+ // because the mouse event handlers are on the container, not the view
71
+ event.stopPropagation();
72
+ this.setState({
73
+ showModeToggle: true
74
+ });
75
+ }
76
+ };
77
+
78
+ this.handleViewMouseOut = event => {
79
+ if (this.props.mode === 'view') {
80
+ event.stopPropagation();
81
+ this.setState({
82
+ showModeToggle: document.activeElement === this._editButtonRef
83
+ });
84
+ }
85
+ };
86
+
87
+ this.handleViewClick = event => {
88
+ if (event.buttons === 1) {
89
+ (0, _requestAnimationFrame.requestAnimationFrame)(() => {
90
+ this.enterEdit();
91
+ });
92
+ }
93
+ };
94
+
95
+ this.handleEditBlur = event => {
96
+ this.enterView();
97
+ };
98
+
99
+ this.handleEditButtonFocus = event => {
100
+ this.setState({
101
+ showModeToggle: true
102
+ });
103
+ };
104
+
105
+ this.handleEditButtonBlur = event => {
106
+ this.setState({
107
+ showModeToggle: false
108
+ });
109
+ };
110
+
111
+ this.handleEditButtonClick = event => {
112
+ this.enterEdit();
113
+ };
114
+
115
+ this.ref = null;
116
+
117
+ this.handleContainerRef = el => {
118
+ const elementRef = this.props.elementRef;
119
+ this.ref = el;
120
+
121
+ if (typeof elementRef === 'function') {
122
+ elementRef(el);
123
+ }
124
+ };
125
+
126
+ this.getContainerProps = function () {
127
+ let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
128
+ const _this$props = _this.props,
129
+ mode = _this$props.mode,
130
+ readOnly = _this$props.readOnly;
131
+ return {
132
+ onMouseOver: _this.handleViewMouseOver,
133
+ onMouseOut: _this.handleViewMouseOut,
134
+ onMouseDown: mode !== 'edit' ? _this.handleViewClick : null,
135
+ onKeyUp: mode === 'edit' ? _this.handleEditESC : null,
136
+ readOnly,
137
+ ...props,
138
+ ref: _this.handleContainerRef
139
+ };
140
+ };
141
+
142
+ this.getViewerProps = function () {
143
+ let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
144
+ return {
145
+ mode: _this.props.mode,
146
+ readOnly: _this.props.readOnly,
147
+ ...props
148
+ };
149
+ };
150
+
151
+ this.getEditorProps = props => {
152
+ return {
153
+ mode: this.props.mode,
154
+ onBlur: this.handleEditBlur,
155
+ editorRef: el => {
156
+ this._editorRef = el;
157
+ },
158
+ readOnly: this.props.readOnly,
159
+ ...props
160
+ };
161
+ };
162
+
163
+ this.getEditButtonProps = function () {
164
+ let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
165
+ return {
166
+ onClick: _this.handleEditButtonClick,
167
+ onFocus: _this.handleEditButtonFocus,
168
+ onBlur: _this.handleEditButtonBlur,
169
+ isVisible: _this.state.showModeToggle,
170
+ buttonRef: el => {
171
+ _this._editButtonRef = el;
172
+ },
173
+ readOnly: _this.props.readOnly,
174
+ ...props
175
+ };
176
+ };
177
+
178
+ (0, _console.logWarn)(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
67
179
  }
68
180
 
69
181
  componentDidMount() {
@@ -75,10 +187,10 @@ class Editable extends _react.Component {
75
187
  componentWillUnmount() {}
76
188
 
77
189
  componentDidUpdate(prevProps) {
78
- const _this$props = this.props,
79
- mode = _this$props.mode,
80
- value = _this$props.value,
81
- onChange = _this$props.onChange; // on the switch from view -> edit
190
+ const _this$props2 = this.props,
191
+ mode = _this$props2.mode,
192
+ value = _this$props2.value,
193
+ onChange = _this$props2.onChange; // on the switch from view -> edit
82
194
 
83
195
  if (prevProps.mode !== 'edit' && mode === 'edit') {
84
196
  this.setState({
@@ -126,122 +238,6 @@ class Editable extends _react.Component {
126
238
  }
127
239
  }
128
240
 
129
- handleEditESC = event => {
130
- if (event.key === 'Escape') {
131
- this.enterView();
132
- }
133
- };
134
- handleViewMouseOver = event => {
135
- if (this.props.mode === 'view') {
136
- // because the mouse event handlers are on the container, not the view
137
- event.stopPropagation();
138
- this.setState({
139
- showModeToggle: true
140
- });
141
- }
142
- };
143
- handleViewMouseOut = event => {
144
- if (this.props.mode === 'view') {
145
- event.stopPropagation();
146
- this.setState({
147
- showModeToggle: document.activeElement === this._editButtonRef
148
- });
149
- }
150
- };
151
- handleViewClick = event => {
152
- if (event.buttons === 1) {
153
- (0, _requestAnimationFrame.requestAnimationFrame)(() => {
154
- this.enterEdit();
155
- });
156
- }
157
- };
158
- handleEditBlur = event => {
159
- this.enterView();
160
- };
161
- handleEditButtonFocus = event => {
162
- this.setState({
163
- showModeToggle: true
164
- });
165
- };
166
- handleEditButtonBlur = event => {
167
- this.setState({
168
- showModeToggle: false
169
- });
170
- };
171
- handleEditButtonClick = event => {
172
- this.enterEdit();
173
- };
174
- ref = null;
175
- handleContainerRef = el => {
176
- const elementRef = this.props.elementRef;
177
- this.ref = el;
178
-
179
- if (typeof elementRef === 'function') {
180
- elementRef(el);
181
- }
182
- }; // ------- prop getters ------
183
-
184
- getContainerProps = (() => {
185
- var _this = this;
186
-
187
- return function () {
188
- let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
189
- const _this$props2 = _this.props,
190
- mode = _this$props2.mode,
191
- readOnly = _this$props2.readOnly;
192
- return {
193
- onMouseOver: _this.handleViewMouseOver,
194
- onMouseOut: _this.handleViewMouseOut,
195
- onMouseDown: mode !== 'edit' ? _this.handleViewClick : null,
196
- onKeyUp: mode === 'edit' ? _this.handleEditESC : null,
197
- readOnly,
198
- ...props,
199
- ref: _this.handleContainerRef
200
- };
201
- };
202
- })();
203
- getViewerProps = (() => {
204
- var _this2 = this;
205
-
206
- return function () {
207
- let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
208
- return {
209
- mode: _this2.props.mode,
210
- readOnly: _this2.props.readOnly,
211
- ...props
212
- };
213
- };
214
- })();
215
- getEditorProps = props => {
216
- return {
217
- mode: this.props.mode,
218
- onBlur: this.handleEditBlur,
219
- editorRef: el => {
220
- this._editorRef = el;
221
- },
222
- readOnly: this.props.readOnly,
223
- ...props
224
- };
225
- };
226
- getEditButtonProps = (() => {
227
- var _this3 = this;
228
-
229
- return function () {
230
- let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
231
- return {
232
- onClick: _this3.handleEditButtonClick,
233
- onFocus: _this3.handleEditButtonFocus,
234
- onBlur: _this3.handleEditButtonBlur,
235
- isVisible: _this3.state.showModeToggle,
236
- buttonRef: el => {
237
- _this3._editButtonRef = el;
238
- },
239
- readOnly: _this3.props.readOnly,
240
- ...props
241
- };
242
- };
243
- })();
244
-
245
241
  render() {
246
242
  const _this$props3 = this.props,
247
243
  children = _this$props3.children,
@@ -265,5 +261,12 @@ class Editable extends _react.Component {
265
261
  }
266
262
 
267
263
  exports.Editable = Editable;
264
+ Editable.displayName = "Editable";
265
+ Editable.propTypes = _props2.propTypes;
266
+ Editable.allowedProps = _props2.allowedProps;
267
+ Editable.defaultProps = {
268
+ readOnly: false,
269
+ children: null
270
+ };
268
271
  var _default = Editable;
269
272
  exports.default = _default;
@@ -34,31 +34,46 @@ var _props = require("./props");
34
34
  const _excluded = ["buttonRef"],
35
35
  _excluded2 = ["isVisible", "readOnly", "label"];
36
36
 
37
- var _dec, _class;
37
+ var _dec, _class, _class2;
38
38
 
39
39
  /**
40
40
  ---
41
41
  category: components
42
42
  ---
43
43
  **/
44
- let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_class = class InPlaceEdit extends _react.Component {
45
- static displayName = "InPlaceEdit";
46
- static componentId = 'InPlaceEdit';
47
- static propTypes = _props.propTypes;
48
- static allowedProps = _props.allowedProps;
49
- static defaultProps = {
50
- readOnly: false,
51
- showFocusRing: true,
52
- inline: true,
53
- editButtonPlacement: 'end'
54
- };
55
- ref = null;
56
- handleRef = el => {
57
- this.ref = el;
58
- };
59
-
44
+ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_class = (_class2 = class InPlaceEdit extends _react.Component {
60
45
  constructor(props) {
61
46
  super(props);
47
+ this.ref = null;
48
+
49
+ this.handleRef = el => {
50
+ this.ref = el;
51
+ };
52
+
53
+ this.handleEditButtonRef = el => {
54
+ this._editButtonRef = el;
55
+ };
56
+
57
+ this.renderAll = _ref => {
58
+ let getContainerProps = _ref.getContainerProps,
59
+ getViewerProps = _ref.getViewerProps,
60
+ getEditorProps = _ref.getEditorProps,
61
+ getEditButtonProps = _ref.getEditButtonProps;
62
+ const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
63
+ const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
64
+ const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
65
+ return (0, _emotion.jsx)(_Flex.Flex, Object.assign({
66
+ display: this.props.inline ? 'inline-flex' : 'flex',
67
+ direction: flexDir,
68
+ justifyItems: justifyItems
69
+ }, getContainerProps()), (0, _emotion.jsx)(_Flex.Flex.Item, {
70
+ shouldGrow: true,
71
+ shouldShrink: true
72
+ }, this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())), (0, _emotion.jsx)(_Flex.Flex.Item, {
73
+ margin: buttonMargin
74
+ }, this.renderEditButton(getEditButtonProps())));
75
+ };
76
+
62
77
  (0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
63
78
  }
64
79
 
@@ -70,17 +85,13 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
70
85
  this.props.makeStyles();
71
86
  }
72
87
 
73
- handleEditButtonRef = el => {
74
- this._editButtonRef = el;
75
- };
76
-
77
- renderEditor(_ref) {
88
+ renderEditor(_ref2) {
78
89
  var _this$props$styles;
79
90
 
80
- let mode = _ref.mode,
81
- onBlur = _ref.onBlur,
82
- editorRef = _ref.editorRef,
83
- readOnly = _ref.readOnly;
91
+ let mode = _ref2.mode,
92
+ onBlur = _ref2.onBlur,
93
+ editorRef = _ref2.editorRef,
94
+ readOnly = _ref2.readOnly;
84
95
  const _this$props = this.props,
85
96
  showFocusRing = _this$props.showFocusRing,
86
97
  renderEditor = _this$props.renderEditor;
@@ -99,15 +110,15 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
99
110
  })) : null;
100
111
  }
101
112
 
102
- renderViewer(_ref2) {
103
- let readOnly = _ref2.readOnly,
104
- mode = _ref2.mode;
113
+ renderViewer(_ref3) {
114
+ let readOnly = _ref3.readOnly,
115
+ mode = _ref3.mode;
105
116
  return readOnly || mode === 'view' ? this.props.renderViewer() : null;
106
117
  }
107
118
 
108
- renderEditButton(_ref3) {
109
- let buttonRef = _ref3.buttonRef,
110
- rest = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
119
+ renderEditButton(_ref4) {
120
+ let buttonRef = _ref4.buttonRef,
121
+ rest = (0, _objectWithoutProperties2.default)(_ref4, _excluded);
111
122
  return this.props.renderEditButton({
112
123
  elementRef: (0, _createChainedFunction.createChainedFunction)(this.handleEditButtonRef, buttonRef),
113
124
  ...rest
@@ -116,43 +127,6 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
116
127
  // the margin makes room for the focus ring
117
128
 
118
129
 
119
- static renderDefaultEditButton = _ref4 => {
120
- let isVisible = _ref4.isVisible,
121
- readOnly = _ref4.readOnly,
122
- label = _ref4.label,
123
- buttonProps = (0, _objectWithoutProperties2.default)(_ref4, _excluded2);
124
-
125
- if (readOnly) {
126
- return null;
127
- }
128
-
129
- return (0, _emotion.jsx)(_IconButton.IconButton, Object.assign({
130
- size: "small",
131
- screenReaderLabel: label,
132
- withBackground: false,
133
- withBorder: false
134
- }, buttonProps), isVisible ? _IconEditLine.IconEditLine : null);
135
- };
136
- renderAll = _ref5 => {
137
- let getContainerProps = _ref5.getContainerProps,
138
- getViewerProps = _ref5.getViewerProps,
139
- getEditorProps = _ref5.getEditorProps,
140
- getEditButtonProps = _ref5.getEditButtonProps;
141
- const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
142
- const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
143
- const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
144
- return (0, _emotion.jsx)(_Flex.Flex, Object.assign({
145
- display: this.props.inline ? 'inline-flex' : 'flex',
146
- direction: flexDir,
147
- justifyItems: justifyItems
148
- }, getContainerProps()), (0, _emotion.jsx)(_Flex.Flex.Item, {
149
- shouldGrow: true,
150
- shouldShrink: true
151
- }, this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())), (0, _emotion.jsx)(_Flex.Flex.Item, {
152
- margin: buttonMargin
153
- }, this.renderEditButton(getEditButtonProps())));
154
- };
155
-
156
130
  render() {
157
131
  const _this$props2 = this.props,
158
132
  mode = _this$props2.mode,
@@ -171,7 +145,28 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
171
145
  });
172
146
  }
173
147
 
174
- }) || _class);
148
+ }, _class2.displayName = "InPlaceEdit", _class2.componentId = 'InPlaceEdit', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
149
+ readOnly: false,
150
+ showFocusRing: true,
151
+ inline: true,
152
+ editButtonPlacement: 'end'
153
+ }, _class2.renderDefaultEditButton = _ref5 => {
154
+ let isVisible = _ref5.isVisible,
155
+ readOnly = _ref5.readOnly,
156
+ label = _ref5.label,
157
+ buttonProps = (0, _objectWithoutProperties2.default)(_ref5, _excluded2);
158
+
159
+ if (readOnly) {
160
+ return null;
161
+ }
162
+
163
+ return (0, _emotion.jsx)(_IconButton.IconButton, Object.assign({
164
+ size: "small",
165
+ screenReaderLabel: label,
166
+ withBackground: false,
167
+ withBorder: false
168
+ }, buttonProps), isVisible ? _IconEditLine.IconEditLine : null);
169
+ }, _class2)) || _class);
175
170
  exports.InPlaceEdit = InPlaceEdit;
176
171
  var _default = InPlaceEdit;
177
172
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-editable",
3
- "version": "8.25.1-snapshot-10",
3
+ "version": "8.25.1-snapshot-13",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,21 +23,21 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.25.1-snapshot-10",
27
- "@instructure/ui-test-utils": "8.25.1-snapshot-10"
26
+ "@instructure/ui-babel-preset": "8.25.1-snapshot-13",
27
+ "@instructure/ui-test-utils": "8.25.1-snapshot-13"
28
28
  },
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.13.10",
31
- "@instructure/console": "8.25.1-snapshot-10",
32
- "@instructure/emotion": "8.25.1-snapshot-10",
33
- "@instructure/ui-a11y-content": "8.25.1-snapshot-10",
34
- "@instructure/ui-buttons": "8.25.1-snapshot-10",
35
- "@instructure/ui-dom-utils": "8.25.1-snapshot-10",
36
- "@instructure/ui-flex": "8.25.1-snapshot-10",
37
- "@instructure/ui-focusable": "8.25.1-snapshot-10",
38
- "@instructure/ui-icons": "8.25.1-snapshot-10",
39
- "@instructure/ui-utils": "8.25.1-snapshot-10",
40
- "@instructure/ui-view": "8.25.1-snapshot-10",
31
+ "@instructure/console": "8.25.1-snapshot-13",
32
+ "@instructure/emotion": "8.25.1-snapshot-13",
33
+ "@instructure/ui-a11y-content": "8.25.1-snapshot-13",
34
+ "@instructure/ui-buttons": "8.25.1-snapshot-13",
35
+ "@instructure/ui-dom-utils": "8.25.1-snapshot-13",
36
+ "@instructure/ui-flex": "8.25.1-snapshot-13",
37
+ "@instructure/ui-focusable": "8.25.1-snapshot-13",
38
+ "@instructure/ui-icons": "8.25.1-snapshot-13",
39
+ "@instructure/ui-utils": "8.25.1-snapshot-13",
40
+ "@instructure/ui-view": "8.25.1-snapshot-13",
41
41
  "prop-types": "^15"
42
42
  },
43
43
  "peerDependencies": {