@wordpress/format-library 4.15.0 → 4.17.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 +4 -0
- package/build/bold/index.js +1 -10
- package/build/bold/index.js.map +1 -1
- package/build/code/index.js +3 -17
- package/build/code/index.js.map +1 -1
- package/build/default-formats.js +0 -14
- package/build/default-formats.js.map +1 -1
- package/build/default-formats.native.js +0 -6
- package/build/default-formats.native.js.map +1 -1
- package/build/image/index.js +5 -14
- package/build/image/index.js.map +1 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/italic/index.js +1 -10
- package/build/italic/index.js.map +1 -1
- package/build/keyboard/index.js +1 -10
- package/build/keyboard/index.js.map +1 -1
- package/build/language/index.js +1 -11
- package/build/language/index.js.map +1 -1
- package/build/link/index.js +5 -26
- package/build/link/index.js.map +1 -1
- package/build/link/index.native.js +14 -39
- package/build/link/index.native.js.map +1 -1
- package/build/link/inline.js +47 -84
- package/build/link/inline.js.map +1 -1
- package/build/link/modal-screens/link-picker-screen.native.js +1 -13
- package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build/link/modal-screens/link-settings-screen.native.js +9 -36
- package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build/link/modal-screens/screens.native.js.map +1 -1
- package/build/link/modal.native.js +1 -9
- package/build/link/modal.native.js.map +1 -1
- package/build/link/use-link-instance-key.js +3 -7
- package/build/link/use-link-instance-key.js.map +1 -1
- package/build/link/utils.js +23 -47
- package/build/link/utils.js.map +1 -1
- package/build/strikethrough/index.js +1 -9
- package/build/strikethrough/index.js.map +1 -1
- package/build/subscript/index.js +1 -10
- package/build/subscript/index.js.map +1 -1
- package/build/superscript/index.js +1 -10
- package/build/superscript/index.js.map +1 -1
- package/build/text-color/index.js +7 -25
- package/build/text-color/index.js.map +1 -1
- package/build/text-color/index.native.js +11 -34
- package/build/text-color/index.native.js.map +1 -1
- package/build/text-color/inline.js +5 -26
- package/build/text-color/inline.js.map +1 -1
- package/build/text-color/inline.native.js +9 -25
- package/build/text-color/inline.native.js.map +1 -1
- package/build/underline/index.js +1 -8
- package/build/underline/index.js.map +1 -1
- package/build/unknown/index.js +1 -11
- package/build/unknown/index.js.map +1 -1
- package/build-module/bold/index.js +0 -7
- package/build-module/bold/index.js.map +1 -1
- package/build-module/code/index.js +2 -14
- package/build-module/code/index.js.map +1 -1
- package/build-module/default-formats.js.map +1 -1
- package/build-module/default-formats.native.js.map +1 -1
- package/build-module/image/index.js +4 -10
- package/build-module/image/index.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/italic/index.js +0 -7
- package/build-module/italic/index.js.map +1 -1
- package/build-module/keyboard/index.js +0 -7
- package/build-module/keyboard/index.js.map +1 -1
- package/build-module/language/index.js +1 -8
- package/build-module/language/index.js.map +1 -1
- package/build-module/link/index.js +5 -17
- package/build-module/link/index.js.map +1 -1
- package/build-module/link/index.native.js +15 -30
- package/build-module/link/index.native.js.map +1 -1
- package/build-module/link/inline.js +45 -72
- package/build-module/link/inline.js.map +1 -1
- package/build-module/link/modal-screens/link-picker-screen.native.js +2 -8
- package/build-module/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build-module/link/modal-screens/link-settings-screen.native.js +10 -28
- package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build-module/link/modal-screens/screens.native.js.map +1 -1
- package/build-module/link/modal.native.js +1 -4
- package/build-module/link/modal.native.js.map +1 -1
- package/build-module/link/use-link-instance-key.js +3 -7
- package/build-module/link/use-link-instance-key.js.map +1 -1
- package/build-module/link/utils.js +24 -43
- package/build-module/link/utils.js.map +1 -1
- package/build-module/strikethrough/index.js +0 -6
- package/build-module/strikethrough/index.js.map +1 -1
- package/build-module/subscript/index.js +0 -7
- package/build-module/subscript/index.js.map +1 -1
- package/build-module/superscript/index.js +0 -7
- package/build-module/superscript/index.js.map +1 -1
- package/build-module/text-color/index.js +7 -20
- package/build-module/text-color/index.js.map +1 -1
- package/build-module/text-color/index.native.js +12 -24
- package/build-module/text-color/index.native.js.map +1 -1
- package/build-module/text-color/inline.js +5 -20
- package/build-module/text-color/inline.js.map +1 -1
- package/build-module/text-color/inline.native.js +9 -21
- package/build-module/text-color/inline.native.js.map +1 -1
- package/build-module/underline/index.js +0 -6
- package/build-module/underline/index.js.map +1 -1
- package/build-module/unknown/index.js +0 -8
- package/build-module/unknown/index.js.map +1 -1
- package/package.json +13 -13
- package/src/link/inline.js +14 -37
- package/src/link/test/__snapshots__/modal.native.js.snap +372 -295
- package/src/text-color/test/index.native.js +4 -0
package/build/link/utils.js
CHANGED
|
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createLinkFormat = createLinkFormat;
|
|
7
7
|
exports.getFormatBoundary = getFormatBoundary;
|
|
8
8
|
exports.isValidHref = isValidHref;
|
|
9
|
-
|
|
10
9
|
var _url = require("@wordpress/url");
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* WordPress dependencies
|
|
14
12
|
*/
|
|
@@ -24,59 +22,48 @@ function isValidHref(href) {
|
|
|
24
22
|
if (!href) {
|
|
25
23
|
return false;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
const trimmedHref = href.trim();
|
|
29
|
-
|
|
30
26
|
if (!trimmedHref) {
|
|
31
27
|
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
28
|
+
}
|
|
34
29
|
|
|
30
|
+
// Does the href start with something that looks like a URL protocol?
|
|
35
31
|
if (/^\S+:/.test(trimmedHref)) {
|
|
36
32
|
const protocol = (0, _url.getProtocol)(trimmedHref);
|
|
37
|
-
|
|
38
33
|
if (!(0, _url.isValidProtocol)(protocol)) {
|
|
39
34
|
return false;
|
|
40
|
-
}
|
|
41
|
-
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
|
|
42
|
-
|
|
35
|
+
}
|
|
43
36
|
|
|
37
|
+
// Add some extra checks for http(s) URIs, since these are the most common use-case.
|
|
38
|
+
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
|
|
44
39
|
if (protocol.startsWith('http') && !/^https?:\/\/[^\/\s]/i.test(trimmedHref)) {
|
|
45
40
|
return false;
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
const authority = (0, _url.getAuthority)(trimmedHref);
|
|
49
|
-
|
|
50
43
|
if (!(0, _url.isValidAuthority)(authority)) {
|
|
51
44
|
return false;
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
const path = (0, _url.getPath)(trimmedHref);
|
|
55
|
-
|
|
56
47
|
if (path && !(0, _url.isValidPath)(path)) {
|
|
57
48
|
return false;
|
|
58
49
|
}
|
|
59
|
-
|
|
60
50
|
const queryString = (0, _url.getQueryString)(trimmedHref);
|
|
61
|
-
|
|
62
51
|
if (queryString && !(0, _url.isValidQueryString)(queryString)) {
|
|
63
52
|
return false;
|
|
64
53
|
}
|
|
65
|
-
|
|
66
54
|
const fragment = (0, _url.getFragment)(trimmedHref);
|
|
67
|
-
|
|
68
55
|
if (fragment && !(0, _url.isValidFragment)(fragment)) {
|
|
69
56
|
return false;
|
|
70
57
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
58
|
+
}
|
|
73
59
|
|
|
60
|
+
// Validate anchor links.
|
|
74
61
|
if (trimmedHref.startsWith('#') && !(0, _url.isValidFragment)(trimmedHref)) {
|
|
75
62
|
return false;
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
return true;
|
|
79
65
|
}
|
|
66
|
+
|
|
80
67
|
/**
|
|
81
68
|
* Generates the format object that will be applied to the link text.
|
|
82
69
|
*
|
|
@@ -88,8 +75,6 @@ function isValidHref(href) {
|
|
|
88
75
|
*
|
|
89
76
|
* @return {Object} The final format object.
|
|
90
77
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
78
|
function createLinkFormat({
|
|
94
79
|
url,
|
|
95
80
|
type,
|
|
@@ -104,16 +89,14 @@ function createLinkFormat({
|
|
|
104
89
|
};
|
|
105
90
|
if (type) format.attributes.type = type;
|
|
106
91
|
if (id) format.attributes.id = id;
|
|
107
|
-
|
|
108
92
|
if (opensInNewWindow) {
|
|
109
93
|
format.attributes.target = '_blank';
|
|
110
94
|
format.attributes.rel = 'noreferrer noopener';
|
|
111
95
|
}
|
|
112
|
-
|
|
113
96
|
return format;
|
|
114
97
|
}
|
|
115
|
-
/* eslint-disable jsdoc/no-undefined-types */
|
|
116
98
|
|
|
99
|
+
/* eslint-disable jsdoc/no-undefined-types */
|
|
117
100
|
/**
|
|
118
101
|
* Get the start and end boundaries of a given format from a rich text value.
|
|
119
102
|
*
|
|
@@ -124,10 +107,7 @@ function createLinkFormat({
|
|
|
124
107
|
* @param {number?} endIndex optional endIndex to seek from.
|
|
125
108
|
* @return {Object} object containing start and end values for the given format.
|
|
126
109
|
*/
|
|
127
|
-
|
|
128
110
|
/* eslint-enable jsdoc/no-undefined-types */
|
|
129
|
-
|
|
130
|
-
|
|
131
111
|
function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) {
|
|
132
112
|
const EMPTY_BOUNDARIES = {
|
|
133
113
|
start: null,
|
|
@@ -138,12 +118,11 @@ function getFormatBoundary(value, format, startIndex = value.start, endIndex = v
|
|
|
138
118
|
} = value;
|
|
139
119
|
let targetFormat;
|
|
140
120
|
let initialIndex;
|
|
141
|
-
|
|
142
121
|
if (!formats?.length) {
|
|
143
122
|
return EMPTY_BOUNDARIES;
|
|
144
|
-
}
|
|
145
|
-
|
|
123
|
+
}
|
|
146
124
|
|
|
125
|
+
// Clone formats to avoid modifying source formats.
|
|
147
126
|
const newFormats = formats.slice();
|
|
148
127
|
const formatAtStart = newFormats[startIndex]?.find(({
|
|
149
128
|
type
|
|
@@ -154,7 +133,6 @@ function getFormatBoundary(value, format, startIndex = value.start, endIndex = v
|
|
|
154
133
|
const formatAtEndMinusOne = newFormats[endIndex - 1]?.find(({
|
|
155
134
|
type
|
|
156
135
|
}) => type === format.type);
|
|
157
|
-
|
|
158
136
|
if (!!formatAtStart) {
|
|
159
137
|
// Set values to conform to "start"
|
|
160
138
|
targetFormat = formatAtStart;
|
|
@@ -172,21 +150,25 @@ function getFormatBoundary(value, format, startIndex = value.start, endIndex = v
|
|
|
172
150
|
} else {
|
|
173
151
|
return EMPTY_BOUNDARIES;
|
|
174
152
|
}
|
|
175
|
-
|
|
176
153
|
const index = newFormats[initialIndex].indexOf(targetFormat);
|
|
177
|
-
const walkingArgs = [newFormats, initialIndex, targetFormat, index];
|
|
154
|
+
const walkingArgs = [newFormats, initialIndex, targetFormat, index];
|
|
178
155
|
|
|
179
|
-
|
|
156
|
+
// Walk the startIndex "backwards" to the leading "edge" of the matching format.
|
|
157
|
+
startIndex = walkToStart(...walkingArgs);
|
|
180
158
|
|
|
181
|
-
|
|
159
|
+
// Walk the endIndex "forwards" until the trailing "edge" of the matching format.
|
|
160
|
+
endIndex = walkToEnd(...walkingArgs);
|
|
182
161
|
|
|
183
|
-
|
|
162
|
+
// Safe guard: start index cannot be less than 0.
|
|
163
|
+
startIndex = startIndex < 0 ? 0 : startIndex;
|
|
184
164
|
|
|
165
|
+
// // Return the indicies of the "edges" as the boundaries.
|
|
185
166
|
return {
|
|
186
167
|
start: startIndex,
|
|
187
168
|
end: endIndex
|
|
188
169
|
};
|
|
189
170
|
}
|
|
171
|
+
|
|
190
172
|
/**
|
|
191
173
|
* Walks forwards/backwards towards the boundary of a given format within an
|
|
192
174
|
* array of format objects. Returns the index of the boundary.
|
|
@@ -198,8 +180,6 @@ function getFormatBoundary(value, format, startIndex = value.start, endIndex = v
|
|
|
198
180
|
* @param {string} direction either 'forwards' or 'backwards' to indicate the direction.
|
|
199
181
|
* @return {number} the index of the boundary of the given format.
|
|
200
182
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
183
|
function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) {
|
|
204
184
|
let index = initialIndex;
|
|
205
185
|
const directions = {
|
|
@@ -207,22 +187,18 @@ function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, dir
|
|
|
207
187
|
backwards: -1
|
|
208
188
|
};
|
|
209
189
|
const directionIncrement = directions[direction] || 1; // invalid direction arg default to forwards
|
|
210
|
-
|
|
211
190
|
const inverseDirectionIncrement = directionIncrement * -1;
|
|
212
|
-
|
|
213
191
|
while (formats[index] && formats[index][formatIndex] === targetFormatRef) {
|
|
214
192
|
// Increment/decrement in the direction of operation.
|
|
215
193
|
index = index + directionIncrement;
|
|
216
|
-
}
|
|
217
|
-
// to avoid out of bounds.
|
|
218
|
-
|
|
194
|
+
}
|
|
219
195
|
|
|
196
|
+
// Restore by one in inverse direction of operation
|
|
197
|
+
// to avoid out of bounds.
|
|
220
198
|
index = index + inverseDirectionIncrement;
|
|
221
199
|
return index;
|
|
222
200
|
}
|
|
223
|
-
|
|
224
201
|
const partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
|
|
225
|
-
|
|
226
202
|
const walkToStart = partialRight(walkToBoundary, 'backwards');
|
|
227
203
|
const walkToEnd = partialRight(walkToBoundary, 'forwards');
|
|
228
204
|
//# sourceMappingURL=utils.js.map
|
package/build/link/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/link/utils.js"],"names":["isValidHref","href","trimmedHref","trim","test","protocol","startsWith","authority","path","queryString","fragment","createLinkFormat","url","type","id","opensInNewWindow","format","attributes","target","rel","getFormatBoundary","value","startIndex","start","endIndex","end","EMPTY_BOUNDARIES","formats","targetFormat","initialIndex","length","newFormats","slice","formatAtStart","find","formatAtEnd","formatAtEndMinusOne","index","indexOf","walkingArgs","walkToStart","walkToEnd","walkToBoundary","targetFormatRef","formatIndex","direction","directions","forwards","backwards","directionIncrement","inverseDirectionIncrement","partialRight","fn","partialArgs","args"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAT,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,IAAAA,GAAG,EAAED;AAFC,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASkB,cAAT,CACCf,OADD,EAECE,YAFD,EAGCc,eAHD,EAICC,WAJD,EAKCC,SALD,EAME;AACD,MAAIR,KAAK,GAAGR,YAAZ;AAEA,QAAMiB,UAAU,GAAG;AAClBC,IAAAA,QAAQ,EAAE,CADQ;AAElBC,IAAAA,SAAS,EAAE,CAAC;AAFM,GAAnB;AAKA,QAAMC,kBAAkB,GAAGH,UAAU,CAAED,SAAF,CAAV,IAA2B,CAAtD,CARC,CAQwD;;AACzD,QAAMK,yBAAyB,GAAGD,kBAAkB,GAAG,CAAC,CAAxD;;AAEA,SACCtB,OAAO,CAAEU,KAAF,CAAP,IACAV,OAAO,CAAEU,KAAF,CAAP,CAAkBO,WAAlB,MAAoCD,eAFrC,EAGE;AACD;AACAN,IAAAA,KAAK,GAAGA,KAAK,GAAGY,kBAAhB;AACA,GAjBA,CAmBD;AACA;;;AACAZ,EAAAA,KAAK,GAAGA,KAAK,GAAGa,yBAAhB;AAEA,SAAOb,KAAP;AACA;;AAED,MAAMc,YAAY,GACjB,CAAEC,EAAF,EAAM,GAAGC,WAAT,KACA,CAAE,GAAGC,IAAL,KACCF,EAAE,CAAE,GAAGE,IAAL,EAAW,GAAGD,WAAd,CAHJ;;AAKA,MAAMb,WAAW,GAAGW,YAAY,CAAET,cAAF,EAAkB,WAAlB,CAAhC;AAEA,MAAMD,SAAS,GAAGU,YAAY,CAAET,cAAF,EAAkB,UAAlB,CAA9B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tgetProtocol,\n\tisValidProtocol,\n\tgetAuthority,\n\tisValidAuthority,\n\tgetPath,\n\tisValidPath,\n\tgetQueryString,\n\tisValidQueryString,\n\tgetFragment,\n\tisValidFragment,\n} from '@wordpress/url';\n\n/**\n * Check for issues with the provided href.\n *\n * @param {string} href The href.\n *\n * @return {boolean} Is the href invalid?\n */\nexport function isValidHref( href ) {\n\tif ( ! href ) {\n\t\treturn false;\n\t}\n\n\tconst trimmedHref = href.trim();\n\n\tif ( ! trimmedHref ) {\n\t\treturn false;\n\t}\n\n\t// Does the href start with something that looks like a URL protocol?\n\tif ( /^\\S+:/.test( trimmedHref ) ) {\n\t\tconst protocol = getProtocol( trimmedHref );\n\t\tif ( ! isValidProtocol( protocol ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Add some extra checks for http(s) URIs, since these are the most common use-case.\n\t\t// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.\n\t\tif (\n\t\t\tprotocol.startsWith( 'http' ) &&\n\t\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( trimmedHref )\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst authority = getAuthority( trimmedHref );\n\t\tif ( ! isValidAuthority( authority ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst path = getPath( trimmedHref );\n\t\tif ( path && ! isValidPath( path ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst queryString = getQueryString( trimmedHref );\n\t\tif ( queryString && ! isValidQueryString( queryString ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst fragment = getFragment( trimmedHref );\n\t\tif ( fragment && ! isValidFragment( fragment ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// Validate anchor links.\n\tif ( trimmedHref.startsWith( '#' ) && ! isValidFragment( trimmedHref ) ) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Generates the format object that will be applied to the link text.\n *\n * @param {Object} options\n * @param {string} options.url The href of the link.\n * @param {string} options.type The type of the link.\n * @param {string} options.id The ID of the link.\n * @param {boolean} options.opensInNewWindow Whether this link will open in a new window.\n *\n * @return {Object} The final format object.\n */\nexport function createLinkFormat( { url, type, id, opensInNewWindow } ) {\n\tconst format = {\n\t\ttype: 'core/link',\n\t\tattributes: {\n\t\t\turl,\n\t\t},\n\t};\n\n\tif ( type ) format.attributes.type = type;\n\tif ( id ) format.attributes.id = id;\n\n\tif ( opensInNewWindow ) {\n\t\tformat.attributes.target = '_blank';\n\t\tformat.attributes.rel = 'noreferrer noopener';\n\t}\n\n\treturn format;\n}\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Get the start and end boundaries of a given format from a rich text value.\n *\n *\n * @param {RichTextValue} value the rich text value to interrogate.\n * @param {string} format the identifier for the target format (e.g. `core/link`, `core/bold`).\n * @param {number?} startIndex optional startIndex to seek from.\n * @param {number?} endIndex optional endIndex to seek from.\n * @return {Object}\tobject containing start and end values for the given format.\n */\n/* eslint-enable jsdoc/no-undefined-types */\nexport function getFormatBoundary(\n\tvalue,\n\tformat,\n\tstartIndex = value.start,\n\tendIndex = value.end\n) {\n\tconst EMPTY_BOUNDARIES = {\n\t\tstart: null,\n\t\tend: null,\n\t};\n\n\tconst { formats } = value;\n\tlet targetFormat;\n\tlet initialIndex;\n\n\tif ( ! formats?.length ) {\n\t\treturn EMPTY_BOUNDARIES;\n\t}\n\n\t// Clone formats to avoid modifying source formats.\n\tconst newFormats = formats.slice();\n\n\tconst formatAtStart = newFormats[ startIndex ]?.find(\n\t\t( { type } ) => type === format.type\n\t);\n\n\tconst formatAtEnd = newFormats[ endIndex ]?.find(\n\t\t( { type } ) => type === format.type\n\t);\n\n\tconst formatAtEndMinusOne = newFormats[ endIndex - 1 ]?.find(\n\t\t( { type } ) => type === format.type\n\t);\n\n\tif ( !! formatAtStart ) {\n\t\t// Set values to conform to \"start\"\n\t\ttargetFormat = formatAtStart;\n\t\tinitialIndex = startIndex;\n\t} else if ( !! formatAtEnd ) {\n\t\t// Set values to conform to \"end\"\n\t\ttargetFormat = formatAtEnd;\n\t\tinitialIndex = endIndex;\n\t} else if ( !! formatAtEndMinusOne ) {\n\t\t// This is an edge case which will occur if you create a format, then place\n\t\t// the caret just before the format and hit the back ARROW key. The resulting\n\t\t// value object will have start and end +1 beyond the edge of the format boundary.\n\t\ttargetFormat = formatAtEndMinusOne;\n\t\tinitialIndex = endIndex - 1;\n\t} else {\n\t\treturn EMPTY_BOUNDARIES;\n\t}\n\n\tconst index = newFormats[ initialIndex ].indexOf( targetFormat );\n\n\tconst walkingArgs = [ newFormats, initialIndex, targetFormat, index ];\n\n\t// Walk the startIndex \"backwards\" to the leading \"edge\" of the matching format.\n\tstartIndex = walkToStart( ...walkingArgs );\n\n\t// Walk the endIndex \"forwards\" until the trailing \"edge\" of the matching format.\n\tendIndex = walkToEnd( ...walkingArgs );\n\n\t// Safe guard: start index cannot be less than 0.\n\tstartIndex = startIndex < 0 ? 0 : startIndex;\n\n\t// // Return the indicies of the \"edges\" as the boundaries.\n\treturn {\n\t\tstart: startIndex,\n\t\tend: endIndex,\n\t};\n}\n\n/**\n * Walks forwards/backwards towards the boundary of a given format within an\n * array of format objects. Returns the index of the boundary.\n *\n * @param {Array} formats the formats to search for the given format type.\n * @param {number} initialIndex the starting index from which to walk.\n * @param {Object} targetFormatRef a reference to the format type object being sought.\n * @param {number} formatIndex the index at which we expect the target format object to be.\n * @param {string} direction either 'forwards' or 'backwards' to indicate the direction.\n * @return {number} the index of the boundary of the given format.\n */\nfunction walkToBoundary(\n\tformats,\n\tinitialIndex,\n\ttargetFormatRef,\n\tformatIndex,\n\tdirection\n) {\n\tlet index = initialIndex;\n\n\tconst directions = {\n\t\tforwards: 1,\n\t\tbackwards: -1,\n\t};\n\n\tconst directionIncrement = directions[ direction ] || 1; // invalid direction arg default to forwards\n\tconst inverseDirectionIncrement = directionIncrement * -1;\n\n\twhile (\n\t\tformats[ index ] &&\n\t\tformats[ index ][ formatIndex ] === targetFormatRef\n\t) {\n\t\t// Increment/decrement in the direction of operation.\n\t\tindex = index + directionIncrement;\n\t}\n\n\t// Restore by one in inverse direction of operation\n\t// to avoid out of bounds.\n\tindex = index + inverseDirectionIncrement;\n\n\treturn index;\n}\n\nconst partialRight =\n\t( fn, ...partialArgs ) =>\n\t( ...args ) =>\n\t\tfn( ...args, ...partialArgs );\n\nconst walkToStart = partialRight( walkToBoundary, 'backwards' );\n\nconst walkToEnd = partialRight( walkToBoundary, 'forwards' );\n"]}
|
|
1
|
+
{"version":3,"names":["_url","require","isValidHref","href","trimmedHref","trim","test","protocol","getProtocol","isValidProtocol","startsWith","authority","getAuthority","isValidAuthority","path","getPath","isValidPath","queryString","getQueryString","isValidQueryString","fragment","getFragment","isValidFragment","createLinkFormat","url","type","id","opensInNewWindow","format","attributes","target","rel","getFormatBoundary","value","startIndex","start","endIndex","end","EMPTY_BOUNDARIES","formats","targetFormat","initialIndex","length","newFormats","slice","formatAtStart","find","formatAtEnd","formatAtEndMinusOne","index","indexOf","walkingArgs","walkToStart","walkToEnd","walkToBoundary","targetFormatRef","formatIndex","direction","directions","forwards","backwards","directionIncrement","inverseDirectionIncrement","partialRight","fn","partialArgs","args"],"sources":["@wordpress/format-library/src/link/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tgetProtocol,\n\tisValidProtocol,\n\tgetAuthority,\n\tisValidAuthority,\n\tgetPath,\n\tisValidPath,\n\tgetQueryString,\n\tisValidQueryString,\n\tgetFragment,\n\tisValidFragment,\n} from '@wordpress/url';\n\n/**\n * Check for issues with the provided href.\n *\n * @param {string} href The href.\n *\n * @return {boolean} Is the href invalid?\n */\nexport function isValidHref( href ) {\n\tif ( ! href ) {\n\t\treturn false;\n\t}\n\n\tconst trimmedHref = href.trim();\n\n\tif ( ! trimmedHref ) {\n\t\treturn false;\n\t}\n\n\t// Does the href start with something that looks like a URL protocol?\n\tif ( /^\\S+:/.test( trimmedHref ) ) {\n\t\tconst protocol = getProtocol( trimmedHref );\n\t\tif ( ! isValidProtocol( protocol ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Add some extra checks for http(s) URIs, since these are the most common use-case.\n\t\t// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.\n\t\tif (\n\t\t\tprotocol.startsWith( 'http' ) &&\n\t\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( trimmedHref )\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst authority = getAuthority( trimmedHref );\n\t\tif ( ! isValidAuthority( authority ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst path = getPath( trimmedHref );\n\t\tif ( path && ! isValidPath( path ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst queryString = getQueryString( trimmedHref );\n\t\tif ( queryString && ! isValidQueryString( queryString ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst fragment = getFragment( trimmedHref );\n\t\tif ( fragment && ! isValidFragment( fragment ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// Validate anchor links.\n\tif ( trimmedHref.startsWith( '#' ) && ! isValidFragment( trimmedHref ) ) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Generates the format object that will be applied to the link text.\n *\n * @param {Object} options\n * @param {string} options.url The href of the link.\n * @param {string} options.type The type of the link.\n * @param {string} options.id The ID of the link.\n * @param {boolean} options.opensInNewWindow Whether this link will open in a new window.\n *\n * @return {Object} The final format object.\n */\nexport function createLinkFormat( { url, type, id, opensInNewWindow } ) {\n\tconst format = {\n\t\ttype: 'core/link',\n\t\tattributes: {\n\t\t\turl,\n\t\t},\n\t};\n\n\tif ( type ) format.attributes.type = type;\n\tif ( id ) format.attributes.id = id;\n\n\tif ( opensInNewWindow ) {\n\t\tformat.attributes.target = '_blank';\n\t\tformat.attributes.rel = 'noreferrer noopener';\n\t}\n\n\treturn format;\n}\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Get the start and end boundaries of a given format from a rich text value.\n *\n *\n * @param {RichTextValue} value the rich text value to interrogate.\n * @param {string} format the identifier for the target format (e.g. `core/link`, `core/bold`).\n * @param {number?} startIndex optional startIndex to seek from.\n * @param {number?} endIndex optional endIndex to seek from.\n * @return {Object}\tobject containing start and end values for the given format.\n */\n/* eslint-enable jsdoc/no-undefined-types */\nexport function getFormatBoundary(\n\tvalue,\n\tformat,\n\tstartIndex = value.start,\n\tendIndex = value.end\n) {\n\tconst EMPTY_BOUNDARIES = {\n\t\tstart: null,\n\t\tend: null,\n\t};\n\n\tconst { formats } = value;\n\tlet targetFormat;\n\tlet initialIndex;\n\n\tif ( ! formats?.length ) {\n\t\treturn EMPTY_BOUNDARIES;\n\t}\n\n\t// Clone formats to avoid modifying source formats.\n\tconst newFormats = formats.slice();\n\n\tconst formatAtStart = newFormats[ startIndex ]?.find(\n\t\t( { type } ) => type === format.type\n\t);\n\n\tconst formatAtEnd = newFormats[ endIndex ]?.find(\n\t\t( { type } ) => type === format.type\n\t);\n\n\tconst formatAtEndMinusOne = newFormats[ endIndex - 1 ]?.find(\n\t\t( { type } ) => type === format.type\n\t);\n\n\tif ( !! formatAtStart ) {\n\t\t// Set values to conform to \"start\"\n\t\ttargetFormat = formatAtStart;\n\t\tinitialIndex = startIndex;\n\t} else if ( !! formatAtEnd ) {\n\t\t// Set values to conform to \"end\"\n\t\ttargetFormat = formatAtEnd;\n\t\tinitialIndex = endIndex;\n\t} else if ( !! formatAtEndMinusOne ) {\n\t\t// This is an edge case which will occur if you create a format, then place\n\t\t// the caret just before the format and hit the back ARROW key. The resulting\n\t\t// value object will have start and end +1 beyond the edge of the format boundary.\n\t\ttargetFormat = formatAtEndMinusOne;\n\t\tinitialIndex = endIndex - 1;\n\t} else {\n\t\treturn EMPTY_BOUNDARIES;\n\t}\n\n\tconst index = newFormats[ initialIndex ].indexOf( targetFormat );\n\n\tconst walkingArgs = [ newFormats, initialIndex, targetFormat, index ];\n\n\t// Walk the startIndex \"backwards\" to the leading \"edge\" of the matching format.\n\tstartIndex = walkToStart( ...walkingArgs );\n\n\t// Walk the endIndex \"forwards\" until the trailing \"edge\" of the matching format.\n\tendIndex = walkToEnd( ...walkingArgs );\n\n\t// Safe guard: start index cannot be less than 0.\n\tstartIndex = startIndex < 0 ? 0 : startIndex;\n\n\t// // Return the indicies of the \"edges\" as the boundaries.\n\treturn {\n\t\tstart: startIndex,\n\t\tend: endIndex,\n\t};\n}\n\n/**\n * Walks forwards/backwards towards the boundary of a given format within an\n * array of format objects. Returns the index of the boundary.\n *\n * @param {Array} formats the formats to search for the given format type.\n * @param {number} initialIndex the starting index from which to walk.\n * @param {Object} targetFormatRef a reference to the format type object being sought.\n * @param {number} formatIndex the index at which we expect the target format object to be.\n * @param {string} direction either 'forwards' or 'backwards' to indicate the direction.\n * @return {number} the index of the boundary of the given format.\n */\nfunction walkToBoundary(\n\tformats,\n\tinitialIndex,\n\ttargetFormatRef,\n\tformatIndex,\n\tdirection\n) {\n\tlet index = initialIndex;\n\n\tconst directions = {\n\t\tforwards: 1,\n\t\tbackwards: -1,\n\t};\n\n\tconst directionIncrement = directions[ direction ] || 1; // invalid direction arg default to forwards\n\tconst inverseDirectionIncrement = directionIncrement * -1;\n\n\twhile (\n\t\tformats[ index ] &&\n\t\tformats[ index ][ formatIndex ] === targetFormatRef\n\t) {\n\t\t// Increment/decrement in the direction of operation.\n\t\tindex = index + directionIncrement;\n\t}\n\n\t// Restore by one in inverse direction of operation\n\t// to avoid out of bounds.\n\tindex = index + inverseDirectionIncrement;\n\n\treturn index;\n}\n\nconst partialRight =\n\t( fn, ...partialArgs ) =>\n\t( ...args ) =>\n\t\tfn( ...args, ...partialArgs );\n\nconst walkToStart = partialRight( walkToBoundary, 'backwards' );\n\nconst walkToEnd = partialRight( walkToBoundary, 'forwards' );\n"],"mappings":";;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAAEC,IAAI,EAAG;EACnC,IAAK,CAAEA,IAAI,EAAG;IACb,OAAO,KAAK;EACb;EAEA,MAAMC,WAAW,GAAGD,IAAI,CAACE,IAAI,CAAC,CAAC;EAE/B,IAAK,CAAED,WAAW,EAAG;IACpB,OAAO,KAAK;EACb;;EAEA;EACA,IAAK,OAAO,CAACE,IAAI,CAAEF,WAAY,CAAC,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zD,MAAMK,yBAAyB,GAAGD,kBAAkB,GAAG,CAAC,CAAC;EAEzD,OACCtB,OAAO,CAAEU,KAAK,CAAE,IAChBV,OAAO,CAAEU,KAAK,CAAE,CAAEO,WAAW,CAAE,KAAKD,eAAe,EAClD;IACD;IACAN,KAAK,GAAGA,KAAK,GAAGY,kBAAkB;EACnC;;EAEA;EACA;EACAZ,KAAK,GAAGA,KAAK,GAAGa,yBAAyB;EAEzC,OAAOb,KAAK;AACb;AAEA,MAAMc,YAAY,GACjBA,CAAEC,EAAE,EAAE,GAAGC,WAAW,KACpB,CAAE,GAAGC,IAAI,KACRF,EAAE,CAAE,GAAGE,IAAI,EAAE,GAAGD,WAAY,CAAC;AAE/B,MAAMb,WAAW,GAAGW,YAAY,CAAET,cAAc,EAAE,WAAY,CAAC;AAE/D,MAAMD,SAAS,GAAGU,YAAY,CAAET,cAAc,EAAE,UAAW,CAAC"}
|
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.strikethrough = void 0;
|
|
7
|
-
|
|
8
7
|
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
8
|
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
|
|
12
9
|
var _richText = require("@wordpress/rich-text");
|
|
13
|
-
|
|
14
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
15
|
-
|
|
16
11
|
var _icons = require("@wordpress/icons");
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* WordPress dependencies
|
|
20
14
|
*/
|
|
15
|
+
|
|
21
16
|
const name = 'core/strikethrough';
|
|
22
17
|
const title = (0, _i18n.__)('Strikethrough');
|
|
23
18
|
const strikethrough = {
|
|
@@ -25,7 +20,6 @@ const strikethrough = {
|
|
|
25
20
|
title,
|
|
26
21
|
tagName: 's',
|
|
27
22
|
className: null,
|
|
28
|
-
|
|
29
23
|
edit({
|
|
30
24
|
isActive,
|
|
31
25
|
value,
|
|
@@ -39,7 +33,6 @@ const strikethrough = {
|
|
|
39
33
|
}));
|
|
40
34
|
onFocus();
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.RichTextShortcut, {
|
|
44
37
|
type: "access",
|
|
45
38
|
character: "d",
|
|
@@ -52,7 +45,6 @@ const strikethrough = {
|
|
|
52
45
|
role: "menuitemcheckbox"
|
|
53
46
|
}));
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
};
|
|
57
49
|
exports.strikethrough = strikethrough;
|
|
58
50
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","strikethrough","tagName","className","edit","isActive","value","onChange","onFocus","onClick","toggleFormat","type","_element","createElement","Fragment","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","formatStrikethrough","role","exports"],"sources":["@wordpress/format-library/src/strikethrough/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { formatStrikethrough } from '@wordpress/icons';\n\nconst name = 'core/strikethrough';\nconst title = __( 'Strikethrough' );\n\nexport const strikethrough = {\n\tname,\n\ttitle,\n\ttagName: 's',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\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=\"access\"\n\t\t\t\t\tcharacter=\"d\"\n\t\t\t\t\tonUse={ onClick }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\ticon={ formatStrikethrough }\n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,aAAA,GAAAA,aAAA"}
|
package/build/subscript/index.js
CHANGED
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.subscript = void 0;
|
|
7
|
-
|
|
8
7
|
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
8
|
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
|
|
12
9
|
var _richText = require("@wordpress/rich-text");
|
|
13
|
-
|
|
14
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
15
|
-
|
|
16
11
|
var _icons = require("@wordpress/icons");
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* WordPress dependencies
|
|
20
14
|
*/
|
|
15
|
+
|
|
21
16
|
const name = 'core/subscript';
|
|
22
17
|
const title = (0, _i18n.__)('Subscript');
|
|
23
18
|
const subscript = {
|
|
@@ -25,7 +20,6 @@ const subscript = {
|
|
|
25
20
|
title,
|
|
26
21
|
tagName: 'sub',
|
|
27
22
|
className: null,
|
|
28
|
-
|
|
29
23
|
edit({
|
|
30
24
|
isActive,
|
|
31
25
|
value,
|
|
@@ -38,12 +32,10 @@ const subscript = {
|
|
|
38
32
|
title
|
|
39
33
|
}));
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
function onClick() {
|
|
43
36
|
onToggle();
|
|
44
37
|
onFocus();
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
return (0, _element.createElement)(_blockEditor.RichTextToolbarButton, {
|
|
48
40
|
icon: _icons.subscript,
|
|
49
41
|
title: title,
|
|
@@ -52,7 +44,6 @@ const subscript = {
|
|
|
52
44
|
role: "menuitemcheckbox"
|
|
53
45
|
});
|
|
54
46
|
}
|
|
55
|
-
|
|
56
47
|
};
|
|
57
48
|
exports.subscript = subscript;
|
|
58
49
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","subscript","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","toggleFormat","type","onClick","_element","createElement","RichTextToolbarButton","icon","subscriptIcon","role","exports"],"sources":["@wordpress/format-library/src/subscript/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { subscript as subscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/subscript';\nconst title = __( 'Subscript' );\n\nexport const subscript = {\n\tname,\n\ttitle,\n\ttagName: 'sub',\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\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ subscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\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;AACA,IAAAG,MAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAMA,MAAMI,IAAI,GAAG,gBAAgB;AAC7B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,WAAY,CAAC;AAExB,MAAMC,SAAS,GAAG;EACxBH,IAAI;EACJC,KAAK;EACLG,OAAO,EAAE,KAAK;EACdC,SAAS,EAAE,IAAI;EACfC,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,EAAEb,IAAI;QAAEC;MAAM,CAAE,CAAE,CAAC;IACzD;IAEA,SAASa,OAAOA,CAAA,EAAG;MAClBH,QAAQ,CAAC,CAAC;MACVD,OAAO,CAAC,CAAC;IACV;IAEA,OACC,IAAAK,QAAA,CAAAC,aAAA,EAAClB,YAAA,CAAAmB,qBAAqB;MACrBC,IAAI,EAAGC,gBAAe;MACtBlB,KAAK,EAAGA,KAAO;MACfa,OAAO,EAAGA,OAAS;MACnBP,QAAQ,EAAGA,QAAU;MACrBa,IAAI,EAAC;IAAkB,CACvB,CAAC;EAEJ;AACD,CAAC;AAACC,OAAA,CAAAlB,SAAA,GAAAA,SAAA"}
|
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.superscript = void 0;
|
|
7
|
-
|
|
8
7
|
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
8
|
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
|
|
12
9
|
var _richText = require("@wordpress/rich-text");
|
|
13
|
-
|
|
14
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
15
|
-
|
|
16
11
|
var _icons = require("@wordpress/icons");
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* WordPress dependencies
|
|
20
14
|
*/
|
|
15
|
+
|
|
21
16
|
const name = 'core/superscript';
|
|
22
17
|
const title = (0, _i18n.__)('Superscript');
|
|
23
18
|
const superscript = {
|
|
@@ -25,7 +20,6 @@ const superscript = {
|
|
|
25
20
|
title,
|
|
26
21
|
tagName: 'sup',
|
|
27
22
|
className: null,
|
|
28
|
-
|
|
29
23
|
edit({
|
|
30
24
|
isActive,
|
|
31
25
|
value,
|
|
@@ -38,12 +32,10 @@ const superscript = {
|
|
|
38
32
|
title
|
|
39
33
|
}));
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
function onClick() {
|
|
43
36
|
onToggle();
|
|
44
37
|
onFocus();
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
return (0, _element.createElement)(_blockEditor.RichTextToolbarButton, {
|
|
48
40
|
icon: _icons.superscript,
|
|
49
41
|
title: title,
|
|
@@ -52,7 +44,6 @@ const superscript = {
|
|
|
52
44
|
role: "menuitemcheckbox"
|
|
53
45
|
});
|
|
54
46
|
}
|
|
55
|
-
|
|
56
47
|
};
|
|
57
48
|
exports.superscript = superscript;
|
|
58
49
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","superscript","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","toggleFormat","type","onClick","_element","createElement","RichTextToolbarButton","icon","superscriptIcon","role","exports"],"sources":["@wordpress/format-library/src/superscript/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { superscript as superscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/superscript';\nconst title = __( 'Superscript' );\n\nexport const superscript = {\n\tname,\n\ttitle,\n\ttagName: 'sup',\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\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ superscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\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;AACA,IAAAG,MAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAMA,MAAMI,IAAI,GAAG,kBAAkB;AAC/B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,aAAc,CAAC;AAE1B,MAAMC,WAAW,GAAG;EAC1BH,IAAI;EACJC,KAAK;EACLG,OAAO,EAAE,KAAK;EACdC,SAAS,EAAE,IAAI;EACfC,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,EAAEb,IAAI;QAAEC;MAAM,CAAE,CAAE,CAAC;IACzD;IAEA,SAASa,OAAOA,CAAA,EAAG;MAClBH,QAAQ,CAAC,CAAC;MACVD,OAAO,CAAC,CAAC;IACV;IAEA,OACC,IAAAK,QAAA,CAAAC,aAAA,EAAClB,YAAA,CAAAmB,qBAAqB;MACrBC,IAAI,EAAGC,kBAAiB;MACxBlB,KAAK,EAAGA,KAAO;MACfa,OAAO,EAAGA,OAAS;MACnBP,QAAQ,EAAGA,QAAU;MACrBa,IAAI,EAAC;IAAkB,CACvB,CAAC;EAEJ;AACD,CAAC;AAACC,OAAA,CAAAlB,WAAA,GAAAA,WAAA"}
|
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.transparentValue = exports.textColor = void 0;
|
|
7
|
-
|
|
8
7
|
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
8
|
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
|
|
12
9
|
var _blockEditor = require("@wordpress/block-editor");
|
|
13
|
-
|
|
14
10
|
var _icons = require("@wordpress/icons");
|
|
15
|
-
|
|
16
11
|
var _richText = require("@wordpress/rich-text");
|
|
17
|
-
|
|
18
12
|
var _inline = _interopRequireWildcard(require("./inline"));
|
|
19
|
-
|
|
20
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* WordPress dependencies
|
|
26
17
|
*/
|
|
@@ -28,12 +19,12 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
28
19
|
/**
|
|
29
20
|
* Internal dependencies
|
|
30
21
|
*/
|
|
22
|
+
|
|
31
23
|
const transparentValue = 'rgba(0, 0, 0, 0)';
|
|
32
24
|
exports.transparentValue = transparentValue;
|
|
33
25
|
const name = 'core/text-color';
|
|
34
26
|
const title = (0, _i18n.__)('Highlight');
|
|
35
27
|
const EMPTY_ARRAY = [];
|
|
36
|
-
|
|
37
28
|
function getComputedStyleProperty(element, property) {
|
|
38
29
|
const {
|
|
39
30
|
ownerDocument
|
|
@@ -43,14 +34,11 @@ function getComputedStyleProperty(element, property) {
|
|
|
43
34
|
} = ownerDocument;
|
|
44
35
|
const style = defaultView.getComputedStyle(element);
|
|
45
36
|
const value = style.getPropertyValue(property);
|
|
46
|
-
|
|
47
37
|
if (property === 'background-color' && value === transparentValue && element.parentElement) {
|
|
48
38
|
return getComputedStyleProperty(element.parentElement, property);
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
return value;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
42
|
function fillComputedColors(element, {
|
|
55
43
|
color,
|
|
56
44
|
backgroundColor
|
|
@@ -58,13 +46,11 @@ function fillComputedColors(element, {
|
|
|
58
46
|
if (!color && !backgroundColor) {
|
|
59
47
|
return;
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
return {
|
|
63
50
|
color: color || getComputedStyleProperty(element, 'color'),
|
|
64
51
|
backgroundColor: backgroundColor === transparentValue ? getComputedStyleProperty(element, 'background-color') : backgroundColor
|
|
65
52
|
};
|
|
66
53
|
}
|
|
67
|
-
|
|
68
54
|
function TextColorEdit({
|
|
69
55
|
value,
|
|
70
56
|
onChange,
|
|
@@ -79,11 +65,9 @@ function TextColorEdit({
|
|
|
79
65
|
const disableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
80
66
|
const colorIndicatorStyle = (0, _element.useMemo)(() => fillComputedColors(contentRef.current, (0, _inline.getActiveColors)(value, name, colors)), [value, colors]);
|
|
81
67
|
const hasColorsToChoose = colors.length || !allowCustomControl;
|
|
82
|
-
|
|
83
68
|
if (!hasColorsToChoose && !isActive) {
|
|
84
69
|
return null;
|
|
85
70
|
}
|
|
86
|
-
|
|
87
71
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.RichTextToolbarButton, {
|
|
88
72
|
className: "format-library-text-color-button",
|
|
89
73
|
isActive: isActive,
|
|
@@ -91,7 +75,8 @@ function TextColorEdit({
|
|
|
91
75
|
icon: Object.keys(activeAttributes).length ? _icons.textColor : _icons.color,
|
|
92
76
|
style: colorIndicatorStyle
|
|
93
77
|
}),
|
|
94
|
-
title: title
|
|
78
|
+
title: title
|
|
79
|
+
// If has no colors to choose but a color is active remove the color onClick.
|
|
95
80
|
,
|
|
96
81
|
onClick: hasColorsToChoose ? enableIsAddingColor : () => onChange((0, _richText.removeFormat)(value, name)),
|
|
97
82
|
role: "menuitemcheckbox"
|
|
@@ -104,7 +89,6 @@ function TextColorEdit({
|
|
|
104
89
|
contentRef: contentRef
|
|
105
90
|
}));
|
|
106
91
|
}
|
|
107
|
-
|
|
108
92
|
const textColor = {
|
|
109
93
|
name,
|
|
110
94
|
title,
|
|
@@ -114,7 +98,6 @@ const textColor = {
|
|
|
114
98
|
style: 'style',
|
|
115
99
|
class: 'class'
|
|
116
100
|
},
|
|
117
|
-
|
|
118
101
|
/*
|
|
119
102
|
* Since this format relies on the <mark> tag, it's important to
|
|
120
103
|
* prevent the default yellow background color applied by most
|
|
@@ -125,15 +108,14 @@ const textColor = {
|
|
|
125
108
|
* @see https://github.com/WordPress/gutenberg/pull/35516
|
|
126
109
|
*/
|
|
127
110
|
__unstableFilterAttributeValue(key, value) {
|
|
128
|
-
if (key !== 'style') return value;
|
|
129
|
-
|
|
111
|
+
if (key !== 'style') return value;
|
|
112
|
+
// We should not add a background-color if it's already set.
|
|
130
113
|
if (value && value.includes('background-color')) return value;
|
|
131
|
-
const addedCSS = ['background-color', transparentValue].join(':');
|
|
114
|
+
const addedCSS = ['background-color', transparentValue].join(':');
|
|
115
|
+
// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS
|
|
132
116
|
// rules will already include a `;`.
|
|
133
|
-
|
|
134
117
|
return value ? [addedCSS, value].join(';') : addedCSS;
|
|
135
118
|
},
|
|
136
|
-
|
|
137
119
|
edit: TextColorEdit
|
|
138
120
|
};
|
|
139
121
|
exports.textColor = textColor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_blockEditor","_icons","_richText","_inline","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","transparentValue","exports","name","title","__","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","color","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","useSetting","colors","isAddingColor","setIsAddingColor","useState","enableIsAddingColor","useCallback","disableIsAddingColor","colorIndicatorStyle","useMemo","current","getActiveColors","hasColorsToChoose","length","createElement","Fragment","RichTextToolbarButton","className","icon","Icon","keys","textColorIcon","colorIcon","onClick","removeFormat","role","onClose","textColor","tagName","attributes","class","__unstableFilterAttributeValue","includes","addedCSS","join","edit"],"sources":["@wordpress/format-library/src/text-color/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { RichTextToolbarButton, useSetting } from '@wordpress/block-editor';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { default as InlineColorUI, getActiveColors } from './inline';\n\nexport const transparentValue = 'rgba(0, 0, 0, 0)';\n\nconst name = 'core/text-color';\nconst title = __( 'Highlight' );\n\nconst EMPTY_ARRAY = [];\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst { ownerDocument } = element;\n\tconst { defaultView } = ownerDocument;\n\tconst style = defaultView.getComputedStyle( element );\n\tconst value = style.getPropertyValue( property );\n\n\tif (\n\t\tproperty === 'background-color' &&\n\t\tvalue === transparentValue &&\n\t\telement.parentElement\n\t) {\n\t\treturn getComputedStyleProperty( element.parentElement, property );\n\t}\n\n\treturn value;\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor:\n\t\t\tbackgroundColor === transparentValue\n\t\t\t\t? getComputedStyleProperty( element, 'background-color' )\n\t\t\t\t: backgroundColor,\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst allowCustomControl = useSetting( 'color.custom' );\n\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( true ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst disableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( false ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef.current,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = colors.length || ! allowCustomControl;\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tclassName=\"format-library-text-color-button\"\n\t\t\t\tisActive={ isActive }\n\t\t\t\ticon={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstyle={ colorIndicatorStyle }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\ttitle={ title }\n\t\t\t\t// If has no colors to choose but a color is active remove the color onClick.\n\t\t\t\tonClick={\n\t\t\t\t\thasColorsToChoose\n\t\t\t\t\t\t? enableIsAddingColor\n\t\t\t\t\t\t: () => onChange( removeFormat( value, name ) )\n\t\t\t\t}\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\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/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\t/*\n\t * Since this format relies on the <mark> tag, it's important to\n\t * prevent the default yellow background color applied by most\n\t * browsers. The solution is to detect when this format is used with a\n\t * text color but no background color, and in such cases to override\n\t * the default styling with a transparent background.\n\t *\n\t * @see https://github.com/WordPress/gutenberg/pull/35516\n\t */\n\t__unstableFilterAttributeValue( key, value ) {\n\t\tif ( key !== 'style' ) return value;\n\t\t// We should not add a background-color if it's already set.\n\t\tif ( value && value.includes( 'background-color' ) ) return value;\n\t\tconst addedCSS = [ 'background-color', transparentValue ].join( ':' );\n\t\t// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS\n\t\t// rules will already include a `;`.\n\t\treturn value ? [ addedCSS, value ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"],"mappings":";;;;;;AAIA,IAAAA,QAAA,GAAAC,OAAA;AADA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAKA,IAAAI,SAAA,GAAAJ,OAAA;AAKA,IAAAK,OAAA,GAAAC,uBAAA,CAAAN,OAAA;AAAqE,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD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