@wordpress/format-library 5.28.0 → 5.29.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 +2 -0
- package/build/bold/index.js +9 -0
- package/build/bold/index.js.map +1 -1
- package/build/italic/index.js +9 -0
- package/build/italic/index.js.map +1 -1
- package/build/link/index.js +5 -0
- package/build/link/index.js.map +1 -1
- package/build-module/bold/index.js +10 -1
- package/build-module/bold/index.js.map +1 -1
- package/build-module/italic/index.js +10 -1
- package/build-module/italic/index.js.map +1 -1
- package/build-module/link/index.js +6 -1
- package/build-module/link/index.js.map +1 -1
- package/package.json +14 -14
- package/src/bold/index.js +9 -0
- package/src/italic/index.js +9 -0
- package/src/link/index.js +5 -0
package/CHANGELOG.md
CHANGED
package/build/bold/index.js
CHANGED
|
@@ -8,11 +8,19 @@ var _i18n = require("@wordpress/i18n");
|
|
|
8
8
|
var _richText = require("@wordpress/rich-text");
|
|
9
9
|
var _blockEditor = require("@wordpress/block-editor");
|
|
10
10
|
var _icons = require("@wordpress/icons");
|
|
11
|
+
var _lockUnlock = require("../lock-unlock");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
/**
|
|
13
14
|
* WordPress dependencies
|
|
14
15
|
*/
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
essentialFormatKey
|
|
23
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
16
24
|
const name = 'core/bold';
|
|
17
25
|
const title = (0, _i18n.__)('Bold');
|
|
18
26
|
const bold = exports.bold = {
|
|
@@ -20,6 +28,7 @@ const bold = exports.bold = {
|
|
|
20
28
|
title,
|
|
21
29
|
tagName: 'strong',
|
|
22
30
|
className: null,
|
|
31
|
+
[essentialFormatKey]: true,
|
|
23
32
|
edit({
|
|
24
33
|
isActive,
|
|
25
34
|
value,
|
package/build/bold/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","_jsxRuntime","name","title","__","bold","exports","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","toggleFormat","type","onClick","jsxs","Fragment","children","jsx","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","formatBold","shortcutType","shortcutCharacter","__unstableRichTextInputEvent","inputType","onInput"],"sources":["@wordpress/format-library/src/bold/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatBold } from '@wordpress/icons';\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;
|
|
1
|
+
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","_lockUnlock","_jsxRuntime","essentialFormatKey","unlock","blockEditorPrivateApis","name","title","__","bold","exports","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","toggleFormat","type","onClick","jsxs","Fragment","children","jsx","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","formatBold","shortcutType","shortcutCharacter","__unstableRichTextInputEvent","inputType","onInput"],"sources":["@wordpress/format-library/src/bold/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { formatBold } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\n\tclassName: null,\n\t[ essentialFormatKey ]: true,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAMA,IAAAG,MAAA,GAAAH,OAAA;AAKA,IAAAI,WAAA,GAAAJ,OAAA;AAAwC,IAAAK,WAAA,GAAAL,OAAA;AAhBxC;AACA;AACA;;AAWA;AACA;AACA;;AAGA,MAAM;EAAEM;AAAmB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAE/D,MAAMC,IAAI,GAAG,WAAW;AACxB,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,MAAO,CAAC;AAEnB,MAAMC,IAAI,GAAAC,OAAA,CAAAD,IAAA,GAAG;EACnBH,IAAI;EACJC,KAAK;EACLI,OAAO,EAAE,QAAQ;EACjBC,SAAS,EAAE,IAAI;EACf,CAAET,kBAAkB,GAAI,IAAI;EAC5BU,IAAIA,CAAE;IAAEC,QAAQ;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,SAASC,QAAQA,CAAA,EAAG;MACnBF,QAAQ,CAAE,IAAAG,sBAAY,EAAEJ,KAAK,EAAE;QAAEK,IAAI,EAAEd,IAAI;QAAEC;MAAM,CAAE,CAAE,CAAC;IACzD;IAEA,SAASc,OAAOA,CAAA,EAAG;MAClBL,QAAQ,CAAE,IAAAG,sBAAY,EAAEJ,KAAK,EAAE;QAAEK,IAAI,EAAEd;MAAK,CAAE,CAAE,CAAC;MACjDW,OAAO,CAAC,CAAC;IACV;IAEA,oBACC,IAAAf,WAAA,CAAAoB,IAAA,EAAApB,WAAA,CAAAqB,QAAA;MAAAC,QAAA,gBACC,IAAAtB,WAAA,CAAAuB,GAAA,EAAC1B,YAAA,CAAA2B,gBAAgB;QAChBN,IAAI,EAAC,SAAS;QACdO,SAAS,EAAC,GAAG;QACbC,KAAK,EAAGV;MAAU,CAClB,CAAC,eACF,IAAAhB,WAAA,CAAAuB,GAAA,EAAC1B,YAAA,CAAA8B,qBAAqB;QACrBvB,IAAI,EAAC,MAAM;QACXwB,IAAI,EAAGC,iBAAY;QACnBxB,KAAK,EAAGA,KAAO;QACfc,OAAO,EAAGA,OAAS;QACnBP,QAAQ,EAAGA,QAAU;QACrBkB,YAAY,EAAC,SAAS;QACtBC,iBAAiB,EAAC;MAAG,CACrB,CAAC,eACF,IAAA/B,WAAA,CAAAuB,GAAA,EAAC1B,YAAA,CAAAmC,4BAA4B;QAC5BC,SAAS,EAAC,YAAY;QACtBC,OAAO,EAAGlB;MAAU,CACpB,CAAC;IAAA,CACD,CAAC;EAEL;AACD,CAAC","ignoreList":[]}
|
package/build/italic/index.js
CHANGED
|
@@ -8,11 +8,19 @@ var _i18n = require("@wordpress/i18n");
|
|
|
8
8
|
var _richText = require("@wordpress/rich-text");
|
|
9
9
|
var _blockEditor = require("@wordpress/block-editor");
|
|
10
10
|
var _icons = require("@wordpress/icons");
|
|
11
|
+
var _lockUnlock = require("../lock-unlock");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
/**
|
|
13
14
|
* WordPress dependencies
|
|
14
15
|
*/
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
essentialFormatKey
|
|
23
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
16
24
|
const name = 'core/italic';
|
|
17
25
|
const title = (0, _i18n.__)('Italic');
|
|
18
26
|
const italic = exports.italic = {
|
|
@@ -20,6 +28,7 @@ const italic = exports.italic = {
|
|
|
20
28
|
title,
|
|
21
29
|
tagName: 'em',
|
|
22
30
|
className: null,
|
|
31
|
+
[essentialFormatKey]: true,
|
|
23
32
|
edit({
|
|
24
33
|
isActive,
|
|
25
34
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","_jsxRuntime","name","title","__","italic","exports","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","toggleFormat","type","onClick","jsxs","Fragment","children","jsx","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","formatItalic","shortcutType","shortcutCharacter","__unstableRichTextInputEvent","inputType","onInput"],"sources":["@wordpress/format-library/src/italic/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatItalic } from '@wordpress/icons';\n\nconst name = 'core/italic';\nconst title = __( 'Italic' );\n\nexport const italic = {\n\tname,\n\ttitle,\n\ttagName: 'em',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"i\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"italic\"\n\t\t\t\t\ticon={ formatItalic }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"i\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatItalic\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;
|
|
1
|
+
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","_lockUnlock","_jsxRuntime","essentialFormatKey","unlock","blockEditorPrivateApis","name","title","__","italic","exports","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","toggleFormat","type","onClick","jsxs","Fragment","children","jsx","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","formatItalic","shortcutType","shortcutCharacter","__unstableRichTextInputEvent","inputType","onInput"],"sources":["@wordpress/format-library/src/italic/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { formatItalic } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\n\nconst name = 'core/italic';\nconst title = __( 'Italic' );\n\nexport const italic = {\n\tname,\n\ttitle,\n\ttagName: 'em',\n\tclassName: null,\n\t[ essentialFormatKey ]: true,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"i\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"italic\"\n\t\t\t\t\ticon={ formatItalic }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"i\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatItalic\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAMA,IAAAG,MAAA,GAAAH,OAAA;AAKA,IAAAI,WAAA,GAAAJ,OAAA;AAAwC,IAAAK,WAAA,GAAAL,OAAA;AAhBxC;AACA;AACA;;AAWA;AACA;AACA;;AAGA,MAAM;EAAEM;AAAmB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAE/D,MAAMC,IAAI,GAAG,aAAa;AAC1B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,QAAS,CAAC;AAErB,MAAMC,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG;EACrBH,IAAI;EACJC,KAAK;EACLI,OAAO,EAAE,IAAI;EACbC,SAAS,EAAE,IAAI;EACf,CAAET,kBAAkB,GAAI,IAAI;EAC5BU,IAAIA,CAAE;IAAEC,QAAQ;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,SAASC,QAAQA,CAAA,EAAG;MACnBF,QAAQ,CAAE,IAAAG,sBAAY,EAAEJ,KAAK,EAAE;QAAEK,IAAI,EAAEd,IAAI;QAAEC;MAAM,CAAE,CAAE,CAAC;IACzD;IAEA,SAASc,OAAOA,CAAA,EAAG;MAClBL,QAAQ,CAAE,IAAAG,sBAAY,EAAEJ,KAAK,EAAE;QAAEK,IAAI,EAAEd;MAAK,CAAE,CAAE,CAAC;MACjDW,OAAO,CAAC,CAAC;IACV;IAEA,oBACC,IAAAf,WAAA,CAAAoB,IAAA,EAAApB,WAAA,CAAAqB,QAAA;MAAAC,QAAA,gBACC,IAAAtB,WAAA,CAAAuB,GAAA,EAAC1B,YAAA,CAAA2B,gBAAgB;QAChBN,IAAI,EAAC,SAAS;QACdO,SAAS,EAAC,GAAG;QACbC,KAAK,EAAGV;MAAU,CAClB,CAAC,eACF,IAAAhB,WAAA,CAAAuB,GAAA,EAAC1B,YAAA,CAAA8B,qBAAqB;QACrBvB,IAAI,EAAC,QAAQ;QACbwB,IAAI,EAAGC,mBAAc;QACrBxB,KAAK,EAAGA,KAAO;QACfc,OAAO,EAAGA,OAAS;QACnBP,QAAQ,EAAGA,QAAU;QACrBkB,YAAY,EAAC,SAAS;QACtBC,iBAAiB,EAAC;MAAG,CACrB,CAAC,eACF,IAAA/B,WAAA,CAAAuB,GAAA,EAAC1B,YAAA,CAAAmC,4BAA4B;QAC5BC,SAAS,EAAC,cAAc;QACxBC,OAAO,EAAGlB;MAAU,CACpB,CAAC;IAAA,CACD,CAAC;EAEL;AACD,CAAC","ignoreList":[]}
|
package/build/link/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var _icons = require("@wordpress/icons");
|
|
|
15
15
|
var _a11y = require("@wordpress/a11y");
|
|
16
16
|
var _inline = _interopRequireDefault(require("./inline"));
|
|
17
17
|
var _utils = require("./utils");
|
|
18
|
+
var _lockUnlock = require("../lock-unlock");
|
|
18
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
20
|
/**
|
|
20
21
|
* WordPress dependencies
|
|
@@ -24,6 +25,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
24
25
|
* Internal dependencies
|
|
25
26
|
*/
|
|
26
27
|
|
|
28
|
+
const {
|
|
29
|
+
essentialFormatKey
|
|
30
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
27
31
|
const name = 'core/link';
|
|
28
32
|
const title = (0, _i18n.__)('Link');
|
|
29
33
|
function Edit({
|
|
@@ -200,6 +204,7 @@ const link = exports.link = {
|
|
|
200
204
|
target: 'target',
|
|
201
205
|
rel: 'rel'
|
|
202
206
|
},
|
|
207
|
+
[essentialFormatKey]: true,
|
|
203
208
|
__unstablePasteRule(value, {
|
|
204
209
|
html,
|
|
205
210
|
plainText
|
package/build/link/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_richText","_url","_blockEditor","_htmlEntities","_icons","_a11y","_inline","_interopRequireDefault","_utils","_jsxRuntime","name","title","__","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","useState","openedBy","setOpenedBy","useEffect","useLayoutEffect","editableContentElement","current","handleClick","event","link","target","closest","el","action","addEventListener","removeEventListener","addLink","text","getTextContent","slice","isURL","isValidHref","applyFormat","type","attributes","url","isEmail","isPhoneNumber","replace","stopAddingLink","tagName","focus","onFocusOutside","onRemoveFormat","removeFormat","speak","shouldAutoFocus","hasSelection","isCollapsed","jsxs","Fragment","children","jsx","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","linkIcon","onClick","currentTarget","shortcutType","shortcutCharacter","default","focusOnMount","exports","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","trim","test","window","console","log","format","decodeEntities","insert","create","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail, isPhoneNumber } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\n\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetAddingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tconst link = event.target.closest( '[contenteditable] a' );\n\t\t\tif (\n\t\t\t\t! link || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t\tsetOpenedBy( {\n\t\t\t\tel: link,\n\t\t\t\taction: 'click',\n\t\t\t} );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isPhoneNumber( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `tel:${ text.replace( /\\D/g, '' ) }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( {\n\t\t\t\t\tel: target,\n\t\t\t\t\taction: null, // We don't need to distinguish between click or keyboard here\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.el?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.el.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\t// Only autofocus if we have clicked a link within the editor\n\tconst shouldAutoFocus = ! (\n\t\topenedBy?.el?.tagName === 'A' && openedBy?.action === 'click'\n\t);\n\n\tconst hasSelection = ! isCollapsed( value );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasSelection && (\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"k\"\n\t\t\t\t\tonUse={ addLink }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,S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G,EAAE,MAAM;IACXF,IAAI,EAAE,WAAW;IACjBkC,EAAE,EAAE,SAAS;IACbC,GAAG,EAAE,IAAI;IACThD,MAAM,EAAE,QAAQ;IAChBiD,GAAG,EAAE;EACN,CAAC;EACDC,mBAAmBA,CAAElE,KAAK,EAAE;IAAEmE,IAAI;IAAEC;EAAU,CAAC,EAAG;IACjD,MAAMC,UAAU,GAAG,CAAEF,IAAI,IAAIC,SAAS,EACpClC,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,CACzBoC,IAAI,CAAC,CAAC;;IAER;IACA;IACA,IAAK,CAAE,IAAA5C,UAAK,EAAE2C,UAAW,CAAC,IAAI,CAAE,UAAU,CAACE,IAAI,CAAEF,UAAW,CAAC,EAAG;MAC/D,OAAOrE,KAAK;IACb;;IAEA;IACAwE,MAAM,CAACC,OAAO,CAACC,GAAG,CAAE,mBAAmB,EAAEL,UAAW,CAAC;IAErD,MAAMM,MAAM,GAAG;MACd9C,IAAI,EAAEnC,IAAI;MACVoC,UAAU,EAAE;QACXC,GAAG,EAAE,IAAA6C,4BAAc,EAAEP,UAAW;MACjC;IACD,CAAC;IAED,IAAK,IAAAzB,qBAAW,EAAE5C,KAAM,CAAC,EAAG;MAC3B,OAAO,IAAA6E,gBAAM,EACZ7E,KAAK,EACL,IAAA4B,qBAAW,EACV,IAAAkD,gBAAM,EAAE;QAAEvD,IAAI,EAAE6C;MAAU,CAAE,CAAC,EAC7BO,MAAM,EACN,CAAC,EACDP,SAAS,CAACW,MACX,CACD,CAAC;IACF;IAEA,OAAO,IAAAnD,qBAAW,EAAE5B,KAAK,EAAE2E,MAAO,CAAC;EACpC,CAAC;EACDK,IAAI,EAAEnF;AACP,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_richText","_url","_blockEditor","_htmlEntities","_icons","_a11y","_inline","_interopRequireDefault","_utils","_lockUnlock","_jsxRuntime","essentialFormatKey","unlock","blockEditorPrivateApis","name","title","__","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","useState","openedBy","setOpenedBy","useEffect","useLayoutEffect","editableContentElement","current","handleClick","event","link","target","closest","el","action","addEventListener","removeEventListener","addLink","text","getTextContent","slice","isURL","isValidHref","applyFormat","type","attributes","url","isEmail","isPhoneNumber","replace","stopAddingLink","tagName","focus","onFocusOutside","onRemoveFormat","removeFormat","speak","shouldAutoFocus","hasSelection","isCollapsed","jsxs","Fragment","children","jsx","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","linkIcon","onClick","currentTarget","shortcutType","shortcutCharacter","default","focusOnMount","exports","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","trim","test","window","console","log","format","decodeEntities","insert","create","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail, isPhoneNumber } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\n\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetAddingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tconst link = event.target.closest( '[contenteditable] a' );\n\t\t\tif (\n\t\t\t\t! link || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t\tsetOpenedBy( {\n\t\t\t\tel: link,\n\t\t\t\taction: 'click',\n\t\t\t} );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isPhoneNumber( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `tel:${ text.replace( /\\D/g, '' ) }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( {\n\t\t\t\t\tel: target,\n\t\t\t\t\taction: null, // We don't need to distinguish between click or keyboard here\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.el?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.el.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\t// Only autofocus if we have clicked a link within the editor\n\tconst shouldAutoFocus = ! (\n\t\topenedBy?.el?.tagName === 'A' && openedBy?.action === 'click'\n\t);\n\n\tconst hasSelection = ! isCollapsed( value );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasSelection && (\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"k\"\n\t\t\t\t\tonUse={ addLink }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t[ essentialFormatKey ]: true,\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AASA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAKA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AAKA,IAAAQ,OAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,MAAA,GAAAV,OAAA;AACA,IAAAW,WAAA,GAAAX,OAAA;AAAwC,IAAAY,WAAA,GAAAZ,OAAA;AA7BxC;AACA;AACA;;AAsBA;AACA;AACA;;AAKA,MAAM;EAAEa;AAAmB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAE/D,MAAMC,IAAI,GAAG,WAAW;AACxB,MAAMC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AAC;;IAER;IACA;IACA,IAAK,CAAE,IAAA5C,UAAK,EAAE2C,UAAW,CAAC,IAAI,CAAE,UAAU,CAACE,IAAI,CAAEF,UAAW,CAAC,EAAG;MAC/D,OAAOrE,KAAK;IACb;;IAEA;IACAwE,MAAM,CAACC,OAAO,CAACC,GAAG,CAAE,mBAAmB,EAAEL,UAAW,CAAC;IAErD,MAAMM,MAAM,GAAG;MACd9C,IAAI,EAAEnC,IAAI;MACVoC,UAAU,EAAE;QACXC,GAAG,EAAE,IAAA6C,4BAAc,EAAEP,UAAW;MACjC;IACD,CAAC;IAED,IAAK,IAAAzB,qBAAW,EAAE5C,KAAM,CAAC,EAAG;MAC3B,OAAO,IAAA6E,gBAAM,EACZ7E,KAAK,EACL,IAAA4B,qBAAW,EACV,IAAAkD,gBAAM,EAAE;QAAEvD,IAAI,EAAE6C;MAAU,CAAE,CAAC,EAC7BO,MAAM,EACN,CAAC,EACDP,SAAS,CAACW,MACX,CACD,CAAC;IACF;IAEA,OAAO,IAAAnD,qBAAW,EAAE5B,KAAK,EAAE2E,MAAO,CAAC;EACpC,CAAC;EACDK,IAAI,EAAEnF;AACP,CAAC","ignoreList":[]}
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { toggleFormat } from '@wordpress/rich-text';
|
|
6
|
-
import { RichTextToolbarButton, RichTextShortcut, __unstableRichTextInputEvent } from '@wordpress/block-editor';
|
|
6
|
+
import { RichTextToolbarButton, RichTextShortcut, __unstableRichTextInputEvent, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
7
7
|
import { formatBold } from '@wordpress/icons';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { unlock } from '../lock-unlock';
|
|
8
13
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const {
|
|
15
|
+
essentialFormatKey
|
|
16
|
+
} = unlock(blockEditorPrivateApis);
|
|
9
17
|
const name = 'core/bold';
|
|
10
18
|
const title = __('Bold');
|
|
11
19
|
export const bold = {
|
|
@@ -13,6 +21,7 @@ export const bold = {
|
|
|
13
21
|
title,
|
|
14
22
|
tagName: 'strong',
|
|
15
23
|
className: null,
|
|
24
|
+
[essentialFormatKey]: true,
|
|
16
25
|
edit({
|
|
17
26
|
isActive,
|
|
18
27
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatBold","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","name","title","bold","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","children","character","onUse","icon","shortcutType","shortcutCharacter","inputType","onInput"],"sources":["@wordpress/format-library/src/bold/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatBold } from '@wordpress/icons';\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SACCC,qBAAqB,EACrBC,gBAAgB,EAChBC,4BAA4B,
|
|
1
|
+
{"version":3,"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","privateApis","blockEditorPrivateApis","formatBold","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","essentialFormatKey","name","title","bold","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","children","character","onUse","icon","shortcutType","shortcutCharacter","inputType","onInput"],"sources":["@wordpress/format-library/src/bold/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { formatBold } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\n\tclassName: null,\n\t[ essentialFormatKey ]: true,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SACCC,qBAAqB,EACrBC,gBAAgB,EAChBC,4BAA4B,EAC5BC,WAAW,IAAIC,sBAAsB,QAC/B,yBAAyB;AAChC,SAASC,UAAU,QAAQ,kBAAkB;;AAE7C;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAExC,MAAM;EAAEC;AAAmB,CAAC,GAAGP,MAAM,CAAEF,sBAAuB,CAAC;AAE/D,MAAMU,IAAI,GAAG,WAAW;AACxB,MAAMC,KAAK,GAAGjB,EAAE,CAAE,MAAO,CAAC;AAE1B,OAAO,MAAMkB,IAAI,GAAG;EACnBF,IAAI;EACJC,KAAK;EACLE,OAAO,EAAE,QAAQ;EACjBC,SAAS,EAAE,IAAI;EACf,CAAEL,kBAAkB,GAAI,IAAI;EAC5BM,IAAIA,CAAE;IAAEC,QAAQ;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,SAASC,QAAQA,CAAA,EAAG;MACnBF,QAAQ,CAAEvB,YAAY,CAAEsB,KAAK,EAAE;QAAEI,IAAI,EAAEX,IAAI;QAAEC;MAAM,CAAE,CAAE,CAAC;IACzD;IAEA,SAASW,OAAOA,CAAA,EAAG;MAClBJ,QAAQ,CAAEvB,YAAY,CAAEsB,KAAK,EAAE;QAAEI,IAAI,EAAEX;MAAK,CAAE,CAAE,CAAC;MACjDS,OAAO,CAAC,CAAC;IACV;IAEA,oBACCX,KAAA,CAAAF,SAAA;MAAAiB,QAAA,gBACCnB,IAAA,CAACP,gBAAgB;QAChBwB,IAAI,EAAC,SAAS;QACdG,SAAS,EAAC,GAAG;QACbC,KAAK,EAAGL;MAAU,CAClB,CAAC,eACFhB,IAAA,CAACR,qBAAqB;QACrBc,IAAI,EAAC,MAAM;QACXgB,IAAI,EAAGzB,UAAY;QACnBU,KAAK,EAAGA,KAAO;QACfW,OAAO,EAAGA,OAAS;QACnBN,QAAQ,EAAGA,QAAU;QACrBW,YAAY,EAAC,SAAS;QACtBC,iBAAiB,EAAC;MAAG,CACrB,CAAC,eACFxB,IAAA,CAACN,4BAA4B;QAC5B+B,SAAS,EAAC,YAAY;QACtBC,OAAO,EAAGV;MAAU,CACpB,CAAC;IAAA,CACD,CAAC;EAEL;AACD,CAAC","ignoreList":[]}
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { toggleFormat } from '@wordpress/rich-text';
|
|
6
|
-
import { RichTextToolbarButton, RichTextShortcut, __unstableRichTextInputEvent } from '@wordpress/block-editor';
|
|
6
|
+
import { RichTextToolbarButton, RichTextShortcut, __unstableRichTextInputEvent, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
7
7
|
import { formatItalic } from '@wordpress/icons';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { unlock } from '../lock-unlock';
|
|
8
13
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const {
|
|
15
|
+
essentialFormatKey
|
|
16
|
+
} = unlock(blockEditorPrivateApis);
|
|
9
17
|
const name = 'core/italic';
|
|
10
18
|
const title = __('Italic');
|
|
11
19
|
export const italic = {
|
|
@@ -13,6 +21,7 @@ export const italic = {
|
|
|
13
21
|
title,
|
|
14
22
|
tagName: 'em',
|
|
15
23
|
className: null,
|
|
24
|
+
[essentialFormatKey]: true,
|
|
16
25
|
edit({
|
|
17
26
|
isActive,
|
|
18
27
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatItalic","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","name","title","italic","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","children","character","onUse","icon","shortcutType","shortcutCharacter","inputType","onInput"],"sources":["@wordpress/format-library/src/italic/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatItalic } from '@wordpress/icons';\n\nconst name = 'core/italic';\nconst title = __( 'Italic' );\n\nexport const italic = {\n\tname,\n\ttitle,\n\ttagName: 'em',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"i\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"italic\"\n\t\t\t\t\ticon={ formatItalic }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"i\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatItalic\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SACCC,qBAAqB,EACrBC,gBAAgB,EAChBC,4BAA4B,
|
|
1
|
+
{"version":3,"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","privateApis","blockEditorPrivateApis","formatItalic","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","essentialFormatKey","name","title","italic","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","children","character","onUse","icon","shortcutType","shortcutCharacter","inputType","onInput"],"sources":["@wordpress/format-library/src/italic/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { formatItalic } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\n\nconst name = 'core/italic';\nconst title = __( 'Italic' );\n\nexport const italic = {\n\tname,\n\ttitle,\n\ttagName: 'em',\n\tclassName: null,\n\t[ essentialFormatKey ]: true,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"i\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"italic\"\n\t\t\t\t\ticon={ formatItalic }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"i\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatItalic\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SACCC,qBAAqB,EACrBC,gBAAgB,EAChBC,4BAA4B,EAC5BC,WAAW,IAAIC,sBAAsB,QAC/B,yBAAyB;AAChC,SAASC,YAAY,QAAQ,kBAAkB;;AAE/C;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAExC,MAAM;EAAEC;AAAmB,CAAC,GAAGP,MAAM,CAAEF,sBAAuB,CAAC;AAE/D,MAAMU,IAAI,GAAG,aAAa;AAC1B,MAAMC,KAAK,GAAGjB,EAAE,CAAE,QAAS,CAAC;AAE5B,OAAO,MAAMkB,MAAM,GAAG;EACrBF,IAAI;EACJC,KAAK;EACLE,OAAO,EAAE,IAAI;EACbC,SAAS,EAAE,IAAI;EACf,CAAEL,kBAAkB,GAAI,IAAI;EAC5BM,IAAIA,CAAE;IAAEC,QAAQ;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,SAASC,QAAQA,CAAA,EAAG;MACnBF,QAAQ,CAAEvB,YAAY,CAAEsB,KAAK,EAAE;QAAEI,IAAI,EAAEX,IAAI;QAAEC;MAAM,CAAE,CAAE,CAAC;IACzD;IAEA,SAASW,OAAOA,CAAA,EAAG;MAClBJ,QAAQ,CAAEvB,YAAY,CAAEsB,KAAK,EAAE;QAAEI,IAAI,EAAEX;MAAK,CAAE,CAAE,CAAC;MACjDS,OAAO,CAAC,CAAC;IACV;IAEA,oBACCX,KAAA,CAAAF,SAAA;MAAAiB,QAAA,gBACCnB,IAAA,CAACP,gBAAgB;QAChBwB,IAAI,EAAC,SAAS;QACdG,SAAS,EAAC,GAAG;QACbC,KAAK,EAAGL;MAAU,CAClB,CAAC,eACFhB,IAAA,CAACR,qBAAqB;QACrBc,IAAI,EAAC,QAAQ;QACbgB,IAAI,EAAGzB,YAAc;QACrBU,KAAK,EAAGA,KAAO;QACfW,OAAO,EAAGA,OAAS;QACnBN,QAAQ,EAAGA,QAAU;QACrBW,YAAY,EAAC,SAAS;QACtBC,iBAAiB,EAAC;MAAG,CACrB,CAAC,eACFxB,IAAA,CAACN,4BAA4B;QAC5B+B,SAAS,EAAC,cAAc;QACxBC,OAAO,EAAGV;MAAU,CACpB,CAAC;IAAA,CACD,CAAC;EAEL;AACD,CAAC","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
5
5
|
import { useState, useLayoutEffect, useEffect } from '@wordpress/element';
|
|
6
6
|
import { getTextContent, applyFormat, removeFormat, slice, isCollapsed, insert, create } from '@wordpress/rich-text';
|
|
7
7
|
import { isURL, isEmail, isPhoneNumber } from '@wordpress/url';
|
|
8
|
-
import { RichTextToolbarButton, RichTextShortcut } from '@wordpress/block-editor';
|
|
8
|
+
import { RichTextToolbarButton, RichTextShortcut, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
9
9
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
10
10
|
import { link as linkIcon } from '@wordpress/icons';
|
|
11
11
|
import { speak } from '@wordpress/a11y';
|
|
@@ -15,7 +15,11 @@ import { speak } from '@wordpress/a11y';
|
|
|
15
15
|
*/
|
|
16
16
|
import InlineLinkUI from './inline';
|
|
17
17
|
import { isValidHref } from './utils';
|
|
18
|
+
import { unlock } from '../lock-unlock';
|
|
18
19
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const {
|
|
21
|
+
essentialFormatKey
|
|
22
|
+
} = unlock(blockEditorPrivateApis);
|
|
19
23
|
const name = 'core/link';
|
|
20
24
|
const title = __('Link');
|
|
21
25
|
function Edit({
|
|
@@ -192,6 +196,7 @@ export const link = {
|
|
|
192
196
|
target: 'target',
|
|
193
197
|
rel: 'rel'
|
|
194
198
|
},
|
|
199
|
+
[essentialFormatKey]: true,
|
|
195
200
|
__unstablePasteRule(value, {
|
|
196
201
|
html,
|
|
197
202
|
plainText
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","useState","useLayoutEffect","useEffect","getTextContent","applyFormat","removeFormat","slice","isCollapsed","insert","create","isURL","isEmail","isPhoneNumber","RichTextToolbarButton","RichTextShortcut","decodeEntities","link","linkIcon","speak","InlineLinkUI","isValidHref","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","openedBy","setOpenedBy","editableContentElement","current","handleClick","event","target","closest","el","action","addEventListener","removeEventListener","addLink","text","type","attributes","url","replace","stopAddingLink","tagName","focus","onFocusOutside","onRemoveFormat","shouldAutoFocus","hasSelection","children","character","onUse","icon","onClick","currentTarget","shortcutType","shortcutCharacter","focusOnMount","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","trim","test","window","console","log","format","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail, isPhoneNumber } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\n\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetAddingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tconst link = event.target.closest( '[contenteditable] a' );\n\t\t\tif (\n\t\t\t\t! link || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t\tsetOpenedBy( {\n\t\t\t\tel: link,\n\t\t\t\taction: 'click',\n\t\t\t} );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isPhoneNumber( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `tel:${ text.replace( /\\D/g, '' ) }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( {\n\t\t\t\t\tel: target,\n\t\t\t\t\taction: null, // We don't need to distinguish between click or keyboard here\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.el?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.el.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\t// Only autofocus if we have clicked a link within the editor\n\tconst shouldAutoFocus = ! (\n\t\topenedBy?.el?.tagName === 'A' && openedBy?.action === 'click'\n\t);\n\n\tconst hasSelection = ! isCollapsed( value );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasSelection && (\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"k\"\n\t\t\t\t\tonUse={ addLink }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,eAAe,EAAEC,SAAS,QAAQ,oBAAoB;AACzE,SACCC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,MAAM,QACA,sBAAsB;AAC7B,SAASC,KAAK,EAAEC,OAAO,EAAEC,aAAa,QAAQ,gBAAgB;AAC9D,SACCC,qBAAqB,EACrBC,gBAAgB,QACV,yBAAyB;AAChC,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,IAAI,IAAIC,QAAQ,QAAQ,kBAAkB;AACnD,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA;AACA;AACA,OAAOC,YAAY,MAAM,UAAU;AACnC,SAASC,WAAW,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAEtC,MAAMC,IAAI,GAAG,WAAW;AACxB,MAAMC,KAAK,GAAG7B,EAAE,CAAE,MAAO,CAAC;AAE1B,SAAS8B,IAAIA,CAAE;EACdC,QAAQ;EACRC,gBAAgB;EAChBC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,UAAU,EAAEC,aAAa,CAAE,GAAGrC,QAAQ,CAAE,KAAM,CAAC;;EAEvD;EACA,MAAM,CAAEsC,QAAQ,EAAEC,WAAW,CAAE,GAAGvC,QAAQ,CAAE,IAAK,CAAC;EAElDE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1
|
+
{"version":3,"names":["__","useState","useLayoutEffect","useEffect","getTextContent","applyFormat","removeFormat","slice","isCollapsed","insert","create","isURL","isEmail","isPhoneNumber","RichTextToolbarButton","RichTextShortcut","privateApis","blockEditorPrivateApis","decodeEntities","link","linkIcon","speak","InlineLinkUI","isValidHref","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","essentialFormatKey","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","openedBy","setOpenedBy","editableContentElement","current","handleClick","event","target","closest","el","action","addEventListener","removeEventListener","addLink","text","type","attributes","url","replace","stopAddingLink","tagName","focus","onFocusOutside","onRemoveFormat","shouldAutoFocus","hasSelection","children","character","onUse","icon","onClick","currentTarget","shortcutType","shortcutCharacter","focusOnMount","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","trim","test","window","console","log","format","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail, isPhoneNumber } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\n\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetAddingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tconst link = event.target.closest( '[contenteditable] a' );\n\t\t\tif (\n\t\t\t\t! link || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t\tsetOpenedBy( {\n\t\t\t\tel: link,\n\t\t\t\taction: 'click',\n\t\t\t} );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isPhoneNumber( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `tel:${ text.replace( /\\D/g, '' ) }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( {\n\t\t\t\t\tel: target,\n\t\t\t\t\taction: null, // We don't need to distinguish between click or keyboard here\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.el?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.el.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\t// Only autofocus if we have clicked a link within the editor\n\tconst shouldAutoFocus = ! (\n\t\topenedBy?.el?.tagName === 'A' && openedBy?.action === 'click'\n\t);\n\n\tconst hasSelection = ! isCollapsed( value );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasSelection && (\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"k\"\n\t\t\t\t\tonUse={ addLink }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t[ essentialFormatKey ]: true,\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,eAAe,EAAEC,SAAS,QAAQ,oBAAoB;AACzE,SACCC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,MAAM,QACA,sBAAsB;AAC7B,SAASC,KAAK,EAAEC,OAAO,EAAEC,aAAa,QAAQ,gBAAgB;AAC9D,SACCC,qBAAqB,EACrBC,gBAAgB,EAChBC,WAAW,IAAIC,sBAAsB,QAC/B,yBAAyB;AAChC,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,IAAI,IAAIC,QAAQ,QAAQ,kBAAkB;AACnD,SAASC,KAAK,QAAQ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C,CAAC;;IAER;IACA;IACA,IAAK,CAAE1E,KAAK,CAAEyE,UAAW,CAAC,IAAI,CAAE,UAAU,CAACE,IAAI,CAAEF,UAAW,CAAC,EAAG;MAC/D,OAAO/C,KAAK;IACb;;IAEA;IACAkD,MAAM,CAACC,OAAO,CAACC,GAAG,CAAE,mBAAmB,EAAEL,UAAW,CAAC;IAErD,MAAMM,MAAM,GAAG;MACdjC,IAAI,EAAEzB,IAAI;MACV0B,UAAU,EAAE;QACXC,GAAG,EAAEzC,cAAc,CAAEkE,UAAW;MACjC;IACD,CAAC;IAED,IAAK5E,WAAW,CAAE6B,KAAM,CAAC,EAAG;MAC3B,OAAO5B,MAAM,CACZ4B,KAAK,EACLhC,WAAW,CACVK,MAAM,CAAE;QAAE8C,IAAI,EAAE2B;MAAU,CAAE,CAAC,EAC7BO,MAAM,EACN,CAAC,EACDP,SAAS,CAACQ,MACX,CACD,CAAC;IACF;IAEA,OAAOtF,WAAW,CAAEgC,KAAK,EAAEqD,MAAO,CAAC;EACpC,CAAC;EACDE,IAAI,EAAE1D;AACP,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/format-library",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.29.0",
|
|
4
4
|
"description": "Format library for the WordPress editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
"wpScript": true,
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime": "7.25.7",
|
|
31
|
-
"@wordpress/a11y": "^4.
|
|
32
|
-
"@wordpress/block-editor": "^15.
|
|
33
|
-
"@wordpress/components": "^30.
|
|
34
|
-
"@wordpress/compose": "^7.
|
|
35
|
-
"@wordpress/data": "^10.
|
|
36
|
-
"@wordpress/element": "^6.
|
|
37
|
-
"@wordpress/html-entities": "^4.
|
|
38
|
-
"@wordpress/i18n": "^6.
|
|
39
|
-
"@wordpress/icons": "^10.
|
|
40
|
-
"@wordpress/private-apis": "^1.
|
|
41
|
-
"@wordpress/rich-text": "^7.
|
|
42
|
-
"@wordpress/url": "^4.
|
|
31
|
+
"@wordpress/a11y": "^4.29.0",
|
|
32
|
+
"@wordpress/block-editor": "^15.2.0",
|
|
33
|
+
"@wordpress/components": "^30.2.0",
|
|
34
|
+
"@wordpress/compose": "^7.29.0",
|
|
35
|
+
"@wordpress/data": "^10.29.0",
|
|
36
|
+
"@wordpress/element": "^6.29.0",
|
|
37
|
+
"@wordpress/html-entities": "^4.29.0",
|
|
38
|
+
"@wordpress/i18n": "^6.2.0",
|
|
39
|
+
"@wordpress/icons": "^10.29.0",
|
|
40
|
+
"@wordpress/private-apis": "^1.29.0",
|
|
41
|
+
"@wordpress/rich-text": "^7.29.0",
|
|
42
|
+
"@wordpress/url": "^4.29.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^18.0.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "445ede01e8abc8e49a1101b21a3651adbe852120"
|
|
52
52
|
}
|
package/src/bold/index.js
CHANGED
|
@@ -7,9 +7,17 @@ import {
|
|
|
7
7
|
RichTextToolbarButton,
|
|
8
8
|
RichTextShortcut,
|
|
9
9
|
__unstableRichTextInputEvent,
|
|
10
|
+
privateApis as blockEditorPrivateApis,
|
|
10
11
|
} from '@wordpress/block-editor';
|
|
11
12
|
import { formatBold } from '@wordpress/icons';
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { unlock } from '../lock-unlock';
|
|
18
|
+
|
|
19
|
+
const { essentialFormatKey } = unlock( blockEditorPrivateApis );
|
|
20
|
+
|
|
13
21
|
const name = 'core/bold';
|
|
14
22
|
const title = __( 'Bold' );
|
|
15
23
|
|
|
@@ -18,6 +26,7 @@ export const bold = {
|
|
|
18
26
|
title,
|
|
19
27
|
tagName: 'strong',
|
|
20
28
|
className: null,
|
|
29
|
+
[ essentialFormatKey ]: true,
|
|
21
30
|
edit( { isActive, value, onChange, onFocus } ) {
|
|
22
31
|
function onToggle() {
|
|
23
32
|
onChange( toggleFormat( value, { type: name, title } ) );
|
package/src/italic/index.js
CHANGED
|
@@ -7,9 +7,17 @@ import {
|
|
|
7
7
|
RichTextToolbarButton,
|
|
8
8
|
RichTextShortcut,
|
|
9
9
|
__unstableRichTextInputEvent,
|
|
10
|
+
privateApis as blockEditorPrivateApis,
|
|
10
11
|
} from '@wordpress/block-editor';
|
|
11
12
|
import { formatItalic } from '@wordpress/icons';
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { unlock } from '../lock-unlock';
|
|
18
|
+
|
|
19
|
+
const { essentialFormatKey } = unlock( blockEditorPrivateApis );
|
|
20
|
+
|
|
13
21
|
const name = 'core/italic';
|
|
14
22
|
const title = __( 'Italic' );
|
|
15
23
|
|
|
@@ -18,6 +26,7 @@ export const italic = {
|
|
|
18
26
|
title,
|
|
19
27
|
tagName: 'em',
|
|
20
28
|
className: null,
|
|
29
|
+
[ essentialFormatKey ]: true,
|
|
21
30
|
edit( { isActive, value, onChange, onFocus } ) {
|
|
22
31
|
function onToggle() {
|
|
23
32
|
onChange( toggleFormat( value, { type: name, title } ) );
|
package/src/link/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { isURL, isEmail, isPhoneNumber } from '@wordpress/url';
|
|
|
16
16
|
import {
|
|
17
17
|
RichTextToolbarButton,
|
|
18
18
|
RichTextShortcut,
|
|
19
|
+
privateApis as blockEditorPrivateApis,
|
|
19
20
|
} from '@wordpress/block-editor';
|
|
20
21
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
21
22
|
import { link as linkIcon } from '@wordpress/icons';
|
|
@@ -26,6 +27,9 @@ import { speak } from '@wordpress/a11y';
|
|
|
26
27
|
*/
|
|
27
28
|
import InlineLinkUI from './inline';
|
|
28
29
|
import { isValidHref } from './utils';
|
|
30
|
+
import { unlock } from '../lock-unlock';
|
|
31
|
+
|
|
32
|
+
const { essentialFormatKey } = unlock( blockEditorPrivateApis );
|
|
29
33
|
|
|
30
34
|
const name = 'core/link';
|
|
31
35
|
const title = __( 'Link' );
|
|
@@ -228,6 +232,7 @@ export const link = {
|
|
|
228
232
|
target: 'target',
|
|
229
233
|
rel: 'rel',
|
|
230
234
|
},
|
|
235
|
+
[ essentialFormatKey ]: true,
|
|
231
236
|
__unstablePasteRule( value, { html, plainText } ) {
|
|
232
237
|
const pastedText = ( html || plainText )
|
|
233
238
|
.replace( /<[^>]+>/g, '' )
|