@wordpress/block-library 8.12.12 → 8.12.13
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/build/footnotes/edit.js +11 -0
- package/build/footnotes/edit.js.map +1 -1
- package/build/footnotes/format.js +19 -1
- package/build/footnotes/format.js.map +1 -1
- package/build/footnotes/index.js +1 -2
- package/build/footnotes/index.js.map +1 -1
- package/build-module/footnotes/edit.js +11 -0
- package/build-module/footnotes/edit.js.map +1 -1
- package/build-module/footnotes/format.js +20 -3
- package/build-module/footnotes/format.js.map +1 -1
- package/build-module/footnotes/index.js +1 -2
- package/build-module/footnotes/index.js.map +1 -1
- package/package.json +8 -8
- package/src/footnotes/edit.js +12 -0
- package/src/footnotes/format.js +23 -2
- package/src/footnotes/index.js +0 -1
- package/src/template-part/index.php +1 -1
package/build/footnotes/edit.js
CHANGED
|
@@ -30,6 +30,17 @@ function FootnotesEdit({
|
|
|
30
30
|
const footnotes = meta?.footnotes ? JSON.parse(meta.footnotes) : [];
|
|
31
31
|
const blockProps = (0, _blockEditor.useBlockProps)();
|
|
32
32
|
|
|
33
|
+
if (postType !== 'post' && postType !== 'page') {
|
|
34
|
+
return (0, _element.createElement)("div", { ...blockProps
|
|
35
|
+
}, (0, _element.createElement)(_components.Placeholder, {
|
|
36
|
+
icon: (0, _element.createElement)(_blockEditor.BlockIcon, {
|
|
37
|
+
icon: _icons.formatListNumbered
|
|
38
|
+
}),
|
|
39
|
+
label: (0, _i18n.__)('Footnotes') // To do: add instructions. We can't add new string in RC.
|
|
40
|
+
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
if (!footnotes.length) {
|
|
34
45
|
return (0, _element.createElement)("div", { ...blockProps
|
|
35
46
|
}, (0, _element.createElement)(_components.Placeholder, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/footnotes/edit.js"],"names":["FootnotesEdit","context","postType","postId","meta","updateMeta","footnotes","JSON","parse","blockProps","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/footnotes/edit.js"],"names":["FootnotesEdit","context","postType","postId","meta","updateMeta","footnotes","JSON","parse","blockProps","icon","length","map","id","content","event","target","textContent","trim","scrollIntoView","nextFootnote","stringify","footnote"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAPA;AACA;AACA;AAOe,SAASA,aAAT,CAAwB;AAAEC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ;AAAX,CAAxB,EAA4D;AAC1E,QAAM,CAAEC,IAAF,EAAQC,UAAR,IAAuB,6BAC5B,UAD4B,EAE5BH,QAF4B,EAG5B,MAH4B,EAI5BC,MAJ4B,CAA7B;AAMA,QAAMG,SAAS,GAAGF,IAAI,EAAEE,SAAN,GAAkBC,IAAI,CAACC,KAAL,CAAYJ,IAAI,CAACE,SAAjB,CAAlB,GAAiD,EAAnE;AACA,QAAMG,UAAU,GAAG,iCAAnB;;AAEA,MAAKP,QAAQ,KAAK,MAAb,IAAuBA,QAAQ,KAAK,MAAzC,EAAkD;AACjD,WACC,wCAAUO;AAAV,OACC,4BAAC,uBAAD;AACC,MAAA,IAAI,EAAG,4BAAC,sBAAD;AAAW,QAAA,IAAI,EAAGC;AAAlB,QADR;AAEC,MAAA,KAAK,EAAG,cAAI,WAAJ,CAFT,CAGC;;AAHD,MADD,CADD;AASA;;AAED,MAAK,CAAEJ,SAAS,CAACK,MAAjB,EAA0B;AACzB,WACC,wCAAUF;AAAV,OACC,4BAAC,uBAAD;AACC,MAAA,IAAI,EAAG,4BAAC,sBAAD;AAAW,QAAA,IAAI,EAAGC;AAAlB,QADR;AAEC,MAAA,KAAK,EAAG,cAAI,WAAJ,CAFT;AAGC,MAAA,YAAY,EAAG,cACd,wEADc;AAHhB,MADD,CADD;AAWA;;AAED,SACC,uCAASD;AAAT,KACGH,SAAS,CAACM,GAAV,CAAe,CAAE;AAAEC,IAAAA,EAAF;AAAMC,IAAAA;AAAN,GAAF,KAChB;AAAI,IAAA,GAAG,EAAGD;AAAV,KACC,4BAAC,qBAAD;AACC,IAAA,EAAE,EAAGA,EADN;AAEC,IAAA,OAAO,EAAC,MAFT;AAGC,IAAA,KAAK,EAAGC,OAHT;AAIC,IAAA,UAAU,EAAGD,EAJd,CAKC;AACA;AAND;AAOC,IAAA,OAAO,EAAKE,KAAF,IAAa;AACtB,UAAK,CAAEA,KAAK,CAACC,MAAN,CAAaC,WAAb,CAAyBC,IAAzB,EAAP,EAAyC;AACxCH,QAAAA,KAAK,CAACC,MAAN,CAAaG,cAAb;AACA;AACD,KAXF;AAYC,IAAA,QAAQ,EAAKC,YAAF,IAAoB;AAC9Bf,MAAAA,UAAU,CAAE,EACX,GAAGD,IADQ;AAEXE,QAAAA,SAAS,EAAEC,IAAI,CAACc,SAAL,CACVf,SAAS,CAACM,GAAV,CAAiBU,QAAF,IAAgB;AAC9B,iBAAOA,QAAQ,CAACT,EAAT,KAAgBA,EAAhB,GACJ;AACAC,YAAAA,OAAO,EAAEM,YADT;AAEAP,YAAAA;AAFA,WADI,GAKJS,QALH;AAMA,SAPD,CADU;AAFA,OAAF,CAAV;AAaA;AA1BF,IADD,EA4BK,GA5BL,EA6BC;AAAG,IAAA,IAAI,EAAI,IAAIT,EAAI;AAAnB,oBA7BD,CADC,CADH,CADD;AAqCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { Placeholder } from '@wordpress/components';\nimport { formatListNumbered as icon } from '@wordpress/icons';\n\nexport default function FootnotesEdit( { context: { postType, postId } } ) {\n\tconst [ meta, updateMeta ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'meta',\n\t\tpostId\n\t);\n\tconst footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst blockProps = useBlockProps();\n\n\tif ( postType !== 'post' && postType !== 'page' ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\t// To do: add instructions. We can't add new string in RC.\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( ! footnotes.length ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t'Footnotes found in blocks within this document will be displayed here.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ol { ...blockProps }>\n\t\t\t{ footnotes.map( ( { id, content } ) => (\n\t\t\t\t<li key={ id }>\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tid={ id }\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\tidentifier={ id }\n\t\t\t\t\t\t// To do: figure out why the browser is not scrolling\n\t\t\t\t\t\t// into view when it receives focus.\n\t\t\t\t\t\tonFocus={ ( event ) => {\n\t\t\t\t\t\t\tif ( ! event.target.textContent.trim() ) {\n\t\t\t\t\t\t\t\tevent.target.scrollIntoView();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonChange={ ( nextFootnote ) => {\n\t\t\t\t\t\t\tupdateMeta( {\n\t\t\t\t\t\t\t\t...meta,\n\t\t\t\t\t\t\t\tfootnotes: JSON.stringify(\n\t\t\t\t\t\t\t\t\tfootnotes.map( ( footnote ) => {\n\t\t\t\t\t\t\t\t\t\treturn footnote.id === id\n\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: nextFootnote,\n\t\t\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t\t\t: footnote;\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>{ ' ' }\n\t\t\t\t\t<a href={ `#${ id }-link` }>↩︎</a>\n\t\t\t\t</li>\n\t\t\t) ) }\n\t\t</ol>\n\t);\n}\n"]}
|
|
@@ -21,6 +21,8 @@ var _data = require("@wordpress/data");
|
|
|
21
21
|
|
|
22
22
|
var _blocks = require("@wordpress/blocks");
|
|
23
23
|
|
|
24
|
+
var _lockUnlock = require("../lock-unlock");
|
|
25
|
+
|
|
24
26
|
/**
|
|
25
27
|
* External dependencies
|
|
26
28
|
*/
|
|
@@ -51,6 +53,9 @@ const {
|
|
|
51
53
|
},
|
|
52
54
|
style: "wp-block-footnotes"
|
|
53
55
|
};
|
|
56
|
+
const {
|
|
57
|
+
usesContextKey
|
|
58
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
54
59
|
const formatName = 'core/footnote';
|
|
55
60
|
exports.formatName = formatName;
|
|
56
61
|
const format = {
|
|
@@ -61,10 +66,14 @@ const format = {
|
|
|
61
66
|
'data-fn': 'data-fn'
|
|
62
67
|
},
|
|
63
68
|
contentEditable: false,
|
|
69
|
+
[usesContextKey]: ['postType'],
|
|
64
70
|
edit: function Edit({
|
|
65
71
|
value,
|
|
66
72
|
onChange,
|
|
67
|
-
isObjectActive
|
|
73
|
+
isObjectActive,
|
|
74
|
+
context: {
|
|
75
|
+
postType
|
|
76
|
+
}
|
|
68
77
|
}) {
|
|
69
78
|
const registry = (0, _data.useRegistry)();
|
|
70
79
|
const {
|
|
@@ -73,11 +82,20 @@ const format = {
|
|
|
73
82
|
getBlockName,
|
|
74
83
|
getBlocks
|
|
75
84
|
} = (0, _data.useSelect)(_blockEditor.store);
|
|
85
|
+
const footnotesBlockType = (0, _data.useSelect)(select => select(_blocks.store).getBlockType(name));
|
|
76
86
|
const {
|
|
77
87
|
selectionChange,
|
|
78
88
|
insertBlock
|
|
79
89
|
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
80
90
|
|
|
91
|
+
if (!footnotesBlockType) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (postType !== 'post' && postType !== 'page') {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
81
99
|
function onClick() {
|
|
82
100
|
registry.batch(() => {
|
|
83
101
|
let id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/footnotes/format.js"],"names":["formatName","format","title","tagName","className","attributes","contentEditable","edit","Edit","value","onChange","isObjectActive","registry","getSelectedBlockClientId","getBlockRootClientId","getBlockName","getBlocks","blockEditorStore","selectionChange","insertBlock","onClick","batch","id","object","replacements","start","newValue","type","innerHTML","end","fnBlock","queue","length","block","shift","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/footnotes/format.js"],"names":["usesContextKey","privateApis","formatName","format","title","tagName","className","attributes","contentEditable","edit","Edit","value","onChange","isObjectActive","context","postType","registry","getSelectedBlockClientId","getBlockRootClientId","getBlockName","getBlocks","blockEditorStore","footnotesBlockType","select","blocksStore","getBlockType","name","selectionChange","insertBlock","onClick","batch","id","object","replacements","start","newValue","type","innerHTML","end","fnBlock","queue","length","block","shift","push","innerBlocks","clientId","rootClientId","undefined","icon"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAMA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;;;;;;;;;;;;;;;;;;;AAIA,MAAM;AAAEA,EAAAA;AAAF,IAAqB,wBAAQC,wBAAR,CAA3B;AAEO,MAAMC,UAAU,GAAG,eAAnB;;AACA,MAAMC,MAAM,GAAG;A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AAV,EAAoBf,EAApB,EAAwB,CAAxB,EAA2B,CAA3B,CAAf;AACA,OAzDD;AA0DA;;AAED,WACC,4BAAC,kCAAD;AACC,MAAA,IAAI,EAAGkB,yBADR;AAEC,MAAA,KAAK,EAAG,cAAI,UAAJ,CAFT;AAGC,MAAA,OAAO,EAAGpB,OAHX;AAIC,MAAA,QAAQ,EAAGhB;AAJZ,MADD;AAQA;AAzGoB,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as createId } from 'uuid';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { formatListNumbered as icon } from '@wordpress/icons';\nimport { insertObject } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tstore as blockEditorStore,\n\tprivateApis,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { name } from './block.json';\nimport { unlock } from '../lock-unlock';\n\nconst { usesContextKey } = unlock( privateApis );\n\nexport const formatName = 'core/footnote';\nexport const format = {\n\ttitle: __( 'Footnote' ),\n\ttagName: 'sup',\n\tclassName: 'fn',\n\tattributes: {\n\t\t'data-fn': 'data-fn',\n\t},\n\tcontentEditable: false,\n\t[ usesContextKey ]: [ 'postType' ],\n\tedit: function Edit( {\n\t\tvalue,\n\t\tonChange,\n\t\tisObjectActive,\n\t\tcontext: { postType },\n\t} ) {\n\t\tconst registry = useRegistry();\n\t\tconst {\n\t\t\tgetSelectedBlockClientId,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlockName,\n\t\t\tgetBlocks,\n\t\t} = useSelect( blockEditorStore );\n\t\tconst footnotesBlockType = useSelect( ( select ) =>\n\t\t\tselect( blocksStore ).getBlockType( name )\n\t\t);\n\t\tconst { selectionChange, insertBlock } =\n\t\t\tuseDispatch( blockEditorStore );\n\n\t\tif ( ! footnotesBlockType ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif ( postType !== 'post' && postType !== 'page' ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tregistry.batch( () => {\n\t\t\t\tlet id;\n\t\t\t\tif ( isObjectActive ) {\n\t\t\t\t\tconst object = value.replacements[ value.start ];\n\t\t\t\t\tid = object?.attributes?.[ 'data-fn' ];\n\t\t\t\t} else {\n\t\t\t\t\tid = createId();\n\t\t\t\t\tconst newValue = insertObject(\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: formatName,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t'data-fn': id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tinnerHTML: `<a href=\"#${ id }\" id=\"${ id }-link\">*</a>`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvalue.end,\n\t\t\t\t\t\tvalue.end\n\t\t\t\t\t);\n\t\t\t\t\tnewValue.start = newValue.end - 1;\n\t\t\t\t\tonChange( newValue );\n\t\t\t\t}\n\n\t\t\t\t// BFS search to find the first footnote block.\n\t\t\t\tlet fnBlock = null;\n\t\t\t\t{\n\t\t\t\t\tconst queue = [ ...getBlocks() ];\n\t\t\t\t\twhile ( queue.length ) {\n\t\t\t\t\t\tconst block = queue.shift();\n\t\t\t\t\t\tif ( block.name === name ) {\n\t\t\t\t\t\t\tfnBlock = block;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tqueue.push( ...block.innerBlocks );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Maybe this should all also be moved to the entity provider.\n\t\t\t\t// When there is no footnotes block in the post, create one and\n\t\t\t\t// insert it at the bottom.\n\t\t\t\tif ( ! fnBlock ) {\n\t\t\t\t\tconst clientId = getSelectedBlockClientId();\n\t\t\t\t\tlet rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\trootClientId &&\n\t\t\t\t\t\tgetBlockName( rootClientId ) !== 'core/post-content'\n\t\t\t\t\t) {\n\t\t\t\t\t\trootClientId = getBlockRootClientId( rootClientId );\n\t\t\t\t\t}\n\n\t\t\t\t\tfnBlock = createBlock( name );\n\n\t\t\t\t\tinsertBlock( fnBlock, undefined, rootClientId );\n\t\t\t\t}\n\n\t\t\t\tselectionChange( fnBlock.clientId, id, 0, 0 );\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ icon }\n\t\t\t\ttitle={ __( 'Footnote' ) }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isObjectActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
|
package/build/footnotes/index.js
CHANGED
|
@@ -49,8 +49,7 @@ exports.name = name;
|
|
|
49
49
|
const settings = {
|
|
50
50
|
icon: _icons.formatListNumbered,
|
|
51
51
|
edit: _edit.default
|
|
52
|
-
};
|
|
53
|
-
|
|
52
|
+
};
|
|
54
53
|
exports.settings = settings;
|
|
55
54
|
(0, _richText.registerFormatType)(_format.formatName, _format.format);
|
|
56
55
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/footnotes/index.js"],"names":["name","metadata","settings","icon","edit","formatName","format","init"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAEA;;AAZA;AACA;AACA;;AAIA;AACA;AACA;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,yBADuB;AAEvBC,EAAAA,IAAI,EAAJA;AAFuB,CAAjB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/footnotes/index.js"],"names":["name","metadata","settings","icon","edit","formatName","format","init"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAEA;;AAZA;AACA;AACA;;AAIA;AACA;AACA;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,yBADuB;AAEvBC,EAAAA,IAAI,EAAJA;AAFuB,CAAjB;;AAKP,kCAAoBC,kBAApB,EAAgCC,cAAhC;;AAEO,MAAMC,IAAI,GAAG,MAAM;AACzB,0BAAW;AAAEP,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA;AAAlB,GAAX;AACA,CAFM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { formatListNumbered as icon } from '@wordpress/icons';\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport { formatName, format } from './format';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n\nregisterFormatType( formatName, format );\n\nexport const init = () => {\n\tinitBlock( { name, metadata, settings } );\n};\n"]}
|
|
@@ -18,6 +18,17 @@ export default function FootnotesEdit({
|
|
|
18
18
|
const footnotes = meta?.footnotes ? JSON.parse(meta.footnotes) : [];
|
|
19
19
|
const blockProps = useBlockProps();
|
|
20
20
|
|
|
21
|
+
if (postType !== 'post' && postType !== 'page') {
|
|
22
|
+
return createElement("div", { ...blockProps
|
|
23
|
+
}, createElement(Placeholder, {
|
|
24
|
+
icon: createElement(BlockIcon, {
|
|
25
|
+
icon: icon
|
|
26
|
+
}),
|
|
27
|
+
label: __('Footnotes') // To do: add instructions. We can't add new string in RC.
|
|
28
|
+
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
if (!footnotes.length) {
|
|
22
33
|
return createElement("div", { ...blockProps
|
|
23
34
|
}, createElement(Placeholder, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/footnotes/edit.js"],"names":["BlockIcon","RichText","useBlockProps","useEntityProp","__","Placeholder","formatListNumbered","icon","FootnotesEdit","context","postType","postId","meta","updateMeta","footnotes","JSON","parse","blockProps","length","map","id","content","event","target","textContent","trim","scrollIntoView","nextFootnote","stringify","footnote"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,QAApB,EAA8BC,aAA9B,QAAmD,yBAAnD;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,kBAAkB,IAAIC,IAA/B,QAA2C,kBAA3C;AAEA,eAAe,SAASC,aAAT,CAAwB;AAAEC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ;AAAX,CAAxB,EAA4D;AAC1E,QAAM,CAAEC,IAAF,EAAQC,UAAR,IAAuBV,aAAa,CACzC,UADyC,EAEzCO,QAFyC,EAGzC,MAHyC,EAIzCC,MAJyC,CAA1C;AAMA,QAAMG,SAAS,GAAGF,IAAI,EAAEE,SAAN,GAAkBC,IAAI,CAACC,KAAL,CAAYJ,IAAI,CAACE,SAAjB,CAAlB,GAAiD,EAAnE;AACA,QAAMG,UAAU,GAAGf,aAAa,EAAhC;;AAEA,MAAK,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/footnotes/edit.js"],"names":["BlockIcon","RichText","useBlockProps","useEntityProp","__","Placeholder","formatListNumbered","icon","FootnotesEdit","context","postType","postId","meta","updateMeta","footnotes","JSON","parse","blockProps","length","map","id","content","event","target","textContent","trim","scrollIntoView","nextFootnote","stringify","footnote"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,QAApB,EAA8BC,aAA9B,QAAmD,yBAAnD;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,kBAAkB,IAAIC,IAA/B,QAA2C,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KC;AACA;AAND;AAOC,IAAA,OAAO,EAAKE,KAAF,IAAa;AACtB,UAAK,CAAEA,KAAK,CAACC,MAAN,CAAaC,WAAb,CAAyBC,IAAzB,EAAP,EAAyC;AACxCH,QAAAA,KAAK,CAACC,MAAN,CAAaG,cAAb;AACA;AACD,KAXF;AAYC,IAAA,QAAQ,EAAKC,YAAF,IAAoB;AAC9Bd,MAAAA,UAAU,CAAE,EACX,GAAGD,IADQ;AAEXE,QAAAA,SAAS,EAAEC,IAAI,CAACa,SAAL,CACVd,SAAS,CAACK,GAAV,CAAiBU,QAAF,IAAgB;AAC9B,iBAAOA,QAAQ,CAACT,EAAT,KAAgBA,EAAhB,GACJ;AACAC,YAAAA,OAAO,EAAEM,YADT;AAEAP,YAAAA;AAFA,WADI,GAKJS,QALH;AAMA,SAPD,CADU;AAFA,OAAF,CAAV;AAaA;AA1BF,IADD,EA4BK,GA5BL,EA6BC;AAAG,IAAA,IAAI,EAAI,IAAIT,EAAI;AAAnB,oBA7BD,CADC,CADH,CADD;AAqCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { Placeholder } from '@wordpress/components';\nimport { formatListNumbered as icon } from '@wordpress/icons';\n\nexport default function FootnotesEdit( { context: { postType, postId } } ) {\n\tconst [ meta, updateMeta ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'meta',\n\t\tpostId\n\t);\n\tconst footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst blockProps = useBlockProps();\n\n\tif ( postType !== 'post' && postType !== 'page' ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\t// To do: add instructions. We can't add new string in RC.\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( ! footnotes.length ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t'Footnotes found in blocks within this document will be displayed here.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ol { ...blockProps }>\n\t\t\t{ footnotes.map( ( { id, content } ) => (\n\t\t\t\t<li key={ id }>\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tid={ id }\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\tidentifier={ id }\n\t\t\t\t\t\t// To do: figure out why the browser is not scrolling\n\t\t\t\t\t\t// into view when it receives focus.\n\t\t\t\t\t\tonFocus={ ( event ) => {\n\t\t\t\t\t\t\tif ( ! event.target.textContent.trim() ) {\n\t\t\t\t\t\t\t\tevent.target.scrollIntoView();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonChange={ ( nextFootnote ) => {\n\t\t\t\t\t\t\tupdateMeta( {\n\t\t\t\t\t\t\t\t...meta,\n\t\t\t\t\t\t\t\tfootnotes: JSON.stringify(\n\t\t\t\t\t\t\t\t\tfootnotes.map( ( footnote ) => {\n\t\t\t\t\t\t\t\t\t\treturn footnote.id === id\n\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: nextFootnote,\n\t\t\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t\t\t: footnote;\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>{ ' ' }\n\t\t\t\t\t<a href={ `#${ id }-link` }>↩︎</a>\n\t\t\t\t</li>\n\t\t\t) ) }\n\t\t</ol>\n\t);\n}\n"]}
|
|
@@ -11,9 +11,9 @@ import { v4 as createId } from 'uuid';
|
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
12
|
import { formatListNumbered as icon } from '@wordpress/icons';
|
|
13
13
|
import { insertObject } from '@wordpress/rich-text';
|
|
14
|
-
import { RichTextToolbarButton, store as blockEditorStore } from '@wordpress/block-editor';
|
|
14
|
+
import { RichTextToolbarButton, store as blockEditorStore, privateApis } from '@wordpress/block-editor';
|
|
15
15
|
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
|
|
16
|
-
import { createBlock } from '@wordpress/blocks';
|
|
16
|
+
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
17
17
|
/**
|
|
18
18
|
* Internal dependencies
|
|
19
19
|
*/
|
|
@@ -37,6 +37,10 @@ const {
|
|
|
37
37
|
},
|
|
38
38
|
style: "wp-block-footnotes"
|
|
39
39
|
};
|
|
40
|
+
import { unlock } from '../lock-unlock';
|
|
41
|
+
const {
|
|
42
|
+
usesContextKey
|
|
43
|
+
} = unlock(privateApis);
|
|
40
44
|
export const formatName = 'core/footnote';
|
|
41
45
|
export const format = {
|
|
42
46
|
title: __('Footnote'),
|
|
@@ -46,10 +50,14 @@ export const format = {
|
|
|
46
50
|
'data-fn': 'data-fn'
|
|
47
51
|
},
|
|
48
52
|
contentEditable: false,
|
|
53
|
+
[usesContextKey]: ['postType'],
|
|
49
54
|
edit: function Edit({
|
|
50
55
|
value,
|
|
51
56
|
onChange,
|
|
52
|
-
isObjectActive
|
|
57
|
+
isObjectActive,
|
|
58
|
+
context: {
|
|
59
|
+
postType
|
|
60
|
+
}
|
|
53
61
|
}) {
|
|
54
62
|
const registry = useRegistry();
|
|
55
63
|
const {
|
|
@@ -58,11 +66,20 @@ export const format = {
|
|
|
58
66
|
getBlockName,
|
|
59
67
|
getBlocks
|
|
60
68
|
} = useSelect(blockEditorStore);
|
|
69
|
+
const footnotesBlockType = useSelect(select => select(blocksStore).getBlockType(name));
|
|
61
70
|
const {
|
|
62
71
|
selectionChange,
|
|
63
72
|
insertBlock
|
|
64
73
|
} = useDispatch(blockEditorStore);
|
|
65
74
|
|
|
75
|
+
if (!footnotesBlockType) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (postType !== 'post' && postType !== 'page') {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
66
83
|
function onClick() {
|
|
67
84
|
registry.batch(() => {
|
|
68
85
|
let id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/footnotes/format.js"],"names":["v4","createId","__","formatListNumbered","icon","insertObject","RichTextToolbarButton","store","blockEditorStore","useSelect","useDispatch","useRegistry","createBlock","formatName","format","title","tagName","className","attributes","contentEditable","edit","Edit","value","onChange","isObjectActive","registry","getSelectedBlockClientId","getBlockRootClientId","getBlockName","getBlocks","selectionChange","insertBlock","onClick","batch","id","object","replacements","start","newValue","type","innerHTML","end","fnBlock","queue","length","block","shift","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/footnotes/format.js"],"names":["v4","createId","__","formatListNumbered","icon","insertObject","RichTextToolbarButton","store","blockEditorStore","privateApis","useSelect","useDispatch","useRegistry","createBlock","blocksStore","unlock","usesContextKey","formatName","format","title","tagName","className","attributes","contentEditable","edit","Edit","value","onChange","isObjectActive","context","postType","registry","getSelectedBlockClientId","getBlockRootClientId","getBlockName","getBlocks","footnotesBlockType","select","getBlockType","name","selectionChange","insertBlock","onClick","batch","id","object","replacements","start","newValue","type","innerHTML","end","fnBlock","queue","length","block","shift","push","innerBlocks","clientId","rootClientId","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,QAAf,QAA+B,MAA/B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAm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O,GAAGG,KAAV;AACA;AACA;;AACDF,YAAAA,KAAK,CAACI,IAAN,CAAY,GAAGF,KAAK,CAACG,WAArB;AACA;AACD,SAnCoB,CAqCrB;AACA;AACA;;AACA,YAAK,CAAEN,OAAP,EAAiB;AAChB,gBAAMO,QAAQ,GAAG3B,wBAAwB,EAAzC;AACA,cAAI4B,YAAY,GAAG3B,oBAAoB,CAAE0B,QAAF,CAAvC;;AAEA,iBACCC,YAAY,IACZ1B,YAAY,CAAE0B,YAAF,CAAZ,KAAiC,mBAFlC,EAGE;AACDA,YAAAA,YAAY,GAAG3B,oBAAoB,CAAE2B,YAAF,CAAnC;AACA;;AAEDR,UAAAA,OAAO,GAAGvC,WAAW,CAAE0B,IAAF,CAArB;AAEAE,UAAAA,WAAW,CAAEW,OAAF,EAAWS,SAAX,EAAsBD,YAAtB,CAAX;AACA;;AAEDpB,QAAAA,eAAe,CAAEY,OAAO,CAACO,QAAV,EAAoBf,EAApB,EAAwB,CAAxB,EAA2B,CAA3B,CAAf;AACA,OAzDD;AA0DA;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGxC,IADR;AAEC,MAAA,KAAK,EAAGF,EAAE,CAAE,UAAF,CAFX;AAGC,MAAA,OAAO,EAAGwC,OAHX;AAIC,MAAA,QAAQ,EAAGd;AAJZ,MADD;AAQA;AAzGoB,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as createId } from 'uuid';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { formatListNumbered as icon } from '@wordpress/icons';\nimport { insertObject } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tstore as blockEditorStore,\n\tprivateApis,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { name } from './block.json';\nimport { unlock } from '../lock-unlock';\n\nconst { usesContextKey } = unlock( privateApis );\n\nexport const formatName = 'core/footnote';\nexport const format = {\n\ttitle: __( 'Footnote' ),\n\ttagName: 'sup',\n\tclassName: 'fn',\n\tattributes: {\n\t\t'data-fn': 'data-fn',\n\t},\n\tcontentEditable: false,\n\t[ usesContextKey ]: [ 'postType' ],\n\tedit: function Edit( {\n\t\tvalue,\n\t\tonChange,\n\t\tisObjectActive,\n\t\tcontext: { postType },\n\t} ) {\n\t\tconst registry = useRegistry();\n\t\tconst {\n\t\t\tgetSelectedBlockClientId,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlockName,\n\t\t\tgetBlocks,\n\t\t} = useSelect( blockEditorStore );\n\t\tconst footnotesBlockType = useSelect( ( select ) =>\n\t\t\tselect( blocksStore ).getBlockType( name )\n\t\t);\n\t\tconst { selectionChange, insertBlock } =\n\t\t\tuseDispatch( blockEditorStore );\n\n\t\tif ( ! footnotesBlockType ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif ( postType !== 'post' && postType !== 'page' ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tregistry.batch( () => {\n\t\t\t\tlet id;\n\t\t\t\tif ( isObjectActive ) {\n\t\t\t\t\tconst object = value.replacements[ value.start ];\n\t\t\t\t\tid = object?.attributes?.[ 'data-fn' ];\n\t\t\t\t} else {\n\t\t\t\t\tid = createId();\n\t\t\t\t\tconst newValue = insertObject(\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: formatName,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t'data-fn': id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tinnerHTML: `<a href=\"#${ id }\" id=\"${ id }-link\">*</a>`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvalue.end,\n\t\t\t\t\t\tvalue.end\n\t\t\t\t\t);\n\t\t\t\t\tnewValue.start = newValue.end - 1;\n\t\t\t\t\tonChange( newValue );\n\t\t\t\t}\n\n\t\t\t\t// BFS search to find the first footnote block.\n\t\t\t\tlet fnBlock = null;\n\t\t\t\t{\n\t\t\t\t\tconst queue = [ ...getBlocks() ];\n\t\t\t\t\twhile ( queue.length ) {\n\t\t\t\t\t\tconst block = queue.shift();\n\t\t\t\t\t\tif ( block.name === name ) {\n\t\t\t\t\t\t\tfnBlock = block;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tqueue.push( ...block.innerBlocks );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Maybe this should all also be moved to the entity provider.\n\t\t\t\t// When there is no footnotes block in the post, create one and\n\t\t\t\t// insert it at the bottom.\n\t\t\t\tif ( ! fnBlock ) {\n\t\t\t\t\tconst clientId = getSelectedBlockClientId();\n\t\t\t\t\tlet rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\trootClientId &&\n\t\t\t\t\t\tgetBlockName( rootClientId ) !== 'core/post-content'\n\t\t\t\t\t) {\n\t\t\t\t\t\trootClientId = getBlockRootClientId( rootClientId );\n\t\t\t\t\t}\n\n\t\t\t\t\tfnBlock = createBlock( name );\n\n\t\t\t\t\tinsertBlock( fnBlock, undefined, rootClientId );\n\t\t\t\t}\n\n\t\t\t\tselectionChange( fnBlock.clientId, id, 0, 0 );\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ icon }\n\t\t\t\ttitle={ __( 'Footnote' ) }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isObjectActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/footnotes/index.js"],"names":["formatListNumbered","icon","registerFormatType","initBlock","edit","formatName","format","name","metadata","settings","init"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,kBAAkB,IAAIC,IAA/B,QAA2C,kBAA3C;AACA,SAASC,kBAAT,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,qBAAtB;AACA,OAAOC,IAAP,MAAiB,QAAjB;;;;;;;;;;;;;;;;;;AAEA,SAASC,UAAT,EAAqBC,MAArB,QAAmC,UAAnC;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AAEA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBR,EAAAA,IADuB;AAEvBG,EAAAA;AAFuB,CAAjB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/footnotes/index.js"],"names":["formatListNumbered","icon","registerFormatType","initBlock","edit","formatName","format","name","metadata","settings","init"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,kBAAkB,IAAIC,IAA/B,QAA2C,kBAA3C;AACA,SAASC,kBAAT,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,qBAAtB;AACA,OAAOC,IAAP,MAAiB,QAAjB;;;;;;;;;;;;;;;;;;AAEA,SAASC,UAAT,EAAqBC,MAArB,QAAmC,UAAnC;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AAEA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBR,EAAAA,IADuB;AAEvBG,EAAAA;AAFuB,CAAjB;AAKPF,kBAAkB,CAAEG,UAAF,EAAcC,MAAd,CAAlB;AAEA,OAAO,MAAMI,IAAI,GAAG,MAAM;AACzBP,EAAAA,SAAS,CAAE;AAAEI,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA;AAAlB,GAAF,CAAT;AACA,CAFM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { formatListNumbered as icon } from '@wordpress/icons';\nimport { registerFormatType } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport { formatName, format } from './format';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n\nregisterFormatType( formatName, format );\n\nexport const init = () => {\n\tinitBlock( { name, metadata, settings } );\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-library",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.13",
|
|
4
4
|
"description": "Block library for the WordPress editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"@wordpress/api-fetch": "^6.32.1",
|
|
38
38
|
"@wordpress/autop": "^3.35.1",
|
|
39
39
|
"@wordpress/blob": "^3.35.1",
|
|
40
|
-
"@wordpress/block-editor": "^12.3.
|
|
40
|
+
"@wordpress/block-editor": "^12.3.11",
|
|
41
41
|
"@wordpress/blocks": "^12.12.6",
|
|
42
|
-
"@wordpress/components": "^25.1.
|
|
42
|
+
"@wordpress/components": "^25.1.10",
|
|
43
43
|
"@wordpress/compose": "^6.12.2",
|
|
44
|
-
"@wordpress/core-data": "^6.12.
|
|
44
|
+
"@wordpress/core-data": "^6.12.11",
|
|
45
45
|
"@wordpress/data": "^9.5.5",
|
|
46
46
|
"@wordpress/date": "^4.35.1",
|
|
47
47
|
"@wordpress/deprecated": "^3.35.1",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"@wordpress/notices": "^4.3.5",
|
|
57
57
|
"@wordpress/primitives": "^3.33.1",
|
|
58
58
|
"@wordpress/private-apis": "^0.17.2",
|
|
59
|
-
"@wordpress/reusable-blocks": "^4.12.
|
|
60
|
-
"@wordpress/rich-text": "^6.12.
|
|
61
|
-
"@wordpress/server-side-render": "^4.12.
|
|
59
|
+
"@wordpress/reusable-blocks": "^4.12.11",
|
|
60
|
+
"@wordpress/rich-text": "^6.12.7",
|
|
61
|
+
"@wordpress/server-side-render": "^4.12.11",
|
|
62
62
|
"@wordpress/url": "^3.36.1",
|
|
63
63
|
"@wordpress/viewport": "^5.12.5",
|
|
64
64
|
"@wordpress/wordcount": "^3.35.1",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "a6c8348f0058e714c97df49b4025e5d7d1c9e437"
|
|
87
87
|
}
|
package/src/footnotes/edit.js
CHANGED
|
@@ -17,6 +17,18 @@ export default function FootnotesEdit( { context: { postType, postId } } ) {
|
|
|
17
17
|
const footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];
|
|
18
18
|
const blockProps = useBlockProps();
|
|
19
19
|
|
|
20
|
+
if ( postType !== 'post' && postType !== 'page' ) {
|
|
21
|
+
return (
|
|
22
|
+
<div { ...blockProps }>
|
|
23
|
+
<Placeholder
|
|
24
|
+
icon={ <BlockIcon icon={ icon } /> }
|
|
25
|
+
label={ __( 'Footnotes' ) }
|
|
26
|
+
// To do: add instructions. We can't add new string in RC.
|
|
27
|
+
/>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
if ( ! footnotes.length ) {
|
|
21
33
|
return (
|
|
22
34
|
<div { ...blockProps }>
|
package/src/footnotes/format.js
CHANGED
|
@@ -12,14 +12,18 @@ import { insertObject } from '@wordpress/rich-text';
|
|
|
12
12
|
import {
|
|
13
13
|
RichTextToolbarButton,
|
|
14
14
|
store as blockEditorStore,
|
|
15
|
+
privateApis,
|
|
15
16
|
} from '@wordpress/block-editor';
|
|
16
17
|
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
|
|
17
|
-
import { createBlock } from '@wordpress/blocks';
|
|
18
|
+
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Internal dependencies
|
|
21
22
|
*/
|
|
22
23
|
import { name } from './block.json';
|
|
24
|
+
import { unlock } from '../lock-unlock';
|
|
25
|
+
|
|
26
|
+
const { usesContextKey } = unlock( privateApis );
|
|
23
27
|
|
|
24
28
|
export const formatName = 'core/footnote';
|
|
25
29
|
export const format = {
|
|
@@ -30,7 +34,13 @@ export const format = {
|
|
|
30
34
|
'data-fn': 'data-fn',
|
|
31
35
|
},
|
|
32
36
|
contentEditable: false,
|
|
33
|
-
|
|
37
|
+
[ usesContextKey ]: [ 'postType' ],
|
|
38
|
+
edit: function Edit( {
|
|
39
|
+
value,
|
|
40
|
+
onChange,
|
|
41
|
+
isObjectActive,
|
|
42
|
+
context: { postType },
|
|
43
|
+
} ) {
|
|
34
44
|
const registry = useRegistry();
|
|
35
45
|
const {
|
|
36
46
|
getSelectedBlockClientId,
|
|
@@ -38,9 +48,20 @@ export const format = {
|
|
|
38
48
|
getBlockName,
|
|
39
49
|
getBlocks,
|
|
40
50
|
} = useSelect( blockEditorStore );
|
|
51
|
+
const footnotesBlockType = useSelect( ( select ) =>
|
|
52
|
+
select( blocksStore ).getBlockType( name )
|
|
53
|
+
);
|
|
41
54
|
const { selectionChange, insertBlock } =
|
|
42
55
|
useDispatch( blockEditorStore );
|
|
43
56
|
|
|
57
|
+
if ( ! footnotesBlockType ) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ( postType !== 'post' && postType !== 'page' ) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
44
65
|
function onClick() {
|
|
45
66
|
registry.batch( () => {
|
|
46
67
|
let id;
|
package/src/footnotes/index.js
CHANGED
|
@@ -250,7 +250,7 @@ function build_template_part_block_instance_variations() {
|
|
|
250
250
|
'area' => $template_part->area,
|
|
251
251
|
),
|
|
252
252
|
'scope' => array( 'inserter' ),
|
|
253
|
-
'icon' => $icon_by_area[ $template_part->area ],
|
|
253
|
+
'icon' => isset( $icon_by_area[ $template_part->area ] ) ? $icon_by_area[ $template_part->area ] : null,
|
|
254
254
|
'example' => array(
|
|
255
255
|
'attributes' => array(
|
|
256
256
|
'slug' => $template_part->slug,
|