@instructure/ui-editable 11.7.8 → 11.7.9-pr-snapshot-1792147648392

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.
@@ -1,28 +1,5 @@
1
- var _dec, _class;
2
- /*
3
- * The MIT License (MIT)
4
- *
5
- * Copyright (c) 2015 - present Instructure, Inc.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
-
1
+ import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
26
3
  import { Component } from 'react';
27
4
  import { Flex } from '@instructure/ui-flex/v11_6';
28
5
  import { IconButton } from '@instructure/ui-buttons/v11_6';
@@ -34,143 +11,118 @@ import { View } from '@instructure/ui-view/v11_6';
34
11
  import { Editable } from '../../Editable/v1/index.js';
35
12
  import generateStyle from './styles.js';
36
13
  import { allowedProps } from './props.js';
37
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
38
- /**
39
- ---
40
- category: components
41
- ---
42
- **/
43
- let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class InPlaceEdit extends Component {
44
- static displayName = 'InPlaceEdit';
45
- static componentId = 'InPlaceEdit';
46
- static allowedProps = allowedProps;
47
- static defaultProps = {
48
- readOnly: false,
49
- showFocusRing: true,
50
- inline: true,
51
- editButtonPlacement: 'end'
52
- };
53
- ref = null;
54
- _editButtonRef = null;
55
- handleRef = el => {
56
- this.ref = el;
57
- };
58
- constructor(props) {
59
- super(props);
60
- warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
61
- }
62
- componentDidMount() {
63
- this.props.makeStyles?.();
64
- }
65
- componentDidUpdate() {
66
- this.props.makeStyles?.();
67
- }
68
- handleEditButtonRef = el => {
69
- this._editButtonRef = el;
70
- };
71
- renderEditor({
72
- mode,
73
- onBlur,
74
- editorRef,
75
- readOnly
76
- }) {
77
- const {
78
- showFocusRing,
79
- renderEditor
80
- } = this.props;
81
- const isEditMode = !readOnly && mode === 'edit';
82
- return isEditMode ? _jsx(View, {
83
- as: "span",
84
- display: "block",
85
- withFocusOutline: showFocusRing,
86
- position: "relative",
87
- css: this.props.styles?.inPlaceEdit,
88
- borderRadius: "medium",
89
- margin: "auto",
90
- children: renderEditor({
91
- onBlur,
92
- editorRef
93
- })
94
- }) : null;
95
- }
96
- renderViewer({
97
- readOnly,
98
- mode
99
- }) {
100
- return readOnly || mode === 'view' ? this.props.renderViewer() : null;
101
- }
102
- renderEditButton({
103
- buttonRef,
104
- ...rest
105
- }) {
106
- return this.props.renderEditButton({
107
- elementRef: createChainedFunction(this.handleEditButtonRef, buttonRef),
108
- ...rest
109
- });
110
- }
111
-
112
- // Render a default edit button, an icon button with the edit icon
113
- // the margin makes room for the focus ring
114
- static renderDefaultEditButton = ({
115
- isVisible,
116
- readOnly,
117
- label,
118
- ...buttonProps
119
- }) => {
120
- if (readOnly) {
121
- return null;
14
+ class InPlaceEdit extends Component {
15
+ static{
16
+ this.displayName = 'InPlaceEdit';
17
+ }
18
+ static{
19
+ this.componentId = 'InPlaceEdit';
20
+ }
21
+ static{
22
+ this.allowedProps = allowedProps;
23
+ }
24
+ static{
25
+ this.defaultProps = {
26
+ readOnly: false,
27
+ showFocusRing: true,
28
+ inline: true,
29
+ editButtonPlacement: 'end'
30
+ };
31
+ }
32
+ constructor(props){
33
+ super(props), this.ref = null, this._editButtonRef = null, this.handleRef = (el)=>{
34
+ this.ref = el;
35
+ }, this.handleEditButtonRef = (el)=>{
36
+ this._editButtonRef = el;
37
+ }, this.renderAll = ({ getContainerProps, getViewerProps, getEditorProps, getEditButtonProps })=>{
38
+ const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
39
+ const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
40
+ const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
41
+ return /*#__PURE__*/ _jsxs(Flex, {
42
+ display: this.props.inline ? 'inline-flex' : 'flex',
43
+ direction: flexDir,
44
+ justifyItems: justifyItems,
45
+ ...getContainerProps(),
46
+ children: [
47
+ /*#__PURE__*/ _jsxs(Flex.Item, {
48
+ shouldGrow: true,
49
+ shouldShrink: true,
50
+ children: [
51
+ this.renderEditor(getEditorProps()),
52
+ this.renderViewer(getViewerProps())
53
+ ]
54
+ }),
55
+ /*#__PURE__*/ _jsx(Flex.Item, {
56
+ margin: buttonMargin,
57
+ children: this.renderEditButton(getEditButtonProps())
58
+ })
59
+ ]
60
+ });
61
+ };
62
+ warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
63
+ }
64
+ componentDidMount() {
65
+ this.props.makeStyles?.();
66
+ }
67
+ componentDidUpdate() {
68
+ this.props.makeStyles?.();
69
+ }
70
+ renderEditor({ mode, onBlur, editorRef, readOnly }) {
71
+ const { showFocusRing, renderEditor } = this.props;
72
+ const isEditMode = !readOnly && mode === 'edit';
73
+ return isEditMode ? /*#__PURE__*/ _jsx(View, {
74
+ as: "span",
75
+ display: "block",
76
+ withFocusOutline: showFocusRing,
77
+ position: "relative",
78
+ css: this.props.styles?.inPlaceEdit,
79
+ borderRadius: "medium",
80
+ margin: "auto",
81
+ children: renderEditor({
82
+ onBlur,
83
+ editorRef
84
+ })
85
+ }) : null;
86
+ }
87
+ renderViewer({ readOnly, mode }) {
88
+ return readOnly || mode === 'view' ? this.props.renderViewer() : null;
89
+ }
90
+ renderEditButton({ buttonRef, ...rest }) {
91
+ return this.props.renderEditButton({
92
+ elementRef: createChainedFunction(this.handleEditButtonRef, buttonRef),
93
+ ...rest
94
+ });
95
+ }
96
+ static{
97
+ this.renderDefaultEditButton = ({ isVisible, readOnly, label, ...buttonProps })=>{
98
+ if (readOnly) {
99
+ return null;
100
+ }
101
+ return /*#__PURE__*/ _jsx(IconButton, {
102
+ size: "small",
103
+ screenReaderLabel: label,
104
+ withBackground: false,
105
+ withBorder: false,
106
+ ...buttonProps,
107
+ children: isVisible ? IconEditLine : null
108
+ });
109
+ };
110
+ }
111
+ render() {
112
+ const { mode, value, onChange, onChangeMode, readOnly } = this.props;
113
+ return /*#__PURE__*/ _jsx(Editable, {
114
+ mode: mode,
115
+ onChangeMode: onChangeMode,
116
+ render: this.renderAll,
117
+ value: value,
118
+ onChange: onChange,
119
+ readOnly: readOnly,
120
+ elementRef: this.handleRef
121
+ });
122
122
  }
123
- return _jsx(IconButton, {
124
- size: "small",
125
- screenReaderLabel: label,
126
- withBackground: false,
127
- withBorder: false,
128
- ...buttonProps,
129
- children: isVisible ? IconEditLine : null
130
- });
131
- };
132
- renderAll = ({
133
- getContainerProps,
134
- getViewerProps,
135
- getEditorProps,
136
- getEditButtonProps
137
- }) => {
138
- const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
139
- const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
140
- const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
141
- return _jsxs(Flex, {
142
- display: this.props.inline ? 'inline-flex' : 'flex',
143
- direction: flexDir,
144
- justifyItems: justifyItems,
145
- ...getContainerProps(),
146
- children: [_jsxs(Flex.Item, {
147
- shouldGrow: true,
148
- shouldShrink: true,
149
- children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
150
- }), _jsx(Flex.Item, {
151
- margin: buttonMargin,
152
- children: this.renderEditButton(getEditButtonProps())
153
- })]
154
- });
155
- };
156
- render() {
157
- const {
158
- mode,
159
- value,
160
- onChange,
161
- onChangeMode,
162
- readOnly
163
- } = this.props;
164
- return _jsx(Editable, {
165
- mode: mode,
166
- onChangeMode: onChangeMode,
167
- render: this.renderAll,
168
- value: value,
169
- onChange: onChange,
170
- readOnly: readOnly,
171
- elementRef: this.handleRef
172
- });
173
- }
174
- }) || _class);
123
+ }
124
+ InPlaceEdit = _ts_decorate([
125
+ withStyle(generateStyle, null)
126
+ ], InPlaceEdit);
175
127
  export default InPlaceEdit;
