torch-glare 2.5.5 → 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 -338
- package/apps/lib/components/Breadcrumb.tsx +0 -280
- package/apps/lib/components/Button.tsx +0 -317
- 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 -383
- 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 -84
- 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 -63
- package/apps/lib/components/DataViews/states.tsx +0 -38
- 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 -420
- package/apps/lib/components/DropdownMenu.tsx +0 -540
- package/apps/lib/components/FieldHint.tsx +0 -69
- package/apps/lib/components/Form.tsx +0 -182
- package/apps/lib/components/FormBuilder/context.ts +0 -73
- 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 -163
- 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 -91
- 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 -47
- package/apps/lib/components/FormBuilder/types.ts +0 -311
- package/apps/lib/components/FormRenderer/FormDrawer.tsx +0 -128
- package/apps/lib/components/FormRenderer/detail.tsx +0 -207
- package/apps/lib/components/FormRenderer/form-renderer.tsx +0 -297
- package/apps/lib/components/FormRenderer/header.tsx +0 -88
- package/apps/lib/components/FormRenderer/index.ts +0 -15
- package/apps/lib/components/FormRenderer/section.tsx +0 -39
- package/apps/lib/components/FormRenderer/stepper.tsx +0 -339
- package/apps/lib/components/FormRenderer/types.ts +0 -78
- 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 -147
- 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 -253
- 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 -610
- 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 -58
- package/apps/lib/hooks/useClickOutside.ts +0 -27
- package/apps/lib/hooks/useDragDrop.tsx +0 -365
- 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 -214
- 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 -1201
- 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/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 -712
- 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 -1495
- package/docs/components/data-views/migration.md +0 -79
- 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 -276
- package/docs/components/form-renderer.md +0 -326
- 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 -477
- 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 -54
- 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 -1500
- 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 -704
- 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,676 +0,0 @@
|
|
|
1
|
-
import { Chart, registerables } from "chart.js";
|
|
2
|
-
|
|
3
|
-
Chart.register(...registerables);
|
|
4
|
-
|
|
5
|
-
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
6
|
-
export interface ChartBlockData {
|
|
7
|
-
chartType: "bar" | "line" | "pie" | "doughnut" | "radar" | "polarArea";
|
|
8
|
-
title: string;
|
|
9
|
-
labels: string[];
|
|
10
|
-
datasets: Array<{
|
|
11
|
-
label: string;
|
|
12
|
-
data: number[];
|
|
13
|
-
backgroundColor: string;
|
|
14
|
-
borderColor: string;
|
|
15
|
-
}>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface ChartBlockConstructorOptions {
|
|
19
|
-
data: Partial<ChartBlockData>;
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
api: any;
|
|
22
|
-
readOnly: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// ─── Constants ──────────────────────────────────────────────────────────────
|
|
26
|
-
const CHART_TYPES: Array<{
|
|
27
|
-
value: ChartBlockData["chartType"];
|
|
28
|
-
label: string;
|
|
29
|
-
icon: string;
|
|
30
|
-
}> = [
|
|
31
|
-
{
|
|
32
|
-
value: "bar",
|
|
33
|
-
label: "Bar",
|
|
34
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="12" width="4" height="9" rx="1"/><rect x="10" y="7" width="4" height="14" rx="1"/><rect x="17" y="3" width="4" height="18" rx="1"/></svg>',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
value: "line",
|
|
38
|
-
label: "Line",
|
|
39
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 17 9 11 13 15 21 7"/><polyline points="17 7 21 7 21 11"/></svg>',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
value: "pie",
|
|
43
|
-
label: "Pie",
|
|
44
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12a9 9 0 1 1-9-9"/><path d="M21 12H12V3a9 9 0 0 1 9 9z"/></svg>',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
value: "doughnut",
|
|
48
|
-
label: "Doughnut",
|
|
49
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="4"/><path d="M12 3v4"/></svg>',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
value: "radar",
|
|
53
|
-
label: "Radar",
|
|
54
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 22 8.5 22 15.5 12 22 2 15.5 2 8.5"/><polygon points="12 6 18 9.5 18 14.5 12 18 6 14.5 6 9.5"/></svg>',
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
value: "polarArea",
|
|
58
|
-
label: "Polar",
|
|
59
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"/><line x1="12" y1="3" x2="12" y2="21"/><line x1="3" y1="12" x2="21" y2="12"/></svg>',
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
const COLOR_PALETTE = [
|
|
64
|
-
{ bg: "rgba(54, 162, 235, 0.5)", border: "rgb(54, 162, 235)" },
|
|
65
|
-
{ bg: "rgba(255, 99, 132, 0.5)", border: "rgb(255, 99, 132)" },
|
|
66
|
-
{ bg: "rgba(75, 192, 192, 0.5)", border: "rgb(75, 192, 192)" },
|
|
67
|
-
{ bg: "rgba(255, 205, 86, 0.5)", border: "rgb(255, 205, 86)" },
|
|
68
|
-
{ bg: "rgba(153, 102, 255, 0.5)", border: "rgb(153, 102, 255)" },
|
|
69
|
-
{ bg: "rgba(255, 159, 64, 0.5)", border: "rgb(255, 159, 64)" },
|
|
70
|
-
{ bg: "rgba(201, 203, 207, 0.5)", border: "rgb(201, 203, 207)" },
|
|
71
|
-
{ bg: "rgba(46, 204, 113, 0.5)", border: "rgb(46, 204, 113)" },
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
const DEFAULT_DATA: ChartBlockData = {
|
|
75
|
-
chartType: "bar",
|
|
76
|
-
title: "",
|
|
77
|
-
labels: ["Label 1", "Label 2", "Label 3"],
|
|
78
|
-
datasets: [
|
|
79
|
-
{
|
|
80
|
-
label: "Dataset 1",
|
|
81
|
-
data: [10, 20, 30],
|
|
82
|
-
backgroundColor: COLOR_PALETTE[0].bg,
|
|
83
|
-
borderColor: COLOR_PALETTE[0].border,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const TOOLBOX_ICON =
|
|
89
|
-
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="12" width="4" height="9" rx="1"/><rect x="10" y="7" width="4" height="14" rx="1"/><rect x="17" y="3" width="4" height="18" rx="1"/></svg>';
|
|
90
|
-
|
|
91
|
-
// ─── ChartBlockTool ─────────────────────────────────────────────────────────
|
|
92
|
-
export default class ChartBlockTool {
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
private api: any;
|
|
95
|
-
private readOnly: boolean;
|
|
96
|
-
private data: ChartBlockData;
|
|
97
|
-
private chart: Chart | null = null;
|
|
98
|
-
private wrapper: HTMLDivElement | null = null;
|
|
99
|
-
private canvas: HTMLCanvasElement | null = null;
|
|
100
|
-
private tableWrapper: HTMLDivElement | null = null;
|
|
101
|
-
private editorPanel: HTMLDivElement | null = null;
|
|
102
|
-
private updateTimeout: number | null = null;
|
|
103
|
-
private boundOnClickOutside: ((e: MouseEvent) => void) | null = null;
|
|
104
|
-
|
|
105
|
-
static get isReadOnlySupported(): boolean {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
static get toolbox(): { title: string; icon: string } {
|
|
110
|
-
return { title: "Chart", icon: TOOLBOX_ICON };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
constructor({ data, api, readOnly }: ChartBlockConstructorOptions) {
|
|
114
|
-
this.api = api;
|
|
115
|
-
this.readOnly = readOnly;
|
|
116
|
-
this.data = this.normalizeData(data);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// ─── Lifecycle ──────────────────────────────────────────────────────────────
|
|
120
|
-
|
|
121
|
-
render(): HTMLElement {
|
|
122
|
-
this.wrapper = document.createElement("div");
|
|
123
|
-
this.wrapper.classList.add("cdx-chart-block");
|
|
124
|
-
|
|
125
|
-
if (this.readOnly) {
|
|
126
|
-
this.buildReadOnlyUI();
|
|
127
|
-
} else {
|
|
128
|
-
this.buildEditUI();
|
|
129
|
-
|
|
130
|
-
// Start collapsed — show only the chart
|
|
131
|
-
if (this.editorPanel) {
|
|
132
|
-
this.editorPanel.classList.add("cdx-chart-block__editor-panel--hidden");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Click on the block → expand editing panel
|
|
136
|
-
this.wrapper.addEventListener("click", () => {
|
|
137
|
-
if (
|
|
138
|
-
this.editorPanel &&
|
|
139
|
-
this.editorPanel.classList.contains("cdx-chart-block__editor-panel--hidden")
|
|
140
|
-
) {
|
|
141
|
-
this.editorPanel.classList.remove("cdx-chart-block__editor-panel--hidden");
|
|
142
|
-
// Re-create chart since canvas may have been resized
|
|
143
|
-
this.createChart();
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
// Click outside → collapse
|
|
148
|
-
this.boundOnClickOutside = (e: MouseEvent) => {
|
|
149
|
-
if (this.wrapper && this.editorPanel && !this.wrapper.contains(e.target as Node)) {
|
|
150
|
-
this.editorPanel.classList.add("cdx-chart-block__editor-panel--hidden");
|
|
151
|
-
// Re-create chart to fit new size
|
|
152
|
-
this.createChart();
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
document.addEventListener("click", this.boundOnClickOutside);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Defer chart creation until DOM is mounted
|
|
159
|
-
requestAnimationFrame(() => this.createChart());
|
|
160
|
-
|
|
161
|
-
return this.wrapper;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
save(): ChartBlockData {
|
|
165
|
-
return {
|
|
166
|
-
chartType: this.data.chartType,
|
|
167
|
-
title: this.data.title,
|
|
168
|
-
labels: [...this.data.labels],
|
|
169
|
-
datasets: this.data.datasets.map((ds) => ({
|
|
170
|
-
label: ds.label,
|
|
171
|
-
data: [...ds.data],
|
|
172
|
-
backgroundColor: ds.backgroundColor,
|
|
173
|
-
borderColor: ds.borderColor,
|
|
174
|
-
})),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
validate(savedData: ChartBlockData): boolean {
|
|
179
|
-
return (
|
|
180
|
-
Array.isArray(savedData.labels) &&
|
|
181
|
-
savedData.labels.length > 0 &&
|
|
182
|
-
Array.isArray(savedData.datasets) &&
|
|
183
|
-
savedData.datasets.length > 0
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
destroy(): void {
|
|
188
|
-
if (this.updateTimeout !== null) {
|
|
189
|
-
clearTimeout(this.updateTimeout);
|
|
190
|
-
this.updateTimeout = null;
|
|
191
|
-
}
|
|
192
|
-
if (this.chart) {
|
|
193
|
-
this.chart.destroy();
|
|
194
|
-
this.chart = null;
|
|
195
|
-
}
|
|
196
|
-
if (this.boundOnClickOutside) {
|
|
197
|
-
document.removeEventListener("click", this.boundOnClickOutside);
|
|
198
|
-
this.boundOnClickOutside = null;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
renderSettings() {
|
|
203
|
-
return CHART_TYPES.map((type) => ({
|
|
204
|
-
icon: type.icon,
|
|
205
|
-
label: type.label,
|
|
206
|
-
isActive: this.data.chartType === type.value,
|
|
207
|
-
closeOnActivate: true,
|
|
208
|
-
onActivate: () => {
|
|
209
|
-
this.data.chartType = type.value;
|
|
210
|
-
this.updateTypeSelector();
|
|
211
|
-
this.createChart();
|
|
212
|
-
},
|
|
213
|
-
}));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// ─── UI Builders ────────────────────────────────────────────────────────────
|
|
217
|
-
|
|
218
|
-
private buildReadOnlyUI(): void {
|
|
219
|
-
if (!this.wrapper) return;
|
|
220
|
-
|
|
221
|
-
if (this.data.title) {
|
|
222
|
-
const title = document.createElement("div");
|
|
223
|
-
title.className = "cdx-chart-block__title";
|
|
224
|
-
title.textContent = this.data.title;
|
|
225
|
-
this.wrapper.appendChild(title);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
this.appendCanvas();
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private buildEditUI(): void {
|
|
232
|
-
if (!this.wrapper) return;
|
|
233
|
-
|
|
234
|
-
// Editor panel — all editing controls wrapped in a collapsible container
|
|
235
|
-
this.editorPanel = document.createElement("div");
|
|
236
|
-
this.editorPanel.className = "cdx-chart-block__editor-panel";
|
|
237
|
-
|
|
238
|
-
// Title input
|
|
239
|
-
const titleInput = document.createElement("input");
|
|
240
|
-
titleInput.type = "text";
|
|
241
|
-
titleInput.className = "cdx-chart-block__title-input";
|
|
242
|
-
titleInput.placeholder = "Chart title (optional)";
|
|
243
|
-
titleInput.value = this.data.title;
|
|
244
|
-
titleInput.addEventListener("input", () => {
|
|
245
|
-
this.data.title = titleInput.value;
|
|
246
|
-
this.scheduleChartUpdate();
|
|
247
|
-
});
|
|
248
|
-
this.editorPanel.appendChild(titleInput);
|
|
249
|
-
|
|
250
|
-
// Chart type selector
|
|
251
|
-
const typeSelector = document.createElement("div");
|
|
252
|
-
typeSelector.className = "cdx-chart-block__type-selector";
|
|
253
|
-
|
|
254
|
-
CHART_TYPES.forEach((type) => {
|
|
255
|
-
const btn = document.createElement("button");
|
|
256
|
-
btn.type = "button";
|
|
257
|
-
btn.className = "cdx-chart-block__type-btn";
|
|
258
|
-
btn.dataset.chartType = type.value;
|
|
259
|
-
if (this.data.chartType === type.value) {
|
|
260
|
-
btn.classList.add("cdx-chart-block__type-btn--active");
|
|
261
|
-
}
|
|
262
|
-
btn.innerHTML = `${type.icon} ${type.label}`;
|
|
263
|
-
btn.addEventListener("click", () => {
|
|
264
|
-
this.data.chartType = type.value;
|
|
265
|
-
this.updateTypeSelector();
|
|
266
|
-
this.createChart();
|
|
267
|
-
});
|
|
268
|
-
typeSelector.appendChild(btn);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
this.editorPanel.appendChild(typeSelector);
|
|
272
|
-
|
|
273
|
-
// Data table
|
|
274
|
-
this.tableWrapper = document.createElement("div");
|
|
275
|
-
this.tableWrapper.className = "cdx-chart-block__table-wrapper";
|
|
276
|
-
this.editorPanel.appendChild(this.tableWrapper);
|
|
277
|
-
this.rebuildDataTable();
|
|
278
|
-
|
|
279
|
-
// Action buttons
|
|
280
|
-
const actions = document.createElement("div");
|
|
281
|
-
actions.className = "cdx-chart-block__actions";
|
|
282
|
-
|
|
283
|
-
const addLabelBtn = document.createElement("button");
|
|
284
|
-
addLabelBtn.type = "button";
|
|
285
|
-
addLabelBtn.className = "cdx-chart-block__action-btn";
|
|
286
|
-
addLabelBtn.textContent = "+ Add Label";
|
|
287
|
-
addLabelBtn.addEventListener("click", () => this.addLabel());
|
|
288
|
-
|
|
289
|
-
const addDatasetBtn = document.createElement("button");
|
|
290
|
-
addDatasetBtn.type = "button";
|
|
291
|
-
addDatasetBtn.className = "cdx-chart-block__action-btn";
|
|
292
|
-
addDatasetBtn.textContent = "+ Add Dataset";
|
|
293
|
-
addDatasetBtn.addEventListener("click", () => this.addDataset());
|
|
294
|
-
|
|
295
|
-
actions.appendChild(addLabelBtn);
|
|
296
|
-
actions.appendChild(addDatasetBtn);
|
|
297
|
-
this.editorPanel.appendChild(actions);
|
|
298
|
-
|
|
299
|
-
this.wrapper.appendChild(this.editorPanel);
|
|
300
|
-
|
|
301
|
-
// Canvas — always visible, outside the editor panel
|
|
302
|
-
this.appendCanvas();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
private appendCanvas(): void {
|
|
306
|
-
if (!this.wrapper) return;
|
|
307
|
-
|
|
308
|
-
const canvasWrapper = document.createElement("div");
|
|
309
|
-
canvasWrapper.className = "cdx-chart-block__canvas-wrapper";
|
|
310
|
-
|
|
311
|
-
this.canvas = document.createElement("canvas");
|
|
312
|
-
canvasWrapper.appendChild(this.canvas);
|
|
313
|
-
this.wrapper.appendChild(canvasWrapper);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// ─── Data Table ─────────────────────────────────────────────────────────────
|
|
317
|
-
|
|
318
|
-
private rebuildDataTable(): void {
|
|
319
|
-
if (!this.tableWrapper) return;
|
|
320
|
-
this.tableWrapper.innerHTML = "";
|
|
321
|
-
|
|
322
|
-
const table = document.createElement("table");
|
|
323
|
-
table.className = "cdx-chart-block__table";
|
|
324
|
-
|
|
325
|
-
// Header row: corner + label inputs + empty controls column
|
|
326
|
-
const thead = document.createElement("thead");
|
|
327
|
-
const headerRow = document.createElement("tr");
|
|
328
|
-
|
|
329
|
-
// Corner cell
|
|
330
|
-
const corner = document.createElement("th");
|
|
331
|
-
corner.className = "cdx-chart-block__corner-cell";
|
|
332
|
-
headerRow.appendChild(corner);
|
|
333
|
-
|
|
334
|
-
// Label cells
|
|
335
|
-
this.data.labels.forEach((label, colIdx) => {
|
|
336
|
-
const th = document.createElement("th");
|
|
337
|
-
th.className = "cdx-chart-block__label-cell";
|
|
338
|
-
|
|
339
|
-
const labelInput = document.createElement("input");
|
|
340
|
-
labelInput.type = "text";
|
|
341
|
-
labelInput.className = "cdx-chart-block__label-input";
|
|
342
|
-
labelInput.value = label;
|
|
343
|
-
labelInput.addEventListener("input", () => {
|
|
344
|
-
this.data.labels[colIdx] = labelInput.value;
|
|
345
|
-
this.scheduleChartUpdate();
|
|
346
|
-
});
|
|
347
|
-
th.appendChild(labelInput);
|
|
348
|
-
|
|
349
|
-
if (this.data.labels.length > 1) {
|
|
350
|
-
const removeBtn = document.createElement("button");
|
|
351
|
-
removeBtn.type = "button";
|
|
352
|
-
removeBtn.className = "cdx-chart-block__remove-col-btn";
|
|
353
|
-
removeBtn.innerHTML = "×";
|
|
354
|
-
removeBtn.title = "Remove label";
|
|
355
|
-
removeBtn.addEventListener("click", () => this.removeLabel(colIdx));
|
|
356
|
-
th.appendChild(removeBtn);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
headerRow.appendChild(th);
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
// Controls column header (empty)
|
|
363
|
-
const controlsHeader = document.createElement("th");
|
|
364
|
-
controlsHeader.className = "cdx-chart-block__controls-header";
|
|
365
|
-
headerRow.appendChild(controlsHeader);
|
|
366
|
-
|
|
367
|
-
thead.appendChild(headerRow);
|
|
368
|
-
table.appendChild(thead);
|
|
369
|
-
|
|
370
|
-
// Body rows: one per dataset
|
|
371
|
-
const tbody = document.createElement("tbody");
|
|
372
|
-
|
|
373
|
-
this.data.datasets.forEach((dataset, rowIdx) => {
|
|
374
|
-
const tr = document.createElement("tr");
|
|
375
|
-
tr.className = "cdx-chart-block__dataset-row";
|
|
376
|
-
|
|
377
|
-
// Dataset name cell
|
|
378
|
-
const nameCell = document.createElement("td");
|
|
379
|
-
nameCell.className = "cdx-chart-block__dataset-name-cell";
|
|
380
|
-
const nameInput = document.createElement("input");
|
|
381
|
-
nameInput.type = "text";
|
|
382
|
-
nameInput.className = "cdx-chart-block__dataset-name";
|
|
383
|
-
nameInput.value = dataset.label;
|
|
384
|
-
nameInput.placeholder = "Dataset name";
|
|
385
|
-
nameInput.addEventListener("input", () => {
|
|
386
|
-
this.data.datasets[rowIdx].label = nameInput.value;
|
|
387
|
-
this.scheduleChartUpdate();
|
|
388
|
-
});
|
|
389
|
-
nameCell.appendChild(nameInput);
|
|
390
|
-
tr.appendChild(nameCell);
|
|
391
|
-
|
|
392
|
-
// Data value cells
|
|
393
|
-
this.data.labels.forEach((_, colIdx) => {
|
|
394
|
-
const td = document.createElement("td");
|
|
395
|
-
const dataInput = document.createElement("input");
|
|
396
|
-
dataInput.type = "number";
|
|
397
|
-
dataInput.className = "cdx-chart-block__data-input";
|
|
398
|
-
dataInput.value = String(dataset.data[colIdx] ?? 0);
|
|
399
|
-
dataInput.addEventListener("input", () => {
|
|
400
|
-
this.data.datasets[rowIdx].data[colIdx] = parseFloat(dataInput.value) || 0;
|
|
401
|
-
this.scheduleChartUpdate();
|
|
402
|
-
});
|
|
403
|
-
td.appendChild(dataInput);
|
|
404
|
-
tr.appendChild(td);
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// Controls cell: color picker + remove button
|
|
408
|
-
const controlsCell = document.createElement("td");
|
|
409
|
-
controlsCell.className = "cdx-chart-block__dataset-controls";
|
|
410
|
-
|
|
411
|
-
const colorPicker = document.createElement("input");
|
|
412
|
-
colorPicker.type = "color";
|
|
413
|
-
colorPicker.className = "cdx-chart-block__color-picker";
|
|
414
|
-
colorPicker.value = this.rgbaToHex(dataset.backgroundColor);
|
|
415
|
-
colorPicker.title = "Dataset color";
|
|
416
|
-
colorPicker.addEventListener("input", () => {
|
|
417
|
-
this.data.datasets[rowIdx].backgroundColor = this.hexToRgba(colorPicker.value, 0.5);
|
|
418
|
-
this.data.datasets[rowIdx].borderColor = this.hexToRgba(colorPicker.value, 1);
|
|
419
|
-
this.scheduleChartUpdate();
|
|
420
|
-
});
|
|
421
|
-
controlsCell.appendChild(colorPicker);
|
|
422
|
-
|
|
423
|
-
if (this.data.datasets.length > 1) {
|
|
424
|
-
const removeBtn = document.createElement("button");
|
|
425
|
-
removeBtn.type = "button";
|
|
426
|
-
removeBtn.className = "cdx-chart-block__remove-btn";
|
|
427
|
-
removeBtn.innerHTML = "×";
|
|
428
|
-
removeBtn.title = "Remove dataset";
|
|
429
|
-
removeBtn.addEventListener("click", () => this.removeDataset(rowIdx));
|
|
430
|
-
controlsCell.appendChild(removeBtn);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
tr.appendChild(controlsCell);
|
|
434
|
-
tbody.appendChild(tr);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
table.appendChild(tbody);
|
|
438
|
-
this.tableWrapper.appendChild(table);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// ─── Chart ──────────────────────────────────────────────────────────────────
|
|
442
|
-
|
|
443
|
-
private createChart(): void {
|
|
444
|
-
if (!this.canvas) return;
|
|
445
|
-
|
|
446
|
-
if (this.chart) {
|
|
447
|
-
this.chart.destroy();
|
|
448
|
-
this.chart = null;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
const dark = this.isDarkMode();
|
|
452
|
-
const textColor = dark ? "#e0e0e0" : "#333";
|
|
453
|
-
const gridColor = dark ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)";
|
|
454
|
-
const legendColor = dark ? "#ccc" : "#666";
|
|
455
|
-
|
|
456
|
-
const isPieType = ["pie", "doughnut", "polarArea"].includes(this.data.chartType);
|
|
457
|
-
|
|
458
|
-
// For pie/doughnut/polar, use per-segment colors from all datasets flattened
|
|
459
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
460
|
-
const datasets: any[] = this.data.datasets.map((ds) => {
|
|
461
|
-
if (isPieType) {
|
|
462
|
-
return {
|
|
463
|
-
label: ds.label,
|
|
464
|
-
data: [...ds.data],
|
|
465
|
-
borderWidth: 2,
|
|
466
|
-
backgroundColor: ds.data.map((_, i) => COLOR_PALETTE[i % COLOR_PALETTE.length].bg),
|
|
467
|
-
borderColor: ds.data.map((_, i) => COLOR_PALETTE[i % COLOR_PALETTE.length].border),
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
label: ds.label,
|
|
472
|
-
data: [...ds.data],
|
|
473
|
-
borderWidth: 2,
|
|
474
|
-
backgroundColor: ds.backgroundColor,
|
|
475
|
-
borderColor: ds.borderColor,
|
|
476
|
-
};
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
480
|
-
const options: any = {
|
|
481
|
-
responsive: true,
|
|
482
|
-
maintainAspectRatio: false,
|
|
483
|
-
plugins: {
|
|
484
|
-
title: {
|
|
485
|
-
display: !!this.data.title,
|
|
486
|
-
text: this.data.title,
|
|
487
|
-
color: textColor,
|
|
488
|
-
font: { size: 16, weight: "600" as const },
|
|
489
|
-
},
|
|
490
|
-
legend: {
|
|
491
|
-
labels: { color: legendColor },
|
|
492
|
-
},
|
|
493
|
-
},
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
// Add scales for axis-based chart types
|
|
497
|
-
if (this.data.chartType === "radar") {
|
|
498
|
-
options.scales = {
|
|
499
|
-
r: {
|
|
500
|
-
ticks: { color: textColor, backdropColor: "transparent" },
|
|
501
|
-
grid: { color: gridColor },
|
|
502
|
-
pointLabels: { color: textColor },
|
|
503
|
-
},
|
|
504
|
-
};
|
|
505
|
-
} else if (!isPieType) {
|
|
506
|
-
options.scales = {
|
|
507
|
-
x: {
|
|
508
|
-
ticks: { color: textColor },
|
|
509
|
-
grid: { color: gridColor },
|
|
510
|
-
},
|
|
511
|
-
y: {
|
|
512
|
-
ticks: { color: textColor },
|
|
513
|
-
grid: { color: gridColor },
|
|
514
|
-
beginAtZero: true,
|
|
515
|
-
},
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
this.chart = new Chart(this.canvas, {
|
|
520
|
-
type: this.data.chartType,
|
|
521
|
-
data: {
|
|
522
|
-
labels: [...this.data.labels],
|
|
523
|
-
datasets,
|
|
524
|
-
},
|
|
525
|
-
options,
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
private scheduleChartUpdate(): void {
|
|
530
|
-
if (this.updateTimeout !== null) {
|
|
531
|
-
clearTimeout(this.updateTimeout);
|
|
532
|
-
}
|
|
533
|
-
this.updateTimeout = window.setTimeout(() => {
|
|
534
|
-
this.updateTimeout = null;
|
|
535
|
-
if (!this.chart) return;
|
|
536
|
-
|
|
537
|
-
const isPieType = ["pie", "doughnut", "polarArea"].includes(this.data.chartType);
|
|
538
|
-
|
|
539
|
-
this.chart.data.labels = [...this.data.labels];
|
|
540
|
-
this.chart.data.datasets = this.data.datasets.map((ds) => {
|
|
541
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
542
|
-
const base: any = {
|
|
543
|
-
label: ds.label,
|
|
544
|
-
data: [...ds.data],
|
|
545
|
-
borderWidth: 2,
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
if (isPieType) {
|
|
549
|
-
base.backgroundColor = ds.data.map((_, i) => COLOR_PALETTE[i % COLOR_PALETTE.length].bg);
|
|
550
|
-
base.borderColor = ds.data.map((_, i) => COLOR_PALETTE[i % COLOR_PALETTE.length].border);
|
|
551
|
-
} else {
|
|
552
|
-
base.backgroundColor = ds.backgroundColor;
|
|
553
|
-
base.borderColor = ds.borderColor;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
return base;
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
// Update title
|
|
560
|
-
if (this.chart.options.plugins?.title) {
|
|
561
|
-
this.chart.options.plugins.title.display = !!this.data.title;
|
|
562
|
-
this.chart.options.plugins.title.text = this.data.title;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
this.chart.update();
|
|
566
|
-
}, 150);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// ─── Data Management ────────────────────────────────────────────────────────
|
|
570
|
-
|
|
571
|
-
private addLabel(): void {
|
|
572
|
-
const idx = this.data.labels.length + 1;
|
|
573
|
-
this.data.labels.push(`Label ${idx}`);
|
|
574
|
-
this.data.datasets.forEach((ds) => ds.data.push(0));
|
|
575
|
-
this.rebuildDataTable();
|
|
576
|
-
this.scheduleChartUpdate();
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
private removeLabel(index: number): void {
|
|
580
|
-
if (this.data.labels.length <= 1) return;
|
|
581
|
-
this.data.labels.splice(index, 1);
|
|
582
|
-
this.data.datasets.forEach((ds) => ds.data.splice(index, 1));
|
|
583
|
-
this.rebuildDataTable();
|
|
584
|
-
this.scheduleChartUpdate();
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
private addDataset(): void {
|
|
588
|
-
const idx = this.data.datasets.length;
|
|
589
|
-
const color = COLOR_PALETTE[idx % COLOR_PALETTE.length];
|
|
590
|
-
this.data.datasets.push({
|
|
591
|
-
label: `Dataset ${idx + 1}`,
|
|
592
|
-
data: this.data.labels.map(() => 0),
|
|
593
|
-
backgroundColor: color.bg,
|
|
594
|
-
borderColor: color.border,
|
|
595
|
-
});
|
|
596
|
-
this.rebuildDataTable();
|
|
597
|
-
this.scheduleChartUpdate();
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
private removeDataset(index: number): void {
|
|
601
|
-
if (this.data.datasets.length <= 1) return;
|
|
602
|
-
this.data.datasets.splice(index, 1);
|
|
603
|
-
this.rebuildDataTable();
|
|
604
|
-
this.scheduleChartUpdate();
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
608
|
-
|
|
609
|
-
private updateTypeSelector(): void {
|
|
610
|
-
if (!this.wrapper) return;
|
|
611
|
-
const buttons = this.wrapper.querySelectorAll<HTMLButtonElement>(".cdx-chart-block__type-btn");
|
|
612
|
-
buttons.forEach((btn) => {
|
|
613
|
-
btn.classList.toggle(
|
|
614
|
-
"cdx-chart-block__type-btn--active",
|
|
615
|
-
btn.dataset.chartType === this.data.chartType,
|
|
616
|
-
);
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
private normalizeData(data: Partial<ChartBlockData>): ChartBlockData {
|
|
621
|
-
const chartType =
|
|
622
|
-
data.chartType &&
|
|
623
|
-
["bar", "line", "pie", "doughnut", "radar", "polarArea"].includes(data.chartType)
|
|
624
|
-
? data.chartType
|
|
625
|
-
: DEFAULT_DATA.chartType;
|
|
626
|
-
|
|
627
|
-
const title = data.title ?? DEFAULT_DATA.title;
|
|
628
|
-
const labels =
|
|
629
|
-
Array.isArray(data.labels) && data.labels.length > 0 ? data.labels : [...DEFAULT_DATA.labels];
|
|
630
|
-
|
|
631
|
-
const datasets =
|
|
632
|
-
Array.isArray(data.datasets) && data.datasets.length > 0
|
|
633
|
-
? data.datasets.map((ds, idx) => {
|
|
634
|
-
const color = COLOR_PALETTE[idx % COLOR_PALETTE.length];
|
|
635
|
-
return {
|
|
636
|
-
label: ds.label || `Dataset ${idx + 1}`,
|
|
637
|
-
data: Array.isArray(ds.data)
|
|
638
|
-
? labels.map((_, i) => ds.data[i] ?? 0)
|
|
639
|
-
: labels.map(() => 0),
|
|
640
|
-
backgroundColor: ds.backgroundColor || color.bg,
|
|
641
|
-
borderColor: ds.borderColor || color.border,
|
|
642
|
-
};
|
|
643
|
-
})
|
|
644
|
-
: DEFAULT_DATA.datasets.map((ds) => ({
|
|
645
|
-
...ds,
|
|
646
|
-
data: labels.map((_, i) => ds.data[i] ?? 0),
|
|
647
|
-
}));
|
|
648
|
-
|
|
649
|
-
return { chartType, title, labels, datasets };
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
private isDarkMode(): boolean {
|
|
653
|
-
let el: HTMLElement | null = this.wrapper;
|
|
654
|
-
while (el) {
|
|
655
|
-
if (el.getAttribute("data-theme") === "dark") return true;
|
|
656
|
-
el = el.parentElement;
|
|
657
|
-
}
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
private hexToRgba(hex: string, alpha: number): string {
|
|
662
|
-
const r = parseInt(hex.slice(1, 3), 16);
|
|
663
|
-
const g = parseInt(hex.slice(3, 5), 16);
|
|
664
|
-
const b = parseInt(hex.slice(5, 7), 16);
|
|
665
|
-
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
private rgbaToHex(rgba: string): string {
|
|
669
|
-
const match = rgba.match(/(\d+),\s*(\d+),\s*(\d+)/);
|
|
670
|
-
if (!match) return "#000000";
|
|
671
|
-
const r = parseInt(match[1]).toString(16).padStart(2, "0");
|
|
672
|
-
const g = parseInt(match[2]).toString(16).padStart(2, "0");
|
|
673
|
-
const b = parseInt(match[3]).toString(16).padStart(2, "0");
|
|
674
|
-
return `#${r}${g}${b}`;
|
|
675
|
-
}
|
|
676
|
-
}
|