@wordpress/format-library 5.48.1 → 5.49.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/language/index.cjs +0 -1
- package/build/language/index.cjs.map +2 -2
- package/build/math/index.cjs +28 -13
- 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/language/index.mjs +0 -1
- package/build-module/language/index.mjs.map +2 -2
- package/build-module/math/index.mjs +35 -14
- 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/language/index.js +0 -1
- package/src/math/index.js +47 -14
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 5.49.0 (2026-06-24)
|
|
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/language/index.cjs
CHANGED
|
@@ -114,7 +114,6 @@ function InlineLanguageUI({ value, contentRef, onChange, onClose }) {
|
|
|
114
114
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
115
|
import_components.TextControl,
|
|
116
116
|
{
|
|
117
|
-
__next40pxDefaultSize: true,
|
|
118
117
|
label: title,
|
|
119
118
|
value: lang,
|
|
120
119
|
onChange: (val) => setLang(val),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/language/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\tSelectControl,\n\tButton,\n\tPopover,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useState } from '@wordpress/element';\nimport { applyFormat, removeFormat, useAnchor } from '@wordpress/rich-text';\nimport { language as languageIcon } from '@wordpress/icons';\n\nconst name = 'core/language';\nconst title = __( 'Language' );\n\nexport const language = {\n\tname,\n\ttitle,\n\ttagName: 'bdo',\n\tclassName: null,\n\tattributes: {\n\t\tlang: 'lang',\n\t\tdir: 'dir',\n\t},\n\tedit: Edit,\n};\n\nfunction Edit( { isActive, value, onChange, contentRef } ) {\n\tconst [ isPopoverVisible, setIsPopoverVisible ] = useState( false );\n\tconst togglePopover = () => {\n\t\tsetIsPopoverVisible( ( state ) => ! state );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ languageIcon }\n\t\t\t\tlabel={ title }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tif ( isActive ) {\n\t\t\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttogglePopover();\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isPopoverVisible && (\n\t\t\t\t<InlineLanguageUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonClose={ togglePopover }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction InlineLanguageUI( { value, contentRef, onChange, onClose } ) {\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: language,\n\t} );\n\n\tconst [ lang, setLang ] = useState( '' );\n\tconst [ dir, setDir ] = useState( 'ltr' );\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-format-toolbar__language-popover\"\n\t\t\tanchor={ popoverAnchor }\n\t\t\tonClose={ onClose }\n\t\t>\n\t\t\t<Stack\n\t\t\t\trender={ <form /> }\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t\tclassName=\"block-editor-format-toolbar__language-container-content\"\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tapplyFormat( value, {\n\t\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\t\tdir,\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\tonClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAKnB,0BAAsC;AACtC,wBAKO;AACP,gBAAsB;AACtB,qBAAyB;AACzB,uBAAqD;AACrD,mBAAyC;AAwBvC;AAtBF,IAAM,OAAO;AACb,IAAM,YAAQ,gBAAI,UAAW;AAEtB,IAAM,WAAW;AAAA,EACvB;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,IACX,MAAM;AAAA,IACN,KAAK;AAAA,EACN;AAAA,EACA,MAAM;AACP;AAEA,SAAS,KAAM,EAAE,UAAU,OAAO,UAAU,WAAW,GAAI;AAC1D,QAAM,CAAE,kBAAkB,mBAAoB,QAAI,yBAAU,KAAM;AAClE,QAAM,gBAAgB,MAAM;AAC3B,wBAAqB,CAAE,UAAW,CAAE,KAAM;AAAA,EAC3C;AAEA,SACC,4EACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO,aAAAA;AAAA,QACP,OAAQ;AAAA,QACR;AAAA,QACA,SAAU,MAAM;AACf,cAAK,UAAW;AACf,yBAAU,+BAAc,OAAO,IAAK,CAAE;AAAA,UACvC,OAAO;AACN,0BAAc;AAAA,UACf;AAAA,QACD;AAAA,QACA;AAAA,QACA,MAAK;AAAA;AAAA,IACN;AAAA,IACE,oBACD;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAU;AAAA,QACV;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEA,SAAS,iBAAkB,EAAE,OAAO,YAAY,UAAU,QAAQ,GAAI;AACrE,QAAM,oBAAgB,4BAAW;AAAA,IAChC,wBAAwB,WAAW;AAAA,IACnC,UAAU;AAAA,EACX,CAAE;AAEF,QAAM,CAAE,MAAM,OAAQ,QAAI,yBAAU,EAAG;AACvC,QAAM,CAAE,KAAK,MAAO,QAAI,yBAAU,KAAM;AAExC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,QAAS;AAAA,MACT;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACA,QAAS,4CAAC,UAAK;AAAA,UACf,WAAU;AAAA,UACV,KAAI;AAAA,UACJ,WAAU;AAAA,UACV,UAAW,CAAE,UAAW;AACvB,kBAAM,eAAe;AACrB;AAAA,kBACC,8BAAa,OAAO;AAAA,gBACnB,MAAM;AAAA,gBACN,YAAY;AAAA,kBACX;AAAA,kBACA;AAAA,gBACD;AAAA,cACD,CAAE;AAAA,YACH;AACA,oBAAQ;AAAA,UACT;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\tSelectControl,\n\tButton,\n\tPopover,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useState } from '@wordpress/element';\nimport { applyFormat, removeFormat, useAnchor } from '@wordpress/rich-text';\nimport { language as languageIcon } from '@wordpress/icons';\n\nconst name = 'core/language';\nconst title = __( 'Language' );\n\nexport const language = {\n\tname,\n\ttitle,\n\ttagName: 'bdo',\n\tclassName: null,\n\tattributes: {\n\t\tlang: 'lang',\n\t\tdir: 'dir',\n\t},\n\tedit: Edit,\n};\n\nfunction Edit( { isActive, value, onChange, contentRef } ) {\n\tconst [ isPopoverVisible, setIsPopoverVisible ] = useState( false );\n\tconst togglePopover = () => {\n\t\tsetIsPopoverVisible( ( state ) => ! state );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ languageIcon }\n\t\t\t\tlabel={ title }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tif ( isActive ) {\n\t\t\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttogglePopover();\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isPopoverVisible && (\n\t\t\t\t<InlineLanguageUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonClose={ togglePopover }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction InlineLanguageUI( { value, contentRef, onChange, onClose } ) {\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: language,\n\t} );\n\n\tconst [ lang, setLang ] = useState( '' );\n\tconst [ dir, setDir ] = useState( 'ltr' );\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-format-toolbar__language-popover\"\n\t\t\tanchor={ popoverAnchor }\n\t\t\tonClose={ onClose }\n\t\t>\n\t\t\t<Stack\n\t\t\t\trender={ <form /> }\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t\tclassName=\"block-editor-format-toolbar__language-container-content\"\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tapplyFormat( value, {\n\t\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\t\tdir,\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\tonClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ title }\n\t\t\t\t\tvalue={ lang }\n\t\t\t\t\tonChange={ ( val ) => setLang( val ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'A valid language attribute, like \"en\" or \"fr\".'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<SelectControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Text direction' ) }\n\t\t\t\t\tvalue={ dir }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Left to right' ),\n\t\t\t\t\t\t\tvalue: 'ltr',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Right to left' ),\n\t\t\t\t\t\t\tvalue: 'rtl',\n\t\t\t\t\t\t},\n\t\t\t\t\t] }\n\t\t\t\t\tonChange={ ( val ) => setDir( val ) }\n\t\t\t\t/>\n\t\t\t\t<Stack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\ttext={ __( 'Apply' ) }\n\t\t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
package/build/math/index.cjs
CHANGED
|
@@ -104,7 +104,6 @@ function InlineUI({
|
|
|
104
104
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
105
105
|
import_components.TextControl,
|
|
106
106
|
{
|
|
107
|
-
__next40pxDefaultSize: true,
|
|
108
107
|
hideLabelFromVision: true,
|
|
109
108
|
label: (0, import_i18n.__)("LaTeX math syntax"),
|
|
110
109
|
value: latex,
|
|
@@ -147,24 +146,40 @@ function Edit({
|
|
|
147
146
|
setLatexToMathML(() => module2.default);
|
|
148
147
|
});
|
|
149
148
|
}, []);
|
|
149
|
+
function onClick() {
|
|
150
|
+
let newValue;
|
|
151
|
+
if (isObjectActive) {
|
|
152
|
+
const latex = activeObjectAttributes?.["data-latex"] || "";
|
|
153
|
+
newValue = (0, import_rich_text.insert)(value, latex);
|
|
154
|
+
newValue.start = newValue.end - latex.length;
|
|
155
|
+
} else {
|
|
156
|
+
const selectedText = (0, import_rich_text.getTextContent)((0, import_rich_text.slice)(value));
|
|
157
|
+
let innerHTML = "";
|
|
158
|
+
if (selectedText && latexToMathML) {
|
|
159
|
+
try {
|
|
160
|
+
innerHTML = latexToMathML(selectedText, {
|
|
161
|
+
displayMode: false
|
|
162
|
+
});
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
newValue = (0, import_rich_text.insertObject)(value, {
|
|
167
|
+
type: name,
|
|
168
|
+
attributes: { "data-latex": selectedText },
|
|
169
|
+
innerHTML
|
|
170
|
+
});
|
|
171
|
+
newValue.start = newValue.end - 1;
|
|
172
|
+
}
|
|
173
|
+
onChange(newValue);
|
|
174
|
+
onFocus();
|
|
175
|
+
}
|
|
150
176
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
151
177
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
152
178
|
import_block_editor.RichTextToolbarButton,
|
|
153
179
|
{
|
|
154
180
|
icon: import_icons.math,
|
|
155
181
|
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
|
-
},
|
|
182
|
+
onClick,
|
|
168
183
|
isActive: isObjectActive
|
|
169
184
|
}
|
|
170
185
|
),
|
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\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,EAA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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,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/language/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\tSelectControl,\n\tButton,\n\tPopover,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useState } from '@wordpress/element';\nimport { applyFormat, removeFormat, useAnchor } from '@wordpress/rich-text';\nimport { language as languageIcon } from '@wordpress/icons';\n\nconst name = 'core/language';\nconst title = __( 'Language' );\n\nexport const language = {\n\tname,\n\ttitle,\n\ttagName: 'bdo',\n\tclassName: null,\n\tattributes: {\n\t\tlang: 'lang',\n\t\tdir: 'dir',\n\t},\n\tedit: Edit,\n};\n\nfunction Edit( { isActive, value, onChange, contentRef } ) {\n\tconst [ isPopoverVisible, setIsPopoverVisible ] = useState( false );\n\tconst togglePopover = () => {\n\t\tsetIsPopoverVisible( ( state ) => ! state );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ languageIcon }\n\t\t\t\tlabel={ title }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tif ( isActive ) {\n\t\t\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttogglePopover();\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isPopoverVisible && (\n\t\t\t\t<InlineLanguageUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonClose={ togglePopover }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction InlineLanguageUI( { value, contentRef, onChange, onClose } ) {\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: language,\n\t} );\n\n\tconst [ lang, setLang ] = useState( '' );\n\tconst [ dir, setDir ] = useState( 'ltr' );\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-format-toolbar__language-popover\"\n\t\t\tanchor={ popoverAnchor }\n\t\t\tonClose={ onClose }\n\t\t>\n\t\t\t<Stack\n\t\t\t\trender={ <form /> }\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t\tclassName=\"block-editor-format-toolbar__language-container-content\"\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tapplyFormat( value, {\n\t\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\t\tdir,\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\tonClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU;AAKnB,SAAS,6BAA6B;AACtC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,aAAa,cAAc,iBAAiB;AACrD,SAAS,YAAY,oBAAoB;AAwBvC,mBACC,KADD;AAtBF,IAAM,OAAO;AACb,IAAM,QAAQ,GAAI,UAAW;AAEtB,IAAM,WAAW;AAAA,EACvB;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,IACX,MAAM;AAAA,IACN,KAAK;AAAA,EACN;AAAA,EACA,MAAM;AACP;AAEA,SAAS,KAAM,EAAE,UAAU,OAAO,UAAU,WAAW,GAAI;AAC1D,QAAM,CAAE,kBAAkB,mBAAoB,IAAI,SAAU,KAAM;AAClE,QAAM,gBAAgB,MAAM;AAC3B,wBAAqB,CAAE,UAAW,CAAE,KAAM;AAAA,EAC3C;AAEA,SACC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,OAAQ;AAAA,QACR;AAAA,QACA,SAAU,MAAM;AACf,cAAK,UAAW;AACf,qBAAU,aAAc,OAAO,IAAK,CAAE;AAAA,UACvC,OAAO;AACN,0BAAc;AAAA,UACf;AAAA,QACD;AAAA,QACA;AAAA,QACA,MAAK;AAAA;AAAA,IACN;AAAA,IACE,oBACD;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAU;AAAA,QACV;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEA,SAAS,iBAAkB,EAAE,OAAO,YAAY,UAAU,QAAQ,GAAI;AACrE,QAAM,gBAAgB,UAAW;AAAA,IAChC,wBAAwB,WAAW;AAAA,IACnC,UAAU;AAAA,EACX,CAAE;AAEF,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAU,EAAG;AACvC,QAAM,CAAE,KAAK,MAAO,IAAI,SAAU,KAAM;AAExC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,QAAS;AAAA,MACT;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACA,QAAS,oBAAC,UAAK;AAAA,UACf,WAAU;AAAA,UACV,KAAI;AAAA,UACJ,WAAU;AAAA,UACV,UAAW,CAAE,UAAW;AACvB,kBAAM,eAAe;AACrB;AAAA,cACC,YAAa,OAAO;AAAA,gBACnB,MAAM;AAAA,gBACN,YAAY;AAAA,kBACX;AAAA,kBACA;AAAA,gBACD;AAAA,cACD,CAAE;AAAA,YACH;AACA,oBAAQ;AAAA,UACT;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\tSelectControl,\n\tButton,\n\tPopover,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useState } from '@wordpress/element';\nimport { applyFormat, removeFormat, useAnchor } from '@wordpress/rich-text';\nimport { language as languageIcon } from '@wordpress/icons';\n\nconst name = 'core/language';\nconst title = __( 'Language' );\n\nexport const language = {\n\tname,\n\ttitle,\n\ttagName: 'bdo',\n\tclassName: null,\n\tattributes: {\n\t\tlang: 'lang',\n\t\tdir: 'dir',\n\t},\n\tedit: Edit,\n};\n\nfunction Edit( { isActive, value, onChange, contentRef } ) {\n\tconst [ isPopoverVisible, setIsPopoverVisible ] = useState( false );\n\tconst togglePopover = () => {\n\t\tsetIsPopoverVisible( ( state ) => ! state );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ languageIcon }\n\t\t\t\tlabel={ title }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tif ( isActive ) {\n\t\t\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttogglePopover();\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isPopoverVisible && (\n\t\t\t\t<InlineLanguageUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonClose={ togglePopover }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction InlineLanguageUI( { value, contentRef, onChange, onClose } ) {\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: language,\n\t} );\n\n\tconst [ lang, setLang ] = useState( '' );\n\tconst [ dir, setDir ] = useState( 'ltr' );\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-format-toolbar__language-popover\"\n\t\t\tanchor={ popoverAnchor }\n\t\t\tonClose={ onClose }\n\t\t>\n\t\t\t<Stack\n\t\t\t\trender={ <form /> }\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t\tclassName=\"block-editor-format-toolbar__language-container-content\"\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tapplyFormat( value, {\n\t\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\t\tdir,\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\tonClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ title }\n\t\t\t\t\tvalue={ lang }\n\t\t\t\t\tonChange={ ( val ) => setLang( val ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'A valid language attribute, like \"en\" or \"fr\".'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<SelectControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Text direction' ) }\n\t\t\t\t\tvalue={ dir }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Left to right' ),\n\t\t\t\t\t\t\tvalue: 'ltr',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Right to left' ),\n\t\t\t\t\t\t\tvalue: 'rtl',\n\t\t\t\t\t\t},\n\t\t\t\t\t] }\n\t\t\t\t\tonChange={ ( val ) => setDir( val ) }\n\t\t\t\t/>\n\t\t\t\t<Stack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\ttext={ __( 'Apply' ) }\n\t\t\t\t\t/>\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t</Popover>\n\t);\n}\n"],
|
|
5
|
+
"m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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,
|
|
@@ -75,7 +81,6 @@ function InlineUI({
|
|
|
75
81
|
/* @__PURE__ */ jsx(
|
|
76
82
|
TextControl,
|
|
77
83
|
{
|
|
78
|
-
__next40pxDefaultSize: true,
|
|
79
84
|
hideLabelFromVision: true,
|
|
80
85
|
label: __("LaTeX math syntax"),
|
|
81
86
|
value: latex,
|
|
@@ -118,24 +123,40 @@ function Edit({
|
|
|
118
123
|
setLatexToMathML(() => module.default);
|
|
119
124
|
});
|
|
120
125
|
}, []);
|
|
126
|
+
function onClick() {
|
|
127
|
+
let newValue;
|
|
128
|
+
if (isObjectActive) {
|
|
129
|
+
const latex = activeObjectAttributes?.["data-latex"] || "";
|
|
130
|
+
newValue = insert(value, latex);
|
|
131
|
+
newValue.start = newValue.end - latex.length;
|
|
132
|
+
} else {
|
|
133
|
+
const selectedText = getTextContent(slice(value));
|
|
134
|
+
let innerHTML = "";
|
|
135
|
+
if (selectedText && latexToMathML) {
|
|
136
|
+
try {
|
|
137
|
+
innerHTML = latexToMathML(selectedText, {
|
|
138
|
+
displayMode: false
|
|
139
|
+
});
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
newValue = insertObject(value, {
|
|
144
|
+
type: name,
|
|
145
|
+
attributes: { "data-latex": selectedText },
|
|
146
|
+
innerHTML
|
|
147
|
+
});
|
|
148
|
+
newValue.start = newValue.end - 1;
|
|
149
|
+
}
|
|
150
|
+
onChange(newValue);
|
|
151
|
+
onFocus();
|
|
152
|
+
}
|
|
121
153
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
122
154
|
/* @__PURE__ */ jsx(
|
|
123
155
|
RichTextToolbarButton,
|
|
124
156
|
{
|
|
125
157
|
icon,
|
|
126
158
|
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
|
-
},
|
|
159
|
+
onClick,
|
|
139
160
|
isActive: isObjectActive
|
|
140
161
|
}
|
|
141
162
|
),
|
|
@@ -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\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": ";AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,UAAU,iBAAiB;AACpC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,6BAA6B;AACtC;AAAA,EACC;AAAA,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AAc,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.0",
|
|
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.
|
|
45
|
-
"@wordpress/base-styles": "^10.0
|
|
46
|
-
"@wordpress/block-editor": "^15.
|
|
47
|
-
"@wordpress/components": "^
|
|
48
|
-
"@wordpress/compose": "^8.
|
|
49
|
-
"@wordpress/data": "^10.
|
|
50
|
-
"@wordpress/element": "^8.0
|
|
51
|
-
"@wordpress/html-entities": "^4.
|
|
52
|
-
"@wordpress/i18n": "^6.
|
|
53
|
-
"@wordpress/icons": "^
|
|
54
|
-
"@wordpress/latex-to-mathml": "^1.
|
|
55
|
-
"@wordpress/private-apis": "^1.
|
|
56
|
-
"@wordpress/rich-text": "^7.
|
|
57
|
-
"@wordpress/ui": "^0.
|
|
58
|
-
"@wordpress/url": "^4.
|
|
44
|
+
"@wordpress/a11y": "^4.49.0",
|
|
45
|
+
"@wordpress/base-styles": "^10.1.0",
|
|
46
|
+
"@wordpress/block-editor": "^15.22.0",
|
|
47
|
+
"@wordpress/components": "^36.0.0",
|
|
48
|
+
"@wordpress/compose": "^8.2.0",
|
|
49
|
+
"@wordpress/data": "^10.49.0",
|
|
50
|
+
"@wordpress/element": "^8.1.0",
|
|
51
|
+
"@wordpress/html-entities": "^4.49.0",
|
|
52
|
+
"@wordpress/i18n": "^6.22.0",
|
|
53
|
+
"@wordpress/icons": "^15.0.0",
|
|
54
|
+
"@wordpress/latex-to-mathml": "^1.17.0",
|
|
55
|
+
"@wordpress/private-apis": "^1.49.0",
|
|
56
|
+
"@wordpress/rich-text": "^7.49.0",
|
|
57
|
+
"@wordpress/ui": "^0.16.0",
|
|
58
|
+
"@wordpress/url": "^4.49.0"
|
|
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": "0e7112a4f4fde4ea15bd9060489b8f6fe11eb6ca"
|
|
73
73
|
}
|
package/src/language/index.js
CHANGED
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,
|
|
@@ -90,7 +96,6 @@ function InlineUI( {
|
|
|
90
96
|
<div style={ { minWidth: '300px', padding: '4px' } }>
|
|
91
97
|
<Stack direction="column" gap="xs">
|
|
92
98
|
<TextControl
|
|
93
|
-
__next40pxDefaultSize
|
|
94
99
|
hideLabelFromVision
|
|
95
100
|
label={ __( 'LaTeX math syntax' ) }
|
|
96
101
|
value={ latex }
|
|
@@ -135,23 +140,51 @@ function Edit( {
|
|
|
135
140
|
setLatexToMathML( () => module.default );
|
|
136
141
|
} );
|
|
137
142
|
}, [] );
|
|
143
|
+
|
|
144
|
+
function onClick() {
|
|
145
|
+
let newValue;
|
|
146
|
+
|
|
147
|
+
if ( isObjectActive ) {
|
|
148
|
+
// Revert the active math object to its LaTeX source so clicking
|
|
149
|
+
// the button toggles back to the exact text it was created from.
|
|
150
|
+
// Keep the restored text selected so it can be edited or
|
|
151
|
+
// re-marked right away.
|
|
152
|
+
const latex = activeObjectAttributes?.[ 'data-latex' ] || '';
|
|
153
|
+
newValue = insert( value, latex );
|
|
154
|
+
newValue.start = newValue.end - latex.length;
|
|
155
|
+
} else {
|
|
156
|
+
// If there's a selection, seed the format with it so you can type
|
|
157
|
+
// LaTeX inline and then mark it as math.
|
|
158
|
+
const selectedText = getTextContent( slice( value ) );
|
|
159
|
+
let innerHTML = '';
|
|
160
|
+
if ( selectedText && latexToMathML ) {
|
|
161
|
+
try {
|
|
162
|
+
innerHTML = latexToMathML( selectedText, {
|
|
163
|
+
displayMode: false,
|
|
164
|
+
} );
|
|
165
|
+
} catch {
|
|
166
|
+
// Leave unrendered; the popover opens with the text
|
|
167
|
+
// prefilled so the expression can be corrected.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
newValue = insertObject( value, {
|
|
171
|
+
type: name,
|
|
172
|
+
attributes: { 'data-latex': selectedText },
|
|
173
|
+
innerHTML,
|
|
174
|
+
} );
|
|
175
|
+
newValue.start = newValue.end - 1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
onChange( newValue );
|
|
179
|
+
onFocus();
|
|
180
|
+
}
|
|
181
|
+
|
|
138
182
|
return (
|
|
139
183
|
<>
|
|
140
184
|
<RichTextToolbarButton
|
|
141
185
|
icon={ icon }
|
|
142
186
|
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
|
-
} }
|
|
187
|
+
onClick={ onClick }
|
|
155
188
|
isActive={ isObjectActive }
|
|
156
189
|
/>
|
|
157
190
|
{ isObjectActive && (
|