@portone/docx-editor 0.1.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 +7 -0
- package/CONTRIBUTING.md +63 -0
- package/LICENSE +203 -0
- package/README.md +48 -0
- package/assets/editor.png +0 -0
- package/dist/DocxEditor.d.ts +123 -0
- package/dist/DocxEditor.js +348 -0
- package/dist/core.d.ts +36 -0
- package/dist/core.js +38 -0
- package/dist/docx/comments/constants.d.ts +8 -0
- package/dist/docx/comments/constants.js +20 -0
- package/dist/docx/comments/model.d.ts +37 -0
- package/dist/docx/comments/model.js +104 -0
- package/dist/docx/comments/reading.d.ts +36 -0
- package/dist/docx/comments/reading.js +149 -0
- package/dist/docx/comments/writing.d.ts +11 -0
- package/dist/docx/comments/writing.js +327 -0
- package/dist/docx/comments.d.ts +3 -0
- package/dist/docx/comments.js +4 -0
- package/dist/docx/container.d.ts +12 -0
- package/dist/docx/container.js +130 -0
- package/dist/docx/documentSettings.d.ts +4 -0
- package/dist/docx/documentSettings.js +14 -0
- package/dist/docx/exportDocx.d.ts +15 -0
- package/dist/docx/exportDocx.js +163 -0
- package/dist/docx/exportRefs.d.ts +16 -0
- package/dist/docx/exportRefs.js +10 -0
- package/dist/docx/formatting/direct.d.ts +30 -0
- package/dist/docx/formatting/direct.js +201 -0
- package/dist/docx/formatting/effectiveParagraph.d.ts +15 -0
- package/dist/docx/formatting/effectiveParagraph.js +81 -0
- package/dist/docx/formatting/styles.d.ts +67 -0
- package/dist/docx/formatting/styles.js +165 -0
- package/dist/docx/formatting/tabStops.d.ts +8 -0
- package/dist/docx/formatting/tabStops.js +65 -0
- package/dist/docx/formatting.d.ts +4 -0
- package/dist/docx/formatting.js +4 -0
- package/dist/docx/headersFooters.d.ts +36 -0
- package/dist/docx/headersFooters.js +218 -0
- package/dist/docx/hyperlink.d.ts +75 -0
- package/dist/docx/hyperlink.js +71 -0
- package/dist/docx/importDocx.d.ts +21 -0
- package/dist/docx/importDocx.js +263 -0
- package/dist/docx/importParagraph.d.ts +32 -0
- package/dist/docx/importParagraph.js +308 -0
- package/dist/docx/importTable.d.ts +9 -0
- package/dist/docx/importTable.js +275 -0
- package/dist/docx/media.d.ts +60 -0
- package/dist/docx/media.js +213 -0
- package/dist/docx/notes.d.ts +22 -0
- package/dist/docx/notes.js +71 -0
- package/dist/docx/pageGeometry.d.ts +75 -0
- package/dist/docx/pageGeometry.js +88 -0
- package/dist/docx/paraProps.d.ts +74 -0
- package/dist/docx/paraProps.js +167 -0
- package/dist/docx/propsXml.d.ts +49 -0
- package/dist/docx/propsXml.js +302 -0
- package/dist/docx/relationships.d.ts +42 -0
- package/dist/docx/relationships.js +94 -0
- package/dist/docx/runProps.d.ts +51 -0
- package/dist/docx/runProps.js +207 -0
- package/dist/docx/scan.d.ts +20 -0
- package/dist/docx/scan.js +110 -0
- package/dist/docx/sdt.d.ts +56 -0
- package/dist/docx/sdt.js +104 -0
- package/dist/docx/sdtProps.d.ts +18 -0
- package/dist/docx/sdtProps.js +11 -0
- package/dist/docx/serializeBlock.d.ts +4 -0
- package/dist/docx/serializeBlock.js +30 -0
- package/dist/docx/serializeParagraph.d.ts +15 -0
- package/dist/docx/serializeParagraph.js +208 -0
- package/dist/docx/serializeTable.d.ts +12 -0
- package/dist/docx/serializeTable.js +134 -0
- package/dist/docx/session.d.ts +81 -0
- package/dist/docx/session.js +79 -0
- package/dist/docx/tableFormatting/editing.d.ts +64 -0
- package/dist/docx/tableFormatting/editing.js +318 -0
- package/dist/docx/tableFormatting/reading.d.ts +96 -0
- package/dist/docx/tableFormatting/reading.js +221 -0
- package/dist/docx/tableFormatting.d.ts +2 -0
- package/dist/docx/tableFormatting.js +3 -0
- package/dist/docx/tableTemplate.d.ts +22 -0
- package/dist/docx/tableTemplate.js +111 -0
- package/dist/docx/theme.d.ts +40 -0
- package/dist/docx/theme.js +61 -0
- package/dist/docx/uniqueControls.d.ts +14 -0
- package/dist/docx/uniqueControls.js +62 -0
- package/dist/download.d.ts +57 -0
- package/dist/download.js +44 -0
- package/dist/editor/clipboard/images.d.ts +14 -0
- package/dist/editor/clipboard/images.js +158 -0
- package/dist/editor/clipboard/inlineFormatting.d.ts +21 -0
- package/dist/editor/clipboard/inlineFormatting.js +232 -0
- package/dist/editor/commands/breakCommands.d.ts +8 -0
- package/dist/editor/commands/breakCommands.js +19 -0
- package/dist/editor/commands/canRunCommand.d.ts +6 -0
- package/dist/editor/commands/canRunCommand.js +10 -0
- package/dist/editor/commands/commentCommands.d.ts +3 -0
- package/dist/editor/commands/commentCommands.js +4 -0
- package/dist/editor/commands/comments/editing.d.ts +21 -0
- package/dist/editor/commands/comments/editing.js +305 -0
- package/dist/editor/commands/comments/model.d.ts +31 -0
- package/dist/editor/commands/comments/model.js +0 -0
- package/dist/editor/commands/comments/reading.d.ts +8 -0
- package/dist/editor/commands/comments/reading.js +58 -0
- package/dist/editor/commands/formatting/editing.d.ts +32 -0
- package/dist/editor/commands/formatting/editing.js +138 -0
- package/dist/editor/commands/formatting/reading.d.ts +57 -0
- package/dist/editor/commands/formatting/reading.js +82 -0
- package/dist/editor/commands/formatting/shared.d.ts +32 -0
- package/dist/editor/commands/formatting/shared.js +53 -0
- package/dist/editor/commands/formattingCommands.d.ts +2 -0
- package/dist/editor/commands/formattingCommands.js +3 -0
- package/dist/editor/commands/historyCommands.d.ts +11 -0
- package/dist/editor/commands/historyCommands.js +16 -0
- package/dist/editor/commands/indentCommands.d.ts +15 -0
- package/dist/editor/commands/indentCommands.js +44 -0
- package/dist/editor/commands/index.d.ts +82 -0
- package/dist/editor/commands/index.js +171 -0
- package/dist/editor/commands/linkCommands.d.ts +56 -0
- package/dist/editor/commands/linkCommands.js +146 -0
- package/dist/editor/commands/listCommands.d.ts +58 -0
- package/dist/editor/commands/listCommands.js +140 -0
- package/dist/editor/commands/lockCommands.d.ts +47 -0
- package/dist/editor/commands/lockCommands.js +198 -0
- package/dist/editor/commands/noteQueries.d.ts +12 -0
- package/dist/editor/commands/noteQueries.js +29 -0
- package/dist/editor/commands/paragraphCommands.d.ts +59 -0
- package/dist/editor/commands/paragraphCommands.js +113 -0
- package/dist/editor/commands/spacingCommands.d.ts +23 -0
- package/dist/editor/commands/spacingCommands.js +48 -0
- package/dist/editor/commands/tabCommands.d.ts +5 -0
- package/dist/editor/commands/tabCommands.js +65 -0
- package/dist/editor/createEditor.d.ts +59 -0
- package/dist/editor/createEditor.js +160 -0
- package/dist/editor/documentStyles.d.ts +60 -0
- package/dist/editor/documentStyles.js +80 -0
- package/dist/editor/externalClipboard.d.ts +11 -0
- package/dist/editor/externalClipboard.js +323 -0
- package/dist/editor/imageFiles.d.ts +74 -0
- package/dist/editor/imageFiles.js +173 -0
- package/dist/editor/insertImage.d.ts +31 -0
- package/dist/editor/insertImage.js +35 -0
- package/dist/editor/insertTable.d.ts +18 -0
- package/dist/editor/insertTable.js +44 -0
- package/dist/editor/paragraphEdits.d.ts +42 -0
- package/dist/editor/paragraphEdits.js +59 -0
- package/dist/editor/plainText.d.ts +3 -0
- package/dist/editor/plainText.js +50 -0
- package/dist/editor/plugins/bookmarkProtection.d.ts +3 -0
- package/dist/editor/plugins/bookmarkProtection.js +28 -0
- package/dist/editor/plugins/columnResize.d.ts +27 -0
- package/dist/editor/plugins/columnResize.js +192 -0
- package/dist/editor/plugins/commentDecorations.d.ts +3 -0
- package/dist/editor/plugins/commentDecorations.js +23 -0
- package/dist/editor/plugins/commentReservations.d.ts +5 -0
- package/dist/editor/plugins/commentReservations.js +26 -0
- package/dist/editor/plugins/dropCaret.d.ts +10 -0
- package/dist/editor/plugins/dropCaret.js +11 -0
- package/dist/editor/plugins/imagePaste.d.ts +8 -0
- package/dist/editor/plugins/imagePaste.js +265 -0
- package/dist/editor/plugins/keymap.d.ts +5 -0
- package/dist/editor/plugins/keymap.js +94 -0
- package/dist/editor/plugins/linkPanel.d.ts +23 -0
- package/dist/editor/plugins/linkPanel.js +39 -0
- package/dist/editor/plugins/listInputRules.d.ts +14 -0
- package/dist/editor/plugins/listInputRules.js +36 -0
- package/dist/editor/plugins/lockedContent.d.ts +6 -0
- package/dist/editor/plugins/lockedContent.js +41 -0
- package/dist/editor/plugins/noteProtection.d.ts +3 -0
- package/dist/editor/plugins/noteProtection.js +25 -0
- package/dist/editor/plugins/numberingDecorations.d.ts +42 -0
- package/dist/editor/plugins/numberingDecorations.js +110 -0
- package/dist/editor/plugins/rowResize.d.ts +15 -0
- package/dist/editor/plugins/rowResize.js +196 -0
- package/dist/editor/plugins/styledParagraphs.d.ts +15 -0
- package/dist/editor/plugins/styledParagraphs.js +65 -0
- package/dist/editor/plugins/tabCaret.d.ts +3 -0
- package/dist/editor/plugins/tabCaret.js +126 -0
- package/dist/editor/plugins/tabDecorations.d.ts +11 -0
- package/dist/editor/plugins/tabDecorations.js +87 -0
- package/dist/editor/plugins/tabLayout.d.ts +16 -0
- package/dist/editor/plugins/tabLayout.js +328 -0
- package/dist/editor/plugins/tabPointer.d.ts +7 -0
- package/dist/editor/plugins/tabPointer.js +95 -0
- package/dist/editor/plugins/tableContextMenu.d.ts +21 -0
- package/dist/editor/plugins/tableContextMenu.js +88 -0
- package/dist/editor/plugins/textContextMenu.d.ts +15 -0
- package/dist/editor/plugins/textContextMenu.js +90 -0
- package/dist/editor/views/imageResize.d.ts +53 -0
- package/dist/editor/views/imageResize.js +167 -0
- package/dist/editor/views/runMarkView.d.ts +15 -0
- package/dist/editor/views/runMarkView.js +9 -0
- package/dist/editor/views/tableView.d.ts +24 -0
- package/dist/editor/views/tableView.js +32 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +38 -0
- package/dist/model/format.d.ts +240 -0
- package/dist/model/format.js +305 -0
- package/dist/model/tabStops.d.ts +17 -0
- package/dist/model/tabStops.js +22 -0
- package/dist/numbering/listTemplate.d.ts +29 -0
- package/dist/numbering/listTemplate.js +83 -0
- package/dist/numbering/markers.d.ts +24 -0
- package/dist/numbering/markers.js +93 -0
- package/dist/numbering/parseNumbering.d.ts +65 -0
- package/dist/numbering/parseNumbering.js +116 -0
- package/dist/numbering/writeNumbering.d.ts +13 -0
- package/dist/numbering/writeNumbering.js +49 -0
- package/dist/ooxml/errors.d.ts +39 -0
- package/dist/ooxml/errors.js +21 -0
- package/dist/ooxml/image.d.ts +88 -0
- package/dist/ooxml/image.js +106 -0
- package/dist/ooxml/tabStops.d.ts +3 -0
- package/dist/ooxml/tabStops.js +51 -0
- package/dist/ooxml/units.d.ts +37 -0
- package/dist/ooxml/units.js +116 -0
- package/dist/ooxml/xml.d.ts +36 -0
- package/dist/ooxml/xml.js +89 -0
- package/dist/page/PageGuides.d.ts +16 -0
- package/dist/page/PageGuides.js +114 -0
- package/dist/page/measureBlocks.d.ts +25 -0
- package/dist/page/measureBlocks.js +80 -0
- package/dist/page/pageDecorations.d.ts +36 -0
- package/dist/page/pageDecorations.js +211 -0
- package/dist/page/pageLayout.d.ts +176 -0
- package/dist/page/pageLayout.js +157 -0
- package/dist/page/tableMeasurements.d.ts +10 -0
- package/dist/page/tableMeasurements.js +115 -0
- package/dist/page/usePageLayout.d.ts +57 -0
- package/dist/page/usePageLayout.js +141 -0
- package/dist/schema/docxSchema.d.ts +9 -0
- package/dist/schema/docxSchema.js +863 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +9 -0
- package/dist/schema/locks.d.ts +112 -0
- package/dist/schema/locks.js +211 -0
- package/dist/schema/rendering.d.ts +6 -0
- package/dist/schema/rendering.js +46 -0
- package/dist/styles/classNames.d.ts +214 -0
- package/dist/styles/classNames.js +208 -0
- package/dist/styles/colors.d.ts +11 -0
- package/dist/styles/colors.js +14 -0
- package/dist/styles/fontSizes.d.ts +6 -0
- package/dist/styles/fontSizes.js +20 -0
- package/dist/styles/fontStack.d.ts +55 -0
- package/dist/styles/fontStack.js +262 -0
- package/dist/styles/fonts.d.ts +6 -0
- package/dist/styles/fonts.js +11 -0
- package/dist/styles/inlineStyle.d.ts +67 -0
- package/dist/styles/inlineStyle.js +212 -0
- package/dist/styles/lineSpacings.d.ts +11 -0
- package/dist/styles/lineSpacings.js +10 -0
- package/dist/styles.css +1650 -0
- package/dist/table/cellBorders.d.ts +12 -0
- package/dist/table/cellBorders.js +9 -0
- package/dist/table/cellFormatting.d.ts +57 -0
- package/dist/table/cellFormatting.js +173 -0
- package/dist/table/columns.d.ts +25 -0
- package/dist/table/columns.js +155 -0
- package/dist/table/commands.d.ts +19 -0
- package/dist/table/commands.js +63 -0
- package/dist/table/format.d.ts +35 -0
- package/dist/table/format.js +26 -0
- package/dist/table/gridBorders.d.ts +42 -0
- package/dist/table/gridBorders.js +192 -0
- package/dist/table/index.d.ts +16 -0
- package/dist/table/index.js +52 -0
- package/dist/table/merge.d.ts +36 -0
- package/dist/table/merge.js +125 -0
- package/dist/table/resize.d.ts +55 -0
- package/dist/table/resize.js +66 -0
- package/dist/table/rowResize.d.ts +14 -0
- package/dist/table/rowResize.js +44 -0
- package/dist/table/rows.d.ts +32 -0
- package/dist/table/rows.js +89 -0
- package/dist/table/widths.d.ts +69 -0
- package/dist/table/widths.js +97 -0
- package/dist/ui/AlignMenu.d.ts +15 -0
- package/dist/ui/AlignMenu.js +64 -0
- package/dist/ui/CellStyleGroup.d.ts +15 -0
- package/dist/ui/CellStyleGroup.js +232 -0
- package/dist/ui/ColorPicker.d.ts +13 -0
- package/dist/ui/ColorPicker.js +165 -0
- package/dist/ui/CommentsPanel.d.ts +15 -0
- package/dist/ui/CommentsPanel.js +348 -0
- package/dist/ui/FontFamilySelect.d.ts +14 -0
- package/dist/ui/FontFamilySelect.js +59 -0
- package/dist/ui/FontSizeSelect.d.ts +11 -0
- package/dist/ui/FontSizeSelect.js +49 -0
- package/dist/ui/InsertImageButton.d.ts +9 -0
- package/dist/ui/InsertImageButton.js +47 -0
- package/dist/ui/LinkCard.d.ts +12 -0
- package/dist/ui/LinkCard.js +127 -0
- package/dist/ui/LinkPanel.d.ts +9 -0
- package/dist/ui/LinkPanel.js +121 -0
- package/dist/ui/MenuChoice.d.ts +11 -0
- package/dist/ui/MenuChoice.js +32 -0
- package/dist/ui/NotesPanel.d.ts +6 -0
- package/dist/ui/NotesPanel.js +33 -0
- package/dist/ui/ParagraphStyleSelect.d.ts +11 -0
- package/dist/ui/ParagraphStyleSelect.js +62 -0
- package/dist/ui/Popover.d.ts +22 -0
- package/dist/ui/Popover.js +74 -0
- package/dist/ui/SpacingMenu.d.ts +12 -0
- package/dist/ui/SpacingMenu.js +54 -0
- package/dist/ui/TableMenu.d.ts +12 -0
- package/dist/ui/TableMenu.js +112 -0
- package/dist/ui/TableSizePicker.d.ts +9 -0
- package/dist/ui/TableSizePicker.js +53 -0
- package/dist/ui/TextMenu.d.ts +15 -0
- package/dist/ui/TextMenu.js +194 -0
- package/dist/ui/Toolbar.d.ts +19 -0
- package/dist/ui/Toolbar.js +448 -0
- package/dist/ui/ToolbarButton.d.ts +23 -0
- package/dist/ui/ToolbarButton.js +56 -0
- package/dist/ui/Tooltip.d.ts +19 -0
- package/dist/ui/Tooltip.js +47 -0
- package/dist/ui/ZoomSelect.d.ts +7 -0
- package/dist/ui/ZoomSelect.js +44 -0
- package/dist/ui/comments/CommentComposer.d.ts +17 -0
- package/dist/ui/comments/CommentComposer.js +59 -0
- package/dist/ui/comments/useCommentRailLayout.d.ts +18 -0
- package/dist/ui/comments/useCommentRailLayout.js +183 -0
- package/dist/ui/keyboardWalk.d.ts +22 -0
- package/dist/ui/keyboardWalk.js +70 -0
- package/dist/ui/openAddress.d.ts +11 -0
- package/dist/ui/openAddress.js +16 -0
- package/dist/ui/panelPlacement.d.ts +51 -0
- package/dist/ui/panelPlacement.js +71 -0
- package/dist/ui/presets.d.ts +11 -0
- package/dist/ui/presets.js +0 -0
- package/dist/ui/rovingFocus.d.ts +20 -0
- package/dist/ui/rovingFocus.js +61 -0
- package/dist/ui/runCommand.d.ts +5 -0
- package/dist/ui/runCommand.js +13 -0
- package/dist/ui/useDismiss.d.ts +6 -0
- package/dist/ui/useDismiss.js +31 -0
- package/dist/ui/useFitWidthZoom.d.ts +2 -0
- package/dist/ui/useFitWidthZoom.js +26 -0
- package/dist/ui/useGridKeyboard.d.ts +12 -0
- package/dist/ui/useGridKeyboard.js +90 -0
- package/dist/ui/useMenuKeyboard.d.ts +12 -0
- package/dist/ui/useMenuKeyboard.js +56 -0
- package/dist/ui/zoom.d.ts +4 -0
- package/dist/ui/zoom.js +21 -0
- package/package.json +120 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// src/ui/ColorPicker.tsx
|
|
2
|
+
import { Check } from "lucide-react";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
5
|
+
import { DEFAULT_COLORS } from "../styles/colors.js";
|
|
6
|
+
import { useGridKeyboard } from "./useGridKeyboard.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
var FALLBACK_CUSTOM_COLOR = "#000000";
|
|
9
|
+
function normalizeHexColor(value) {
|
|
10
|
+
const digits = value.trim().replace(/^#/, "");
|
|
11
|
+
if (/^[0-9a-f]{3}$/i.test(digits)) {
|
|
12
|
+
return `#${[...digits].map((digit) => `${digit}${digit}`).join("")}`.toUpperCase();
|
|
13
|
+
}
|
|
14
|
+
return /^[0-9a-f]{6}$/i.test(digits) ? `#${digits.toUpperCase()}` : null;
|
|
15
|
+
}
|
|
16
|
+
function sameColor(a, b) {
|
|
17
|
+
return a !== null && a.toLowerCase() === b.toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
function ColorPicker({
|
|
20
|
+
current,
|
|
21
|
+
colors = DEFAULT_COLORS,
|
|
22
|
+
clearLabel = "None",
|
|
23
|
+
close,
|
|
24
|
+
takeFocus,
|
|
25
|
+
onPick
|
|
26
|
+
}) {
|
|
27
|
+
const grid = useRef(null);
|
|
28
|
+
const nativePicker = useRef(null);
|
|
29
|
+
const applyButton = useRef(null);
|
|
30
|
+
const initialCustomColor = normalizeHexColor(current ?? "");
|
|
31
|
+
const [customColor, setCustomColor] = useState(
|
|
32
|
+
initialCustomColor ?? FALLBACK_CUSTOM_COLOR
|
|
33
|
+
);
|
|
34
|
+
const normalizedCustomColor = normalizeHexColor(customColor);
|
|
35
|
+
const keys = useGridKeyboard({
|
|
36
|
+
grid,
|
|
37
|
+
onClose: close,
|
|
38
|
+
start: (cells) => cells.find((cell) => cell.getAttribute("aria-selected") === "true"),
|
|
39
|
+
takeFocus
|
|
40
|
+
});
|
|
41
|
+
const selectedCell = () => grid.current?.querySelector('[tabindex="0"]');
|
|
42
|
+
const onPanelKeyDownCapture = (event) => {
|
|
43
|
+
if (event.key !== "Tab" || event.shiftKey || !(event.target instanceof Element) || !event.target.closest('[role="grid"]')) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
nativePicker.current?.focus();
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
};
|
|
50
|
+
const onCustomKeyDown = (event) => {
|
|
51
|
+
if (event.key !== "Tab") return;
|
|
52
|
+
if (event.shiftKey && event.target === nativePicker.current) {
|
|
53
|
+
selectedCell()?.focus({ preventScroll: true });
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!event.shiftKey && event.target === applyButton.current) {
|
|
58
|
+
close();
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsxs(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
className: editorClassNames.colorPicker,
|
|
66
|
+
onKeyDownCapture: onPanelKeyDownCapture,
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ jsxs(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
ref: grid,
|
|
72
|
+
className: editorClassNames.colorGrid,
|
|
73
|
+
role: "grid",
|
|
74
|
+
"aria-label": "Colors",
|
|
75
|
+
...keys,
|
|
76
|
+
children: [
|
|
77
|
+
/* @__PURE__ */ jsx("div", { className: editorClassNames.colorClearRow, role: "row", children: /* @__PURE__ */ jsx(
|
|
78
|
+
"button",
|
|
79
|
+
{
|
|
80
|
+
type: "button",
|
|
81
|
+
role: "gridcell",
|
|
82
|
+
className: editorClassNames.menuItem,
|
|
83
|
+
"aria-selected": current === null,
|
|
84
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
85
|
+
onClick: () => onPick(null),
|
|
86
|
+
children: clearLabel
|
|
87
|
+
}
|
|
88
|
+
) }),
|
|
89
|
+
colors.map((row) => /* @__PURE__ */ jsx("div", { className: editorClassNames.colorRow, role: "row", children: row.map((hex) => /* @__PURE__ */ jsx(
|
|
90
|
+
"button",
|
|
91
|
+
{
|
|
92
|
+
type: "button",
|
|
93
|
+
role: "gridcell",
|
|
94
|
+
className: editorClassNames.swatch,
|
|
95
|
+
"aria-label": hex,
|
|
96
|
+
"aria-selected": sameColor(current, hex),
|
|
97
|
+
style: { background: hex },
|
|
98
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
99
|
+
onClick: () => onPick(hex)
|
|
100
|
+
},
|
|
101
|
+
hex
|
|
102
|
+
)) }, row[0]))
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ jsxs(
|
|
107
|
+
"form",
|
|
108
|
+
{
|
|
109
|
+
className: editorClassNames.colorCustom,
|
|
110
|
+
onKeyDown: onCustomKeyDown,
|
|
111
|
+
onSubmit: (event) => {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
if (normalizedCustomColor) onPick(normalizedCustomColor);
|
|
114
|
+
},
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx(
|
|
117
|
+
"input",
|
|
118
|
+
{
|
|
119
|
+
ref: nativePicker,
|
|
120
|
+
type: "color",
|
|
121
|
+
className: editorClassNames.colorNativeInput,
|
|
122
|
+
"aria-label": "Choose custom color",
|
|
123
|
+
value: normalizedCustomColor ?? initialCustomColor ?? FALLBACK_CUSTOM_COLOR,
|
|
124
|
+
onChange: (event) => {
|
|
125
|
+
const color = normalizeHexColor(event.target.value);
|
|
126
|
+
if (color) setCustomColor(color);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
"input",
|
|
132
|
+
{
|
|
133
|
+
type: "text",
|
|
134
|
+
className: editorClassNames.colorHexInput,
|
|
135
|
+
"aria-label": "Custom color",
|
|
136
|
+
"aria-invalid": customColor.length > 0 && !normalizedCustomColor,
|
|
137
|
+
autoComplete: "off",
|
|
138
|
+
maxLength: 7,
|
|
139
|
+
placeholder: "#RRGGBB",
|
|
140
|
+
spellCheck: false,
|
|
141
|
+
value: customColor,
|
|
142
|
+
onChange: (event) => setCustomColor(event.target.value)
|
|
143
|
+
}
|
|
144
|
+
),
|
|
145
|
+
/* @__PURE__ */ jsx(
|
|
146
|
+
"button",
|
|
147
|
+
{
|
|
148
|
+
ref: applyButton,
|
|
149
|
+
type: "submit",
|
|
150
|
+
className: editorClassNames.colorApply,
|
|
151
|
+
"aria-label": "Apply color",
|
|
152
|
+
disabled: !normalizedCustomColor,
|
|
153
|
+
children: /* @__PURE__ */ jsx(Check, { size: 16, "aria-hidden": "true" })
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
ColorPicker
|
|
165
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EditorState } from "prosemirror-state";
|
|
2
|
+
import type { EditorView } from "prosemirror-view";
|
|
3
|
+
import { type ReactElement } from "react";
|
|
4
|
+
import { type CommentAuthor } from "../editor/commands/commentCommands";
|
|
5
|
+
export interface CommentsPanelProps {
|
|
6
|
+
view: EditorView;
|
|
7
|
+
state: EditorState;
|
|
8
|
+
readOnly: boolean;
|
|
9
|
+
composerOpen: boolean;
|
|
10
|
+
author: CommentAuthor;
|
|
11
|
+
closeComposer: () => void;
|
|
12
|
+
scrollContainer: HTMLElement | null;
|
|
13
|
+
allCommentsOpen: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function CommentsPanel({ view, state, readOnly, composerOpen, author, closeComposer, scrollContainer, allCommentsOpen, }: CommentsPanelProps): ReactElement;
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// src/ui/CommentsPanel.tsx
|
|
2
|
+
import { Check, Pencil, RotateCcw, Trash2 } from "lucide-react";
|
|
3
|
+
import { useMemo, useRef, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
addComment,
|
|
6
|
+
addCommentReply,
|
|
7
|
+
documentComments,
|
|
8
|
+
removeComment,
|
|
9
|
+
removeCommentReply,
|
|
10
|
+
selectComment,
|
|
11
|
+
setCommentResolved,
|
|
12
|
+
updateComment,
|
|
13
|
+
updateCommentReply
|
|
14
|
+
} from "../editor/commands/commentCommands.js";
|
|
15
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
16
|
+
import { CommentComposer, FocusedTextarea } from "./comments/CommentComposer.js";
|
|
17
|
+
import {
|
|
18
|
+
COMPOSER_POSITION,
|
|
19
|
+
useCommentRailLayout
|
|
20
|
+
} from "./comments/useCommentRailLayout.js";
|
|
21
|
+
import { tooltipAttribute } from "./Tooltip.js";
|
|
22
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
23
|
+
function shownDate(value) {
|
|
24
|
+
if (value === null) return null;
|
|
25
|
+
const date = new Date(value);
|
|
26
|
+
if (Number.isNaN(date.valueOf())) return value;
|
|
27
|
+
return `${date.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
28
|
+
}
|
|
29
|
+
function run(view, command) {
|
|
30
|
+
const applied = command(
|
|
31
|
+
view.state,
|
|
32
|
+
(transaction) => view.dispatch(transaction),
|
|
33
|
+
view
|
|
34
|
+
);
|
|
35
|
+
if (applied) view.focus();
|
|
36
|
+
return applied;
|
|
37
|
+
}
|
|
38
|
+
function sameTarget(left, right) {
|
|
39
|
+
return left?.commentId === right.commentId && left.replyId === right.replyId;
|
|
40
|
+
}
|
|
41
|
+
function CommentsPanel({
|
|
42
|
+
view,
|
|
43
|
+
state,
|
|
44
|
+
readOnly,
|
|
45
|
+
composerOpen,
|
|
46
|
+
author,
|
|
47
|
+
closeComposer,
|
|
48
|
+
scrollContainer,
|
|
49
|
+
allCommentsOpen
|
|
50
|
+
}) {
|
|
51
|
+
const comments = useMemo(() => documentComments(state), [state.doc]);
|
|
52
|
+
const panel = useRef(null);
|
|
53
|
+
const [editing, setEditing] = useState(null);
|
|
54
|
+
const [draft, setDraft] = useState("");
|
|
55
|
+
const [replying, setReplying] = useState(null);
|
|
56
|
+
const composerSelectionPos = composerOpen ? state.selection.from : -1;
|
|
57
|
+
const visible = useMemo(
|
|
58
|
+
() => allCommentsOpen ? [...comments].sort((left, right) => {
|
|
59
|
+
const leftTime = Date.parse(left.date ?? "");
|
|
60
|
+
const rightTime = Date.parse(right.date ?? "");
|
|
61
|
+
if (Number.isNaN(leftTime) && Number.isNaN(rightTime)) {
|
|
62
|
+
return right.referencePos - left.referencePos;
|
|
63
|
+
}
|
|
64
|
+
if (Number.isNaN(leftTime)) return 1;
|
|
65
|
+
if (Number.isNaN(rightTime)) return -1;
|
|
66
|
+
return rightTime - leftTime;
|
|
67
|
+
}) : comments.filter((comment) => !comment.resolved),
|
|
68
|
+
[allCommentsOpen, comments]
|
|
69
|
+
);
|
|
70
|
+
const { positions, canvasHeight } = useCommentRailLayout({
|
|
71
|
+
panel,
|
|
72
|
+
view,
|
|
73
|
+
scrollContainer,
|
|
74
|
+
visible,
|
|
75
|
+
composerOpen,
|
|
76
|
+
composerSelectionPos,
|
|
77
|
+
allCommentsOpen
|
|
78
|
+
});
|
|
79
|
+
const beginEdit = (commentId, replyId, text) => {
|
|
80
|
+
setReplying(null);
|
|
81
|
+
setEditing({ commentId, replyId });
|
|
82
|
+
setDraft(text);
|
|
83
|
+
};
|
|
84
|
+
const saveEdit = (comment, replyId) => {
|
|
85
|
+
const original = replyId === null ? comment.text : comment.replies.find((reply) => reply.id === replyId)?.text ?? "";
|
|
86
|
+
const saved = draft === original || run(
|
|
87
|
+
view,
|
|
88
|
+
replyId === null ? updateComment(comment.id, draft) : updateCommentReply(comment.id, replyId, draft)
|
|
89
|
+
);
|
|
90
|
+
if (saved) {
|
|
91
|
+
setEditing(null);
|
|
92
|
+
setDraft("");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return /* @__PURE__ */ jsxs(
|
|
96
|
+
"aside",
|
|
97
|
+
{
|
|
98
|
+
ref: panel,
|
|
99
|
+
className: editorClassNames.commentsPanel,
|
|
100
|
+
"aria-label": "Comments",
|
|
101
|
+
"data-view": allCommentsOpen ? "all" : "rail",
|
|
102
|
+
style: allCommentsOpen ? void 0 : { height: `${canvasHeight}px` },
|
|
103
|
+
children: [
|
|
104
|
+
allCommentsOpen && /* @__PURE__ */ jsx("div", { className: editorClassNames.commentsHeading, children: /* @__PURE__ */ jsx("h2", { children: "All comments" }) }),
|
|
105
|
+
/* @__PURE__ */ jsxs(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
className: editorClassNames.commentsCanvas,
|
|
109
|
+
style: { height: allCommentsOpen ? void 0 : `${canvasHeight}px` },
|
|
110
|
+
children: [
|
|
111
|
+
composerOpen && !readOnly && /* @__PURE__ */ jsx(
|
|
112
|
+
"div",
|
|
113
|
+
{
|
|
114
|
+
className: editorClassNames.commentPosition,
|
|
115
|
+
"data-comment-position": COMPOSER_POSITION,
|
|
116
|
+
style: allCommentsOpen ? void 0 : {
|
|
117
|
+
top: `${positions.get(COMPOSER_POSITION) ?? 64}px`
|
|
118
|
+
},
|
|
119
|
+
children: /* @__PURE__ */ jsx(
|
|
120
|
+
CommentComposer,
|
|
121
|
+
{
|
|
122
|
+
author,
|
|
123
|
+
label: "Comment text",
|
|
124
|
+
submitLabel: "Comment",
|
|
125
|
+
onClose: closeComposer,
|
|
126
|
+
onSubmit: (text) => run(
|
|
127
|
+
view,
|
|
128
|
+
addComment({
|
|
129
|
+
text,
|
|
130
|
+
author: author.name,
|
|
131
|
+
initials: author.initials
|
|
132
|
+
})
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
visible.map((comment) => {
|
|
139
|
+
const rootTarget = { commentId: comment.id, replyId: null };
|
|
140
|
+
const rootEditing = !readOnly && sameTarget(editing, rootTarget);
|
|
141
|
+
return /* @__PURE__ */ jsx(
|
|
142
|
+
"article",
|
|
143
|
+
{
|
|
144
|
+
className: editorClassNames.commentPosition,
|
|
145
|
+
"data-resolved": comment.resolved ? "true" : void 0,
|
|
146
|
+
"data-comment-position": comment.id,
|
|
147
|
+
style: allCommentsOpen ? void 0 : { top: `${positions.get(comment.id) ?? 64}px` },
|
|
148
|
+
children: /* @__PURE__ */ jsxs("div", { className: editorClassNames.commentCard, children: [
|
|
149
|
+
/* @__PURE__ */ jsxs("div", { className: editorClassNames.commentHeader, children: [
|
|
150
|
+
/* @__PURE__ */ jsxs(
|
|
151
|
+
"button",
|
|
152
|
+
{
|
|
153
|
+
type: "button",
|
|
154
|
+
className: editorClassNames.commentMeta,
|
|
155
|
+
onClick: () => run(view, selectComment(comment.id)),
|
|
156
|
+
disabled: comment.resolved,
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsx("span", { className: editorClassNames.commentAuthor, children: comment.author ?? "Unknown author" }),
|
|
159
|
+
shownDate(comment.date) && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: shownDate(comment.date) })
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
!readOnly && !rootEditing && /* @__PURE__ */ jsxs("div", { className: editorClassNames.commentIconActions, children: [
|
|
164
|
+
!comment.resolved && /* @__PURE__ */ jsx(
|
|
165
|
+
"button",
|
|
166
|
+
{
|
|
167
|
+
type: "button",
|
|
168
|
+
"aria-label": "Edit",
|
|
169
|
+
...tooltipAttribute("Edit"),
|
|
170
|
+
onClick: () => beginEdit(comment.id, null, comment.text),
|
|
171
|
+
children: /* @__PURE__ */ jsx(Pencil, { size: 16, "aria-hidden": "true" })
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
/* @__PURE__ */ jsx(
|
|
175
|
+
"button",
|
|
176
|
+
{
|
|
177
|
+
type: "button",
|
|
178
|
+
"aria-label": comment.resolved ? "Reopen" : "Resolve",
|
|
179
|
+
...tooltipAttribute(
|
|
180
|
+
comment.resolved ? "Reopen" : "Resolve"
|
|
181
|
+
),
|
|
182
|
+
onClick: () => {
|
|
183
|
+
setReplying(null);
|
|
184
|
+
setEditing(null);
|
|
185
|
+
run(
|
|
186
|
+
view,
|
|
187
|
+
setCommentResolved(comment.id, !comment.resolved)
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
children: comment.resolved ? /* @__PURE__ */ jsx(RotateCcw, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsx(Check, { size: 16, "aria-hidden": "true" })
|
|
191
|
+
}
|
|
192
|
+
),
|
|
193
|
+
!comment.resolved && /* @__PURE__ */ jsx(
|
|
194
|
+
"button",
|
|
195
|
+
{
|
|
196
|
+
type: "button",
|
|
197
|
+
"aria-label": "Delete",
|
|
198
|
+
...tooltipAttribute("Delete"),
|
|
199
|
+
onClick: () => run(view, removeComment(comment.id)),
|
|
200
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 16, "aria-hidden": "true" })
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
] })
|
|
204
|
+
] }),
|
|
205
|
+
rootEditing ? /* @__PURE__ */ jsx(
|
|
206
|
+
FocusedTextarea,
|
|
207
|
+
{
|
|
208
|
+
label: "Edit comment",
|
|
209
|
+
value: draft,
|
|
210
|
+
onChange: setDraft
|
|
211
|
+
}
|
|
212
|
+
) : readOnly || comment.resolved ? /* @__PURE__ */ jsx("p", { className: editorClassNames.commentBody, children: comment.text }) : /* @__PURE__ */ jsx(
|
|
213
|
+
"button",
|
|
214
|
+
{
|
|
215
|
+
type: "button",
|
|
216
|
+
className: editorClassNames.commentBody,
|
|
217
|
+
"aria-label": `Reply to comment: ${comment.text}`,
|
|
218
|
+
onClick: () => {
|
|
219
|
+
setEditing(null);
|
|
220
|
+
setReplying(comment.id);
|
|
221
|
+
},
|
|
222
|
+
children: comment.text
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
!readOnly && /* @__PURE__ */ jsx("div", { className: editorClassNames.commentActions, children: rootEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
226
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => setEditing(null), children: "Cancel" }),
|
|
227
|
+
/* @__PURE__ */ jsx(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
className: editorClassNames.commentPrimaryAction,
|
|
232
|
+
disabled: draft.trim().length === 0,
|
|
233
|
+
onClick: () => saveEdit(comment, null),
|
|
234
|
+
children: "Save"
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
] }) : null }),
|
|
238
|
+
comment.replies.map((reply) => {
|
|
239
|
+
const target = {
|
|
240
|
+
commentId: comment.id,
|
|
241
|
+
replyId: reply.id
|
|
242
|
+
};
|
|
243
|
+
const isEditing = !readOnly && sameTarget(editing, target);
|
|
244
|
+
return /* @__PURE__ */ jsxs(
|
|
245
|
+
"div",
|
|
246
|
+
{
|
|
247
|
+
className: editorClassNames.commentReply,
|
|
248
|
+
children: [
|
|
249
|
+
/* @__PURE__ */ jsxs("div", { className: editorClassNames.commentMeta, children: [
|
|
250
|
+
/* @__PURE__ */ jsx("span", { className: editorClassNames.commentAuthor, children: reply.author ?? "Unknown author" }),
|
|
251
|
+
shownDate(reply.date) && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: shownDate(reply.date) })
|
|
252
|
+
] }),
|
|
253
|
+
isEditing ? /* @__PURE__ */ jsx(
|
|
254
|
+
FocusedTextarea,
|
|
255
|
+
{
|
|
256
|
+
label: "Edit reply",
|
|
257
|
+
value: draft,
|
|
258
|
+
onChange: setDraft
|
|
259
|
+
}
|
|
260
|
+
) : /* @__PURE__ */ jsx("p", { className: editorClassNames.commentBody, children: reply.text }),
|
|
261
|
+
!readOnly && !comment.resolved && /* @__PURE__ */ jsx("div", { className: editorClassNames.commentActions, children: isEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
262
|
+
/* @__PURE__ */ jsx(
|
|
263
|
+
"button",
|
|
264
|
+
{
|
|
265
|
+
type: "button",
|
|
266
|
+
onClick: () => setEditing(null),
|
|
267
|
+
children: "Cancel"
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
/* @__PURE__ */ jsx(
|
|
271
|
+
"button",
|
|
272
|
+
{
|
|
273
|
+
type: "button",
|
|
274
|
+
className: editorClassNames.commentPrimaryAction,
|
|
275
|
+
disabled: draft.trim().length === 0,
|
|
276
|
+
onClick: () => saveEdit(comment, reply.id),
|
|
277
|
+
children: "Save"
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
] }) : /* @__PURE__ */ jsxs(
|
|
281
|
+
"div",
|
|
282
|
+
{
|
|
283
|
+
className: editorClassNames.commentIconActions,
|
|
284
|
+
children: [
|
|
285
|
+
/* @__PURE__ */ jsx(
|
|
286
|
+
"button",
|
|
287
|
+
{
|
|
288
|
+
type: "button",
|
|
289
|
+
"aria-label": "Edit reply",
|
|
290
|
+
...tooltipAttribute("Edit reply"),
|
|
291
|
+
onClick: () => beginEdit(comment.id, reply.id, reply.text),
|
|
292
|
+
children: /* @__PURE__ */ jsx(Pencil, { size: 16, "aria-hidden": "true" })
|
|
293
|
+
}
|
|
294
|
+
),
|
|
295
|
+
/* @__PURE__ */ jsx(
|
|
296
|
+
"button",
|
|
297
|
+
{
|
|
298
|
+
type: "button",
|
|
299
|
+
"aria-label": "Delete reply",
|
|
300
|
+
...tooltipAttribute("Delete reply"),
|
|
301
|
+
onClick: () => run(
|
|
302
|
+
view,
|
|
303
|
+
removeCommentReply(comment.id, reply.id)
|
|
304
|
+
),
|
|
305
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 16, "aria-hidden": "true" })
|
|
306
|
+
}
|
|
307
|
+
)
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
) })
|
|
311
|
+
]
|
|
312
|
+
},
|
|
313
|
+
reply.id
|
|
314
|
+
);
|
|
315
|
+
}),
|
|
316
|
+
replying === comment.id && !readOnly && !comment.resolved && /* @__PURE__ */ jsx(
|
|
317
|
+
CommentComposer,
|
|
318
|
+
{
|
|
319
|
+
author,
|
|
320
|
+
label: "Reply text",
|
|
321
|
+
submitLabel: "Reply",
|
|
322
|
+
onClose: () => setReplying(null),
|
|
323
|
+
onSubmit: (text) => run(
|
|
324
|
+
view,
|
|
325
|
+
addCommentReply(comment.id, {
|
|
326
|
+
text,
|
|
327
|
+
author: author.name,
|
|
328
|
+
initials: author.initials
|
|
329
|
+
})
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
] })
|
|
334
|
+
},
|
|
335
|
+
comment.id
|
|
336
|
+
);
|
|
337
|
+
}),
|
|
338
|
+
allCommentsOpen && visible.length === 0 && !composerOpen && /* @__PURE__ */ jsx("p", { className: editorClassNames.commentsEmpty, children: "This document has no comments." })
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
)
|
|
342
|
+
]
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
export {
|
|
347
|
+
CommentsPanel
|
|
348
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Shows the resolved font, leaves mixed selections blank, and clears explicit fonts via Default. */
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { type ActiveFontFamily } from "../editor/commands/formattingCommands";
|
|
4
|
+
import { type FontFallbacks } from "../styles/fontStack";
|
|
5
|
+
import type { RunCommand } from "./runCommand";
|
|
6
|
+
export interface FontFamilySelectProps {
|
|
7
|
+
current: ActiveFontFamily;
|
|
8
|
+
documentFonts: readonly string[];
|
|
9
|
+
fonts?: readonly string[];
|
|
10
|
+
fontFallbacks?: FontFallbacks;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
run: RunCommand;
|
|
13
|
+
}
|
|
14
|
+
export declare function FontFamilySelect({ current, documentFonts, fonts, fontFallbacks, disabled, run, }: FontFamilySelectProps): ReactElement;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/ui/FontFamilySelect.tsx
|
|
2
|
+
import {
|
|
3
|
+
setFontFamily
|
|
4
|
+
} from "../editor/commands/formattingCommands.js";
|
|
5
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
6
|
+
import { withFontFallback } from "../styles/fontStack.js";
|
|
7
|
+
import { DEFAULT_FONTS } from "../styles/fonts.js";
|
|
8
|
+
import { Tooltip } from "./Tooltip.js";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var LABEL = "Font";
|
|
11
|
+
var CLEAR = ";default";
|
|
12
|
+
var MIXED = "";
|
|
13
|
+
function optionNames(current, fonts, documentFonts) {
|
|
14
|
+
const names = [...fonts, ...documentFonts];
|
|
15
|
+
if (current.kind !== "mixed" && !names.includes(current.name)) {
|
|
16
|
+
names.push(current.name);
|
|
17
|
+
}
|
|
18
|
+
return Array.from(new Set(names));
|
|
19
|
+
}
|
|
20
|
+
function FontFamilySelect({
|
|
21
|
+
current,
|
|
22
|
+
documentFonts,
|
|
23
|
+
fonts = DEFAULT_FONTS,
|
|
24
|
+
fontFallbacks,
|
|
25
|
+
disabled,
|
|
26
|
+
run
|
|
27
|
+
}) {
|
|
28
|
+
const value = current.kind === "mixed" ? MIXED : current.name;
|
|
29
|
+
return /* @__PURE__ */ jsx(Tooltip, { label: LABEL, children: /* @__PURE__ */ jsxs(
|
|
30
|
+
"select",
|
|
31
|
+
{
|
|
32
|
+
className: `${editorClassNames.toolbarSelect} ${editorClassNames.fontFamilySelect}`,
|
|
33
|
+
"aria-label": LABEL,
|
|
34
|
+
value,
|
|
35
|
+
disabled,
|
|
36
|
+
onChange: (event) => {
|
|
37
|
+
const chosen = event.target.value;
|
|
38
|
+
if (chosen === MIXED) return;
|
|
39
|
+
run(setFontFamily(chosen === CLEAR ? null : chosen));
|
|
40
|
+
},
|
|
41
|
+
children: [
|
|
42
|
+
current.kind === "mixed" && /* @__PURE__ */ jsx("option", { value: MIXED }),
|
|
43
|
+
/* @__PURE__ */ jsx("option", { value: CLEAR, children: "Default" }),
|
|
44
|
+
optionNames(current, fonts, documentFonts).map((name) => /* @__PURE__ */ jsx(
|
|
45
|
+
"option",
|
|
46
|
+
{
|
|
47
|
+
value: name,
|
|
48
|
+
style: { fontFamily: withFontFallback(`"${name}"`, fontFallbacks) },
|
|
49
|
+
children: name
|
|
50
|
+
},
|
|
51
|
+
name
|
|
52
|
+
))
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
) });
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
FontFamilySelect
|
|
59
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Shows the resolved size, leaves mixed selections blank, and clears explicit sizes via Default. */
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { type ActiveFontSize } from "../editor/commands/formattingCommands";
|
|
4
|
+
import type { RunCommand } from "./runCommand";
|
|
5
|
+
export interface FontSizeSelectProps {
|
|
6
|
+
current: ActiveFontSize;
|
|
7
|
+
fontSizes?: readonly number[];
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
run: RunCommand;
|
|
10
|
+
}
|
|
11
|
+
export declare function FontSizeSelect({ current, fontSizes, disabled, run, }: FontSizeSelectProps): ReactElement;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/ui/FontSizeSelect.tsx
|
|
2
|
+
import {
|
|
3
|
+
setFontSize
|
|
4
|
+
} from "../editor/commands/formattingCommands.js";
|
|
5
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
6
|
+
import { DEFAULT_FONT_SIZES } from "../styles/fontSizes.js";
|
|
7
|
+
import { Tooltip } from "./Tooltip.js";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var LABEL = "Font size";
|
|
10
|
+
var CLEAR = "default";
|
|
11
|
+
var MIXED = "";
|
|
12
|
+
function FontSizeSelect({
|
|
13
|
+
current,
|
|
14
|
+
fontSizes = DEFAULT_FONT_SIZES,
|
|
15
|
+
disabled,
|
|
16
|
+
run
|
|
17
|
+
}) {
|
|
18
|
+
const value = current.kind === "mixed" ? MIXED : `${current.pt}`;
|
|
19
|
+
const extra = current.kind !== "mixed" && !fontSizes.includes(current.pt) ? current.pt : null;
|
|
20
|
+
return /* @__PURE__ */ jsx(Tooltip, { label: LABEL, children: /* @__PURE__ */ jsxs(
|
|
21
|
+
"select",
|
|
22
|
+
{
|
|
23
|
+
className: editorClassNames.toolbarSelect,
|
|
24
|
+
"aria-label": LABEL,
|
|
25
|
+
value,
|
|
26
|
+
disabled,
|
|
27
|
+
onChange: (event) => {
|
|
28
|
+
const chosen = event.target.value;
|
|
29
|
+
if (chosen === MIXED) return;
|
|
30
|
+
run(setFontSize(chosen === CLEAR ? null : Number(chosen)));
|
|
31
|
+
},
|
|
32
|
+
children: [
|
|
33
|
+
current.kind === "mixed" && /* @__PURE__ */ jsx("option", { value: MIXED }),
|
|
34
|
+
/* @__PURE__ */ jsx("option", { value: CLEAR, children: "Default" }),
|
|
35
|
+
extra !== null && /* @__PURE__ */ jsxs("option", { value: `${extra}`, children: [
|
|
36
|
+
extra,
|
|
37
|
+
"pt"
|
|
38
|
+
] }),
|
|
39
|
+
fontSizes.map((pt) => /* @__PURE__ */ jsxs("option", { value: `${pt}`, children: [
|
|
40
|
+
pt,
|
|
41
|
+
"pt"
|
|
42
|
+
] }, pt))
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
) });
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
FontSizeSelect
|
|
49
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Toolbar button backed by a hidden native image file input. */
|
|
2
|
+
import type { EditorState } from "prosemirror-state";
|
|
3
|
+
import type { EditorView } from "prosemirror-view";
|
|
4
|
+
import { type ReactElement } from "react";
|
|
5
|
+
export interface InsertImageButtonProps {
|
|
6
|
+
view: EditorView;
|
|
7
|
+
state: EditorState;
|
|
8
|
+
}
|
|
9
|
+
export declare function InsertImageButton({ view, state, }: InsertImageButtonProps): ReactElement;
|