@instructure/ui-editable 8.25.1-snapshot-7 → 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.
@@ -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 _props2 = require("./props");
16
+ var _props = require("./props");
17
17
 
18
18
  /*
19
19
  * The MIT License (MIT)
@@ -46,136 +46,24 @@ experimental: true
46
46
  ---
47
47
  **/
48
48
  class Editable extends _react.Component {
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"');
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"');
179
67
  }
180
68
 
181
69
  componentDidMount() {
@@ -187,10 +75,10 @@ class Editable extends _react.Component {
187
75
  componentWillUnmount() {}
188
76
 
189
77
  componentDidUpdate(prevProps) {
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
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
194
82
 
195
83
  if (prevProps.mode !== 'edit' && mode === 'edit') {
196
84
  this.setState({
@@ -238,6 +126,122 @@ class Editable extends _react.Component {
238
126
  }
239
127
  }
240
128
 
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
+
241
245
  render() {
242
246
  const _this$props3 = this.props,
243
247
  children = _this$props3.children,
@@ -261,12 +265,5 @@ class Editable extends _react.Component {
261
265
  }
262
266
 
263
267
  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
- };
271
268
  var _default = Editable;
272
269
  exports.default = _default;
@@ -34,46 +34,31 @@ var _props = require("./props");
34
34
  const _excluded = ["buttonRef"],
35
35
  _excluded2 = ["isVisible", "readOnly", "label"];
36
36
 
37
- var _dec, _class, _class2;
37
+ var _dec, _class;
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 = (_class2 = class InPlaceEdit extends _react.Component {
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
+
45
60
  constructor(props) {
46
61
  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
-
77
62
  (0, _console.logWarn)(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
78
63
  }
79
64
 
@@ -85,13 +70,17 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
85
70
  this.props.makeStyles();
86
71
  }
87
72
 
88
- renderEditor(_ref2) {
73
+ handleEditButtonRef = el => {
74
+ this._editButtonRef = el;
75
+ };
76
+
77
+ renderEditor(_ref) {
89
78
  var _this$props$styles;
90
79
 
91
- let mode = _ref2.mode,
92
- onBlur = _ref2.onBlur,
93
- editorRef = _ref2.editorRef,
94
- readOnly = _ref2.readOnly;
80
+ let mode = _ref.mode,
81
+ onBlur = _ref.onBlur,
82
+ editorRef = _ref.editorRef,
83
+ readOnly = _ref.readOnly;
95
84
  const _this$props = this.props,
96
85
  showFocusRing = _this$props.showFocusRing,
97
86
  renderEditor = _this$props.renderEditor;
@@ -110,15 +99,15 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
110
99
  })) : null;
111
100
  }
112
101
 
113
- renderViewer(_ref3) {
114
- let readOnly = _ref3.readOnly,
115
- mode = _ref3.mode;
102
+ renderViewer(_ref2) {
103
+ let readOnly = _ref2.readOnly,
104
+ mode = _ref2.mode;
116
105
  return readOnly || mode === 'view' ? this.props.renderViewer() : null;
117
106
  }
118
107
 
119
- renderEditButton(_ref4) {
120
- let buttonRef = _ref4.buttonRef,
121
- rest = (0, _objectWithoutProperties2.default)(_ref4, _excluded);
108
+ renderEditButton(_ref3) {
109
+ let buttonRef = _ref3.buttonRef,
110
+ rest = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
122
111
  return this.props.renderEditButton({
123
112
  elementRef: (0, _createChainedFunction.createChainedFunction)(this.handleEditButtonRef, buttonRef),
124
113
  ...rest
@@ -127,6 +116,43 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
127
116
  // the margin makes room for the focus ring
128
117
 
129
118
 
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
+
130
156
  render() {
131
157
  const _this$props2 = this.props,
132
158
  mode = _this$props2.mode,
@@ -145,28 +171,7 @@ let InPlaceEdit = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec(_
145
171
  });
146
172
  }
147
173
 
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);
174
+ }) || _class);
170
175
  exports.InPlaceEdit = InPlaceEdit;
171
176
  var _default = InPlaceEdit;
172
177
  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-7",
3
+ "version": "8.25.1-snapshot-10",
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-7",
27
- "@instructure/ui-test-utils": "8.25.1-snapshot-7"
26
+ "@instructure/ui-babel-preset": "8.25.1-snapshot-10",
27
+ "@instructure/ui-test-utils": "8.25.1-snapshot-10"
28
28
  },
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.13.10",
31
- "@instructure/console": "8.25.1-snapshot-7",
32
- "@instructure/emotion": "8.25.1-snapshot-7",
33
- "@instructure/ui-a11y-content": "8.25.1-snapshot-7",
34
- "@instructure/ui-buttons": "8.25.1-snapshot-7",
35
- "@instructure/ui-dom-utils": "8.25.1-snapshot-7",
36
- "@instructure/ui-flex": "8.25.1-snapshot-7",
37
- "@instructure/ui-focusable": "8.25.1-snapshot-7",
38
- "@instructure/ui-icons": "8.25.1-snapshot-7",
39
- "@instructure/ui-utils": "8.25.1-snapshot-7",
40
- "@instructure/ui-view": "8.25.1-snapshot-7",
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",
41
41
  "prop-types": "^15"
42
42
  },
43
43
  "peerDependencies": {