176
- export { InPlaceEdit };
128
+ export { InPlaceEdit };
@@ -1,26 +1,14 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- const allowedProps = ['renderViewer', 'renderEditor', 'renderEditButton', 'mode', 'onChangeMode', 'value', 'onChange', 'readOnly', 'showFocusRing', 'editButtonPlacement', 'inline'];
26
- export { allowedProps };
1
+ const allowedProps = [
2
+ 'renderViewer',
3
+ 'renderEditor',
4
+ 'renderEditButton',
5
+ 'mode',
6
+ 'onChangeMode',
7
+ 'value',
8
+ 'onChange',
9
+ 'readOnly',
10
+ 'showFocusRing',
11
+ 'editButtonPlacement',
12
+ 'inline'
13
+ ];
14
+ export { allowedProps };
@@ -1,55 +1,21 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * private: true
28
- * ---
29
- * Generates the style object from the theme and provided additional information
30
- * @param {Object} componentTheme The theme variable object.
31
- * @param {Object} props the props of the component, the style is applied to
32
- * @param {Object} state the state of the component, the style is applied to
33
- * @return {Object} The final style object, which will be used in the component
34
- */
35
- const generateStyle = () => {
36
- return {
37
- inPlaceEdit: {
38
- label: 'inPlaceEdit',
39
- boxSizing: 'border-box',
40
- maxWidth: '100%',
41
- position: 'relative',
42
- overflow: 'visible',
43
- direction: 'inherit',
44
- margin: 0,
45
- textDecoration: 'none' /* for links styled as buttons */,
46
- textAlign: 'inherit',
47
- userSelect: 'none',
48
- touchAction: 'manipulation',
49
- background: 'transparent',
50
- border: 'none',
51
- outline: 'none'
52
- }
53
- };
1
+ const generateStyle = ()=>{
2
+ return {
3
+ inPlaceEdit: {
4
+ label: 'inPlaceEdit',
5
+ boxSizing: 'border-box',
6
+ maxWidth: '100%',
7
+ position: 'relative',
8
+ overflow: 'visible',
9
+ direction: 'inherit',
10
+ margin: 0,
11
+ textDecoration: 'none',
12
+ textAlign: 'inherit',
13
+ userSelect: 'none',
14
+ touchAction: 'manipulation',
15
+ background: 'transparent',
16
+ border: 'none',
17
+ outline: 'none'
18
+ }
19
+ };
54
20
  };
55
- export default generateStyle;
21
+ export default generateStyle;