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

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-1](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-1) (2022-06-10)
6
+ ## [8.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-editable
9
9
 
@@ -34,136 +34,24 @@ experimental: true
34
34
  ---
35
35
  **/
36
36
  class Editable extends Component {
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"');
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"');
167
55
  }
168
56
 
169
57
  componentDidMount() {
@@ -175,10 +63,10 @@ class Editable extends Component {
175
63
  componentWillUnmount() {}
176
64
 
177
65
  componentDidUpdate(prevProps) {
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
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
182
70
 
183
71
  if (prevProps.mode !== 'edit' && mode === 'edit') {
184
72
  this.setState({
@@ -226,6 +114,122 @@ class Editable extends Component {
226
114
  }
227
115
  }
228
116
 
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
+
229
233
  render() {
230
234
  const _this$props3 = this.props,
231
235
  children = _this$props3.children,
@@ -248,12 +252,5 @@ class Editable extends Component {
248
252
 
249
253
  }
250
254
 
251
- Editable.displayName = "Editable";
252
- Editable.propTypes = propTypes;
253
- Editable.allowedProps = allowedProps;
254
- Editable.defaultProps = {
255
- readOnly: false,
256
- children: null
257
- };
258
255
  export default Editable;
259
256
  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, _class2;
5
+ var _dec, _class;
6
6
 
7
7
  /*
8
8
  * The MIT License (MIT)
@@ -46,39 +46,24 @@ import { propTypes, allowedProps } from './props';
46
46
  category: components
47
47
  ---
48
48
  **/
49
- let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2 = class InPlaceEdit extends Component {
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
+
50
65
  constructor(props) {
51
66
  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
-
82
67
  warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
83
68
  }
84
69
 
@@ -90,13 +75,17 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
90
75
  this.props.makeStyles();
91
76
  }
92
77
 
93
- renderEditor(_ref2) {
78
+ handleEditButtonRef = el => {
79
+ this._editButtonRef = el;
80
+ };
81
+
82
+ renderEditor(_ref) {
94
83
  var _this$props$styles;
95
84
 
96
- let mode = _ref2.mode,
97
- onBlur = _ref2.onBlur,
98
- editorRef = _ref2.editorRef,
99
- readOnly = _ref2.readOnly;
85
+ let mode = _ref.mode,
86
+ onBlur = _ref.onBlur,
87
+ editorRef = _ref.editorRef,
88
+ readOnly = _ref.readOnly;
100
89
  const _this$props = this.props,
101
90
  showFocusRing = _this$props.showFocusRing,
102
91
  renderEditor = _this$props.renderEditor;
@@ -115,15 +104,15 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
115
104
  })) : null;
116
105
  }
117
106
 
118
- renderViewer(_ref3) {
119
- let readOnly = _ref3.readOnly,
120
- mode = _ref3.mode;
107
+ renderViewer(_ref2) {
108
+ let readOnly = _ref2.readOnly,
109
+ mode = _ref2.mode;
121
110
  return readOnly || mode === 'view' ? this.props.renderViewer() : null;
122
111
  }
123
112
 
124
- renderEditButton(_ref4) {
125
- let buttonRef = _ref4.buttonRef,
126
- rest = _objectWithoutProperties(_ref4, _excluded);
113
+ renderEditButton(_ref3) {
114
+ let buttonRef = _ref3.buttonRef,
115
+ rest = _objectWithoutProperties(_ref3, _excluded);
127
116
 
128
117
  return this.props.renderEditButton({
129
118
  elementRef: createChainedFunction(this.handleEditButtonRef, buttonRef),
@@ -133,6 +122,43 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
133
122
  // the margin makes room for the focus ring
134
123
 
135
124
 
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
+
136
162
  render() {
137
163
  const _this$props2 = this.props,
138
164
  mode = _this$props2.mode,
@@ -151,27 +177,6 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2
151
177
  });
152
178
  }
153
179
 
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);
180
+ }) || _class);
176
181
  export default InPlaceEdit;
177
182
  export { InPlaceEdit };