decap-cms-widget-list 3.6.0 → 3.6.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 +10 -0
- package/dist/decap-cms-widget-list.js +4 -4
- package/dist/decap-cms-widget-list.js.LICENSE.txt +19 -0
- package/dist/decap-cms-widget-list.js.map +1 -1
- package/dist/esm/ListControl.js +135 -109
- package/package.json +17 -14
- package/src/ListControl.js +16 -4
- package/src/__tests__/ListControl.spec.js +73 -1
- package/LICENSE +0 -22
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-widget-list",
|
|
3
3
|
"description": "Widget for editing lists in Decap CMS.",
|
|
4
|
-
"version": "3.6.
|
|
4
|
+
"version": "3.6.2",
|
|
5
5
|
"homepage": "https://www.decapcms.org/docs/widgets/#list",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-list"
|
|
9
|
+
},
|
|
7
10
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
8
11
|
"module": "dist/esm/index.js",
|
|
9
12
|
"main": "dist/decap-cms-widget-list.js",
|
|
@@ -15,11 +18,6 @@
|
|
|
15
18
|
"object"
|
|
16
19
|
],
|
|
17
20
|
"sideEffects": false,
|
|
18
|
-
"scripts": {
|
|
19
|
-
"develop": "npm run build:esm -- --watch",
|
|
20
|
-
"build": "cross-env NODE_ENV=production webpack",
|
|
21
|
-
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore \"**/__tests__\" --root-mode upward"
|
|
22
|
-
},
|
|
23
21
|
"dependencies": {
|
|
24
22
|
"@dnd-kit/core": "^6.0.8",
|
|
25
23
|
"@dnd-kit/modifiers": "^6.0.1",
|
|
@@ -29,14 +27,19 @@
|
|
|
29
27
|
"peerDependencies": {
|
|
30
28
|
"@emotion/react": "^11.11.1",
|
|
31
29
|
"@emotion/styled": "^11.11.0",
|
|
32
|
-
"
|
|
33
|
-
"decap-cms-ui-default": "^3.0.0",
|
|
34
|
-
"decap-cms-widget-object": "^3.0.0",
|
|
35
|
-
"immutable": "^3.7.6",
|
|
30
|
+
"immutable": "^4.3.9",
|
|
36
31
|
"lodash": "^4.17.11",
|
|
37
32
|
"prop-types": "^15.7.2",
|
|
38
33
|
"react": "^19.1.0",
|
|
39
|
-
"react-immutable-proptypes": "^2.1.0"
|
|
34
|
+
"react-immutable-proptypes": "^2.1.0",
|
|
35
|
+
"uuid": "^8.3.2",
|
|
36
|
+
"decap-cms-lib-widgets": "3.4.2",
|
|
37
|
+
"decap-cms-ui-default": "3.9.2",
|
|
38
|
+
"decap-cms-widget-object": "3.7.2"
|
|
40
39
|
},
|
|
41
|
-
"
|
|
42
|
-
|
|
40
|
+
"scripts": {
|
|
41
|
+
"develop": "pnpm run build:esm --watch",
|
|
42
|
+
"build": "cross-env NODE_ENV=production webpack",
|
|
43
|
+
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore \"**/__tests__\" --root-mode upward"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/ListControl.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Component } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
4
4
|
import styled from '@emotion/styled';
|
|
@@ -171,7 +171,7 @@ function LabelComponent({ field, isActive, hasErrors, uniqueFieldId, isFieldOpti
|
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
export default class ListControl extends
|
|
174
|
+
export default class ListControl extends Component {
|
|
175
175
|
childRefs = {};
|
|
176
176
|
|
|
177
177
|
static propTypes = {
|
|
@@ -419,20 +419,32 @@ export default class ListControl extends React.Component {
|
|
|
419
419
|
getObjectValue = idx => this.props.value.get(idx) || Map();
|
|
420
420
|
|
|
421
421
|
handleChangeFor(index) {
|
|
422
|
+
const key = this.state.keys[index];
|
|
423
|
+
|
|
422
424
|
return (f, newValue, newMetadata) => {
|
|
423
425
|
const { value, metadata, onChange, field } = this.props;
|
|
426
|
+
|
|
427
|
+
// Resolve the item's position when the change fires rather than when this
|
|
428
|
+
// handler was created. If an item has been removed or moved in between,
|
|
429
|
+
// `index` now points at a different item, or past the end of the list.
|
|
430
|
+
const currentIndex = this.state.keys.indexOf(key);
|
|
431
|
+
|
|
432
|
+
if (currentIndex === -1) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
424
436
|
const collectionName = field.get('name');
|
|
425
437
|
const listFieldObjectWidget = field.getIn(['field', 'widget']) === 'object';
|
|
426
438
|
const withNameKey =
|
|
427
439
|
this.getValueType() !== valueTypes.SINGLE ||
|
|
428
440
|
(this.getValueType() === valueTypes.SINGLE && listFieldObjectWidget);
|
|
429
441
|
const newObjectValue = withNameKey
|
|
430
|
-
? this.getObjectValue(
|
|
442
|
+
? this.getObjectValue(currentIndex).set(f.get('name'), newValue)
|
|
431
443
|
: newValue;
|
|
432
444
|
const parsedMetadata = {
|
|
433
445
|
[collectionName]: Object.assign(metadata ? metadata.toJS() : {}, newMetadata || {}),
|
|
434
446
|
};
|
|
435
|
-
onChange(value.set(
|
|
447
|
+
onChange(value.set(currentIndex, newObjectValue), parsedMetadata);
|
|
436
448
|
};
|
|
437
449
|
}
|
|
438
450
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { fireEvent, render } from '@testing-library/react';
|
|
3
2
|
import { fromJS } from 'immutable';
|
|
4
3
|
|
|
@@ -787,4 +786,77 @@ describe('ListControl', () => {
|
|
|
787
786
|
listControl.validate();
|
|
788
787
|
expect(props.onValidateObject).toHaveBeenCalledWith('forID', []);
|
|
789
788
|
});
|
|
789
|
+
|
|
790
|
+
const typedField = fromJS({
|
|
791
|
+
name: 'list',
|
|
792
|
+
label: 'List',
|
|
793
|
+
types: [
|
|
794
|
+
{
|
|
795
|
+
name: 'type_one',
|
|
796
|
+
widget: 'object',
|
|
797
|
+
fields: [{ name: 'text', widget: 'markdown', label: 'Text' }],
|
|
798
|
+
},
|
|
799
|
+
],
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
it('should apply a change to the item it was made on after an earlier item is removed', () => {
|
|
803
|
+
const value = fromJS([
|
|
804
|
+
{ type: 'type_one', text: 'one' },
|
|
805
|
+
{ type: 'type_one', text: 'two' },
|
|
806
|
+
{ type: 'type_one', text: 'three' },
|
|
807
|
+
]);
|
|
808
|
+
|
|
809
|
+
let control;
|
|
810
|
+
const { getAllByText, rerender } = render(
|
|
811
|
+
<ListControl ref={ref => (control = ref)} {...props} field={typedField} value={value} />,
|
|
812
|
+
);
|
|
813
|
+
|
|
814
|
+
const changeThirdItem = control.handleChangeFor(2);
|
|
815
|
+
|
|
816
|
+
fireEvent.click(getAllByText('Remove')[0]);
|
|
817
|
+
const afterRemoval = props.onChange.mock.calls[0][0];
|
|
818
|
+
rerender(
|
|
819
|
+
<ListControl
|
|
820
|
+
ref={ref => (control = ref)}
|
|
821
|
+
{...props}
|
|
822
|
+
field={typedField}
|
|
823
|
+
value={afterRemoval}
|
|
824
|
+
/>,
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
changeThirdItem(fromJS({ name: 'text' }), 'three edited');
|
|
828
|
+
|
|
829
|
+
const written = props.onChange.mock.calls[1][0].toJS();
|
|
830
|
+
expect(written).toHaveLength(2);
|
|
831
|
+
expect(written[1]).toEqual({ type: 'type_one', text: 'three edited' });
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
it('should discard a change made on an item that has since been removed', () => {
|
|
835
|
+
const value = fromJS([
|
|
836
|
+
{ type: 'type_one', text: 'one' },
|
|
837
|
+
{ type: 'type_one', text: 'two' },
|
|
838
|
+
]);
|
|
839
|
+
|
|
840
|
+
let control;
|
|
841
|
+
const { getAllByText, rerender } = render(
|
|
842
|
+
<ListControl ref={ref => (control = ref)} {...props} field={typedField} value={value} />,
|
|
843
|
+
);
|
|
844
|
+
|
|
845
|
+
const changeSecondItem = control.handleChangeFor(1);
|
|
846
|
+
|
|
847
|
+
fireEvent.click(getAllByText('Remove')[1]);
|
|
848
|
+
const afterRemoval = props.onChange.mock.calls[0][0];
|
|
849
|
+
rerender(
|
|
850
|
+
<ListControl
|
|
851
|
+
ref={ref => (control = ref)}
|
|
852
|
+
{...props}
|
|
853
|
+
field={typedField}
|
|
854
|
+
value={afterRemoval}
|
|
855
|
+
/>,
|
|
856
|
+
);
|
|
857
|
+
|
|
858
|
+
changeSecondItem(fromJS({ name: 'text' }), 'text for a removed item');
|
|
859
|
+
|
|
860
|
+
expect(props.onChange).toHaveBeenCalledTimes(1);
|
|
861
|
+
});
|
|
790
862
|
});
|
package/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2016 Netlify <decap@p-m.si>
|
|
2
|
-
|
|
3
|
-
MIT License
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|