@wordpress/format-library 5.48.1 → 5.49.1-next.v.202606191442.0
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/CHANGELOG.md +6 -0
- package/build/math/index.cjs +28 -12
- package/build/math/index.cjs.map +2 -2
- package/build/non-breaking-space/index.cjs +1 -1
- package/build/non-breaking-space/index.cjs.map +1 -1
- package/build-module/math/index.mjs +35 -13
- package/build-module/math/index.mjs.map +2 -2
- package/build-module/non-breaking-space/index.mjs +1 -1
- package/build-module/non-breaking-space/index.mjs.map +1 -1
- package/package.json +17 -17
- package/src/math/index.js +47 -13
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 5.49.0-next.0 (2026-06-19)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Math format: seed the LaTeX input from the current selection when marking text as math, and toggle an active math object back to its LaTeX source when the button is clicked again. ([79052](https://github.com/WordPress/gutenberg/pull/79052))
|
|
10
|
+
|
|
5
11
|
## 5.48.1 (2026-06-16)
|
|
6
12
|
|
|
7
13
|
## 5.48.0 (2026-06-10)
|
package/build/math/index.cjs
CHANGED
|
@@ -147,24 +147,40 @@ function Edit({
|
|
|
147
147
|
setLatexToMathML(() => module2.default);
|
|
148
148
|
});
|
|
149
149
|
}, []);
|
|
150
|
+
function onClick() {
|
|
151
|
+
let newValue;
|
|
152
|
+
if (isObjectActive) {
|
|
153
|
+
const latex = activeObjectAttributes?.["data-latex"] || "";
|
|
154
|
+
newValue = (0, import_rich_text.insert)(value, latex);
|
|
155
|
+
newValue.start = newValue.end - latex.length;
|
|
156
|
+
} else {
|
|
157
|
+
const selectedText = (0, import_rich_text.getTextContent)((0, import_rich_text.slice)(value));
|
|
158
|
+
let innerHTML = "";
|
|
159
|
+
if (selectedText && latexToMathML) {
|
|
160
|
+
try {
|
|
161
|
+
innerHTML = latexToMathML(selectedText, {
|
|
162
|
+
displayMode: false
|
|
163
|
+
});
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
newValue = (0, import_rich_text.insertObject)(value, {
|
|
168
|
+
type: name,
|
|
169
|
+
attributes: { "data-latex": selectedText },
|
|
170
|
+
innerHTML
|
|
171
|
+
});
|
|
172
|
+
newValue.start = newValue.end - 1;
|
|
173
|
+
}
|
|
174
|
+
onChange(newValue);
|
|
175
|
+
onFocus();
|
|
176
|
+
}
|
|
150
177
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
151
178
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
152
179
|
import_block_editor.RichTextToolbarButton,
|
|
153
180
|
{
|
|
154
181
|
icon: import_icons.math,
|
|
155
182
|
title,
|
|
156
|
-
onClick
|
|
157
|
-
const newValue = (0, import_rich_text.insertObject)(value, {
|
|
158
|
-
type: name,
|
|
159
|
-
attributes: {
|
|
160
|
-
"data-latex": ""
|
|
161
|
-
},
|
|
162
|
-
innerHTML: ""
|
|
163
|
-
});
|
|
164
|
-
newValue.start = newValue.end - 1;
|
|
165
|
-
onChange(newValue);
|
|
166
|
-
onFocus();
|
|
167
|
-
},
|
|
183
|
+
onClick,
|
|
168
184
|
isActive: isObjectActive
|
|
169
185
|
}
|
|
170
186
|
),
|
package/build/math/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/math/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,qBAAoC;AACpC,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tinsert,\n\tinsertObject,\n\tslice,\n\tgetTextContent,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tPopover,\n\tTextControl,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { math as icon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { Badge: WCBadge } = unlock( componentsPrivateApis );\n\nconst name = 'core/math';\nconst title = __( 'Math' );\n\nfunction InlineUI( {\n\tvalue,\n\tonChange,\n\tactiveAttributes,\n\tcontentRef,\n\tlatexToMathML,\n} ) {\n\tconst [ latex, setLatex ] = useState(\n\t\tactiveAttributes?.[ 'data-latex' ] || ''\n\t);\n\tconst [ error, setError ] = useState( null );\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: math,\n\t} );\n\n\t// Update the math object in real-time as the user types\n\tconst handleLatexChange = ( newLatex ) => {\n\t\tlet mathML = '';\n\n\t\tsetLatex( newLatex );\n\n\t\tif ( newLatex ) {\n\t\t\ttry {\n\t\t\t\tmathML = latexToMathML( newLatex, { displayMode: false } );\n\t\t\t\tsetError( null );\n\t\t\t} catch ( err ) {\n\t\t\t\tsetError( err.message );\n\t\t\t\tspeak(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: error message returned when parsing LaTeX. */\n\t\t\t\t\t\t__( 'Error parsing mathematical expression: %s' ),\n\t\t\t\t\t\terr.message\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst newReplacements = value.replacements.slice();\n\t\tnewReplacements[ value.start ] = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\t'data-latex': newLatex,\n\t\t\t},\n\t\t\tinnerHTML: mathML,\n\t\t};\n\n\t\tonChange( {\n\t\t\t...value,\n\t\t\treplacements: newReplacements,\n\t\t} );\n\t};\n\n\treturn (\n\t\t<Popover\n\t\t\tplacement=\"bottom-start\"\n\t\t\toffset={ 8 }\n\t\t\tfocusOnMount={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\tclassName=\"block-editor-format-toolbar__math-popover\"\n\t\t>\n\t\t\t<div style={ { minWidth: '300px', padding: '4px' } }>\n\t\t\t\t<Stack direction=\"column\" gap=\"xs\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\tlabel={ __( 'LaTeX math syntax' ) }\n\t\t\t\t\t\tvalue={ latex }\n\t\t\t\t\t\tonChange={ handleLatexChange }\n\t\t\t\t\t\tplaceholder={ __( 'e.g., x^2, \\\\frac{a}{b}' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__math-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t{ error && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<WCBadge\n\t\t\t\t\t\t\t\tintent=\"error\"\n\t\t\t\t\t\t\t\tclassName=\"wp-block-math__error\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: error message returned when parsing LaTeX. */\n\t\t\t\t\t\t\t\t\t__( 'Error: %s' ),\n\t\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</WCBadge>\n\t\t\t\t\t\t\t<style children=\".wp-block-math__error .components-badge__content{white-space:normal}\" />\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</div>\n\t\t</Popover>\n\t);\n}\n\nfunction Edit( {\n\tvalue,\n\tonChange,\n\tonFocus,\n\tisObjectActive,\n\tactiveObjectAttributes,\n\tcontentRef,\n} ) {\n\tconst [ latexToMathML, setLatexToMathML ] = useState();\n\n\tuseEffect( () => {\n\t\timport( '@wordpress/latex-to-mathml' ).then( ( module ) => {\n\t\t\tsetLatexToMathML( () => module.default );\n\t\t} );\n\t}, [] );\n\n\tfunction onClick() {\n\t\tlet newValue;\n\n\t\tif ( isObjectActive ) {\n\t\t\t// Revert the active math object to its LaTeX source so clicking\n\t\t\t// the button toggles back to the exact text it was created from.\n\t\t\t// Keep the restored text selected so it can be edited or\n\t\t\t// re-marked right away.\n\t\t\tconst latex = activeObjectAttributes?.[ 'data-latex' ] || '';\n\t\t\tnewValue = insert( value, latex );\n\t\t\tnewValue.start = newValue.end - latex.length;\n\t\t} else {\n\t\t\t// If there's a selection, seed the format with it so you can type\n\t\t\t// LaTeX inline and then mark it as math.\n\t\t\tconst selectedText = getTextContent( slice( value ) );\n\t\t\tlet innerHTML = '';\n\t\t\tif ( selectedText && latexToMathML ) {\n\t\t\t\ttry {\n\t\t\t\t\tinnerHTML = latexToMathML( selectedText, {\n\t\t\t\t\t\tdisplayMode: false,\n\t\t\t\t\t} );\n\t\t\t\t} catch {\n\t\t\t\t\t// Leave unrendered; the popover opens with the text\n\t\t\t\t\t// prefilled so the expression can be corrected.\n\t\t\t\t}\n\t\t\t}\n\t\t\tnewValue = insertObject( value, {\n\t\t\t\ttype: name,\n\t\t\t\tattributes: { 'data-latex': selectedText },\n\t\t\t\tinnerHTML,\n\t\t\t} );\n\t\t\tnewValue.start = newValue.end - 1;\n\t\t}\n\n\t\tonChange( newValue );\n\t\tonFocus();\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ icon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isObjectActive }\n\t\t\t/>\n\t\t\t{ isObjectActive && (\n\t\t\t\t<InlineUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tactiveAttributes={ activeObjectAttributes }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\tlatexToMathML={ latexToMathML }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const math = {\n\tname,\n\ttitle,\n\ttagName: 'math',\n\tclassName: null,\n\tattributes: {\n\t\t'data-latex': 'data-latex',\n\t},\n\tcontentEditable: false,\n\tedit: Edit,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,qBAAoC;AACpC,uBAMO;AACP,0BAAsC;AACtC,wBAIO;AACP,gBAAsB;AACtB,mBAA6B;AAC7B,kBAAsB;AAKtB,yBAAuB;AAwElB;AAtEL,IAAM,EAAE,OAAO,QAAQ,QAAI,2BAAQ,kBAAAA,WAAsB;AAEzD,IAAM,OAAO;AACb,IAAM,YAAQ,gBAAI,MAAO;AAEzB,SAAS,SAAU;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,CAAE,OAAO,QAAS,QAAI;AAAA,IAC3B,mBAAoB,YAAa,KAAK;AAAA,EACvC;AACA,QAAM,CAAE,OAAO,QAAS,QAAI,yBAAU,IAAK;AAE3C,QAAM,oBAAgB,4BAAW;AAAA,IAChC,wBAAwB,WAAW;AAAA,IACnC,UAAU;AAAA,EACX,CAAE;AAGF,QAAM,oBAAoB,CAAE,aAAc;AACzC,QAAI,SAAS;AAEb,aAAU,QAAS;AAEnB,QAAK,UAAW;AACf,UAAI;AACH,iBAAS,cAAe,UAAU,EAAE,aAAa,MAAM,CAAE;AACzD,iBAAU,IAAK;AAAA,MAChB,SAAU,KAAM;AACf,iBAAU,IAAI,OAAQ;AACtB;AAAA,cACC;AAAA;AAAA,gBAEC,gBAAI,2CAA4C;AAA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;AAAA,IACxC,CAAE;AAAA,EACH,GAAG,CAAC,CAAE;AAEN,WAAS,UAAU;AAClB,QAAI;AAEJ,QAAK,gBAAiB;AAKrB,YAAM,QAAQ,yBAA0B,YAAa,KAAK;AAC1D,qBAAW,yBAAQ,OAAO,KAAM;AAChC,eAAS,QAAQ,SAAS,MAAM,MAAM;AAAA,IACvC,OAAO;AAGN,YAAM,mBAAe,qCAAgB,wBAAO,KAAM,CAAE;AACpD,UAAI,YAAY;AAChB,UAAK,gBAAgB,eAAgB;AACpC,YAAI;AACH,sBAAY,cAAe,cAAc;AAAA,YACxC,aAAa;AAAA,UACd,CAAE;AAAA,QACH,QAAQ;AAAA,QAGR;AAAA,MACD;AACA,qBAAW,+BAAc,OAAO;AAAA,QAC/B,MAAM;AAAA,QACN,YAAY,EAAE,cAAc,aAAa;AAAA,QACzC;AAAA,MACD,CAAE;AACF,eAAS,QAAQ,SAAS,MAAM;AAAA,IACjC;AAEA,aAAU,QAAS;AACnB,YAAQ;AAAA,EACT;AAEA,SACC,4EACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO,aAAAC;AAAA,QACP;AAAA,QACA;AAAA,QACA,UAAW;AAAA;AAAA,IACZ;AAAA,IACE,kBACD;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAmB;AAAA,QACnB;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEO,IAAM,OAAO;AAAA,EACnB;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,IACX,cAAc;AAAA,EACf;AAAA,EACA,iBAAiB;AAAA,EACjB,MAAM;AACP;",
|
|
6
6
|
"names": ["componentsPrivateApis", "module", "icon"]
|
|
7
7
|
}
|
|
@@ -35,7 +35,7 @@ var nonBreakingSpace = {
|
|
|
35
35
|
className: null,
|
|
36
36
|
edit({ value, onChange }) {
|
|
37
37
|
function addNonBreakingSpace() {
|
|
38
|
-
onChange((0, import_rich_text.insert)(value, "
|
|
38
|
+
onChange((0, import_rich_text.insert)(value, " "));
|
|
39
39
|
}
|
|
40
40
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
41
41
|
import_block_editor.RichTextShortcut,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/non-breaking-space/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { insert } from '@wordpress/rich-text';\nimport { RichTextShortcut } from '@wordpress/block-editor';\n\nconst name = 'core/non-breaking-space';\nconst title = __( 'Non breaking space' );\n\nexport const nonBreakingSpace = {\n\tname,\n\ttitle,\n\ttagName: 'nbsp',\n\tclassName: null,\n\tedit( { value, onChange } ) {\n\t\tfunction addNonBreakingSpace() {\n\t\t\tonChange( insert( value, '\\u00a0' ) );\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\" \"\n\t\t\t\tonUse={ addNonBreakingSpace }\n\t\t\t/>\n\t\t);\n\t},\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,uBAAuB;AACvB,0BAAiC;AAgB9B;AAdH,IAAM,OAAO;AACb,IAAM,YAAQ,gBAAI,oBAAqB;AAEhC,IAAM,mBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,KAAM,EAAE,OAAO,SAAS,GAAI;AAC3B,aAAS,sBAAsB;AAC9B,mBAAU,yBAAQ,OAAO,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,uBAAuB;AACvB,0BAAiC;AAgB9B;AAdH,IAAM,OAAO;AACb,IAAM,YAAQ,gBAAI,oBAAqB;AAEhC,IAAM,mBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,KAAM,EAAE,OAAO,SAAS,GAAI;AAC3B,aAAS,sBAAsB;AAC9B,mBAAU,yBAAQ,OAAO,GAAS,CAAE;AAAA,IACrC;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,WAAU;AAAA,QACV,OAAQ;AAAA;AAAA,IACT;AAAA,EAEF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// packages/format-library/src/math/index.js
|
|
2
2
|
import { __, sprintf } from "@wordpress/i18n";
|
|
3
3
|
import { useState, useEffect } from "@wordpress/element";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
insert,
|
|
6
|
+
insertObject,
|
|
7
|
+
slice,
|
|
8
|
+
getTextContent,
|
|
9
|
+
useAnchor
|
|
10
|
+
} from "@wordpress/rich-text";
|
|
5
11
|
import { RichTextToolbarButton } from "@wordpress/block-editor";
|
|
6
12
|
import {
|
|
7
13
|
Popover,
|
|
@@ -118,24 +124,40 @@ function Edit({
|
|
|
118
124
|
setLatexToMathML(() => module.default);
|
|
119
125
|
});
|
|
120
126
|
}, []);
|
|
127
|
+
function onClick() {
|
|
128
|
+
let newValue;
|
|
129
|
+
if (isObjectActive) {
|
|
130
|
+
const latex = activeObjectAttributes?.["data-latex"] || "";
|
|
131
|
+
newValue = insert(value, latex);
|
|
132
|
+
newValue.start = newValue.end - latex.length;
|
|
133
|
+
} else {
|
|
134
|
+
const selectedText = getTextContent(slice(value));
|
|
135
|
+
let innerHTML = "";
|
|
136
|
+
if (selectedText && latexToMathML) {
|
|
137
|
+
try {
|
|
138
|
+
innerHTML = latexToMathML(selectedText, {
|
|
139
|
+
displayMode: false
|
|
140
|
+
});
|
|
141
|
+
} catch {
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
newValue = insertObject(value, {
|
|
145
|
+
type: name,
|
|
146
|
+
attributes: { "data-latex": selectedText },
|
|
147
|
+
innerHTML
|
|
148
|
+
});
|
|
149
|
+
newValue.start = newValue.end - 1;
|
|
150
|
+
}
|
|
151
|
+
onChange(newValue);
|
|
152
|
+
onFocus();
|
|
153
|
+
}
|
|
121
154
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
122
155
|
/* @__PURE__ */ jsx(
|
|
123
156
|
RichTextToolbarButton,
|
|
124
157
|
{
|
|
125
158
|
icon,
|
|
126
159
|
title,
|
|
127
|
-
onClick
|
|
128
|
-
const newValue = insertObject(value, {
|
|
129
|
-
type: name,
|
|
130
|
-
attributes: {
|
|
131
|
-
"data-latex": ""
|
|
132
|
-
},
|
|
133
|
-
innerHTML: ""
|
|
134
|
-
});
|
|
135
|
-
newValue.start = newValue.end - 1;
|
|
136
|
-
onChange(newValue);
|
|
137
|
-
onFocus();
|
|
138
|
-
},
|
|
160
|
+
onClick,
|
|
139
161
|
isActive: isObjectActive
|
|
140
162
|
}
|
|
141
163
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/math/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,UAAU,iBAAiB;AACpC,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tinsert,\n\tinsertObject,\n\tslice,\n\tgetTextContent,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tPopover,\n\tTextControl,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { math as icon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { Badge: WCBadge } = unlock( componentsPrivateApis );\n\nconst name = 'core/math';\nconst title = __( 'Math' );\n\nfunction InlineUI( {\n\tvalue,\n\tonChange,\n\tactiveAttributes,\n\tcontentRef,\n\tlatexToMathML,\n} ) {\n\tconst [ latex, setLatex ] = useState(\n\t\tactiveAttributes?.[ 'data-latex' ] || ''\n\t);\n\tconst [ error, setError ] = useState( null );\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: math,\n\t} );\n\n\t// Update the math object in real-time as the user types\n\tconst handleLatexChange = ( newLatex ) => {\n\t\tlet mathML = '';\n\n\t\tsetLatex( newLatex );\n\n\t\tif ( newLatex ) {\n\t\t\ttry {\n\t\t\t\tmathML = latexToMathML( newLatex, { displayMode: false } );\n\t\t\t\tsetError( null );\n\t\t\t} catch ( err ) {\n\t\t\t\tsetError( err.message );\n\t\t\t\tspeak(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: error message returned when parsing LaTeX. */\n\t\t\t\t\t\t__( 'Error parsing mathematical expression: %s' ),\n\t\t\t\t\t\terr.message\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst newReplacements = value.replacements.slice();\n\t\tnewReplacements[ value.start ] = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\t'data-latex': newLatex,\n\t\t\t},\n\t\t\tinnerHTML: mathML,\n\t\t};\n\n\t\tonChange( {\n\t\t\t...value,\n\t\t\treplacements: newReplacements,\n\t\t} );\n\t};\n\n\treturn (\n\t\t<Popover\n\t\t\tplacement=\"bottom-start\"\n\t\t\toffset={ 8 }\n\t\t\tfocusOnMount={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\tclassName=\"block-editor-format-toolbar__math-popover\"\n\t\t>\n\t\t\t<div style={ { minWidth: '300px', padding: '4px' } }>\n\t\t\t\t<Stack direction=\"column\" gap=\"xs\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\tlabel={ __( 'LaTeX math syntax' ) }\n\t\t\t\t\t\tvalue={ latex }\n\t\t\t\t\t\tonChange={ handleLatexChange }\n\t\t\t\t\t\tplaceholder={ __( 'e.g., x^2, \\\\frac{a}{b}' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t\tclassName=\"block-editor-format-toolbar__math-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t{ error && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<WCBadge\n\t\t\t\t\t\t\t\tintent=\"error\"\n\t\t\t\t\t\t\t\tclassName=\"wp-block-math__error\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: error message returned when parsing LaTeX. */\n\t\t\t\t\t\t\t\t\t__( 'Error: %s' ),\n\t\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</WCBadge>\n\t\t\t\t\t\t\t<style children=\".wp-block-math__error .components-badge__content{white-space:normal}\" />\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</div>\n\t\t</Popover>\n\t);\n}\n\nfunction Edit( {\n\tvalue,\n\tonChange,\n\tonFocus,\n\tisObjectActive,\n\tactiveObjectAttributes,\n\tcontentRef,\n} ) {\n\tconst [ latexToMathML, setLatexToMathML ] = useState();\n\n\tuseEffect( () => {\n\t\timport( '@wordpress/latex-to-mathml' ).then( ( module ) => {\n\t\t\tsetLatexToMathML( () => module.default );\n\t\t} );\n\t}, [] );\n\n\tfunction onClick() {\n\t\tlet newValue;\n\n\t\tif ( isObjectActive ) {\n\t\t\t// Revert the active math object to its LaTeX source so clicking\n\t\t\t// the button toggles back to the exact text it was created from.\n\t\t\t// Keep the restored text selected so it can be edited or\n\t\t\t// re-marked right away.\n\t\t\tconst latex = activeObjectAttributes?.[ 'data-latex' ] || '';\n\t\t\tnewValue = insert( value, latex );\n\t\t\tnewValue.start = newValue.end - latex.length;\n\t\t} else {\n\t\t\t// If there's a selection, seed the format with it so you can type\n\t\t\t// LaTeX inline and then mark it as math.\n\t\t\tconst selectedText = getTextContent( slice( value ) );\n\t\t\tlet innerHTML = '';\n\t\t\tif ( selectedText && latexToMathML ) {\n\t\t\t\ttry {\n\t\t\t\t\tinnerHTML = latexToMathML( selectedText, {\n\t\t\t\t\t\tdisplayMode: false,\n\t\t\t\t\t} );\n\t\t\t\t} catch {\n\t\t\t\t\t// Leave unrendered; the popover opens with the text\n\t\t\t\t\t// prefilled so the expression can be corrected.\n\t\t\t\t}\n\t\t\t}\n\t\t\tnewValue = insertObject( value, {\n\t\t\t\ttype: name,\n\t\t\t\tattributes: { 'data-latex': selectedText },\n\t\t\t\tinnerHTML,\n\t\t\t} );\n\t\t\tnewValue.start = newValue.end - 1;\n\t\t}\n\n\t\tonChange( newValue );\n\t\tonFocus();\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ icon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isObjectActive }\n\t\t\t/>\n\t\t\t{ isObjectActive && (\n\t\t\t\t<InlineUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tactiveAttributes={ activeObjectAttributes }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\tlatexToMathML={ latexToMathML }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const math = {\n\tname,\n\ttitle,\n\ttagName: 'math',\n\tclassName: null,\n\tattributes: {\n\t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AChC,eAAS,QAAQ,SAAS,MAAM,MAAM;AAAA,IACvC,OAAO;AAGN,YAAM,eAAe,eAAgB,MAAO,KAAM,CAAE;AACpD,UAAI,YAAY;AAChB,UAAK,gBAAgB,eAAgB;AACpC,YAAI;AACH,sBAAY,cAAe,cAAc;AAAA,YACxC,aAAa;AAAA,UACd,CAAE;AAAA,QACH,QAAQ;AAAA,QAGR;AAAA,MACD;AACA,iBAAW,aAAc,OAAO;AAAA,QAC/B,MAAM;AAAA,QACN,YAAY,EAAE,cAAc,aAAa;AAAA,QACzC;AAAA,MACD,CAAE;AACF,eAAS,QAAQ,SAAS,MAAM;AAAA,IACjC;AAEA,aAAU,QAAS;AACnB,YAAQ;AAAA,EACT;AAEA,SACC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,UAAW;AAAA;AAAA,IACZ;AAAA,IACE,kBACD;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAmB;AAAA,QACnB;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEO,IAAM,OAAO;AAAA,EACnB;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,IACX,cAAc;AAAA,EACf;AAAA,EACA,iBAAiB;AAAA,EACjB,MAAM;AACP;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/non-breaking-space/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { insert } from '@wordpress/rich-text';\nimport { RichTextShortcut } from '@wordpress/block-editor';\n\nconst name = 'core/non-breaking-space';\nconst title = __( 'Non breaking space' );\n\nexport const nonBreakingSpace = {\n\tname,\n\ttitle,\n\ttagName: 'nbsp',\n\tclassName: null,\n\tedit( { value, onChange } ) {\n\t\tfunction addNonBreakingSpace() {\n\t\t\tonChange( insert( value, '\\u00a0' ) );\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\" \"\n\t\t\t\tonUse={ addNonBreakingSpace }\n\t\t\t/>\n\t\t);\n\t},\n};\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,wBAAwB;AAgB9B;AAdH,IAAM,OAAO;AACb,IAAM,QAAQ,GAAI,oBAAqB;AAEhC,IAAM,mBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,KAAM,EAAE,OAAO,SAAS,GAAI;AAC3B,aAAS,sBAAsB;AAC9B,eAAU,OAAQ,OAAO,
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,wBAAwB;AAgB9B;AAdH,IAAM,OAAO;AACb,IAAM,QAAQ,GAAI,oBAAqB;AAEhC,IAAM,mBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,KAAM,EAAE,OAAO,SAAS,GAAI;AAC3B,aAAS,sBAAsB;AAC9B,eAAU,OAAQ,OAAO,GAAS,CAAE;AAAA,IACrC;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,WAAU;AAAA,QACV,OAAQ;AAAA;AAAA,IACT;AAAA,EAEF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/format-library",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.49.1-next.v.202606191442.0+17fe7db8a",
|
|
4
4
|
"description": "Format library for the WordPress editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
},
|
|
42
42
|
"wpScript": true,
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wordpress/a11y": "^4.48.
|
|
45
|
-
"@wordpress/base-styles": "^10.0.
|
|
46
|
-
"@wordpress/block-editor": "^15.
|
|
47
|
-
"@wordpress/components": "^35.
|
|
48
|
-
"@wordpress/compose": "^8.1.
|
|
49
|
-
"@wordpress/data": "^10.48.
|
|
50
|
-
"@wordpress/element": "^8.0.
|
|
51
|
-
"@wordpress/html-entities": "^4.48.
|
|
52
|
-
"@wordpress/i18n": "^6.21.
|
|
53
|
-
"@wordpress/icons": "^14.0.
|
|
54
|
-
"@wordpress/latex-to-mathml": "^1.16.
|
|
55
|
-
"@wordpress/private-apis": "^1.48.
|
|
56
|
-
"@wordpress/rich-text": "^7.48.
|
|
57
|
-
"@wordpress/ui": "^0.
|
|
58
|
-
"@wordpress/url": "^4.48.
|
|
44
|
+
"@wordpress/a11y": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
45
|
+
"@wordpress/base-styles": "^10.0.2-next.v.202606191442.0+17fe7db8a",
|
|
46
|
+
"@wordpress/block-editor": "^15.22.1-next.v.202606191442.0+17fe7db8a",
|
|
47
|
+
"@wordpress/components": "^35.1.1-next.v.202606191442.0+17fe7db8a",
|
|
48
|
+
"@wordpress/compose": "^8.1.2-next.v.202606191442.0+17fe7db8a",
|
|
49
|
+
"@wordpress/data": "^10.48.2-next.v.202606191442.0+17fe7db8a",
|
|
50
|
+
"@wordpress/element": "^8.0.2-next.v.202606191442.0+17fe7db8a",
|
|
51
|
+
"@wordpress/html-entities": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
52
|
+
"@wordpress/i18n": "^6.21.2-next.v.202606191442.0+17fe7db8a",
|
|
53
|
+
"@wordpress/icons": "^14.0.2-next.v.202606191442.0+17fe7db8a",
|
|
54
|
+
"@wordpress/latex-to-mathml": "^1.16.2-next.v.202606191442.0+17fe7db8a",
|
|
55
|
+
"@wordpress/private-apis": "^1.48.2-next.v.202606191442.0+17fe7db8a",
|
|
56
|
+
"@wordpress/rich-text": "^7.48.2-next.v.202606191442.0+17fe7db8a",
|
|
57
|
+
"@wordpress/ui": "^0.16.1-next.v.202606191442.0+17fe7db8a",
|
|
58
|
+
"@wordpress/url": "^4.48.2-next.v.202606191442.0+17fe7db8a"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "1b6a19222df5a88f161880b5789efb3171d8f425"
|
|
73
73
|
}
|
package/src/math/index.js
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __, sprintf } from '@wordpress/i18n';
|
|
5
5
|
import { useState, useEffect } from '@wordpress/element';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
insert,
|
|
8
|
+
insertObject,
|
|
9
|
+
slice,
|
|
10
|
+
getTextContent,
|
|
11
|
+
useAnchor,
|
|
12
|
+
} from '@wordpress/rich-text';
|
|
7
13
|
import { RichTextToolbarButton } from '@wordpress/block-editor';
|
|
8
14
|
import {
|
|
9
15
|
Popover,
|
|
@@ -135,23 +141,51 @@ function Edit( {
|
|
|
135
141
|
setLatexToMathML( () => module.default );
|
|
136
142
|
} );
|
|
137
143
|
}, [] );
|
|
144
|
+
|
|
145
|
+
function onClick() {
|
|
146
|
+
let newValue;
|
|
147
|
+
|
|
148
|
+
if ( isObjectActive ) {
|
|
149
|
+
// Revert the active math object to its LaTeX source so clicking
|
|
150
|
+
// the button toggles back to the exact text it was created from.
|
|
151
|
+
// Keep the restored text selected so it can be edited or
|
|
152
|
+
// re-marked right away.
|
|
153
|
+
const latex = activeObjectAttributes?.[ 'data-latex' ] || '';
|
|
154
|
+
newValue = insert( value, latex );
|
|
155
|
+
newValue.start = newValue.end - latex.length;
|
|
156
|
+
} else {
|
|
157
|
+
// If there's a selection, seed the format with it so you can type
|
|
158
|
+
// LaTeX inline and then mark it as math.
|
|
159
|
+
const selectedText = getTextContent( slice( value ) );
|
|
160
|
+
let innerHTML = '';
|
|
161
|
+
if ( selectedText && latexToMathML ) {
|
|
162
|
+
try {
|
|
163
|
+
innerHTML = latexToMathML( selectedText, {
|
|
164
|
+
displayMode: false,
|
|
165
|
+
} );
|
|
166
|
+
} catch {
|
|
167
|
+
// Leave unrendered; the popover opens with the text
|
|
168
|
+
// prefilled so the expression can be corrected.
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
newValue = insertObject( value, {
|
|
172
|
+
type: name,
|
|
173
|
+
attributes: { 'data-latex': selectedText },
|
|
174
|
+
innerHTML,
|
|
175
|
+
} );
|
|
176
|
+
newValue.start = newValue.end - 1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
onChange( newValue );
|
|
180
|
+
onFocus();
|
|
181
|
+
}
|
|
182
|
+
|
|
138
183
|
return (
|
|
139
184
|
<>
|
|
140
185
|
<RichTextToolbarButton
|
|
141
186
|
icon={ icon }
|
|
142
187
|
title={ title }
|
|
143
|
-
onClick={
|
|
144
|
-
const newValue = insertObject( value, {
|
|
145
|
-
type: name,
|
|
146
|
-
attributes: {
|
|
147
|
-
'data-latex': '',
|
|
148
|
-
},
|
|
149
|
-
innerHTML: '',
|
|
150
|
-
} );
|
|
151
|
-
newValue.start = newValue.end - 1;
|
|
152
|
-
onChange( newValue );
|
|
153
|
-
onFocus();
|
|
154
|
-
} }
|
|
188
|
+
onClick={ onClick }
|
|
155
189
|
isActive={ isObjectActive }
|
|
156
190
|
/>
|
|
157
191
|
{ isObjectActive && (
|