kopia lustrzana https://github.com/wagtail/wagtail
Move checkBlockCounts into BaseSequenceBlock as a general blockCountChanged callback
The call to checkBlockCounts from duplicateBlock can be removed outright, as it already gets called via the call to insert.pull/7345/head
rodzic
8c97c254a7
commit
d22cc560f1
|
@ -332,6 +332,8 @@ export class BaseSequenceBlock {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
this.blockCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onRequestInsert(index, opts) {
|
_onRequestInsert(index, opts) {
|
||||||
|
@ -342,6 +344,10 @@ export class BaseSequenceBlock {
|
||||||
newChild.focus({ soft: true });
|
newChild.focus({ soft: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockCountChanged() {
|
||||||
|
/* Called whenever the block count has changed; subclasses can override this to apply
|
||||||
|
checks on max block count and disable insert / duplicate controls accordingly */
|
||||||
|
}
|
||||||
|
|
||||||
_insert(childBlockDef, initialState, id, index, opts) {
|
_insert(childBlockDef, initialState, id, index, opts) {
|
||||||
const prefix = this.prefix + '-' + this.blockCounter;
|
const prefix = this.prefix + '-' + this.blockCounter;
|
||||||
|
@ -408,6 +414,8 @@ export class BaseSequenceBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.blockCountChanged();
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,6 +443,8 @@ export class BaseSequenceBlock {
|
||||||
/* we have removed the last child; the new last child cannot be moved down */
|
/* we have removed the last child; the new last child cannot be moved down */
|
||||||
this.children[this.children.length - 1].disableMoveDown();
|
this.children[this.children.length - 1].disableMoveDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.blockCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBlock(oldIndex, newIndex) {
|
moveBlock(oldIndex, newIndex) {
|
||||||
|
|
|
@ -221,7 +221,8 @@ export class StreamBlock extends BaseSequenceBlock {
|
||||||
*
|
*
|
||||||
* Updates the state of add / duplicate block buttons to prevent too many blocks being inserted.
|
* Updates the state of add / duplicate block buttons to prevent too many blocks being inserted.
|
||||||
*/
|
*/
|
||||||
checkBlockCounts() {
|
blockCountChanged() {
|
||||||
|
super.blockCountChanged();
|
||||||
this.canAddBlock = true;
|
this.canAddBlock = true;
|
||||||
|
|
||||||
if (typeof this.blockDef.meta.maxNum === 'number' && this.children.length >= this.blockDef.meta.maxNum) {
|
if (typeof this.blockDef.meta.maxNum === 'number' && this.children.length >= this.blockDef.meta.maxNum) {
|
||||||
|
@ -276,12 +277,6 @@ export class StreamBlock extends BaseSequenceBlock {
|
||||||
return this._insert(childBlockDef, value, id, index, opts);
|
return this._insert(childBlockDef, value, id, index, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
_insert(childBlockDef, value, id, index, opts) {
|
|
||||||
const result = super._insert(childBlockDef, value, id, index, opts);
|
|
||||||
this.checkBlockCounts();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
_getChildDataForInsertion({ type }) {
|
_getChildDataForInsertion({ type }) {
|
||||||
/* Called when an 'insert new block' action is triggered: given a dict of data from the insertion control,
|
/* Called when an 'insert new block' action is triggered: given a dict of data from the insertion control,
|
||||||
return the block definition and initial state to be used for the new block.
|
return the block definition and initial state to be used for the new block.
|
||||||
|
@ -292,11 +287,6 @@ export class StreamBlock extends BaseSequenceBlock {
|
||||||
return [blockDef, initialState, uuidv4()];
|
return [blockDef, initialState, uuidv4()];
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
|
||||||
super.clear();
|
|
||||||
this.checkBlockCounts();
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateBlock(index, opts) {
|
duplicateBlock(index, opts) {
|
||||||
const child = this.children[index];
|
const child = this.children[index];
|
||||||
const childState = child.getState();
|
const childState = child.getState();
|
||||||
|
@ -305,13 +295,6 @@ export class StreamBlock extends BaseSequenceBlock {
|
||||||
this.insert(childState, index + 1, { animate, collapsed: child.collapsed });
|
this.insert(childState, index + 1, { animate, collapsed: child.collapsed });
|
||||||
// focus the newly added field if we can do so without obtrusive UI behaviour
|
// focus the newly added field if we can do so without obtrusive UI behaviour
|
||||||
this.children[index + 1].focus({ soft: true });
|
this.children[index + 1].focus({ soft: true });
|
||||||
|
|
||||||
this.checkBlockCounts();
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteBlock(index, opts) {
|
|
||||||
super.deleteBlock(index, opts);
|
|
||||||
this.checkBlockCounts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(values) {
|
setState(values) {
|
||||||
|
|
Ładowanie…
Reference in New Issue