PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / gutenberg / util / custom-attribute / custom-attribute.js

custom-attribute.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/gutenberg/util/custom-attribute/custom-attribute.js

67 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress Dependencies
3 */
4 const { __ } = wp.i18n;
5 const { addFilter } = wp.hooks;
6 const { Fragment } = wp.element;
7 const { compose, createHigherOrderComponent } = wp.compose;
8
9 function addAttributes(settings) {
10 // Add custom selector/id
11 if (typeof settings.attributes !== "undefined") {
12 settings.attributes = {
13 ...settings.attributes,
14 eb: { type: "object" }
15 };
16 }
17
18 return settings;
19 }
20
21 const withAttributes = createHigherOrderComponent(BlockEdit => {
22 return props => {
23 const { attributes, setAttributes } = props;
24
25 if (typeof attributes.eb === "undefined") {
26 attributes.eb = [];
27 }
28
29 //add unique selector
30 if (typeof attributes.eb.id === "undefined") {
31 let d = new Date();
32
33 if (
34 typeof attributes.eb !== "undefined" &&
35 typeof attributes.eb.id !== "undefined"
36 ) {
37 delete attributes.eb.id;
38 }
39
40 const eb = Object.assign(
41 {
42 id:
43 "" +
44 d.getMonth() +
45 d.getDate() +
46 d.getHours() +
47 d.getMinutes() +
48 d.getSeconds() +
49 d.getMilliseconds()
50 },
51 attributes.eb
52 );
53 setAttributes({ eb });
54 }
55
56 return (
57 <Fragment>
58 <BlockEdit {...props} />
59 </Fragment>
60 );
61 };
62 }, "withAttributes");
63
64 addFilter("blocks.registerBlockType", "eb/button", addAttributes);
65
66 addFilter("editor.BlockEdit", "eb/button", withAttributes);
67