@msbci/form-editor 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, ComponentType } from 'react';
3
- import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IVariableTemplate, IVariableTemplateOverrides, IFormType, IDataSourceConnector, IConditionRule, IRosterVariableRef } from '@msbci/form-core';
2
+ import React, { ReactNode, ComponentType } from 'react';
3
+ import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IVariableTemplate, IVariableTemplateOverrides, IFormType, IDataSourceConnector, VariableType, RosterType, IConditionRule, IRosterVariableRef } from '@msbci/form-core';
4
4
  export { IDataSourceConnector, IFormDefinition, IFormPage, IFormRoster, IFormVariable, IMosobiThemeBase } from '@msbci/form-core';
5
5
  import * as zustand from 'zustand';
6
+ import { DragEndEvent } from '@dnd-kit/core';
6
7
 
7
8
  /**
8
9
  * Editor store types.
@@ -331,6 +332,20 @@ interface IEditorLabels {
331
332
  match: string;
332
333
  all: string;
333
334
  any: string;
335
+ modalTitle: (count: number) => string;
336
+ configureButton: (count: number) => string;
337
+ applyButton: string;
338
+ cancelButton: string;
339
+ closeButton: string;
340
+ formulasSummary: string;
341
+ noConditions: string;
342
+ modeVisual: string;
343
+ modeManual: string;
344
+ manualWarning: string;
345
+ manualPlaceholder: string;
346
+ manualHelp: string;
347
+ validationExpression: string;
348
+ validationExpressionPlaceholder: string;
334
349
  actions: {
335
350
  show: string;
336
351
  hide: string;
@@ -442,11 +457,25 @@ interface FormEditorProps {
442
457
  dataSources?: Record<string, IDataSourceConnector>;
443
458
  mode?: string;
444
459
  }>;
445
- /** Custom Toolbox component (e.g. with drag & drop) */
460
+ /**
461
+ * Override the default DnD-enabled Toolbox. Most consumers should leave
462
+ * this undefined and rely on the default `Toolbox` component, which
463
+ * already supports drag & drop and the click-to-add flow.
464
+ */
446
465
  ToolboxComponent?: ComponentType<any>;
447
- /** Custom Canvas component (e.g. with sortable drag & drop) */
466
+ /**
467
+ * Override the default DnD-enabled Canvas. Most consumers should leave
468
+ * this undefined; the default `Canvas` component handles reordering and
469
+ * cross-container drops automatically.
470
+ */
448
471
  CanvasComponent?: ComponentType<any>;
449
- /** Wrapper around the entire editor (e.g. DndContext) */
472
+ /**
473
+ * @deprecated Drag & drop is now provided by `DndManager` internally.
474
+ * If you still pass a `Wrapper`, it is applied AROUND the internal
475
+ * `<DndManager>` so your wrapper keeps running, but you no longer need
476
+ * to mount your own `<DndContext>`. A one-time console warning is
477
+ * emitted to make the deprecation visible.
478
+ */
450
479
  Wrapper?: ComponentType<any>;
451
480
  }
452
481
  declare function FormEditor({ theme, dataSources, adapter, initialForm, formId, onChange, onSave, labels, PreviewComponent, ToolboxComponent, CanvasComponent, Wrapper, }: FormEditorProps): react_jsx_runtime.JSX.Element;
@@ -463,6 +492,67 @@ interface EditorToolbarProps {
463
492
  }
464
493
  declare function EditorToolbar({ onSave, onExport, onImport }: EditorToolbarProps): react_jsx_runtime.JSX.Element;
465
494
 
