@livepreso/react-plugin-textfield 0.0.2
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/.lintstagedrc.js +6 -0
- package/.rush/temp/shrinkwrap-deps.json +311 -0
- package/.vscode/settings.json +22 -0
- package/CHANGELOG.json +17 -0
- package/CHANGELOG.md +9 -0
- package/components/BubbleMenu.js +181 -0
- package/components/BubbleMenu.module.scss +9 -0
- package/components/LinkEditDialog.js +105 -0
- package/components/LinkEditDialog.module.scss +171 -0
- package/components/Popover.js +43 -0
- package/components/Popover.module.scss +80 -0
- package/components/PrimaryToolbar.js +27 -0
- package/components/Select/Select.js +71 -0
- package/components/Select/Select.module.scss +100 -0
- package/components/Select/SelectGroup.js +37 -0
- package/components/Select/index.js +1 -0
- package/components/TableCellMenu.js +43 -0
- package/components/TableToolbar.js +41 -0
- package/components/Tooltip.js +34 -0
- package/components/Tooltip.module.scss +87 -0
- package/components/VerticalAlignToggle.js +65 -0
- package/components/color-picker/ColorPicker.js +28 -0
- package/components/color-picker/ColorPicker.module.scss +8 -0
- package/components/color-picker/ColorPickerChip.js +22 -0
- package/components/color-picker/ColorPickerChip.module.scss +25 -0
- package/components/color-picker/ColorPickerCombo.js +45 -0
- package/components/color-picker/ColorPickerCombo.module.scss +23 -0
- package/components/color-picker/TextColorIcon.js +18 -0
- package/components/editor-toolbars/EditorMenu.js +104 -0
- package/components/editor-toolbars/EditorMenu.module.scss +96 -0
- package/components/editor-toolbars/EditorToolbar.js +146 -0
- package/components/editor-toolbars/EditorToolbar.module.scss +75 -0
- package/components/editor-toolbars/MenuItem.js +24 -0
- package/components/editor-toolbars/SubMenu.js +50 -0
- package/components/editor-toolbars/ToolbarButton.js +26 -0
- package/components/editor-toolbars/ToolbarToggle.js +35 -0
- package/components/editor-toolbars/ToolbarToggleGroup.js +43 -0
- package/components/editor-toolbars/utils.js +7 -0
- package/components/hooks/use-presenter.js +5 -0
- package/components/style.module.scss +63 -0
- package/components/tiptap/ListItem.js +5 -0
- package/components/tiptap/Table.js +397 -0
- package/components/tiptap/TableCells.js +99 -0
- package/components/utils.js +84 -0
- package/configs/generate-toolbar-configuration.js +130 -0
- package/configs/generate-toolbar-options.js +96 -0
- package/configs/table-toolbar-configuration.js +187 -0
- package/configs/toolbar-configuration.js +330 -0
- package/constants.js +198 -0
- package/eslint.config.mjs +15 -0
- package/icons/AddColumnLeft.js +15 -0
- package/icons/AddColumnRight.js +15 -0
- package/icons/AddRowAbove.js +15 -0
- package/icons/AddRowBelow.js +15 -0
- package/icons/AlignHorizontalCenter.js +13 -0
- package/icons/AlignHorizontalLeft.js +13 -0
- package/icons/AlignHorizontalRight.js +13 -0
- package/icons/AlignVerticalBottom.js +13 -0
- package/icons/AlignVerticalCenter.js +13 -0
- package/icons/AlignVerticalTop.js +13 -0
- package/icons/Backspace.js +13 -0
- package/icons/Bold.js +14 -0
- package/icons/BorderAll.js +13 -0
- package/icons/BorderBottom.js +13 -0
- package/icons/BorderClear.js +13 -0
- package/icons/BorderHorizontal.js +13 -0
- package/icons/BorderInner.js +13 -0
- package/icons/BorderLeft.js +13 -0
- package/icons/BorderOuter.js +13 -0
- package/icons/BorderRight.js +13 -0
- package/icons/BorderTop.js +13 -0
- package/icons/BorderVertical.js +13 -0
- package/icons/Close.js +13 -0
- package/icons/Delete.js +13 -0
- package/icons/EvenlyDistribute.js +14 -0
- package/icons/FitWidth.js +13 -0
- package/icons/FitWidthArrows.js +21 -0
- package/icons/FormatAlignCenter.js +13 -0
- package/icons/FormatAlignJustify.js +13 -0
- package/icons/FormatAlignLeft.js +13 -0
- package/icons/FormatAlignRight.js +13 -0
- package/icons/FormatBold.js +13 -0
- package/icons/FormatClear.js +13 -0
- package/icons/FormatColorFill.js +13 -0
- package/icons/FormatColorText.js +13 -0
- package/icons/FormatItalic.js +13 -0
- package/icons/FormatLineSpacing.js +13 -0
- package/icons/FormatListBulleted.js +13 -0
- package/icons/FormatListNumbered.js +13 -0
- package/icons/FormatStrikethrough.js +13 -0
- package/icons/FormatUnderlined.js +13 -0
- package/icons/HorizontalRule.js +13 -0
- package/icons/Italic.js +14 -0
- package/icons/ItalicIcon.js +18 -0
- package/icons/Link.js +13 -0
- package/icons/LinkOff.js +13 -0
- package/icons/MergeCells.js +14 -0
- package/icons/Redo.js +13 -0
- package/icons/RemoveColumnOutline.js +28 -0
- package/icons/RemoveRowOutline.js +25 -0
- package/icons/SplitCells.js +14 -0
- package/icons/SplitScene.js +13 -0
- package/icons/Subscript.js +13 -0
- package/icons/Superscript.js +13 -0
- package/icons/Underline.js +14 -0
- package/icons/Undo.js +13 -0
- package/icons/VerticalAlignBottom.js +13 -0
- package/icons/VerticalAlignCenter.js +13 -0
- package/icons/VerticalAlignTop.js +13 -0
- package/icons/add_column_left.svg +6 -0
- package/icons/add_column_right.svg +6 -0
- package/icons/add_row_above.svg +6 -0
- package/icons/add_row_below.svg +6 -0
- package/icons/align_horizontal_center.svg +1 -0
- package/icons/align_horizontal_left.svg +1 -0
- package/icons/align_horizontal_right.svg +1 -0
- package/icons/align_vertical_bottom.svg +1 -0
- package/icons/align_vertical_center.svg +1 -0
- package/icons/align_vertical_top.svg +1 -0
- package/icons/backspace.svg +1 -0
- package/icons/bold.svg +1 -0
- package/icons/border_all.svg +1 -0
- package/icons/border_bottom.svg +1 -0
- package/icons/border_clear.svg +1 -0
- package/icons/border_horizontal.svg +1 -0
- package/icons/border_inner.svg +1 -0
- package/icons/border_left.svg +1 -0
- package/icons/border_outer.svg +1 -0
- package/icons/border_right.svg +1 -0
- package/icons/border_top.svg +1 -0
- package/icons/border_vertical.svg +1 -0
- package/icons/close.svg +1 -0
- package/icons/delete.svg +1 -0
- package/icons/evenly_distribute.svg +5 -0
- package/icons/fit_width.svg +1 -0
- package/icons/fit_width_arrows.svg +12 -0
- package/icons/format_align_center.svg +1 -0
- package/icons/format_align_justify.svg +1 -0
- package/icons/format_align_left.svg +1 -0
- package/icons/format_align_right.svg +1 -0
- package/icons/format_bold.svg +1 -0
- package/icons/format_clear.svg +1 -0
- package/icons/format_color_fill.svg +1 -0
- package/icons/format_color_text.svg +5 -0
- package/icons/format_color_text_ungrouped.svg +6 -0
- package/icons/format_italic.svg +1 -0
- package/icons/format_line_spacing.svg +1 -0
- package/icons/format_list_bulleted.svg +1 -0
- package/icons/format_list_numbered.svg +1 -0
- package/icons/format_strikethrough.svg +1 -0
- package/icons/format_underlined.svg +1 -0
- package/icons/horizontal_rule.svg +1 -0
- package/icons/index.js +191 -0
- package/icons/italic.svg +1 -0
- package/icons/link.svg +1 -0
- package/icons/link_off.svg +1 -0
- package/icons/merge_cells.svg +5 -0
- package/icons/redo.svg +1 -0
- package/icons/remove_column_outline.svg +20 -0
- package/icons/remove_row_outline.svg +17 -0
- package/icons/split_cells.svg +5 -0
- package/icons/split_scene.svg +1 -0
- package/icons/subscript.svg +1 -0
- package/icons/superscript.svg +1 -0
- package/icons/underline.svg +1 -0
- package/icons/undo.svg +1 -0
- package/icons/vertical_align_bottom.svg +1 -0
- package/icons/vertical_align_center.svg +1 -0
- package/icons/vertical_align_top.svg +1 -0
- package/index.js +334 -0
- package/index.module.scss +106 -0
- package/package.json +63 -0
- package/scripts/extract-svg.js +288 -0
- package/utils/color-utils.js +42 -0
- package/utils/generate-vertical-alignment-icon.js +22 -0
- package/utils/generateCustomExtensions.js +49 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const { transform } = require("@svgr/core");
|
|
5
|
+
// const svgrJSX = require("@svgr/plugin-jsx");
|
|
6
|
+
|
|
7
|
+
// Array of symbol names to download
|
|
8
|
+
const SYMBOL_NAMES = [
|
|
9
|
+
"backspace",
|
|
10
|
+
"align_horizontal_center",
|
|
11
|
+
"align_horizontal_left",
|
|
12
|
+
"align_horizontal_right",
|
|
13
|
+
"align_vertical_bottom",
|
|
14
|
+
"align_vertical_center",
|
|
15
|
+
"align_vertical_top",
|
|
16
|
+
"border_all",
|
|
17
|
+
"border_bottom",
|
|
18
|
+
"border_clear",
|
|
19
|
+
"border_horizontal",
|
|
20
|
+
"border_inner",
|
|
21
|
+
"border_left",
|
|
22
|
+
"border_outer",
|
|
23
|
+
"border_right",
|
|
24
|
+
"border_top",
|
|
25
|
+
"border_vertical",
|
|
26
|
+
"close",
|
|
27
|
+
"delete",
|
|
28
|
+
"delete_column",
|
|
29
|
+
"delete_row",
|
|
30
|
+
"format_align_center",
|
|
31
|
+
"format_align_justify",
|
|
32
|
+
"format_align_left",
|
|
33
|
+
"format_align_right",
|
|
34
|
+
"format_bold",
|
|
35
|
+
"format_clear",
|
|
36
|
+
"format_color_fill",
|
|
37
|
+
"format_color_text",
|
|
38
|
+
"format_italic",
|
|
39
|
+
"format_list_bulleted",
|
|
40
|
+
"format_list_numbered",
|
|
41
|
+
"format_strikethrough",
|
|
42
|
+
"format_underlined",
|
|
43
|
+
"horizontal_rule",
|
|
44
|
+
"link",
|
|
45
|
+
"link_off",
|
|
46
|
+
"redo",
|
|
47
|
+
"undo",
|
|
48
|
+
"format_line_spacing",
|
|
49
|
+
"vertical_align_top",
|
|
50
|
+
"vertical_align_center",
|
|
51
|
+
"vertical_align_bottom",
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Extracts SVG files from GitHub and saves them with new names
|
|
56
|
+
* @param {string} style - The style directory (rounded/sharp/outlined)
|
|
57
|
+
* @param {string} weight - The weight parameter for the file name (e.g., 'wght600')
|
|
58
|
+
* @param {string} size - The size parameter for the file name (e.g., '24px')
|
|
59
|
+
* @param {string} outputDir - Optional output directory (defaults to current directory)
|
|
60
|
+
* @param {boolean} createIndex - Whether to create an index.js file (defaults to true)
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line max-params
|
|
64
|
+
function extractSvgFiles(
|
|
65
|
+
style,
|
|
66
|
+
weight,
|
|
67
|
+
size,
|
|
68
|
+
outputDir = "./",
|
|
69
|
+
createIndex = true,
|
|
70
|
+
) {
|
|
71
|
+
// Ensure output directory exists
|
|
72
|
+
if (!fs.existsSync(outputDir)) {
|
|
73
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Track promises for all downloads
|
|
77
|
+
const downloadPromises = [];
|
|
78
|
+
|
|
79
|
+
// Process each symbol from the predefined array
|
|
80
|
+
SYMBOL_NAMES.forEach((symbolName) => {
|
|
81
|
+
const githubUrl = `https://raw.githubusercontent.com/google/material-design-icons/refs/heads/master/symbols/web/${symbolName}/materialsymbols${style}/${symbolName}_${weight}_${size}.svg`;
|
|
82
|
+
|
|
83
|
+
const outputFileName = `${symbolName}.svg`;
|
|
84
|
+
const outputFilePath = path.join(outputDir, outputFileName);
|
|
85
|
+
|
|
86
|
+
// Add download promise to array
|
|
87
|
+
const downloadPromise = downloadFile(githubUrl, outputFilePath)
|
|
88
|
+
.then(() => {
|
|
89
|
+
console.log(`Downloaded: ${outputFilePath}`);
|
|
90
|
+
})
|
|
91
|
+
.catch((error) =>
|
|
92
|
+
console.error(`Failed to download ${symbolName}: ${error.message}`),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
downloadPromises.push(downloadPromise);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Wait for all downloads to complete, then create index if requested
|
|
99
|
+
Promise.all(downloadPromises)
|
|
100
|
+
.then(() => {
|
|
101
|
+
console.log("All downloads complete!");
|
|
102
|
+
|
|
103
|
+
// Get all SVG files in the directory
|
|
104
|
+
const svgFiles = fs
|
|
105
|
+
.readdirSync(outputDir)
|
|
106
|
+
.filter((file) => file.toLowerCase().endsWith(".svg"));
|
|
107
|
+
|
|
108
|
+
// Create React components from all found SVGs
|
|
109
|
+
svgFiles.forEach((file) => {
|
|
110
|
+
const baseName = path.basename(file, ".svg");
|
|
111
|
+
|
|
112
|
+
const componentName = toCamelCase(baseName, true);
|
|
113
|
+
const svgCode = fs.readFileSync(`${outputDir}/${file}`, "utf-8");
|
|
114
|
+
const reactFilePath = `${outputDir}/${componentName}.js`;
|
|
115
|
+
|
|
116
|
+
const reactSvg = transform.sync(
|
|
117
|
+
svgCode,
|
|
118
|
+
{
|
|
119
|
+
icon: size,
|
|
120
|
+
jsxRuntime: "classic",
|
|
121
|
+
plugins: ["@svgr/plugin-jsx"],
|
|
122
|
+
},
|
|
123
|
+
{ componentName, filePath: reactFilePath },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
fs.writeFileSync(reactFilePath, reactSvg);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (createIndex) {
|
|
130
|
+
createSvgIndex({
|
|
131
|
+
style,
|
|
132
|
+
weight,
|
|
133
|
+
size,
|
|
134
|
+
svgDir: outputDir,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
.catch((error) => {
|
|
139
|
+
console.error("Error during download & React component creation:", error);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Downloads a file from a URL and saves it to the specified path
|
|
145
|
+
* @param {string} url - The URL to download from
|
|
146
|
+
* @param {string} outputPath - The path to save the file to
|
|
147
|
+
* @returns {Promise} A promise that resolves when the file is downloaded
|
|
148
|
+
*/
|
|
149
|
+
function downloadFile(url, outputPath) {
|
|
150
|
+
return new Promise((resolve, reject) => {
|
|
151
|
+
https
|
|
152
|
+
.get(url, (response) => {
|
|
153
|
+
if (response.statusCode === 200) {
|
|
154
|
+
const file = fs.createWriteStream(outputPath);
|
|
155
|
+
response.pipe(file);
|
|
156
|
+
|
|
157
|
+
file.on("finish", () => {
|
|
158
|
+
file.close();
|
|
159
|
+
resolve();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
file.on("error", (err) => {
|
|
163
|
+
fs.unlink(outputPath, () => {}); // Delete the file if there was an error
|
|
164
|
+
reject(err);
|
|
165
|
+
});
|
|
166
|
+
} else if (response.statusCode === 404) {
|
|
167
|
+
reject(new Error(`File not found (404): ${url}`));
|
|
168
|
+
} else {
|
|
169
|
+
reject(new Error(`Failed to download file: ${response.statusCode}`));
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
.on("error", (err) => {
|
|
173
|
+
reject(err);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Converts a string to camelCase format
|
|
180
|
+
* @param {string} str - The string to convert
|
|
181
|
+
* @returns {string} The camelCase formatted string
|
|
182
|
+
*/
|
|
183
|
+
function toCamelCase(str, captitaliseFirstLetter = false) {
|
|
184
|
+
// Replace non-alphanumeric characters with spaces, then split into words
|
|
185
|
+
return str
|
|
186
|
+
.replace(/[^a-zA-Z0-9]/g, " ")
|
|
187
|
+
.split(" ")
|
|
188
|
+
.filter((word) => word.length > 0) // Remove empty strings
|
|
189
|
+
.map((word, index) => {
|
|
190
|
+
// First word starts with lowercase, rest with uppercase
|
|
191
|
+
if (index === 0 && !captitaliseFirstLetter) {
|
|
192
|
+
return word.toLowerCase();
|
|
193
|
+
}
|
|
194
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
195
|
+
})
|
|
196
|
+
.join("");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Creates an index.js file that exports all SVG files from a directory
|
|
201
|
+
* @param {string} svgDir - Directory containing SVG files
|
|
202
|
+
* @param {string} outputFile - Path to the output index.js file
|
|
203
|
+
*/
|
|
204
|
+
function createSvgIndex({
|
|
205
|
+
style,
|
|
206
|
+
weight,
|
|
207
|
+
size,
|
|
208
|
+
svgDir,
|
|
209
|
+
outputFile = "index.js",
|
|
210
|
+
}) {
|
|
211
|
+
// Get all SVG files in the directory
|
|
212
|
+
const svgFiles = fs
|
|
213
|
+
.readdirSync(svgDir)
|
|
214
|
+
.filter(
|
|
215
|
+
(file) =>
|
|
216
|
+
file.toLowerCase().endsWith(".js") && file.toLowerCase() !== "index.js",
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
if (svgFiles.length === 0) {
|
|
220
|
+
console.warn(`No SVG files found in ${svgDir}`);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Create the content for the index.js file
|
|
225
|
+
let indexContent = "// Auto-generated index file for SVG exports\n\n";
|
|
226
|
+
|
|
227
|
+
// Add imports and exports
|
|
228
|
+
svgFiles.forEach((file) => {
|
|
229
|
+
const baseName = path.basename(file, ".js");
|
|
230
|
+
indexContent += `import ${baseName} from './${file}';\n`;
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
indexContent += "\nexport const MATERIAL_SVG_PARAMS = {\n";
|
|
234
|
+
indexContent += `\tstyle: "${style}", \n`;
|
|
235
|
+
indexContent += `\tweight: "${weight}", \n`;
|
|
236
|
+
indexContent += `\tsize: "${size}", \n`;
|
|
237
|
+
indexContent += `};\n`;
|
|
238
|
+
|
|
239
|
+
indexContent += "\nexport {\n";
|
|
240
|
+
svgFiles.forEach((file) => {
|
|
241
|
+
const baseName = path.basename(file, ".js");
|
|
242
|
+
indexContent += ` ${baseName},\n`;
|
|
243
|
+
});
|
|
244
|
+
indexContent += "};\n\n";
|
|
245
|
+
|
|
246
|
+
// Add a default export with all icons in an object
|
|
247
|
+
indexContent += "export default {\n";
|
|
248
|
+
svgFiles.forEach((file) => {
|
|
249
|
+
const baseName = path.basename(file, ".js");
|
|
250
|
+
indexContent += ` ${baseName},\n`;
|
|
251
|
+
});
|
|
252
|
+
indexContent += "};\n";
|
|
253
|
+
|
|
254
|
+
// Write the index.js file
|
|
255
|
+
const outputPath = path.join(svgDir, outputFile);
|
|
256
|
+
fs.writeFileSync(outputPath, indexContent);
|
|
257
|
+
console.log(`Created SVG index file: ${outputPath}`);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Example usage:
|
|
261
|
+
// extractSvgFiles('rounded', 'wght600', '24px', './extracted-icons', true);
|
|
262
|
+
|
|
263
|
+
module.exports = extractSvgFiles;
|
|
264
|
+
|
|
265
|
+
// If script is run directly
|
|
266
|
+
if (require.main === module) {
|
|
267
|
+
const args = process.argv.slice(2);
|
|
268
|
+
if (args.length < 3) {
|
|
269
|
+
console.log(
|
|
270
|
+
"Usage: node extract-svg.js <style> <weight> <size> [outputDir] [createIndex]",
|
|
271
|
+
);
|
|
272
|
+
console.log(
|
|
273
|
+
"Example: node extract-svg.js rounded wght600 24px ./icons true",
|
|
274
|
+
);
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const [
|
|
279
|
+
style,
|
|
280
|
+
weight,
|
|
281
|
+
size,
|
|
282
|
+
outputDir = "./extracted-icons",
|
|
283
|
+
createIndexArg = "true",
|
|
284
|
+
] = args;
|
|
285
|
+
const createIndex = createIndexArg.toLowerCase() !== "false";
|
|
286
|
+
console.log({ args, style, weight, size, outputDir, createIndex });
|
|
287
|
+
extractSvgFiles(style, weight, size, outputDir, createIndex);
|
|
288
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function rgbIsDark(rgb, tol) {
|
|
2
|
+
const tolerance = typeof tol !== "undefined" && !isNaN(tol) ? tol : 150;
|
|
3
|
+
|
|
4
|
+
const o = Math.round(
|
|
5
|
+
(parseInt(rgb.r, 10) * 299 +
|
|
6
|
+
parseInt(rgb.g, 10) * 587 +
|
|
7
|
+
parseInt(rgb.b, 10) * 114) /
|
|
8
|
+
1000,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
return o <= tolerance;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// rbg -> hex and hex -> rgb functions from https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
|
|
15
|
+
function hexToRgb(hex) {
|
|
16
|
+
const val = cleanHex(hex);
|
|
17
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(val);
|
|
18
|
+
return result
|
|
19
|
+
? {
|
|
20
|
+
r: parseInt(result[1], 16),
|
|
21
|
+
g: parseInt(result[2], 16),
|
|
22
|
+
b: parseInt(result[3], 16),
|
|
23
|
+
}
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function cleanHex(hex) {
|
|
28
|
+
let val = hex || "#";
|
|
29
|
+
if (val[0] !== "#") val = `#${val}`;
|
|
30
|
+
if (val.length === 4) {
|
|
31
|
+
// Convert 3-digit hex to 6-digit
|
|
32
|
+
const res = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i.exec(val);
|
|
33
|
+
val = `#${res[1]}${res[1]}${res[2]}${res[2]}${res[3]}${res[3]}`;
|
|
34
|
+
}
|
|
35
|
+
return val;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function hexIsDark(hex, tolerance) {
|
|
39
|
+
const rgb = hexToRgb(hex);
|
|
40
|
+
if (!rgb) return null;
|
|
41
|
+
return rgbIsDark(rgb, tolerance);
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import icons from "../icons";
|
|
3
|
+
import {
|
|
4
|
+
CELL_VALIGN_BOTTOM,
|
|
5
|
+
CELL_VALIGN_MIDDLE,
|
|
6
|
+
CELL_VALIGN_MIXED,
|
|
7
|
+
CELL_VALIGN_TOP,
|
|
8
|
+
getCellAlignment,
|
|
9
|
+
} from "../components/tiptap/Table";
|
|
10
|
+
|
|
11
|
+
const iconMap = {
|
|
12
|
+
[CELL_VALIGN_TOP]: icons.VerticalAlignTop,
|
|
13
|
+
[CELL_VALIGN_MIDDLE]: icons.VerticalAlignCenter,
|
|
14
|
+
[CELL_VALIGN_BOTTOM]: icons.VerticalAlignBottom,
|
|
15
|
+
[CELL_VALIGN_MIXED]: icons.FormatLineSpacing,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function generateVerticalAlignmentIcon(editor) {
|
|
19
|
+
const alignment = getCellAlignment(editor);
|
|
20
|
+
const Icon = iconMap[alignment];
|
|
21
|
+
return Icon ? <Icon /> : null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Document from "@tiptap/extension-document";
|
|
2
|
+
import Heading from "@tiptap/extension-heading";
|
|
3
|
+
|
|
4
|
+
const generateSingleTypeDocument = (type) =>
|
|
5
|
+
Document.extend({
|
|
6
|
+
content: type,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const tagMap = {
|
|
10
|
+
p: {
|
|
11
|
+
document: generateSingleTypeDocument("paragraph"),
|
|
12
|
+
},
|
|
13
|
+
h1: {
|
|
14
|
+
document: generateSingleTypeDocument("heading"),
|
|
15
|
+
heading: Heading.configure({ levels: [1] }),
|
|
16
|
+
},
|
|
17
|
+
h2: {
|
|
18
|
+
document: generateSingleTypeDocument("heading"),
|
|
19
|
+
heading: Heading.configure({ levels: [2] }),
|
|
20
|
+
},
|
|
21
|
+
h3: {
|
|
22
|
+
document: generateSingleTypeDocument("heading"),
|
|
23
|
+
heading: Heading.configure({ levels: [3] }),
|
|
24
|
+
},
|
|
25
|
+
h4: {
|
|
26
|
+
document: generateSingleTypeDocument("heading"),
|
|
27
|
+
heading: Heading.configure({ levels: [4] }),
|
|
28
|
+
},
|
|
29
|
+
h5: {
|
|
30
|
+
document: generateSingleTypeDocument("heading"),
|
|
31
|
+
heading: Heading.configure({ levels: [5] }),
|
|
32
|
+
},
|
|
33
|
+
h6: {
|
|
34
|
+
document: generateSingleTypeDocument("heading"),
|
|
35
|
+
heading: Heading.configure({ levels: [6] }),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function generateExtensionsFromTag(tag) {
|
|
40
|
+
if (!tag || tag === "div") return {};
|
|
41
|
+
if (!tagMap[tag]) {
|
|
42
|
+
// esling-disable-next-line no-console
|
|
43
|
+
console.error(
|
|
44
|
+
`tiptap: generateExtensionsFromTag() unsupported tag: ${tag}`,
|
|
45
|
+
);
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
return tagMap[tag];
|
|
49
|
+
}
|