| 1 |
import { createHigherOrderComponent } from "@wordpress/compose"; |
| 2 |
import { useEffect } from "@wordpress/element"; |
| 3 |
import WebFont from "webfontloader"; |
| 4 |
import { addFilter } from "@wordpress/hooks"; |
| 5 |
|
| 6 |
const withAdvancedControls = createHigherOrderComponent((BlockEdit) => { |
| 7 |
|
| 8 |
return (props) => { |
| 9 |
const { attributes } = props; |
| 10 |
|
| 11 |
// typography |
| 12 |
useEffect(() => { |
| 13 |
let googleFontFamily = []; |
| 14 |
for (var key in attributes) { |
| 15 |
if (/^(\w+)FontFamily/.test(key)) { |
| 16 |
if (attributes[key] !== "Default") { |
| 17 |
googleFontFamily.push( |
| 18 |
attributes[key] + |
| 19 |
":100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic" |
| 20 |
); |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
if (googleFontFamily.length > 0) { |
| 26 |
let webFontConfig = { |
| 27 |
google: { |
| 28 |
families: googleFontFamily, |
| 29 |
}, |
| 30 |
context: frames["editor-canvas"], |
| 31 |
}; |
| 32 |
WebFont.load(webFontConfig); |
| 33 |
} |
| 34 |
}, [attributes]); |
| 35 |
|
| 36 |
return <BlockEdit {...props} />; |
| 37 |
|
| 38 |
}; |
| 39 |
}, "withAdvancedControls"); |
| 40 |
|
| 41 |
/** |
| 42 |
* Filter for modification of Edit Function |
| 43 |
*/ |
| 44 |
addFilter("editor.BlockEdit", "betterdocs/global", withAdvancedControls); |
| 45 |
|
| 46 |
|