495
+ /**
496
+ * Toolbox panel (DnD) — left side of the editor.
497
+ * Two tabs:
498
+ * - Champs : variable types + roster variants (draggable).
499
+ * - Variables : reusable templates from the current scope (draggable
500
+ * with data.type='new-variable-from-template').
501
+ */
502
+ declare function Toolbox(): react_jsx_runtime.JSX.Element;
503
+
504
+ /**
505
+ * Canvas panel — center of the editor.
506
+ * Displays the form structure as pages with a unified list of items
507
+ * (variables + rosters). Items share a single SortableContext so the
508
+ * drag & drop reordering works across both kinds.
509
+ */
510
+ declare function Canvas(): react_jsx_runtime.JSX.Element;
511
+
512
+ /**
513
+ * Subset of the editor store the drag-end logic actually needs. Decoupling
514
+ * makes the handler trivially mockable in unit tests.
515
+ */
516
+ interface DragEndActions {
517
+ addVariable: (pageCode: string, variable: IFormVariable, rosterCode?: string) => void;
518
+ addRoster: (pageCode: string, roster: IFormRoster) => void;
519
+ addVariableFromTemplate: (pageCode: string, template: IVariableTemplate, rosterCode?: string) => void;
520
+ moveItem: (pageCode: string, fromIndex: number, toIndex: number) => void;
521
+ moveVariable: (fromPageCode: string, toPageCode: string, variableCode: string, newOrder: number, fromRosterCode?: string, toRosterCode?: string) => void;
522
+ reorderPages: (orderedCodes: string[]) => void;
523
+ }
524
+ /** Active draggable payload — what Canvas / Toolbox put under `data.current`. */
525
+ interface ActiveDragData {
526
+ type?: 'new-variable' | 'new-roster' | 'new-variable-from-template' | 'variable' | 'roster' | 'page';
527
+ variableType?: VariableType;
528
+ rosterType?: RosterType;
529
+ template?: IVariableTemplate;
530
+ pageCode?: string;
531
+ variableCode?: string;
532
+ rosterCode?: string;
533
+ }
534
+ /** Over (drop-target) payload. */
535
+ interface OverDropData {
536
+ type?: 'page' | 'variable' | 'roster' | 'roster-drop';
537
+ pageCode?: string;
538
+ rosterCode?: string;
539
+ }
540
+ /**
541
+ * Build a pure drag-end handler. Given a snapshot accessor for the form
542
+ * and the store actions, returns a function that translates a DragEndEvent
543
+ * into the right action call. Exported for unit tests.
544
+ */
545
+ declare function createDragEndHandler(actions: DragEndActions, getForm: () => IFormDefinition): (event: DragEndEvent) => void;
546
+ /**
547
+ * Wraps the editor tree in a `<DndContext>` configured with pointer +
548
+ * keyboard sensors and the drag-end handler returned by
549
+ * {@link createDragEndHandler}. A `<DragOverlay>` shows a label while
550
+ * something is being dragged.
551
+ */
552
+ declare function DndManager({ children }: {
553
+ children: React.ReactNode;
554
+ }): react_jsx_runtime.JSX.Element;
555
+
466
556
  /**
467
557
  * Toolbox — left panel. Two tabs:
468
558
  * - Champs : variable types + roster variants (original content).
@@ -528,4 +618,4 @@ interface DataSourceSelectorProps {
528
618
  }
529
619
  declare function DataSourceSelector({ dataSourceId, dependencies, availableConnectors, availableVariables, onConnectorChange, onDependenciesChange, }: DataSourceSelectorProps): react_jsx_runtime.JSX.Element;
530
620
 
531
- export { CanvasSimple as Canvas, ConditionBuilder, type ConditionBuilderProps, DataSourceSelector, type DataSourceSelectorProps, type DeepPartial, type EditorActions, EditorLabelsProvider, type EditorSelection, type EditorState, type EditorStore, EditorToolbar, type EditorView, FormEditor, type FormEditorProps, type HistoryEntry, type IEditorAdapter, type IEditorLabels, PropertiesPanel, ToolboxSimple as Toolbox, frLabels as defaultLabels, enLabels, frLabels, mergeLabels, useEditorStore, useLabels };
621
+ export { type ActiveDragData, Canvas, Canvas as CanvasDnd, CanvasSimple, ConditionBuilder, type ConditionBuilderProps, DataSourceSelector, type DataSourceSelectorProps, type DeepPartial, DndManager, type DragEndActions, type EditorActions, EditorLabelsProvider, type EditorSelection, type EditorState, type EditorStore, EditorToolbar, type EditorView, FormEditor, type FormEditorProps, type HistoryEntry, type IEditorAdapter, type IEditorLabels, type OverDropData, PropertiesPanel, Toolbox, Toolbox as ToolboxDnd, ToolboxSimple, createDragEndHandler, frLabels as defaultLabels, enLabels, frLabels, mergeLabels, useEditorStore, useLabels };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, ComponentType } from 'react';
3
- import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IVariableTemplate, IVariableTemplateOverrides, IFormType, IDataSourceConnector, IConditionRule, IRosterVariableRef } from '@msbci/form-core';
2
+ import React, { ReactNode, ComponentType } from 'react';
3
+ import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IVariableTemplate, IVariableTemplateOverrides, IFormType, IDataSourceConnector, VariableType, RosterType, IConditionRule, IRosterVariableRef } from '@msbci/form-core';
4
4
  export { IDataSourceConnector, IFormDefinition, IFormPage, IFormRoster, IFormVariable, IMosobiThemeBase } from '@msbci/form-core';
5
5
  import * as zustand from 'zustand';
6
+ import { DragEndEvent } from '@dnd-kit/core';
6
7
 
7
8
  /**
8
9
  * Editor store types.
@@ -331,6 +332,20 @@ interface IEditorLabels {
331
332
  match: string;
332
333
  all: string;
333
334
  any: string;
335
+ modalTitle: (count: number) => string;
336
+ configureButton: (count: number) => string;
337
+ applyButton: string;
338
+ cancelButton: string;
339
+ closeButton: string;
340
+ formulasSummary: string;
341
+ noConditions: string;
342
+ modeVisual: string;
343
+ modeManual: string;
344
+ manualWarning: string;
345
+ manualPlaceholder: string;
346
+ manualHelp: string;
347
+ validationExpression: string;
348
+ validationExpressionPlaceholder: string;
334
349
  actions: {
335
350
  show: string;
336
351
  hide: string;
@@ -442,11 +457,25 @@ interface FormEditorProps {
442
457
  dataSources?: Record<string, IDataSourceConnector>;
443
458
  mode?: string;
444
459
  }>;
445
- /** Custom Toolbox component (e.g. with drag & drop) */
460
+ /**
461
+ * Override the default DnD-enabled Toolbox. Most consumers should leave
462
+ * this undefined and rely on the default `Toolbox` component, which
463
+ * already supports drag & drop and the click-to-add flow.
464
+ */
446
465
  ToolboxComponent?: ComponentType<any>;
