| 1 |
/** |
| 2 |
* Valid Blocks - 高度な設定を追加するブロックを指定 |
| 3 |
*/ |
| 4 |
function isValidBlockType(blockName) { |
| 5 |
const validBlocks = ['loos-hcb/code-block']; |
| 6 |
return -1 !== validBlocks.indexOf(blockName); |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Override props assigned to save component to inject our custom data. |
| 11 |
* This is only done if the component is a valid block type. |
| 12 |
* |
| 13 |
* @param {Object} extraProps Additional props applied to save element. |
| 14 |
* @param {Object} blockType Block type. |
| 15 |
* @param {Object} attributes Current block attributes. |
| 16 |
* |
| 17 |
* @return {Object} Filtered props applied to save element. |
| 18 |
*/ |
| 19 |
function addSaveProps(extraProps, blockType, attributes) { |
| 20 |
if (isValidBlockType(blockType.name)) { |
| 21 |
// 「wp-block-loos-hcb-code-block」をつけない |
| 22 |
extraProps.className = attributes.className; |
| 23 |
} |
| 24 |
return extraProps; |
| 25 |
} |
| 26 |
// addFilter("blocks.getSaveContent.extraProps", "loos-hcb/add-props", addSaveProps); |
| 27 |
|
| 28 |
/** |
| 29 |
* ベータ版での設定値によるバリデーション回避 |
| 30 |
* |
| 31 |
* @param {Object} attributes Current block attributes. |
| 32 |
* @param {Object} settings Current block settings. |
| 33 |
* @param {Object} content Current block content. |
| 34 |
*/ |
| 35 |
function beforeValidation(attributes, settings, content) { |
| 36 |
//console.log(settings.name); |
| 37 |
if ('loos-hcb/code-block' === settings.name) { |
| 38 |
if ('undefined' === typeof attributes.preClass) { |
| 39 |
let isLineShow = attributes.isLineShow; |
| 40 |
if ('undefined' === typeof isLineShow) { |
| 41 |
isLineShow = 'line'; // "on" or "off" |
| 42 |
} |
| 43 |
const preClass = |
| 44 |
'prism ' + isLineShow + '-numbers lang-' + attributes.langType; |
| 45 |
attributes.preClass = preClass; |
| 46 |
} |
| 47 |
} |
| 48 |
return attributes; |
| 49 |
} |
| 50 |
// addFilter("blocks.getBlockAttributes", "loos-hcb/before-validation", beforeValidation); |
| 51 |
|