@msbci/form-editor 1.2.0 → 1.3.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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, ComponentType } from 'react';
3
- import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IFormType, IDataSourceConnector, IConditionRule, IRosterVariableRef } from '@msbci/form-core';
3
+ import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IVariableTemplate, IVariableTemplateOverrides, IFormType, IDataSourceConnector, 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
6
 
@@ -40,6 +40,12 @@ interface IEditorAdapter {
40
40
  saveForm?: (form: IFormDefinition) => Promise<void>;
41
41
  loadFormTypes?: () => Promise<IFormType[]>;
42
42
  saveFormType?: (type: IFormType) => Promise<void>;
43
+ /**
44
+ * Optional — fetch the variable templates of a scope.
45
+ * When absent, the editor's "Variables" toolbox tab stays empty and
46
+ * shows the {@link IEditorLabels.toolbox.noTemplates} message.
47
+ */
48
+ loadTemplates?: (scopeId: string) => Promise<IVariableTemplate[]>;
43
49
  }
44
50
  /** Complete editor state */
45
51
  interface EditorState {
@@ -52,6 +58,13 @@ interface EditorState {
52
58
  history: HistoryEntry[];
53
59
  historyIndex: number;
54
60
  adapter: IEditorAdapter | null;
61
+ /**
62
+ * Variable templates surfaced to the "Variables" toolbox tab. Populated
63
+ * via `setAvailableTemplates` (typically by `FormEditor` after
64
+ * `adapter.loadTemplates(form.scopeId)`). Out of the undo/redo history —
65
+ * this is editor-UI state, not form state.
66
+ */
67
+ availableTemplates: IVariableTemplate[];
55
68
  }
56
69
  /** Editor actions */
57
70
  interface EditorActions {
@@ -67,7 +80,33 @@ interface EditorActions {
67
80
  addVariable: (pageCode: string, variable: IFormVariable, rosterCode?: string) => void;
68
81
  updateVariable: (pageCode: string, variableCode: string, updates: Partial<IFormVariable>, rosterCode?: string) => void;
69
82
  removeVariable: (pageCode: string, variableCode: string, rosterCode?: string) => void;
83
+ /**
84
+ * Insert a variable that inherits from a `IVariableTemplate`. Template
85
+ * fields are denormalised onto the new variable; `code` and `name` come
86
+ * from the template; `templateOverrides` starts empty.
87
+ */
88
+ addVariableFromTemplate: (pageCode: string, template: IVariableTemplate, rosterCode?: string) => void;
89
+ /**
90
+ * Override a single field of a template-linked variable. Writes the new
91
+ * value into `templateOverrides[key]` AND mirrors it on the variable so
92
+ * the canvas can render without invoking the resolver.
93
+ */
94
+ setVariableOverride: <K extends keyof IVariableTemplateOverrides>(pageCode: string, variableCode: string, key: K, value: IVariableTemplateOverrides[K], rosterCode?: string) => void;
95
+ /**
96
+ * Drop one override key — removes it from `templateOverrides` and
97
+ * restores the variable's mirrored field from the linked template.
98
+ */
99
+ resetVariableOverride: (pageCode: string, variableCode: string, key: keyof IVariableTemplateOverrides, rosterCode?: string) => void;
100
+ /**
101
+ * Cross-page / cross-roster move (kept for the existing dnd flow). Use
102
+ * {@link moveItem} for intra-page reordering of `page.items[]`.
103
+ */
70
104
  moveVariable: (fromPageCode: string, toPageCode: string, variableCode: string, newOrder: number, fromRosterCode?: string, toRosterCode?: string) => void;
105
+ /**
106
+ * Reorder the items of a page (variables + rosters mixed) by index.
107
+ * Updates each item's `order` to its new position.
108
+ */
109
+ moveItem: (pageCode: string, fromIndex: number, toIndex: number) => void;
71
110
  select: (selection: EditorSelection) => void;
72
111
  clearSelection: () => void;
73
112
  setView: (view: EditorView) => void;
@@ -78,6 +117,8 @@ interface EditorActions {
78
117
  addFormType: (type: Omit<IFormType, 'id'>) => void;
79
118
  updateFormType: (id: string, patch: Partial<IFormType>) => void;
80
119
  removeFormType: (id: string) => void;
120
+ /** Replace the variable-template list shown in the Variables tab. */
121
+ setAvailableTemplates: (templates: IVariableTemplate[]) => void;
81
122
  setAdapter: (adapter: IEditorAdapter) => void;
82
123
  save: () => Promise<void>;
83
124
  load: (formId: string) => Promise<void>;
@@ -120,11 +161,26 @@ interface IEditorLabels {
120
161
  toolbox: {
121
162
  searchPlaceholder: string;
122
163
  addPageFirst: string;
164
+ /** Label of the first tab (existing variable/roster types). */
165
+ tabFields: string;
166
+ /** Label of the second tab (variable library from current scope). */
167
+ tabVariables: string;
168
+ /** Empty state for the Variables tab when the form has a scope but no templates. */
169
+ noTemplates: string;
170
+ /** Empty state for the Variables tab when the form has no scope at all. */
171
+ noScope: string;
123
172
  groupText: string;
124
173
  groupSelection: string;
125
174
  groupDateTime: string;
126
175
  groupMedia: string;
127
176
  groupAdvanced: string;
177
+ /** Section label for the four roster variants, displayed after ADVANCED. */
178
+ groupRoster: string;
179
+ /** Roster type labels — surface the four supported variants. */
180
+ typeRosterCheck: string;
181
+ typeRosterList: string;
182
+ typeRosterCollection: string;
183
+ typeRosterCollectionExtend: string;
128
184
  /**
129
185
  * Shared variable-type labels. Re-used by both Toolbox(Simple) and
130
186
  * VariableProperties (single source of truth).
@@ -211,6 +267,14 @@ interface IEditorLabels {
211
267
  collection: string;
212
268
  collection_extend: string;
213
269
  };
270
+ /** Banner title shown on top of VariableProperties when the variable links to a template. */
271
+ linkedTemplate: string;
272
+ /** Label for the read-only code field on a linked variable. */
273
+ templateCode: string;
274
+ /** Label for the read-only name field on a linked variable. */
275
+ templateName: string;
276
+ /** Per-override reset button label. */
277
+ resetOverride: string;
214
278
  type: string;
215
279
  ratingStyle: string;
216
280
  ratingStyles: {
@@ -400,14 +464,19 @@ interface EditorToolbarProps {
400
464
  declare function EditorToolbar({ onSave, onExport, onImport }: EditorToolbarProps): react_jsx_runtime.JSX.Element;
401
465
 
402
466
  /**
403
- * Toolbox — left panel. Click to add variables to selected page.
404
- * No drag & drop dependency.
467
+ * Toolbox — left panel. Two tabs:
468
+ * - Champs : variable types + roster variants (original content).
469
+ * - Variables : reusable templates from the current scope.
470
+ *
471
+ * Click to add. No drag & drop dependency (see Toolbox.tsx for DnD).
405
472
  */
406
473
  declare function ToolboxSimple(): react_jsx_runtime.JSX.Element;
407
474
 
408
475
  /**
409
476
  * Canvas — center panel. Displays form structure.
410
- * Click to select. Supports roster creation and variable management.
477
+ * Click to select. Variables and rosters share a single ordered list
478
+ * (`page.items[]`) and are rendered together; rosters always break the
479
+ * current multi-column row and span the full width.
411
480
  */
412
481
  declare function CanvasSimple(): react_jsx_runtime.JSX.Element;
413
482
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, ComponentType } from 'react';
3
- import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IFormType, IDataSourceConnector, IConditionRule, IRosterVariableRef } from '@msbci/form-core';
3
+ import { IFormDefinition, IFormPage, IFormRoster, IFormVariable, IVariableTemplate, IVariableTemplateOverrides, IFormType, IDataSourceConnector, 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
6
 
@@ -40,6 +40,12 @@ interface IEditorAdapter {
40
40
  saveForm?: (form: IFormDefinition) => Promise<void>;
41
41
  loadFormTypes?: () => Promise<IFormType[]>;
42
42
  saveFormType?: (type: IFormType) => Promise<void>;
43
+ /**
44
+ * Optional — fetch the variable templates of a scope.
45
+ * When absent, the editor's "Variables" toolbox tab stays empty and
46
+ * shows the {@link IEditorLabels.toolbox.noTemplates} message.
47
+ */
48
+ loadTemplates?: (scopeId: string) => Promise<IVariableTemplate[]>;
43
49
  }
44
50
  /** Complete editor state */
45
51
  interface EditorState {
@@ -52,6 +58,13 @@ interface EditorState {
52
58
  history: HistoryEntry[];
53
59
  historyIndex: number;
54
60
  adapter: IEditorAdapter | null;
61
+ /**
62
+ * Variable templates surfaced to the "Variables" toolbox tab. Populated
63
+ * via `setAvailableTemplates` (typically by `FormEditor` after
64
+ * `adapter.loadTemplates(form.scopeId)`). Out of the undo/redo history —
65
+ * this is editor-UI state, not form state.
66
+ */
67
+ availableTemplates: IVariableTemplate[];
55
68
  }
56
69
  /** Editor actions */
57
70
  interface EditorActions {
@@ -67,7 +80,33 @@ interface EditorActions {
67
80
  addVariable: (pageCode: string, variable: IFormVariable, rosterCode?: string) => void;
68
81
  updateVariable: (pageCode: string, variableCode: string, updates: Partial<IFormVariable>, rosterCode?: string) => void;
69
82
  removeVariable: (pageCode: string, variableCode: string, rosterCode?: string) => void;
83
+ /**
84
+ * Insert a variable that inherits from a `IVariableTemplate`. Template
85
+ * fields are denormalised onto the new variable; `code` and `name` come
86
+ * from the template; `templateOverrides` starts empty.
87
+ */
88
+ addVariableFromTemplate: (pageCode: string, template: IVariableTemplate, rosterCode?: string) => void;
89
+ /**
90
+ * Override a single field of a template-linked variable. Writes the new
91
+ * value into `templateOverrides[key]` AND mirrors it on the variable so
92
+ * the canvas can render without invoking the resolver.
93
+ */
94
+ setVariableOverride: <K extends keyof IVariableTemplateOverrides>(pageCode: string, variableCode: string, key: K, value: IVariableTemplateOverrides[K], rosterCode?: string) => void;
95
+ /**
96
+ * Drop one override key — removes it from `templateOverrides` and
97
+ * restores the variable's mirrored field from the linked template.
98
+ */
99
+ resetVariableOverride: (pageCode: string, variableCode: string, key: keyof IVariableTemplateOverrides, rosterCode?: string) => void;
100
+ /**
101
+ * Cross-page / cross-roster move (kept for the existing dnd flow). Use
102
+ * {@link moveItem} for intra-page reordering of `page.items[]`.
103
+ */
70
104
  moveVariable: (fromPageCode: string, toPageCode: string, variableCode: string, newOrder: number, fromRosterCode?: string, toRosterCode?: string) => void;
105
+ /**
106
+ * Reorder the items of a page (variables + rosters mixed) by index.
107
+ * Updates each item's `order` to its new position.
108
+ */
109
+ moveItem: (pageCode: string, fromIndex: number, toIndex: number) => void;
71
110
  select: (selection: EditorSelection) => void;
72
111
  clearSelection: () => void;
73
112
  setView: (view: EditorView) => void;
@@ -78,6 +117,8 @@ interface EditorActions {
78
117
  addFormType: (type: Omit<IFormType, 'id'>) => void;
79
118
  updateFormType: (id: string, patch: Partial<IFormType>) => void;
80
119
  removeFormType: (id: string) => void;
120
+ /** Replace the variable-template list shown in the Variables tab. */
121
+ setAvailableTemplates: (templates: IVariableTemplate[]) => void;
81
122
  setAdapter: (adapter: IEditorAdapter) => void;
82
123
  save: () => Promise<void>;
83
124
  load: (formId: string) => Promise<void>;
@@ -120,11 +161,26 @@ interface IEditorLabels {
120
161
  toolbox: {
121
162
  searchPlaceholder: string;
122
163
  addPageFirst: string;
164
+ /** Label of the first tab (existing variable/roster types). */
165
+ tabFields: string;
166
+ /** Label of the second tab (variable library from current scope). */
167
+ tabVariables: string;
168
+ /** Empty state for the Variables tab when the form has a scope but no templates. */
169
+ noTemplates: string;
170
+ /** Empty state for the Variables tab when the form has no scope at all. */
171
+ noScope: string;
123
172
  groupText: string;
124
173
  groupSelection: string;
125
174
  groupDateTime: string;
126
175
  groupMedia: string;
127
176
  groupAdvanced: string;
177
+ /** Section label for the four roster variants, displayed after ADVANCED. */
178
+ groupRoster: string;
179
+ /** Roster type labels — surface the four supported variants. */
180
+ typeRosterCheck: string;
181
+ typeRosterList: string;
182
+ typeRosterCollection: string;
183
+ typeRosterCollectionExtend: string;
128
184
  /**
129
185
  * Shared variable-type labels. Re-used by both Toolbox(Simple) and
130
186
  * VariableProperties (single source of truth).
@@ -211,6 +267,14 @@ interface IEditorLabels {
211
267
  collection: string;
212
268
  collection_extend: string;
213
269
  };
270
+ /** Banner title shown on top of VariableProperties when the variable links to a template. */
271
+ linkedTemplate: string;
272
+ /** Label for the read-only code field on a linked variable. */
273
+ templateCode: string;
274
+ /** Label for the read-only name field on a linked variable. */
275
+ templateName: string;
276
+ /** Per-override reset button label. */
277
+ resetOverride: string;
214
278
  type: string;
215
279
  ratingStyle: string;
216
280
  ratingStyles: {
@@ -400,14 +464,19 @@ interface EditorToolbarProps {
400
464
  declare function EditorToolbar({ onSave, onExport, onImport }: EditorToolbarProps): react_jsx_runtime.JSX.Element;
401
465
 
402
466
  /**
403
- * Toolbox — left panel. Click to add variables to selected page.
404
- * No drag & drop dependency.
467
+ * Toolbox — left panel. Two tabs:
468
+ * - Champs : variable types + roster variants (original content).
469
+ * - Variables : reusable templates from the current scope.
470
+ *
471
+ * Click to add. No drag & drop dependency (see Toolbox.tsx for DnD).
405
472
  */
406
473
  declare function ToolboxSimple(): react_jsx_runtime.JSX.Element;
407
474
 
408
475
  /**
409
476
  * Canvas — center panel. Displays form structure.
410
- * Click to select. Supports roster creation and variable management.
477
+ * Click to select. Variables and rosters share a single ordered list
478
+ * (`page.items[]`) and are rendered together; rosters always break the
479
+ * current multi-column row and span the full width.
411
480
  */
412
481
  declare function CanvasSimple(): react_jsx_runtime.JSX.Element;
413
482