447
- /** Custom Canvas component (e.g. with sortable drag & drop) */
466
+ /**
467
+ * Override the default DnD-enabled Canvas. Most consumers should leave
468
+ * this undefined; the default `Canvas` component handles reordering and
469
+ * cross-container drops automatically.
470
+ */
448
471
  CanvasComponent?: ComponentType<any>;
449
- /** Wrapper around the entire editor (e.g. DndContext) */
472
+ /**
473
+ * @deprecated Drag & drop is now provided by `DndManager` internally.
474
+ * If you still pass a `Wrapper`, it is applied AROUND the internal
475
+ * `<DndManager>` so your wrapper keeps running, but you no longer need
476
+ * to mount your own `<DndContext>`. A one-time console warning is
477
+ * emitted to make the deprecation visible.
478
+ */
450
479
  Wrapper?: ComponentType<any>;
451
480
  }
452
481
  declare function FormEditor({ theme, dataSources, adapter, initialForm, formId, onChange, onSave, labels, PreviewComponent, ToolboxComponent, CanvasComponent, Wrapper, }: FormEditorProps): react_jsx_runtime.JSX.Element;
@@ -463,6 +492,67 @@ interface EditorToolbarProps {
463
492
  }
464
493
  declare function EditorToolbar({ onSave, onExport, onImport }: EditorToolbarProps): react_jsx_runtime.JSX.Element;
465
494
 
