torch-glare 2.5.6 → 2.6.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/README.md +4 -3
- package/dist/bin/index.js +9 -24
- package/dist/bin/index.js.map +1 -1
- package/dist/src/commands/add.d.ts +2 -2
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js +4 -70
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/hook.d.ts +5 -4
- package/dist/src/commands/hook.d.ts.map +1 -1
- package/dist/src/commands/hook.js +7 -75
- package/dist/src/commands/hook.js.map +1 -1
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/layout.d.ts +5 -4
- package/dist/src/commands/layout.d.ts.map +1 -1
- package/dist/src/commands/layout.js +7 -75
- package/dist/src/commands/layout.js.map +1 -1
- package/dist/src/commands/provider.d.ts +5 -4
- package/dist/src/commands/provider.d.ts.map +1 -1
- package/dist/src/commands/provider.js +7 -75
- package/dist/src/commands/provider.js.map +1 -1
- package/dist/src/commands/update.d.ts.map +1 -1
- package/dist/src/commands/update.js +78 -43
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/utils.d.ts +5 -4
- package/dist/src/commands/utils.d.ts.map +1 -1
- package/dist/src/commands/utils.js +7 -80
- package/dist/src/commands/utils.js.map +1 -1
- package/dist/src/shared/addFromRegistry.d.ts +16 -0
- package/dist/src/shared/addFromRegistry.d.ts.map +1 -0
- package/dist/src/shared/addFromRegistry.js +88 -0
- package/dist/src/shared/addFromRegistry.js.map +1 -0
- package/dist/src/shared/getInstallCommand.d.ts.map +1 -1
- package/dist/src/shared/getInstallCommand.js +5 -0
- package/dist/src/shared/getInstallCommand.js.map +1 -1
- package/dist/src/shared/installDependencies.d.ts +0 -10
- package/dist/src/shared/installDependencies.d.ts.map +1 -1
- package/dist/src/shared/installDependencies.js +0 -17
- package/dist/src/shared/installDependencies.js.map +1 -1
- package/dist/src/shared/installFromPlan.d.ts +7 -5
- package/dist/src/shared/installFromPlan.d.ts.map +1 -1
- package/dist/src/shared/installFromPlan.js +103 -36
- package/dist/src/shared/installFromPlan.js.map +1 -1
- package/dist/src/shared/loadRegistry.d.ts +12 -3
- package/dist/src/shared/loadRegistry.d.ts.map +1 -1
- package/dist/src/shared/loadRegistry.js +19 -20
- package/dist/src/shared/loadRegistry.js.map +1 -1
- package/dist/src/shared/registryClient.d.ts +19 -0
- package/dist/src/shared/registryClient.d.ts.map +1 -0
- package/dist/src/shared/registryClient.js +128 -0
- package/dist/src/shared/registryClient.js.map +1 -0
- package/dist/src/shared/resolveEntry.d.ts +10 -7
- package/dist/src/shared/resolveEntry.d.ts.map +1 -1
- package/dist/src/shared/resolveEntry.js +18 -13
- package/dist/src/shared/resolveEntry.js.map +1 -1
- package/dist/src/shared/suggestOtherCommand.d.ts +7 -1
- package/dist/src/shared/suggestOtherCommand.d.ts.map +1 -1
- package/dist/src/shared/suggestOtherCommand.js +29 -23
- package/dist/src/shared/suggestOtherCommand.js.map +1 -1
- package/dist/src/types/main.d.ts +31 -2
- package/dist/src/types/main.d.ts.map +1 -1
- package/package.json +6 -11
- package/apps/lib/components/ActionButton.tsx +0 -93
- package/apps/lib/components/ActionsGroup.tsx +0 -27
- package/apps/lib/components/AlertDialog.tsx +0 -204
- package/apps/lib/components/Avatar.tsx +0 -46
- package/apps/lib/components/Badge.tsx +0 -250
- package/apps/lib/components/BadgeField.tsx +0 -403
- package/apps/lib/components/Breadcrumb.tsx +0 -280
- package/apps/lib/components/Button.tsx +0 -325
- package/apps/lib/components/ButtonGroup.tsx +0 -190
- package/apps/lib/components/Calendar.tsx +0 -115
- package/apps/lib/components/Card.tsx +0 -95
- package/apps/lib/components/Checkbox.tsx +0 -42
- package/apps/lib/components/ColorPicker.tsx +0 -441
- package/apps/lib/components/ConclusionHeader.tsx +0 -148
- package/apps/lib/components/ContextMenu.tsx +0 -571
- package/apps/lib/components/CountBadge.tsx +0 -52
- package/apps/lib/components/DataTable.tsx +0 -213
- package/apps/lib/components/DataViews/badge.ts +0 -49
- package/apps/lib/components/DataViews/cell.tsx +0 -324
- package/apps/lib/components/DataViews/context.ts +0 -144
- package/apps/lib/components/DataViews/data-views.tsx +0 -395
- package/apps/lib/components/DataViews/filters/children.tsx +0 -98
- package/apps/lib/components/DataViews/filters/custom.tsx +0 -34
- package/apps/lib/components/DataViews/filters/filters.tsx +0 -157
- package/apps/lib/components/DataViews/filters/index.ts +0 -4
- package/apps/lib/components/DataViews/filters/labelled.tsx +0 -20
- package/apps/lib/components/DataViews/filters/presets.tsx +0 -65
- package/apps/lib/components/DataViews/filters/sync.tsx +0 -35
- package/apps/lib/components/DataViews/filters/values.ts +0 -173
- package/apps/lib/components/DataViews/header.tsx +0 -220
- package/apps/lib/components/DataViews/hooks/index.ts +0 -5
- package/apps/lib/components/DataViews/hooks/useActiveRow.ts +0 -22
- package/apps/lib/components/DataViews/hooks/useControllable.ts +0 -52
- package/apps/lib/components/DataViews/index.ts +0 -88
- package/apps/lib/components/DataViews/panel/columns.tsx +0 -153
- package/apps/lib/components/DataViews/panel/controls.tsx +0 -106
- package/apps/lib/components/DataViews/panel/index.ts +0 -3
- package/apps/lib/components/DataViews/panel/panel.tsx +0 -164
- package/apps/lib/components/DataViews/panel/saved-views.tsx +0 -67
- package/apps/lib/components/DataViews/panel/section.tsx +0 -81
- package/apps/lib/components/DataViews/panel/sort.tsx +0 -42
- package/apps/lib/components/DataViews/panel/tab.tsx +0 -31
- package/apps/lib/components/DataViews/slots.ts +0 -72
- package/apps/lib/components/DataViews/states.tsx +0 -73
- package/apps/lib/components/DataViews/types.ts +0 -510
- package/apps/lib/components/DataViews/views/board-view.tsx +0 -381
- package/apps/lib/components/DataViews/views/card-rows.tsx +0 -36
- package/apps/lib/components/DataViews/views/inbox-view.tsx +0 -260
- package/apps/lib/components/DataViews/views/pane-views.tsx +0 -196
- package/apps/lib/components/DataViews/views/table-view.tsx +0 -493
- package/apps/lib/components/DataViews/views/tree-view.tsx +0 -367
- package/apps/lib/components/DatePicker.tsx +0 -232
- package/apps/lib/components/Dialog.tsx +0 -116
- package/apps/lib/components/Divider.tsx +0 -28
- package/apps/lib/components/Drawer.tsx +0 -451
- package/apps/lib/components/DropdownMenu.tsx +0 -554
- package/apps/lib/components/FieldHint.tsx +0 -69
- package/apps/lib/components/Form.tsx +0 -182
- package/apps/lib/components/FormBuilder/context.ts +0 -85
- package/apps/lib/components/FormBuilder/field-kind.ts +0 -28
- package/apps/lib/components/FormBuilder/fields/ChoiceFields.tsx +0 -60
- package/apps/lib/components/FormBuilder/fields/ColorField.tsx +0 -59
- package/apps/lib/components/FormBuilder/fields/CustomField.tsx +0 -11
- package/apps/lib/components/FormBuilder/fields/DateField.tsx +0 -32
- package/apps/lib/components/FormBuilder/fields/FieldArray.tsx +0 -74
- package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +0 -168
- package/apps/lib/components/FormBuilder/fields/FileField.tsx +0 -39
- package/apps/lib/components/FormBuilder/fields/OptionListFields.tsx +0 -132
- package/apps/lib/components/FormBuilder/fields/OtpField.tsx +0 -31
- package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +0 -109
- package/apps/lib/components/FormBuilder/fields/RichTextEditorField.tsx +0 -31
- package/apps/lib/components/FormBuilder/fields/SelectField.tsx +0 -114
- package/apps/lib/components/FormBuilder/fields/SignatureField.tsx +0 -157
- package/apps/lib/components/FormBuilder/fields/SliderField.tsx +0 -67
- package/apps/lib/components/FormBuilder/fields/SwitchBoxField.tsx +0 -41
- package/apps/lib/components/FormBuilder/fields/TableField.tsx +0 -336
- package/apps/lib/components/FormBuilder/fields/TextField.tsx +0 -213
- package/apps/lib/components/FormBuilder/fields/TreeSelectField.tsx +0 -43
- package/apps/lib/components/FormBuilder/fields/countries.ts +0 -303
- package/apps/lib/components/FormBuilder/fields/index.ts +0 -25
- package/apps/lib/components/FormBuilder/form-builder.tsx +0 -198
- package/apps/lib/components/FormBuilder/index.ts +0 -31
- package/apps/lib/components/FormBuilder/numberFormat.ts +0 -16
- package/apps/lib/components/FormBuilder/submit.tsx +0 -67
- package/apps/lib/components/FormBuilder/types.ts +0 -316
- package/apps/lib/components/FormRenderer/FormDrawer.tsx +0 -250
- package/apps/lib/components/FormRenderer/detail.tsx +0 -256
- package/apps/lib/components/FormRenderer/form-renderer.tsx +0 -358
- package/apps/lib/components/FormRenderer/header.tsx +0 -88
- package/apps/lib/components/FormRenderer/index.ts +0 -17
- package/apps/lib/components/FormRenderer/notch-action.tsx +0 -64
- package/apps/lib/components/FormRenderer/section.tsx +0 -39
- package/apps/lib/components/FormRenderer/stepper.tsx +0 -393
- package/apps/lib/components/FormRenderer/types.ts +0 -115
- package/apps/lib/components/FormSummary.tsx +0 -282
- package/apps/lib/components/HeaderBar.tsx +0 -117
- package/apps/lib/components/ImageAttachment.tsx +0 -209
- package/apps/lib/components/InnerLabelField.tsx +0 -154
- package/apps/lib/components/Input.tsx +0 -224
- package/apps/lib/components/InputField.tsx +0 -147
- package/apps/lib/components/InputOTP.tsx +0 -84
- package/apps/lib/components/Label.tsx +0 -129
- package/apps/lib/components/LabelField.tsx +0 -76
- package/apps/lib/components/LabeledCheckBox.tsx +0 -51
- package/apps/lib/components/LabeledRadio.tsx +0 -51
- package/apps/lib/components/LinkButton.tsx +0 -94
- package/apps/lib/components/LoginButton.tsx +0 -51
- package/apps/lib/components/PasswordLevel.tsx +0 -58
- package/apps/lib/components/Popover.tsx +0 -312
- package/apps/lib/components/ProfileMenu.tsx +0 -85
- package/apps/lib/components/Radio.tsx +0 -59
- package/apps/lib/components/RadioCard.tsx +0 -50
- package/apps/lib/components/ScrollArea.tsx +0 -54
- package/apps/lib/components/SearchField.tsx +0 -62
- package/apps/lib/components/SearchableSelect.tsx +0 -318
- package/apps/lib/components/SearchableTable.tsx +0 -344
- package/apps/lib/components/SearchableTree.tsx +0 -485
- package/apps/lib/components/SearchableTreeDialog.tsx +0 -502
- package/apps/lib/components/SectionBlock.tsx +0 -168
- package/apps/lib/components/Select.tsx +0 -347
- package/apps/lib/components/SimpleSelect.tsx +0 -225
- package/apps/lib/components/Skeleton.tsx +0 -12
- package/apps/lib/components/SlideDatePicker.tsx +0 -255
- package/apps/lib/components/SpinLoading.tsx +0 -174
- package/apps/lib/components/Stepper.tsx +0 -480
- package/apps/lib/components/Switch.tsx +0 -82
- package/apps/lib/components/TabFormItem.tsx +0 -153
- package/apps/lib/components/TabSwitch.tsx +0 -172
- package/apps/lib/components/Table.tsx +0 -597
- package/apps/lib/components/TextEditor/ChartBlockTool.ts +0 -676
- package/apps/lib/components/TextEditor/RichTextField.tsx +0 -46
- package/apps/lib/components/TextEditor/TableDnDWrapper.ts +0 -462
- package/apps/lib/components/TextEditor/TextEditor.tsx +0 -1164
- package/apps/lib/components/TextEditor/TextEditorToolbar.tsx +0 -429
- package/apps/lib/components/TextEditor/editor-tools/AlignmentTune.ts +0 -70
- package/apps/lib/components/TextEditor/editor-tools/ColorInlineTool.ts +0 -50
- package/apps/lib/components/TextEditor/editor-tools/StrikethroughInlineTool.ts +0 -48
- package/apps/lib/components/TextEditor/editor-tools/inlineFormat.ts +0 -98
- package/apps/lib/components/TextEditor/editorjs.d.ts +0 -60
- package/apps/lib/components/TextEditor/index.ts +0 -7
- package/apps/lib/components/TextEditor/markdownParser.ts +0 -346
- package/apps/lib/components/Textarea.tsx +0 -117
- package/apps/lib/components/Timeline.tsx +0 -263
- package/apps/lib/components/Toast.tsx +0 -87
- package/apps/lib/components/Toggle.tsx +0 -125
- package/apps/lib/components/ToggleButton.tsx +0 -140
- package/apps/lib/components/Tooltip.tsx +0 -116
- package/apps/lib/components/TransparentLabel.tsx +0 -71
- package/apps/lib/components/TreeDropDown.tsx +0 -115
- package/apps/lib/components/TreeFolder/TreeFolder.tsx +0 -380
- package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +0 -75
- package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +0 -354
- package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +0 -60
- package/apps/lib/components/TreeFolder/icons.tsx +0 -60
- package/apps/lib/components/TreeFolder/index.ts +0 -24
- package/apps/lib/components/TreeFolder/treeFolderUtils.ts +0 -109
- package/apps/lib/components/TreeFolder/types.ts +0 -77
- package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +0 -118
- package/apps/lib/hooks/useActiveTreeItem.ts +0 -61
- package/apps/lib/hooks/useClickOutside.ts +0 -27
- package/apps/lib/hooks/useDragDrop.tsx +0 -365
- package/apps/lib/hooks/useHtmlDir.ts +0 -31
- package/apps/lib/hooks/useInfiniteScroll.ts +0 -108
- package/apps/lib/hooks/useIsMobile.ts +0 -21
- package/apps/lib/hooks/useResize.ts +0 -67
- package/apps/lib/hooks/useTagSelection.ts +0 -300
- package/apps/lib/layouts/CNLayout.tsx +0 -372
- package/apps/lib/layouts/DataViewCard.tsx +0 -62
- package/apps/lib/layouts/FieldSection.tsx +0 -91
- package/apps/lib/layouts/TreeSubLayout.tsx +0 -173
- package/apps/lib/providers/ThemeProvider.tsx +0 -84
- package/apps/lib/registry.json +0 -1217
- package/apps/lib/tsconfig.json +0 -9
- package/apps/lib/tsconfig.tsbuildinfo +0 -1
- package/apps/lib/utils/cn.ts +0 -6
- package/apps/lib/utils/color.ts +0 -175
- package/apps/lib/utils/dataViews/path.ts +0 -67
- package/apps/lib/utils/dataViews/query.ts +0 -73
- package/apps/lib/utils/dataViews/types.ts +0 -187
- package/apps/lib/utils/dateFormat.ts +0 -108
- package/apps/lib/utils/resize.ts +0 -31
- package/apps/lib/utils/scroller.ts +0 -26
- package/apps/lib/utils/types.ts +0 -16
- package/docs/BLOCKS.md +0 -129
- package/docs/CHANGELOG-1.1.16.md +0 -108
- package/docs/Cover.png +0 -0
- package/docs/README.md +0 -215
- package/docs/components/action-button.md +0 -638
- package/docs/components/actions-group.md +0 -708
- package/docs/components/alert-dialog.md +0 -920
- package/docs/components/avatar.md +0 -709
- package/docs/components/badge-field.md +0 -738
- package/docs/components/badge.md +0 -301
- package/docs/components/breadcrumb.md +0 -930
- package/docs/components/button-group.md +0 -650
- package/docs/components/button.md +0 -639
- package/docs/components/calendar.md +0 -555
- package/docs/components/card.md +0 -622
- package/docs/components/chart-block-tool.md +0 -129
- package/docs/components/checkbox.md +0 -699
- package/docs/components/cn-layout.md +0 -854
- package/docs/components/color-picker.md +0 -101
- package/docs/components/conclusion-header.md +0 -80
- package/docs/components/context-menu.md +0 -483
- package/docs/components/count-badge.md +0 -560
- package/docs/components/data-table.md +0 -854
- package/docs/components/data-views/backend-response.md +0 -324
- package/docs/components/data-views/examples/a11y-rtl.md +0 -250
- package/docs/components/data-views/examples/api-orders-route.md +0 -130
- package/docs/components/data-views/examples/fields.md +0 -362
- package/docs/components/data-views/examples/filters.md +0 -307
- package/docs/components/data-views/examples/inbox-routing.md +0 -218
- package/docs/components/data-views/examples/index.md +0 -29
- package/docs/components/data-views/examples/overview.md +0 -244
- package/docs/components/data-views/examples/panel.md +0 -212
- package/docs/components/data-views/examples/scale.md +0 -231
- package/docs/components/data-views/examples/server-side.md +0 -210
- package/docs/components/data-views/examples/state.md +0 -250
- package/docs/components/data-views/examples/tree-custom.md +0 -388
- package/docs/components/data-views/examples/view-registry.md +0 -313
- package/docs/components/data-views/examples/views.md +0 -534
- package/docs/components/data-views/guide.md +0 -405
- package/docs/components/data-views/index.md +0 -1521
- package/docs/components/data-views/migration.md +0 -81
- package/docs/components/date-picker.md +0 -857
- package/docs/components/dialog.md +0 -929
- package/docs/components/divider.md +0 -766
- package/docs/components/drawer.md +0 -654
- package/docs/components/dropdown-menu.md +0 -668
- package/docs/components/field-hint.md +0 -898
- package/docs/components/field-section.md +0 -781
- package/docs/components/form-builder.md +0 -284
- package/docs/components/form-renderer.md +0 -396
- package/docs/components/form-summary.md +0 -138
- package/docs/components/form.md +0 -785
- package/docs/components/header-bar.md +0 -188
- package/docs/components/image-attachment.md +0 -906
- package/docs/components/inner-label-field.md +0 -819
- package/docs/components/input-field.md +0 -623
- package/docs/components/input-otp.md +0 -756
- package/docs/components/input.md +0 -634
- package/docs/components/label-field.md +0 -770
- package/docs/components/label.md +0 -761
- package/docs/components/labeled-check-box.md +0 -642
- package/docs/components/labeled-radio.md +0 -796
- package/docs/components/link-button.md +0 -685
- package/docs/components/login-button.md +0 -872
- package/docs/components/password-level.md +0 -803
- package/docs/components/popover.md +0 -649
- package/docs/components/profile-menu.md +0 -656
- package/docs/components/radio-card.md +0 -801
- package/docs/components/radio.md +0 -735
- package/docs/components/scroll-area.md +0 -691
- package/docs/components/search-field.md +0 -702
- package/docs/components/searchable-select.md +0 -368
- package/docs/components/searchable-table.md +0 -438
- package/docs/components/searchable-tree-dialog.md +0 -190
- package/docs/components/searchable-tree.md +0 -200
- package/docs/components/section-block.md +0 -483
- package/docs/components/select.md +0 -709
- package/docs/components/simple-select.md +0 -741
- package/docs/components/skeleton.md +0 -706
- package/docs/components/slide-date-picker.md +0 -837
- package/docs/components/spin-loading.md +0 -696
- package/docs/components/stepper.md +0 -316
- package/docs/components/switch.md +0 -770
- package/docs/components/tab-form-item.md +0 -773
- package/docs/components/tab-switch.md +0 -170
- package/docs/components/table-dnd-wrapper.md +0 -107
- package/docs/components/table.md +0 -1088
- package/docs/components/text-editor.md +0 -735
- package/docs/components/textarea.md +0 -681
- package/docs/components/timeline.md +0 -254
- package/docs/components/toast.md +0 -773
- package/docs/components/toggle-button.md +0 -643
- package/docs/components/toggle.md +0 -882
- package/docs/components/tooltip.md +0 -513
- package/docs/components/transparent-label.md +0 -721
- package/docs/components/tree-drop-down.md +0 -740
- package/docs/components/tree-folder.md +0 -110
- package/docs/components/tree-sub-layout.md +0 -707
- package/docs/explanation/architecture.md +0 -54
- package/docs/explanation/design-system.md +0 -52
- package/docs/how-to/form-and-list-recipes.md +0 -386
- package/docs/how-to/forms-with-form-builder.md +0 -472
- package/docs/how-to/guides.md +0 -1027
- package/docs/migration/changelog.md +0 -60
- package/docs/migration/form-builder-2.5.2.md +0 -113
- package/docs/reference/cli.md +0 -112
- package/docs/reference/components.md +0 -572
- package/docs/reference/hooks.md +0 -1523
- package/docs/reference/providers.md +0 -866
- package/docs/reference/tailwind-plugins.md +0 -942
- package/docs/reference/theme.md +0 -85
- package/docs/reference/types.md +0 -1016
- package/docs/reference/utilities.md +0 -726
- package/docs/tutorials/building-first-form.md +0 -846
- package/docs/tutorials/component-composition.md +0 -882
- package/docs/tutorials/getting-started.md +0 -302
- package/docs/tutorials/theming-basics.md +0 -785
|
@@ -1,1164 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React, {
|
|
4
|
-
forwardRef,
|
|
5
|
-
useEffect,
|
|
6
|
-
useImperativeHandle,
|
|
7
|
-
useRef,
|
|
8
|
-
useCallback,
|
|
9
|
-
HTMLAttributes,
|
|
10
|
-
useState,
|
|
11
|
-
} from "react";
|
|
12
|
-
import { cva, type VariantProps } from "class-variance-authority";
|
|
13
|
-
import { cn } from "../../utils/cn";
|
|
14
|
-
import { Themes } from "../../utils/types";
|
|
15
|
-
import EditorJS, { type OutputData } from "@editorjs/editorjs";
|
|
16
|
-
import { isMarkdown, parseMarkdownToBlocks } from "./markdownParser";
|
|
17
|
-
|
|
18
|
-
// ─── Tool Imports ────────────────────────────────────────────────────────────
|
|
19
|
-
import Header from "@editorjs/header";
|
|
20
|
-
import List from "@editorjs/list";
|
|
21
|
-
import NestedList from "@editorjs/nested-list";
|
|
22
|
-
import Checklist from "@editorjs/checklist";
|
|
23
|
-
import Quote from "@editorjs/quote";
|
|
24
|
-
import Warning from "@editorjs/warning";
|
|
25
|
-
import CodeTool from "@editorjs/code";
|
|
26
|
-
import Delimiter from "@editorjs/delimiter";
|
|
27
|
-
import Embed from "@editorjs/embed";
|
|
28
|
-
import Table from "@editorjs/table";
|
|
29
|
-
import createTableDnDClass from "./TableDnDWrapper";
|
|
30
|
-
import LinkTool from "@editorjs/link";
|
|
31
|
-
import SimpleImage from "@editorjs/simple-image";
|
|
32
|
-
import RawTool from "@editorjs/raw";
|
|
33
|
-
import Marker from "@editorjs/marker";
|
|
34
|
-
import InlineCode from "@editorjs/inline-code";
|
|
35
|
-
import Underline from "@editorjs/underline";
|
|
36
|
-
import TextVariantTune from "@editorjs/text-variant-tune";
|
|
37
|
-
// `editorjs-undo` touches DOM globals at module-eval, so it is imported dynamically
|
|
38
|
-
// (browser-only) in `onReady`; keep only the type here.
|
|
39
|
-
import type Undo from "editorjs-undo";
|
|
40
|
-
import ChartBlockTool from "./ChartBlockTool";
|
|
41
|
-
import StrikethroughInlineTool from "./editor-tools/StrikethroughInlineTool";
|
|
42
|
-
import ColorInlineTool from "./editor-tools/ColorInlineTool";
|
|
43
|
-
import AlignmentTune from "./editor-tools/AlignmentTune";
|
|
44
|
-
import { TextEditorToolbar } from "./TextEditorToolbar";
|
|
45
|
-
|
|
46
|
-
// ─── RTL Detection ───────────────────────────────────────────────────────────
|
|
47
|
-
const RTL_REGEX = /[\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC]/;
|
|
48
|
-
|
|
49
|
-
/** Find the first visible character (skipping HTML tags and whitespace) and test RTL */
|
|
50
|
-
function getTextDirection(text: string): "rtl" | "ltr" {
|
|
51
|
-
let i = 0;
|
|
52
|
-
const len = text.length;
|
|
53
|
-
while (i < len) {
|
|
54
|
-
const ch = text[i];
|
|
55
|
-
if (ch === "<") {
|
|
56
|
-
// Skip HTML tag
|
|
57
|
-
const end = text.indexOf(">", i);
|
|
58
|
-
if (end === -1) break;
|
|
59
|
-
i = end + 1;
|
|
60
|
-
} else if (ch === " " || ch === "\n" || ch === "\t" || ch === "\r") {
|
|
61
|
-
i++;
|
|
62
|
-
} else {
|
|
63
|
-
return RTL_REGEX.test(ch) ? "rtl" : "ltr";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return "ltr";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function setDirIfChanged(el: HTMLElement, dir: "rtl" | "ltr") {
|
|
70
|
-
if (el.getAttribute("dir") !== dir) {
|
|
71
|
-
el.setAttribute("dir", dir);
|
|
72
|
-
el.style.textAlign = dir === "rtl" ? "right" : "left";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function applyDirectionToBlock(
|
|
77
|
-
block: HTMLElement,
|
|
78
|
-
fallbackDir: "rtl" | "ltr" = "ltr",
|
|
79
|
-
): "rtl" | "ltr" {
|
|
80
|
-
// Skip non-text blocks (delimiters, embeds, code)
|
|
81
|
-
if (block.querySelector(".ce-delimiter, .cdx-embed, .embed-tool")) return fallbackDir;
|
|
82
|
-
|
|
83
|
-
// Handle list blocks — apply direction per list item so bullets flip
|
|
84
|
-
const listItems = block.querySelectorAll<HTMLElement>(
|
|
85
|
-
".cdx-list__item, .cdx-nested-list__item, .cdx-checklist__item",
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
if (listItems.length > 0) {
|
|
89
|
-
let prevDir: "rtl" | "ltr" = fallbackDir;
|
|
90
|
-
listItems.forEach((item) => {
|
|
91
|
-
const editable = item.querySelector<HTMLElement>('[contenteditable="true"]');
|
|
92
|
-
if (!editable) return;
|
|
93
|
-
const text = (editable.textContent || "").trim();
|
|
94
|
-
const dir = text ? getTextDirection(text) : prevDir;
|
|
95
|
-
prevDir = dir;
|
|
96
|
-
setDirIfChanged(item, dir);
|
|
97
|
-
setDirIfChanged(editable, dir);
|
|
98
|
-
});
|
|
99
|
-
return prevDir;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Handle regular blocks (paragraph, header, quote, warning, etc.)
|
|
103
|
-
let lastDir = fallbackDir;
|
|
104
|
-
const editables = block.querySelectorAll<HTMLElement>('[contenteditable="true"]');
|
|
105
|
-
editables.forEach((el) => {
|
|
106
|
-
const text = (el.textContent || "").trim();
|
|
107
|
-
const dir = text ? getTextDirection(text) : fallbackDir;
|
|
108
|
-
setDirIfChanged(el, dir);
|
|
109
|
-
lastDir = dir;
|
|
110
|
-
});
|
|
111
|
-
return lastDir;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function applyAutoDirection(container: HTMLElement) {
|
|
115
|
-
const blocks = container.querySelectorAll<HTMLElement>(".ce-block");
|
|
116
|
-
let lastBlockDir: "rtl" | "ltr" = "ltr";
|
|
117
|
-
blocks.forEach((block) => {
|
|
118
|
-
lastBlockDir = applyDirectionToBlock(block, lastBlockDir);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// ─── Default Tools Configuration ─────────────────────────────────────────────
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
-
const getDefaultTools = (): Record<string, any> => ({
|
|
125
|
-
header: {
|
|
126
|
-
class: Header,
|
|
127
|
-
inlineToolbar: true,
|
|
128
|
-
config: { levels: [1, 2, 3, 4, 5, 6], defaultLevel: 2 },
|
|
129
|
-
shortcut: "CMD+SHIFT+H",
|
|
130
|
-
},
|
|
131
|
-
list: {
|
|
132
|
-
class: List,
|
|
133
|
-
inlineToolbar: true,
|
|
134
|
-
config: { defaultStyle: "unordered" },
|
|
135
|
-
shortcut: "CMD+SHIFT+L",
|
|
136
|
-
},
|
|
137
|
-
nestedList: { class: NestedList, inlineToolbar: true },
|
|
138
|
-
checklist: { class: Checklist, inlineToolbar: true },
|
|
139
|
-
quote: {
|
|
140
|
-
class: Quote,
|
|
141
|
-
inlineToolbar: true,
|
|
142
|
-
config: {
|
|
143
|
-
quotePlaceholder: "Enter a quote",
|
|
144
|
-
captionPlaceholder: "Quote's author",
|
|
145
|
-
},
|
|
146
|
-
shortcut: "CMD+SHIFT+O",
|
|
147
|
-
},
|
|
148
|
-
warning: {
|
|
149
|
-
class: Warning,
|
|
150
|
-
inlineToolbar: true,
|
|
151
|
-
config: { titlePlaceholder: "Title", messagePlaceholder: "Message" },
|
|
152
|
-
},
|
|
153
|
-
code: { class: CodeTool, shortcut: "CMD+SHIFT+C" },
|
|
154
|
-
delimiter: { class: Delimiter },
|
|
155
|
-
embed: {
|
|
156
|
-
class: Embed,
|
|
157
|
-
config: {
|
|
158
|
-
services: {
|
|
159
|
-
youtube: true,
|
|
160
|
-
vimeo: true,
|
|
161
|
-
codepen: true,
|
|
162
|
-
twitter: true,
|
|
163
|
-
instagram: true,
|
|
164
|
-
coub: true,
|
|
165
|
-
github: true,
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
table: {
|
|
170
|
-
class: createTableDnDClass(Table),
|
|
171
|
-
inlineToolbar: true,
|
|
172
|
-
config: { rows: 2, cols: 3 },
|
|
173
|
-
shortcut: "CMD+ALT+T",
|
|
174
|
-
},
|
|
175
|
-
linkTool: { class: LinkTool },
|
|
176
|
-
image: { class: SimpleImage },
|
|
177
|
-
raw: { class: RawTool },
|
|
178
|
-
chart: { class: ChartBlockTool },
|
|
179
|
-
marker: { class: Marker, shortcut: "CMD+SHIFT+M" },
|
|
180
|
-
inlineCode: { class: InlineCode, shortcut: "CMD+SHIFT+I" },
|
|
181
|
-
underline: { class: Underline },
|
|
182
|
-
// Registered so their `sanitize` unions into every block's save config (strike/color
|
|
183
|
-
// markup persists) and they appear in the inline toolbar; the fixed toolbar drives them too.
|
|
184
|
-
strikethrough: { class: StrikethroughInlineTool, shortcut: "CMD+SHIFT+X" },
|
|
185
|
-
color: { class: ColorInlineTool },
|
|
186
|
-
textVariant: { class: TextVariantTune },
|
|
187
|
-
// Per-block text alignment; wired into `tunes` below so every block gets it.
|
|
188
|
-
align: { class: AlignmentTune },
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// ─── Auto-direction CSS ──────────────────────────────────────────────────────
|
|
192
|
-
const AUTO_DIR_STYLES = `
|
|
193
|
-
/* Block alignment (AlignmentTune sets data-align on the block content wrapper). */
|
|
194
|
-
.torch-text-editor .cdx-align-wrap[data-align="center"] { text-align: center; }
|
|
195
|
-
.torch-text-editor .cdx-align-wrap[data-align="right"] { text-align: right; }
|
|
196
|
-
.torch-text-editor .cdx-align-wrap[data-align="left"] { text-align: left; }
|
|
197
|
-
.torch-text-editor [contenteditable="true"][dir="rtl"] {
|
|
198
|
-
unicode-bidi: plaintext;
|
|
199
|
-
}
|
|
200
|
-
/* List items: flip bullet and padding when RTL */
|
|
201
|
-
.torch-text-editor .cdx-list__item[dir="rtl"] {
|
|
202
|
-
direction: rtl;
|
|
203
|
-
}
|
|
204
|
-
.torch-text-editor .cdx-list__item[dir="rtl"]::before {
|
|
205
|
-
padding-right: 0;
|
|
206
|
-
padding-left: 8px;
|
|
207
|
-
}
|
|
208
|
-
.torch-text-editor .cdx-nested-list__item[dir="rtl"] {
|
|
209
|
-
direction: rtl;
|
|
210
|
-
}
|
|
211
|
-
.torch-text-editor .cdx-checklist__item[dir="rtl"] {
|
|
212
|
-
direction: rtl;
|
|
213
|
-
}
|
|
214
|
-
.torch-text-editor .cdx-checklist__item[dir="rtl"] .cdx-checklist__item-checkbox {
|
|
215
|
-
margin-left: 7px;
|
|
216
|
-
margin-right: 0;
|
|
217
|
-
}
|
|
218
|
-
/* Heading level styles (Tailwind reset strips defaults) */
|
|
219
|
-
.torch-text-editor h1.ce-header {
|
|
220
|
-
font-size: 2em;
|
|
221
|
-
font-weight: 700;
|
|
222
|
-
line-height: 1.25;
|
|
223
|
-
}
|
|
224
|
-
.torch-text-editor h2.ce-header {
|
|
225
|
-
font-size: 1.5em;
|
|
226
|
-
font-weight: 700;
|
|
227
|
-
line-height: 1.3;
|
|
228
|
-
}
|
|
229
|
-
.torch-text-editor h3.ce-header {
|
|
230
|
-
font-size: 1.25em;
|
|
231
|
-
font-weight: 600;
|
|
232
|
-
line-height: 1.35;
|
|
233
|
-
}
|
|
234
|
-
.torch-text-editor h4.ce-header {
|
|
235
|
-
font-size: 1.1em;
|
|
236
|
-
font-weight: 600;
|
|
237
|
-
line-height: 1.4;
|
|
238
|
-
}
|
|
239
|
-
.torch-text-editor h5.ce-header {
|
|
240
|
-
font-size: 1em;
|
|
241
|
-
font-weight: 600;
|
|
242
|
-
line-height: 1.4;
|
|
243
|
-
}
|
|
244
|
-
.torch-text-editor h6.ce-header {
|
|
245
|
-
font-size: 0.9em;
|
|
246
|
-
font-weight: 600;
|
|
247
|
-
line-height: 1.45;
|
|
248
|
-
}
|
|
249
|
-
/* Toolbar buttons: inherit theme color */
|
|
250
|
-
.torch-text-editor .ce-toolbar__plus,
|
|
251
|
-
.torch-text-editor .ce-toolbar__settings-btn {
|
|
252
|
-
color: inherit;
|
|
253
|
-
background-color: transparent;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/* ── Table: restore borders stripped by Tailwind preflight ── */
|
|
257
|
-
.torch-text-editor .tc-table {
|
|
258
|
-
border-top: 1px solid var(--color-border);
|
|
259
|
-
}
|
|
260
|
-
.torch-text-editor .tc-row {
|
|
261
|
-
border-bottom: 1px solid var(--color-border);
|
|
262
|
-
}
|
|
263
|
-
.torch-text-editor .tc-row:after {
|
|
264
|
-
border-bottom: 1px solid var(--color-border);
|
|
265
|
-
}
|
|
266
|
-
.torch-text-editor .tc-cell {
|
|
267
|
-
border-right: 1px solid var(--color-border);
|
|
268
|
-
}
|
|
269
|
-
.torch-text-editor .tc-add-column {
|
|
270
|
-
border-top: 1px solid var(--color-border);
|
|
271
|
-
}
|
|
272
|
-
.torch-text-editor .tc-table--heading .tc-row:first-child {
|
|
273
|
-
border-bottom: 2px solid var(--color-border);
|
|
274
|
-
}
|
|
275
|
-
.torch-text-editor .tc-table--heading .tc-row:first-child:after {
|
|
276
|
-
border-bottom: 2px solid var(--color-border);
|
|
277
|
-
}
|
|
278
|
-
.torch-text-editor .tc-popover {
|
|
279
|
-
border: 1px solid var(--color-border);
|
|
280
|
-
}
|
|
281
|
-
.torch-text-editor .tc-popover__item-icon {
|
|
282
|
-
border: 1px solid var(--color-border);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/* ── Table: dark mode variable overrides ── */
|
|
286
|
-
/* Override the plugin's hardcoded light CSS variables for dark themes */
|
|
287
|
-
[data-theme="dark"] .tc-wrap,
|
|
288
|
-
.torch-text-editor[data-theme="dark"] .tc-wrap {
|
|
289
|
-
--color-background: #1e1e1e;
|
|
290
|
-
--color-text-secondary: #999;
|
|
291
|
-
--color-border: #3a3a3a;
|
|
292
|
-
}
|
|
293
|
-
[data-theme="dark"] .tc-popover,
|
|
294
|
-
.torch-text-editor[data-theme="dark"] .tc-popover {
|
|
295
|
-
--color-border: #3a3a3a;
|
|
296
|
-
--color-background: #2a2a2a;
|
|
297
|
-
--color-background-hover: rgba(255, 255, 255, 0.08);
|
|
298
|
-
}
|
|
299
|
-
[data-theme="dark"] .tc-cell--selected,
|
|
300
|
-
.torch-text-editor[data-theme="dark"] .tc-cell--selected {
|
|
301
|
-
background: rgba(255, 255, 255, 0.06);
|
|
302
|
-
}
|
|
303
|
-
[data-theme="dark"] .tc-row--selected,
|
|
304
|
-
.torch-text-editor[data-theme="dark"] .tc-row--selected {
|
|
305
|
-
background: rgba(255, 255, 255, 0.06);
|
|
306
|
-
}
|
|
307
|
-
[data-theme="dark"] .tc-toolbox,
|
|
308
|
-
.torch-text-editor[data-theme="dark"] .tc-toolbox {
|
|
309
|
-
--toggler-dots-color: #999;
|
|
310
|
-
--toggler-dots-color-hovered: #fff;
|
|
311
|
-
}
|
|
312
|
-
[data-theme="dark"] .tc-add-column svg,
|
|
313
|
-
.torch-text-editor[data-theme="dark"] .tc-add-column svg,
|
|
314
|
-
[data-theme="dark"] .tc-add-row svg,
|
|
315
|
-
.torch-text-editor[data-theme="dark"] .tc-add-row svg {
|
|
316
|
-
fill: #999;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/* ── Table DnD: toggler-based drag-and-drop ── */
|
|
320
|
-
.torch-text-editor .tc-dnd-wrap {
|
|
321
|
-
position: relative;
|
|
322
|
-
}
|
|
323
|
-
.torch-text-editor .tc-dnd-wrap .tc-toolbox__toggler {
|
|
324
|
-
cursor: grab;
|
|
325
|
-
}
|
|
326
|
-
/* Hide both toolboxes by default — show only near the relevant edge */
|
|
327
|
-
.torch-text-editor .tc-dnd-wrap .tc-toolbox--row {
|
|
328
|
-
opacity: 0 !important;
|
|
329
|
-
pointer-events: none !important;
|
|
330
|
-
transition: opacity 120ms ease;
|
|
331
|
-
}
|
|
332
|
-
.torch-text-editor .tc-dnd-wrap .tc-toolbox--column {
|
|
333
|
-
opacity: 0 !important;
|
|
334
|
-
pointer-events: none !important;
|
|
335
|
-
transition: opacity 120ms ease;
|
|
336
|
-
}
|
|
337
|
-
.torch-text-editor .tc-dnd-wrap.tc-dnd--show-row .tc-toolbox--row {
|
|
338
|
-
opacity: 1 !important;
|
|
339
|
-
pointer-events: auto !important;
|
|
340
|
-
}
|
|
341
|
-
.torch-text-editor .tc-dnd-wrap.tc-dnd--show-col .tc-toolbox--column {
|
|
342
|
-
opacity: 1 !important;
|
|
343
|
-
pointer-events: auto !important;
|
|
344
|
-
}
|
|
345
|
-
/* Dragging: purple highlight on row */
|
|
346
|
-
.torch-text-editor .tc-dnd__row--dragging {
|
|
347
|
-
outline: 2px solid #8b5cf6 !important;
|
|
348
|
-
outline-offset: -1px;
|
|
349
|
-
background: rgba(139, 92, 246, 0.06) !important;
|
|
350
|
-
position: relative;
|
|
351
|
-
z-index: 2;
|
|
352
|
-
}
|
|
353
|
-
/* Dragging: purple highlight on column cells */
|
|
354
|
-
.torch-text-editor .tc-dnd__cell--dragging {
|
|
355
|
-
outline: 2px solid #8b5cf6 !important;
|
|
356
|
-
outline-offset: -1px;
|
|
357
|
-
background: rgba(139, 92, 246, 0.06) !important;
|
|
358
|
-
}
|
|
359
|
-
/* Drop indicator line */
|
|
360
|
-
.torch-text-editor .tc-dnd__indicator {
|
|
361
|
-
position: absolute;
|
|
362
|
-
background: #8b5cf6;
|
|
363
|
-
border-radius: 2px;
|
|
364
|
-
display: none;
|
|
365
|
-
pointer-events: none;
|
|
366
|
-
z-index: 10;
|
|
367
|
-
transition: top 60ms ease-out, left 60ms ease-out;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/* ── Editor.js core popover: dark mode variable overrides ── */
|
|
371
|
-
[data-theme="dark"] .ce-popover,
|
|
372
|
-
.torch-text-editor[data-theme="dark"] .ce-popover {
|
|
373
|
-
--color-background: #2a2a2a;
|
|
374
|
-
--color-border: #3a3a3a;
|
|
375
|
-
--color-shadow: rgba(0, 0, 0, 0.3);
|
|
376
|
-
--color-text-primary: #e0e0e0;
|
|
377
|
-
--color-text-secondary: #888;
|
|
378
|
-
--color-border-icon: rgba(255, 255, 255, 0.12);
|
|
379
|
-
--color-border-icon-disabled: #3a3a3a;
|
|
380
|
-
--color-text-icon-active: #5ea3f0;
|
|
381
|
-
--color-background-icon-active: rgba(56, 138, 229, 0.15);
|
|
382
|
-
--color-background-item-focus: rgba(255, 255, 255, 0.06);
|
|
383
|
-
--color-shadow-item-focus: rgba(255, 255, 255, 0.04);
|
|
384
|
-
--color-background-item-hover: rgba(255, 255, 255, 0.08);
|
|
385
|
-
--color-background-item-confirm: #E24A4A;
|
|
386
|
-
--color-background-item-confirm-hover: #CE4343;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/* Search field in popover */
|
|
390
|
-
[data-theme="dark"] .cdx-search-field,
|
|
391
|
-
.torch-text-editor[data-theme="dark"] .cdx-search-field {
|
|
392
|
-
background: rgba(255, 255, 255, 0.06);
|
|
393
|
-
border-color: rgba(255, 255, 255, 0.1);
|
|
394
|
-
}
|
|
395
|
-
[data-theme="dark"] .cdx-search-field__input,
|
|
396
|
-
.torch-text-editor[data-theme="dark"] .cdx-search-field__input {
|
|
397
|
-
color: #e0e0e0;
|
|
398
|
-
}
|
|
399
|
-
[data-theme="dark"] .cdx-search-field__icon svg,
|
|
400
|
-
.torch-text-editor[data-theme="dark"] .cdx-search-field__icon svg {
|
|
401
|
-
color: #888;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/* Inline toolbar */
|
|
405
|
-
[data-theme="dark"] .ce-inline-toolbar,
|
|
406
|
-
.torch-text-editor[data-theme="dark"] .ce-inline-toolbar {
|
|
407
|
-
--color-background-icon-active: rgba(56, 138, 229, 0.15);
|
|
408
|
-
--color-text-icon-active: #5ea3f0;
|
|
409
|
-
--color-text-primary: #e0e0e0;
|
|
410
|
-
}
|
|
411
|
-
[data-theme="dark"] .ce-inline-toolbar__dropdown:hover,
|
|
412
|
-
.torch-text-editor[data-theme="dark"] .ce-inline-toolbar__dropdown:hover {
|
|
413
|
-
background: rgba(255, 255, 255, 0.08);
|
|
414
|
-
}
|
|
415
|
-
[data-theme="dark"] .ce-inline-toolbar__dropdown,
|
|
416
|
-
.torch-text-editor[data-theme="dark"] .ce-inline-toolbar__dropdown {
|
|
417
|
-
border-color: rgba(255, 255, 255, 0.12);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/* Popover item separator line */
|
|
421
|
-
[data-theme="dark"] .ce-popover-item-separator__line,
|
|
422
|
-
.torch-text-editor[data-theme="dark"] .ce-popover-item-separator__line {
|
|
423
|
-
background: #3a3a3a;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/* ── Scrollbar styling ── */
|
|
427
|
-
.torch-text-editor .ce-popover__items::-webkit-scrollbar,
|
|
428
|
-
.torch-text-editor .ce-popover__container::-webkit-scrollbar {
|
|
429
|
-
width: 4px;
|
|
430
|
-
}
|
|
431
|
-
.torch-text-editor .ce-popover__items::-webkit-scrollbar-track,
|
|
432
|
-
.torch-text-editor .ce-popover__container::-webkit-scrollbar-track {
|
|
433
|
-
background: transparent;
|
|
434
|
-
}
|
|
435
|
-
.torch-text-editor .ce-popover__items::-webkit-scrollbar-thumb,
|
|
436
|
-
.torch-text-editor .ce-popover__container::-webkit-scrollbar-thumb {
|
|
437
|
-
background: rgba(0, 0, 0, 0.15);
|
|
438
|
-
border-radius: 4px;
|
|
439
|
-
}
|
|
440
|
-
.torch-text-editor .ce-popover__items::-webkit-scrollbar-thumb:hover,
|
|
441
|
-
.torch-text-editor .ce-popover__container::-webkit-scrollbar-thumb:hover {
|
|
442
|
-
background: rgba(0, 0, 0, 0.25);
|
|
443
|
-
}
|
|
444
|
-
[data-theme="dark"] .ce-popover__items::-webkit-scrollbar-thumb,
|
|
445
|
-
[data-theme="dark"] .ce-popover__container::-webkit-scrollbar-thumb,
|
|
446
|
-
.torch-text-editor[data-theme="dark"] .ce-popover__items::-webkit-scrollbar-thumb,
|
|
447
|
-
.torch-text-editor[data-theme="dark"] .ce-popover__container::-webkit-scrollbar-thumb {
|
|
448
|
-
background: rgba(255, 255, 255, 0.15);
|
|
449
|
-
}
|
|
450
|
-
[data-theme="dark"] .ce-popover__items::-webkit-scrollbar-thumb:hover,
|
|
451
|
-
[data-theme="dark"] .ce-popover__container::-webkit-scrollbar-thumb:hover,
|
|
452
|
-
.torch-text-editor[data-theme="dark"] .ce-popover__items::-webkit-scrollbar-thumb:hover,
|
|
453
|
-
.torch-text-editor[data-theme="dark"] .ce-popover__container::-webkit-scrollbar-thumb:hover {
|
|
454
|
-
background: rgba(255, 255, 255, 0.25);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/* ── Chart Block Tool ── */
|
|
458
|
-
.torch-text-editor .cdx-chart-block {
|
|
459
|
-
padding: 16px 0;
|
|
460
|
-
cursor: pointer;
|
|
461
|
-
}
|
|
462
|
-
.torch-text-editor .cdx-chart-block__editor-panel {
|
|
463
|
-
overflow: hidden;
|
|
464
|
-
max-height: 1000px;
|
|
465
|
-
opacity: 1;
|
|
466
|
-
transition: max-height 300ms ease-in-out, opacity 200ms ease-in-out, margin 300ms ease-in-out;
|
|
467
|
-
margin-bottom: 16px;
|
|
468
|
-
}
|
|
469
|
-
.torch-text-editor .cdx-chart-block__editor-panel--hidden {
|
|
470
|
-
max-height: 0;
|
|
471
|
-
opacity: 0;
|
|
472
|
-
margin-bottom: 0;
|
|
473
|
-
pointer-events: none;
|
|
474
|
-
}
|
|
475
|
-
.torch-text-editor .cdx-chart-block__title-input {
|
|
476
|
-
width: 100%;
|
|
477
|
-
border: none;
|
|
478
|
-
border-bottom: 1px solid #e0e0e0;
|
|
479
|
-
padding: 8px 0;
|
|
480
|
-
font-size: 16px;
|
|
481
|
-
font-weight: 600;
|
|
482
|
-
background: transparent;
|
|
483
|
-
color: inherit;
|
|
484
|
-
outline: none;
|
|
485
|
-
margin-bottom: 12px;
|
|
486
|
-
}
|
|
487
|
-
.torch-text-editor .cdx-chart-block__title-input::placeholder {
|
|
488
|
-
color: #999;
|
|
489
|
-
}
|
|
490
|
-
.torch-text-editor .cdx-chart-block__type-selector {
|
|
491
|
-
display: flex;
|
|
492
|
-
gap: 4px;
|
|
493
|
-
flex-wrap: wrap;
|
|
494
|
-
margin-bottom: 12px;
|
|
495
|
-
}
|
|
496
|
-
.torch-text-editor .cdx-chart-block__type-btn {
|
|
497
|
-
display: inline-flex;
|
|
498
|
-
align-items: center;
|
|
499
|
-
gap: 4px;
|
|
500
|
-
padding: 4px 10px;
|
|
501
|
-
border: 1px solid #ddd;
|
|
502
|
-
border-radius: 4px;
|
|
503
|
-
background: transparent;
|
|
504
|
-
color: inherit;
|
|
505
|
-
font-size: 12px;
|
|
506
|
-
cursor: pointer;
|
|
507
|
-
transition: all 200ms ease-in-out;
|
|
508
|
-
}
|
|
509
|
-
.torch-text-editor .cdx-chart-block__type-btn:hover {
|
|
510
|
-
background: rgba(0, 0, 0, 0.05);
|
|
511
|
-
}
|
|
512
|
-
.torch-text-editor .cdx-chart-block__type-btn--active {
|
|
513
|
-
background: rgba(54, 162, 235, 0.15);
|
|
514
|
-
border-color: rgb(54, 162, 235);
|
|
515
|
-
color: rgb(54, 162, 235);
|
|
516
|
-
}
|
|
517
|
-
.torch-text-editor .cdx-chart-block__table-wrapper {
|
|
518
|
-
overflow-x: auto;
|
|
519
|
-
margin-bottom: 12px;
|
|
520
|
-
border: 1px solid #e0e0e0;
|
|
521
|
-
border-radius: 6px;
|
|
522
|
-
}
|
|
523
|
-
.torch-text-editor .cdx-chart-block__table {
|
|
524
|
-
width: 100%;
|
|
525
|
-
border-collapse: collapse;
|
|
526
|
-
font-size: 13px;
|
|
527
|
-
}
|
|
528
|
-
.torch-text-editor .cdx-chart-block__table th,
|
|
529
|
-
.torch-text-editor .cdx-chart-block__table td {
|
|
530
|
-
border: 1px solid #e0e0e0;
|
|
531
|
-
padding: 4px 6px;
|
|
532
|
-
min-width: 80px;
|
|
533
|
-
}
|
|
534
|
-
.torch-text-editor .cdx-chart-block__corner-cell {
|
|
535
|
-
min-width: 100px;
|
|
536
|
-
width: 100px;
|
|
537
|
-
}
|
|
538
|
-
.torch-text-editor .cdx-chart-block__controls-header {
|
|
539
|
-
min-width: 60px;
|
|
540
|
-
width: 60px;
|
|
541
|
-
}
|
|
542
|
-
.torch-text-editor .cdx-chart-block__label-cell {
|
|
543
|
-
position: relative;
|
|
544
|
-
}
|
|
545
|
-
.torch-text-editor .cdx-chart-block__table input {
|
|
546
|
-
width: 100%;
|
|
547
|
-
border: none;
|
|
548
|
-
background: transparent;
|
|
549
|
-
color: inherit;
|
|
550
|
-
outline: none;
|
|
551
|
-
font-size: 13px;
|
|
552
|
-
padding: 2px;
|
|
553
|
-
}
|
|
554
|
-
.torch-text-editor .cdx-chart-block__table input[type="number"] {
|
|
555
|
-
text-align: center;
|
|
556
|
-
-moz-appearance: textfield;
|
|
557
|
-
}
|
|
558
|
-
.torch-text-editor .cdx-chart-block__table input[type="number"]::-webkit-inner-spin-button,
|
|
559
|
-
.torch-text-editor .cdx-chart-block__table input[type="number"]::-webkit-outer-spin-button {
|
|
560
|
-
-webkit-appearance: none;
|
|
561
|
-
margin: 0;
|
|
562
|
-
}
|
|
563
|
-
.torch-text-editor .cdx-chart-block__color-picker {
|
|
564
|
-
width: 24px;
|
|
565
|
-
height: 24px;
|
|
566
|
-
border: none;
|
|
567
|
-
cursor: pointer;
|
|
568
|
-
border-radius: 4px;
|
|
569
|
-
padding: 0;
|
|
570
|
-
}
|
|
571
|
-
.torch-text-editor .cdx-chart-block__dataset-controls {
|
|
572
|
-
display: flex;
|
|
573
|
-
align-items: center;
|
|
574
|
-
gap: 4px;
|
|
575
|
-
min-width: 60px;
|
|
576
|
-
}
|
|
577
|
-
.torch-text-editor .cdx-chart-block__remove-btn,
|
|
578
|
-
.torch-text-editor .cdx-chart-block__remove-col-btn {
|
|
579
|
-
background: none;
|
|
580
|
-
border: none;
|
|
581
|
-
color: #999;
|
|
582
|
-
cursor: pointer;
|
|
583
|
-
font-size: 14px;
|
|
584
|
-
padding: 2px 4px;
|
|
585
|
-
border-radius: 3px;
|
|
586
|
-
transition: all 200ms ease-in-out;
|
|
587
|
-
line-height: 1;
|
|
588
|
-
}
|
|
589
|
-
.torch-text-editor .cdx-chart-block__remove-btn:hover,
|
|
590
|
-
.torch-text-editor .cdx-chart-block__remove-col-btn:hover {
|
|
591
|
-
color: rgb(255, 99, 132);
|
|
592
|
-
background: rgba(255, 99, 132, 0.1);
|
|
593
|
-
}
|
|
594
|
-
.torch-text-editor .cdx-chart-block__remove-col-btn {
|
|
595
|
-
position: absolute;
|
|
596
|
-
top: 2px;
|
|
597
|
-
right: 2px;
|
|
598
|
-
font-size: 11px;
|
|
599
|
-
padding: 0 3px;
|
|
600
|
-
}
|
|
601
|
-
.torch-text-editor .cdx-chart-block__actions {
|
|
602
|
-
display: flex;
|
|
603
|
-
gap: 8px;
|
|
604
|
-
margin-bottom: 16px;
|
|
605
|
-
}
|
|
606
|
-
.torch-text-editor .cdx-chart-block__action-btn {
|
|
607
|
-
padding: 4px 12px;
|
|
608
|
-
border: 1px dashed #ccc;
|
|
609
|
-
border-radius: 4px;
|
|
610
|
-
background: transparent;
|
|
611
|
-
color: inherit;
|
|
612
|
-
font-size: 12px;
|
|
613
|
-
cursor: pointer;
|
|
614
|
-
transition: all 200ms ease-in-out;
|
|
615
|
-
}
|
|
616
|
-
.torch-text-editor .cdx-chart-block__action-btn:hover {
|
|
617
|
-
border-style: solid;
|
|
618
|
-
background: rgba(0, 0, 0, 0.03);
|
|
619
|
-
}
|
|
620
|
-
.torch-text-editor .cdx-chart-block__canvas-wrapper {
|
|
621
|
-
position: relative;
|
|
622
|
-
height: 350px;
|
|
623
|
-
width: 100%;
|
|
624
|
-
}
|
|
625
|
-
.torch-text-editor .cdx-chart-block__canvas-wrapper canvas {
|
|
626
|
-
width: 100% !important;
|
|
627
|
-
height: 100% !important;
|
|
628
|
-
}
|
|
629
|
-
.torch-text-editor .cdx-chart-block__title {
|
|
630
|
-
font-size: 16px;
|
|
631
|
-
font-weight: 600;
|
|
632
|
-
margin-bottom: 8px;
|
|
633
|
-
color: inherit;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
/* ── Chart Block: dark mode ── */
|
|
637
|
-
[data-theme="dark"] .cdx-chart-block__title-input,
|
|
638
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__title-input {
|
|
639
|
-
border-bottom-color: #3a3a3a;
|
|
640
|
-
}
|
|
641
|
-
[data-theme="dark"] .cdx-chart-block__title-input::placeholder,
|
|
642
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__title-input::placeholder {
|
|
643
|
-
color: #666;
|
|
644
|
-
}
|
|
645
|
-
[data-theme="dark"] .cdx-chart-block__type-btn,
|
|
646
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__type-btn {
|
|
647
|
-
border-color: #3a3a3a;
|
|
648
|
-
}
|
|
649
|
-
[data-theme="dark"] .cdx-chart-block__type-btn:hover,
|
|
650
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__type-btn:hover {
|
|
651
|
-
background: rgba(255, 255, 255, 0.08);
|
|
652
|
-
}
|
|
653
|
-
[data-theme="dark"] .cdx-chart-block__table-wrapper,
|
|
654
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__table-wrapper {
|
|
655
|
-
border-color: #3a3a3a;
|
|
656
|
-
}
|
|
657
|
-
[data-theme="dark"] .cdx-chart-block__table th,
|
|
658
|
-
[data-theme="dark"] .cdx-chart-block__table td,
|
|
659
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__table th,
|
|
660
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__table td {
|
|
661
|
-
border-color: #3a3a3a;
|
|
662
|
-
}
|
|
663
|
-
[data-theme="dark"] .cdx-chart-block__action-btn,
|
|
664
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__action-btn {
|
|
665
|
-
border-color: #3a3a3a;
|
|
666
|
-
}
|
|
667
|
-
[data-theme="dark"] .cdx-chart-block__action-btn:hover,
|
|
668
|
-
.torch-text-editor[data-theme="dark"] .cdx-chart-block__action-btn:hover {
|
|
669
|
-
background: rgba(255, 255, 255, 0.06);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/* ── Paste loading overlay ── */
|
|
673
|
-
.torch-text-editor__loading-overlay {
|
|
674
|
-
position: absolute;
|
|
675
|
-
inset: 0;
|
|
676
|
-
z-index: 10;
|
|
677
|
-
display: flex;
|
|
678
|
-
flex-direction: column;
|
|
679
|
-
align-items: center;
|
|
680
|
-
justify-content: center;
|
|
681
|
-
gap: 12px;
|
|
682
|
-
background: inherit;
|
|
683
|
-
opacity: 0.92;
|
|
684
|
-
border-radius: inherit;
|
|
685
|
-
pointer-events: all;
|
|
686
|
-
}
|
|
687
|
-
.torch-text-editor__loading-spinner {
|
|
688
|
-
width: 28px;
|
|
689
|
-
height: 28px;
|
|
690
|
-
border: 3px solid currentColor;
|
|
691
|
-
border-top-color: transparent;
|
|
692
|
-
border-radius: 50%;
|
|
693
|
-
animation: torch-editor-spin 0.7s linear infinite;
|
|
694
|
-
opacity: 0.6;
|
|
695
|
-
}
|
|
696
|
-
.torch-text-editor__loading-text {
|
|
697
|
-
font-size: 13px;
|
|
698
|
-
opacity: 0.6;
|
|
699
|
-
}
|
|
700
|
-
@keyframes torch-editor-spin {
|
|
701
|
-
to { transform: rotate(360deg); }
|
|
702
|
-
}
|
|
703
|
-
`;
|
|
704
|
-
|
|
705
|
-
// ─── CVA Styles ──────────────────────────────────────────────────────────────
|
|
706
|
-
const textEditorStyles = cva(
|
|
707
|
-
[
|
|
708
|
-
"relative w-full rounded-[6px]",
|
|
709
|
-
"border-0 transition-all duration-200 ease-in-out",
|
|
710
|
-
"[&_.codex-editor]:min-h-[inherit]",
|
|
711
|
-
// Content padding lives on the redactor (not the container) so the toolbar stays full-bleed.
|
|
712
|
-
"[&_.codex-editor__redactor]:min-h-[inherit] [&_.codex-editor__redactor]:px-[16px] [&_.codex-editor__redactor]:pt-[12px] [&_.codex-editor__redactor]:pb-[100px]",
|
|
713
|
-
"[&_.ce-paragraph]:typography-body-medium-regular",
|
|
714
|
-
],
|
|
715
|
-
{
|
|
716
|
-
variants: {
|
|
717
|
-
variant: {
|
|
718
|
-
PresentationStyle: [
|
|
719
|
-
"bg-background-presentation-form-field-primary",
|
|
720
|
-
"text-content-presentation-global-primary",
|
|
721
|
-
"[&_.codex-editor]:text-content-presentation-global-primary",
|
|
722
|
-
"[&_.ce-block--selected_.ce-block__content]:bg-background-presentation-action-hover",
|
|
723
|
-
"[&_.cdx-marker]:bg-background-presentation-state-warning-primary",
|
|
724
|
-
"[&_.ce-toolbar__settings-btn]:text-content-presentation-action-light-primary",
|
|
725
|
-
"[&_.ce-toolbar__plus]:text-content-presentation-action-light-primary",
|
|
726
|
-
"[&_.ce-toolbar__settings-btn:hover]:bg-background-presentation-action-hover",
|
|
727
|
-
"[&_.ce-toolbar__plus:hover]:bg-background-presentation-action-hover",
|
|
728
|
-
"[&_.ce-popover]:bg-background-presentation-form-field-primary",
|
|
729
|
-
"[&_.ce-popover]:border-border-presentation-action-primary",
|
|
730
|
-
"[&_.ce-popover__item]:text-content-presentation-action-light-primary",
|
|
731
|
-
"[&_.ce-popover__item:hover]:bg-background-presentation-action-hover",
|
|
732
|
-
"[&_.ce-inline-toolbar]:bg-background-presentation-form-field-primary",
|
|
733
|
-
"[&_.ce-inline-toolbar]:border-border-presentation-action-primary",
|
|
734
|
-
"[&_.ce-inline-toolbar__buttons_.ce-inline-tool]:text-content-presentation-action-light-primary",
|
|
735
|
-
"[&_.ce-code__textarea]:bg-background-presentation-action-secondary",
|
|
736
|
-
"[&_.ce-code__textarea]:text-content-presentation-global-primary",
|
|
737
|
-
"[&_.cdx-quote__text]:text-content-presentation-global-secondary",
|
|
738
|
-
"[&_.cdx-input]:border-border-presentation-action-primary",
|
|
739
|
-
"[&_.cdx-input]:text-content-presentation-global-primary",
|
|
740
|
-
"[&_.tc-cell]:text-content-presentation-global-primary",
|
|
741
|
-
"[&_.cdx-warning]:border-border-presentation-state-warning",
|
|
742
|
-
"[&_.cdx-warning__title]:text-content-presentation-global-primary",
|
|
743
|
-
"[&_.cdx-warning__message]:text-content-presentation-global-secondary",
|
|
744
|
-
"[&_.cdx-checklist__item-checkbox]:border-border-presentation-action-primary",
|
|
745
|
-
"[&_.ce-delimiter]:border-border-presentation-action-primary",
|
|
746
|
-
],
|
|
747
|
-
},
|
|
748
|
-
// No padding on the container — the fixed toolbar must go edge-to-edge. Content
|
|
749
|
-
// padding is applied to the EditorJS redactor below instead.
|
|
750
|
-
size: {
|
|
751
|
-
S: "min-h-[200px]",
|
|
752
|
-
M: "min-h-[300px]",
|
|
753
|
-
L: "min-h-[400px]",
|
|
754
|
-
XL: "min-h-[500px]",
|
|
755
|
-
},
|
|
756
|
-
disabled: {
|
|
757
|
-
true: "cursor-not-allowed opacity-60 pointer-events-none",
|
|
758
|
-
},
|
|
759
|
-
},
|
|
760
|
-
defaultVariants: {
|
|
761
|
-
variant: "PresentationStyle",
|
|
762
|
-
},
|
|
763
|
-
},
|
|
764
|
-
);
|
|
765
|
-
|
|
766
|
-
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
767
|
-
export interface TextEditorRef {
|
|
768
|
-
save: () => Promise<OutputData>;
|
|
769
|
-
clear: () => void;
|
|
770
|
-
render: (data: OutputData) => Promise<void>;
|
|
771
|
-
focus: (atEnd?: boolean) => boolean;
|
|
772
|
-
getInstance: () => EditorJS | null;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
interface TextEditorProps
|
|
776
|
-
extends Omit<HTMLAttributes<HTMLDivElement>, "onChange">, VariantProps<typeof textEditorStyles> {
|
|
777
|
-
theme?: Themes;
|
|
778
|
-
data?: OutputData;
|
|
779
|
-
onChange?: (data: OutputData) => void;
|
|
780
|
-
onReady?: () => void;
|
|
781
|
-
readOnly?: boolean;
|
|
782
|
-
placeholder?: string;
|
|
783
|
-
autofocus?: boolean;
|
|
784
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
785
|
-
tools?: Record<string, any>;
|
|
786
|
-
minHeight?: number;
|
|
787
|
-
/** Show the fixed formatting toolbar (default `true`; hidden when `readOnly`/`disabled`). */
|
|
788
|
-
toolbar?: boolean;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
// ─── Component ───────────────────────────────────────────────────────────────
|
|
792
|
-
export const TextEditor = forwardRef<TextEditorRef, TextEditorProps>(
|
|
793
|
-
(
|
|
794
|
-
{
|
|
795
|
-
className,
|
|
796
|
-
variant,
|
|
797
|
-
size,
|
|
798
|
-
disabled,
|
|
799
|
-
theme,
|
|
800
|
-
data,
|
|
801
|
-
onChange,
|
|
802
|
-
onReady,
|
|
803
|
-
readOnly = false,
|
|
804
|
-
placeholder = "Write something or press / to select a tool",
|
|
805
|
-
autofocus = false,
|
|
806
|
-
tools,
|
|
807
|
-
minHeight,
|
|
808
|
-
toolbar = true,
|
|
809
|
-
...props
|
|
810
|
-
},
|
|
811
|
-
ref,
|
|
812
|
-
) => {
|
|
813
|
-
const editorRef = useRef<EditorJS | null>(null);
|
|
814
|
-
const undoRef = useRef<Undo | null>(null);
|
|
815
|
-
const [toolbarReady, setToolbarReady] = useState(false);
|
|
816
|
-
const holderRef = useRef<HTMLDivElement>(null);
|
|
817
|
-
const observerRef = useRef<MutationObserver | null>(null);
|
|
818
|
-
const [holderId] = useState(() => `torch-editor-${Math.random().toString(36).substring(2, 9)}`);
|
|
819
|
-
const isInitializing = useRef(false);
|
|
820
|
-
const pasteHandlerRef = useRef<((e: ClipboardEvent) => void) | null>(null);
|
|
821
|
-
const saveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
822
|
-
const idleCallbackRef = useRef<number | null>(null);
|
|
823
|
-
const dirRafRef = useRef<number | null>(null);
|
|
824
|
-
const onChangeRef = useRef(onChange);
|
|
825
|
-
onChangeRef.current = onChange;
|
|
826
|
-
|
|
827
|
-
// Refs for initial-only config — changing these does NOT recreate the editor
|
|
828
|
-
const initialDataRef = useRef(data);
|
|
829
|
-
const toolsRef = useRef(tools);
|
|
830
|
-
const onReadyRef = useRef(onReady);
|
|
831
|
-
const readOnlyRef = useRef(readOnly);
|
|
832
|
-
const placeholderRef = useRef(placeholder);
|
|
833
|
-
const autofocusRef = useRef(autofocus);
|
|
834
|
-
|
|
835
|
-
// Keep refs up to date (but don't trigger re-init)
|
|
836
|
-
onReadyRef.current = onReady;
|
|
837
|
-
|
|
838
|
-
// Schedule save via requestIdleCallback so it runs when browser is idle
|
|
839
|
-
const scheduleIdleSave = useCallback(() => {
|
|
840
|
-
if (idleCallbackRef.current != null) {
|
|
841
|
-
(window.cancelIdleCallback || clearTimeout)(idleCallbackRef.current);
|
|
842
|
-
}
|
|
843
|
-
const doSave = async () => {
|
|
844
|
-
idleCallbackRef.current = null;
|
|
845
|
-
if (!editorRef.current || !onChangeRef.current) return;
|
|
846
|
-
try {
|
|
847
|
-
const savedData = await editorRef.current.save();
|
|
848
|
-
onChangeRef.current(savedData);
|
|
849
|
-
} catch {
|
|
850
|
-
// Editor may have been destroyed
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
if (typeof window.requestIdleCallback === "function") {
|
|
854
|
-
idleCallbackRef.current = window.requestIdleCallback(() => doSave(), { timeout: 2000 });
|
|
855
|
-
} else {
|
|
856
|
-
// Fallback for browsers without requestIdleCallback
|
|
857
|
-
idleCallbackRef.current = window.setTimeout(() => doSave(), 100) as unknown as number;
|
|
858
|
-
}
|
|
859
|
-
}, []);
|
|
860
|
-
|
|
861
|
-
// ── Markdown paste handler ──
|
|
862
|
-
const setupMarkdownPaste = useCallback((holderEl: HTMLElement) => {
|
|
863
|
-
const handler = async (e: ClipboardEvent) => {
|
|
864
|
-
if (readOnlyRef.current || !editorRef.current) return;
|
|
865
|
-
|
|
866
|
-
const plain = e.clipboardData?.getData("text/plain") || "";
|
|
867
|
-
|
|
868
|
-
// Only intercept if the plain text is markdown
|
|
869
|
-
if (!isMarkdown(plain)) return;
|
|
870
|
-
|
|
871
|
-
e.preventDefault();
|
|
872
|
-
e.stopPropagation();
|
|
873
|
-
|
|
874
|
-
const parsedBlocks = parseMarkdownToBlocks(plain);
|
|
875
|
-
if (parsedBlocks.length === 0) return;
|
|
876
|
-
|
|
877
|
-
const editor = editorRef.current;
|
|
878
|
-
|
|
879
|
-
// Save existing content, merge new blocks at cursor, render once
|
|
880
|
-
// This avoids per-block insert which freezes the editor on large pastes
|
|
881
|
-
try {
|
|
882
|
-
const existingData = await editor.save();
|
|
883
|
-
const existingBlocks = existingData.blocks || [];
|
|
884
|
-
|
|
885
|
-
// Determine insertion point
|
|
886
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
887
|
-
const blocks = (editor as any).blocks;
|
|
888
|
-
let insertIdx = existingBlocks.length;
|
|
889
|
-
try {
|
|
890
|
-
if (blocks?.getCurrentBlockIndex) {
|
|
891
|
-
insertIdx = blocks.getCurrentBlockIndex() + 1;
|
|
892
|
-
}
|
|
893
|
-
} catch {
|
|
894
|
-
// Use end of document
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
// Convert parsed blocks to OutputData block format
|
|
898
|
-
const newBlocks = parsedBlocks.map((block) => ({
|
|
899
|
-
type: block.type,
|
|
900
|
-
data: block.data,
|
|
901
|
-
}));
|
|
902
|
-
|
|
903
|
-
// Remove empty paragraph at cursor if it's the only content there
|
|
904
|
-
const filteredExisting = [...existingBlocks];
|
|
905
|
-
if (insertIdx > 0) {
|
|
906
|
-
const cursorBlock = filteredExisting[insertIdx - 1];
|
|
907
|
-
if (
|
|
908
|
-
cursorBlock &&
|
|
909
|
-
cursorBlock.type === "paragraph" &&
|
|
910
|
-
(!cursorBlock.data.text ||
|
|
911
|
-
cursorBlock.data.text.trim() === "" ||
|
|
912
|
-
cursorBlock.data.text === "<br>")
|
|
913
|
-
) {
|
|
914
|
-
filteredExisting.splice(insertIdx - 1, 1);
|
|
915
|
-
insertIdx = Math.max(0, insertIdx - 1);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// Merge: existing blocks before cursor + new blocks + existing blocks after cursor
|
|
920
|
-
const mergedBlocks = [
|
|
921
|
-
...filteredExisting.slice(0, insertIdx),
|
|
922
|
-
...newBlocks,
|
|
923
|
-
...filteredExisting.slice(insertIdx),
|
|
924
|
-
];
|
|
925
|
-
|
|
926
|
-
// Pause MutationObserver during bulk render to prevent O(n^2) direction checks
|
|
927
|
-
observerRef.current?.disconnect();
|
|
928
|
-
|
|
929
|
-
// Single render pass — no per-block DOM thrashing
|
|
930
|
-
await editor.render({
|
|
931
|
-
time: Date.now(),
|
|
932
|
-
version: existingData.version,
|
|
933
|
-
blocks: mergedBlocks,
|
|
934
|
-
});
|
|
935
|
-
|
|
936
|
-
// Reconnect observer on the redactor element
|
|
937
|
-
if (observerRef.current) {
|
|
938
|
-
const redactor = holderEl.querySelector(".codex-editor__redactor") || holderEl;
|
|
939
|
-
observerRef.current.observe(redactor, {
|
|
940
|
-
childList: true,
|
|
941
|
-
subtree: false,
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
// Defer direction scan to next frame — let the browser paint first
|
|
945
|
-
requestAnimationFrame(() => applyAutoDirection(holderEl));
|
|
946
|
-
|
|
947
|
-
// Trigger onChange with merged data
|
|
948
|
-
if (onChangeRef.current) {
|
|
949
|
-
const savedData = await editor.save();
|
|
950
|
-
onChangeRef.current(savedData);
|
|
951
|
-
}
|
|
952
|
-
} catch {
|
|
953
|
-
// Fallback: if render approach fails, do nothing rather than freeze
|
|
954
|
-
}
|
|
955
|
-
};
|
|
956
|
-
|
|
957
|
-
holderEl.addEventListener("paste", handler as unknown as EventListener, true);
|
|
958
|
-
pasteHandlerRef.current = handler;
|
|
959
|
-
}, []);
|
|
960
|
-
|
|
961
|
-
// ── Auto-direction: watch for DOM changes & input ──
|
|
962
|
-
const inputHandlerRef = useRef<((e: Event) => void) | null>(null);
|
|
963
|
-
|
|
964
|
-
const setupAutoDirection = useCallback((holderEl: HTMLElement) => {
|
|
965
|
-
// Apply direction to all existing blocks once on init
|
|
966
|
-
applyAutoDirection(holderEl);
|
|
967
|
-
|
|
968
|
-
// On input: batch direction check to next animation frame (non-blocking)
|
|
969
|
-
let pendingBlock: HTMLElement | null = null;
|
|
970
|
-
const inputHandler = (e: Event) => {
|
|
971
|
-
const target = e.target as HTMLElement;
|
|
972
|
-
const block = target.closest<HTMLElement>(".ce-block");
|
|
973
|
-
if (!block) return;
|
|
974
|
-
pendingBlock = block;
|
|
975
|
-
if (dirRafRef.current === null) {
|
|
976
|
-
dirRafRef.current = requestAnimationFrame(() => {
|
|
977
|
-
dirRafRef.current = null;
|
|
978
|
-
if (pendingBlock) {
|
|
979
|
-
applyDirectionToBlock(pendingBlock);
|
|
980
|
-
pendingBlock = null;
|
|
981
|
-
}
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
};
|
|
985
|
-
holderEl.addEventListener("input", inputHandler);
|
|
986
|
-
inputHandlerRef.current = inputHandler;
|
|
987
|
-
|
|
988
|
-
// Watch for block additions/removals — only process NEW blocks (O(1) per mutation)
|
|
989
|
-
const redactor = holderEl.querySelector(".codex-editor__redactor") || holderEl;
|
|
990
|
-
observerRef.current = new MutationObserver((mutations) => {
|
|
991
|
-
for (const mutation of mutations) {
|
|
992
|
-
mutation.addedNodes.forEach((node) => {
|
|
993
|
-
if (node instanceof HTMLElement && node.classList.contains("ce-block")) {
|
|
994
|
-
applyDirectionToBlock(node);
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
observerRef.current.observe(redactor, {
|
|
1000
|
-
childList: true,
|
|
1001
|
-
subtree: false,
|
|
1002
|
-
});
|
|
1003
|
-
}, []);
|
|
1004
|
-
|
|
1005
|
-
const initEditor = useCallback(() => {
|
|
1006
|
-
if (isInitializing.current || editorRef.current) return;
|
|
1007
|
-
isInitializing.current = true;
|
|
1008
|
-
|
|
1009
|
-
// Only enable the `align` tune when using the default tools (a caller-supplied `tools`
|
|
1010
|
-
// map may not register it).
|
|
1011
|
-
const usingDefaultTools = !toolsRef.current;
|
|
1012
|
-
const editor = new EditorJS({
|
|
1013
|
-
holder: holderId,
|
|
1014
|
-
tools: toolsRef.current ?? getDefaultTools(),
|
|
1015
|
-
tunes: usingDefaultTools ? ["textVariant", "align"] : ["textVariant"],
|
|
1016
|
-
data: initialDataRef.current || undefined,
|
|
1017
|
-
readOnly: readOnlyRef.current,
|
|
1018
|
-
placeholder: placeholderRef.current,
|
|
1019
|
-
autofocus: autofocusRef.current,
|
|
1020
|
-
onReady: () => {
|
|
1021
|
-
isInitializing.current = false;
|
|
1022
|
-
|
|
1023
|
-
// Set up auto-direction and markdown paste after editor is ready
|
|
1024
|
-
const holderEl = document.getElementById(holderId);
|
|
1025
|
-
if (holderEl) {
|
|
1026
|
-
setupAutoDirection(holderEl);
|
|
1027
|
-
setupMarkdownPaste(holderEl);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
// History (undo/redo) for the fixed toolbar + Ctrl+Z/Y. Not for readOnly.
|
|
1031
|
-
// Dynamically imported because the package evaluates DOM globals at module load.
|
|
1032
|
-
if (!readOnlyRef.current) {
|
|
1033
|
-
import("editorjs-undo")
|
|
1034
|
-
.then(({ default: UndoCls }) => {
|
|
1035
|
-
if (!editorRef.current) return;
|
|
1036
|
-
undoRef.current = new UndoCls({ editor: editorRef.current });
|
|
1037
|
-
if (initialDataRef.current) undoRef.current.initialize(initialDataRef.current);
|
|
1038
|
-
})
|
|
1039
|
-
.catch(() => {
|
|
1040
|
-
undoRef.current = null;
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
setToolbarReady(true);
|
|
1044
|
-
|
|
1045
|
-
onReadyRef.current?.();
|
|
1046
|
-
},
|
|
1047
|
-
onChange: () => {
|
|
1048
|
-
// Debounce + idle-schedule: wait for typing to pause, then save when browser is idle
|
|
1049
|
-
if (!onChangeRef.current) return;
|
|
1050
|
-
if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
|
|
1051
|
-
saveTimerRef.current = setTimeout(scheduleIdleSave, 500);
|
|
1052
|
-
},
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
editorRef.current = editor;
|
|
1056
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1057
|
-
}, [holderId, setupAutoDirection, setupMarkdownPaste, scheduleIdleSave]);
|
|
1058
|
-
|
|
1059
|
-
useEffect(() => {
|
|
1060
|
-
initEditor();
|
|
1061
|
-
|
|
1062
|
-
return () => {
|
|
1063
|
-
const holderEl = document.getElementById(holderId);
|
|
1064
|
-
|
|
1065
|
-
// Clean up markdown paste handler
|
|
1066
|
-
if (pasteHandlerRef.current && holderEl) {
|
|
1067
|
-
holderEl.removeEventListener(
|
|
1068
|
-
"paste",
|
|
1069
|
-
pasteHandlerRef.current as unknown as EventListener,
|
|
1070
|
-
true,
|
|
1071
|
-
);
|
|
1072
|
-
pasteHandlerRef.current = null;
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
// Clean up input direction handler
|
|
1076
|
-
if (inputHandlerRef.current && holderEl) {
|
|
1077
|
-
holderEl.removeEventListener("input", inputHandlerRef.current);
|
|
1078
|
-
inputHandlerRef.current = null;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
observerRef.current?.disconnect();
|
|
1082
|
-
observerRef.current = null;
|
|
1083
|
-
|
|
1084
|
-
if (dirRafRef.current) cancelAnimationFrame(dirRafRef.current);
|
|
1085
|
-
if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
|
|
1086
|
-
if (idleCallbackRef.current != null) {
|
|
1087
|
-
(window.cancelIdleCallback || clearTimeout)(idleCallbackRef.current);
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
if (editorRef.current && typeof editorRef.current.destroy === "function") {
|
|
1091
|
-
editorRef.current.destroy();
|
|
1092
|
-
editorRef.current = null;
|
|
1093
|
-
}
|
|
1094
|
-
undoRef.current = null;
|
|
1095
|
-
setToolbarReady(false);
|
|
1096
|
-
isInitializing.current = false;
|
|
1097
|
-
};
|
|
1098
|
-
}, [initEditor]);
|
|
1099
|
-
|
|
1100
|
-
// Handle readOnly changes without recreating the editor
|
|
1101
|
-
useEffect(() => {
|
|
1102
|
-
if (editorRef.current && editorRef.current.readOnly) {
|
|
1103
|
-
try {
|
|
1104
|
-
editorRef.current.readOnly.toggle(readOnly);
|
|
1105
|
-
} catch {
|
|
1106
|
-
// Editor may not be ready yet
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
}, [readOnly]);
|
|
1110
|
-
|
|
1111
|
-
useImperativeHandle(ref, () => ({
|
|
1112
|
-
save: async () => {
|
|
1113
|
-
if (!editorRef.current) throw new Error("Editor not initialized");
|
|
1114
|
-
return editorRef.current.save();
|
|
1115
|
-
},
|
|
1116
|
-
clear: () => {
|
|
1117
|
-
editorRef.current?.clear();
|
|
1118
|
-
},
|
|
1119
|
-
render: async (renderData: OutputData) => {
|
|
1120
|
-
if (!editorRef.current) throw new Error("Editor not initialized");
|
|
1121
|
-
return editorRef.current.render(renderData);
|
|
1122
|
-
},
|
|
1123
|
-
focus: (atEnd?: boolean) => {
|
|
1124
|
-
if (!editorRef.current) return false;
|
|
1125
|
-
return editorRef.current.focus(atEnd);
|
|
1126
|
-
},
|
|
1127
|
-
getInstance: () => editorRef.current,
|
|
1128
|
-
}));
|
|
1129
|
-
|
|
1130
|
-
return (
|
|
1131
|
-
<>
|
|
1132
|
-
<style>{AUTO_DIR_STYLES}</style>
|
|
1133
|
-
<div
|
|
1134
|
-
ref={holderRef}
|
|
1135
|
-
data-theme={theme}
|
|
1136
|
-
spellCheck={false}
|
|
1137
|
-
translate="no"
|
|
1138
|
-
className={cn(
|
|
1139
|
-
"torch-text-editor",
|
|
1140
|
-
textEditorStyles({ variant, size, disabled }),
|
|
1141
|
-
className,
|
|
1142
|
-
)}
|
|
1143
|
-
style={minHeight ? { minHeight: `${minHeight}px` } : undefined}
|
|
1144
|
-
{...props}
|
|
1145
|
-
>
|
|
1146
|
-
{toolbar && !readOnly && !disabled && (
|
|
1147
|
-
<TextEditorToolbar
|
|
1148
|
-
editorRef={editorRef}
|
|
1149
|
-
undoRef={undoRef}
|
|
1150
|
-
holderRef={holderRef}
|
|
1151
|
-
ready={toolbarReady}
|
|
1152
|
-
theme={theme}
|
|
1153
|
-
/>
|
|
1154
|
-
)}
|
|
1155
|
-
<div id={holderId} />
|
|
1156
|
-
</div>
|
|
1157
|
-
</>
|
|
1158
|
-
);
|
|
1159
|
-
},
|
|
1160
|
-
);
|
|
1161
|
-
|
|
1162
|
-
TextEditor.displayName = "TextEditor";
|
|
1163
|
-
|
|
1164
|
-
export type { TextEditorProps, OutputData };
|