495
+ /**
496
+ * Toolbox panel (DnD) — left side of the editor.
497
+ * Two tabs:
498
+ * - Champs : variable types + roster variants (draggable).
499
+ * - Variables : reusable templates from the current scope (draggable
500
+ * with data.type='new-variable-from-template').
501
+ */
502
+ declare function Toolbox(): react_jsx_runtime.JSX.Element;
503
+
504
+ /**
505
+ * Canvas panel — center of the editor.
506
+ * Displays the form structure as pages with a unified list of items
507
+ * (variables + rosters). Items share a single SortableContext so the
508
+ * drag & drop reordering works across both kinds.
509
+ */
510
+ declare function Canvas(): react_jsx_runtime.JSX.Element;
511
+
512
+ /**
513
+ * Subset of the editor store the drag-end logic actually needs. Decoupling
514
+ * makes the handler trivially mockable in unit tests.
515
+ */
516
+ interface DragEndActions {
517
+ addVariable: (pageCode: string, variable: IFormVariable, rosterCode?: string) => void;
518
+ addRoster: (pageCode: string, roster: IFormRoster) => void;
519
+ addVariableFromTemplate: (pageCode: string, template: IVariableTemplate, rosterCode?: string) => void;
520
+ moveItem: (pageCode: string, fromIndex: number, toIndex: number) => void;
521
+ moveVariable: (fromPageCode: string, toPageCode: string, variableCode: string, newOrder: number, fromRosterCode?: string, toRosterCode?: string) => void;
522
+ reorderPages: (orderedCodes: string[]) => void;
523
+ }
524
+ /** Active draggable payload — what Canvas / Toolbox put under `data.current`. */
525
+ interface ActiveDragData {
526
+ type?: 'new-variable' | 'new-roster' | 'new-variable-from-template' | 'variable' | 'roster' | 'page';
527
+ variableType?: VariableType;
528
+ rosterType?: RosterType;
529
+ template?: IVariableTemplate;
530
+ pageCode?: string;
531
+ variableCode?: string;
532
+ rosterCode?: string;
533
+ }
534
+ /** Over (drop-target) payload. */
535
+ interface OverDropData {
536
+ type?: 'page' | 'variable' | 'roster' | 'roster-drop';
537
+ pageCode?: string;
538
+ rosterCode?: string;
539
+ }
540
+ /**
541
+ * Build a pure drag-end handler. Given a snapshot accessor for the form
542
+ * and the store actions, returns a function that translates a DragEndEvent
543
+ * into the right action call. Exported for unit tests.
544
+ */
545
+ declare function createDragEndHandler(actions: DragEndActions, getForm: () => IFormDefinition): (event: DragEndEvent) => void;
546
+ /**
547
+ * Wraps the editor tree in a `<DndContext>` configured with pointer +
548
+ * keyboard sensors and the drag-end handler returned by
549
+ * {@link createDragEndHandler}. A `<DragOverlay>` shows a label while
550
+ * something is being dragged.
551
+ */
552
+ declare function DndManager({ children }: {
553
+ children: React.ReactNode;
554
+ }): react_jsx_runtime.JSX.Element;
555
+
466
556
  /**
467
557
  * Toolbox — left panel. Two tabs:
468
558
  * - Champs : variable types + roster variants (original content).
@@ -528,4 +618,4 @@ interface DataSourceSelectorProps {
528
618
  }
529
619
  declare function DataSourceSelector({ dataSourceId, dependencies, availableConnectors, availableVariables, onConnectorChange, onDependenciesChange, }: DataSourceSelectorProps): react_jsx_runtime.JSX.Element;
530
620
 
531
- export { CanvasSimple as Canvas, ConditionBuilder, type ConditionBuilderProps, DataSourceSelector, type DataSourceSelectorProps, type DeepPartial, type EditorActions, EditorLabelsProvider, type EditorSelection, type EditorState, type EditorStore, EditorToolbar, type EditorView, FormEditor, type FormEditorProps, type HistoryEntry, type IEditorAdapter, type IEditorLabels, PropertiesPanel, ToolboxSimple as Toolbox, frLabels as defaultLabels, enLabels, frLabels, mergeLabels, useEditorStore, useLabels };
621
+ export { type ActiveDragData, Canvas, Canvas as CanvasDnd, CanvasSimple, ConditionBuilder, type ConditionBuilderProps, DataSourceSelector, type DataSourceSelectorProps, type DeepPartial, DndManager, type DragEndActions, type EditorActions, EditorLabelsProvider, type EditorSelection, type EditorState, type EditorStore, EditorToolbar, type EditorView, FormEditor, type FormEditorProps, type HistoryEntry, type IEditorAdapter, type IEditorLabels, type OverDropData, PropertiesPanel, Toolbox, Toolbox as ToolboxDnd, ToolboxSimple, createDragEndHandler, frLabels as defaultLabels, enLabels, frLabels, mergeLabels, useEditorStore, useLabels };