### ResourceLoad usage example Source: https://github.com/svar-widgets/react-gantt JSX example showing how to use ResourceLoad with a Gantt component, passing api, mode, template, and draggableRows props. ```JSX const [api, setApi] = useState(); return ( <> `${l.percent}%`} draggableRows={(row) => !row.unassigned} /> ); ``` -------------------------------- ### complexScales example from demos/data.js Source: https://github.com/svar-widgets/react-gantt Example `scales` array from `demos/data.js`. Each scale defines `unit`, `step`, and `format`; `css` is optional and returns a CSS class for weekend highlighting. `unit` can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', or custom units registered via `registerScaleUnit`. `format` can be a template function or a locale format string using tokens like `%Y`, `%Q`, `%F`, `%M`, `%j`, `%w`, `%H:%i`, `%W`. ```javascript const complexScales = [ { unit: 'year', step: 1, format: '%Y' }, { unit: 'month', step: 2, format: '%F %Y' }, { unit: 'week', step: 1, format: '%w' }, { unit: 'day', step: 1, format: '%j', css: (d) => (d.getDay() === 5 || d.getDay() === 6 ? 'sday' : '') }, ]; ``` -------------------------------- ### Imperative show via ref example Source: https://github.com/svar-widgets/react-gantt Shows how to open the context menu programmatically using the ref's show method, e.g., from a button click. ```jsx const menuRef = useRef(); ``` -------------------------------- ### Conditional theme orchestration example Source: https://github.com/svar-widgets/react-gantt Example of conditionally rendering either WillowDark or Material theme based on a dark prop, wrapping a Gantt component. ```jsx // orchestrate several themes / conditional import { Material, WillowDark } from '@svar-ui/react-gantt'; export default function App({ dark }) { return dark ? : ; } ``` -------------------------------- ### Basic toolbar above the Gantt Source: https://github.com/svar-widgets/react-gantt Usage example showing how to render a Toolbar above a Gantt component, passing the api state and an optional Editor. ```JSX import { useState } from 'react'; import { Gantt, Toolbar, Editor } from '@svar-ui/react-gantt'; export default function App() { const [api, setApi] = useState(); return ( <> {api && } ); } ``` -------------------------------- ### locateTask usage example (JSX) Source: https://github.com/svar-widgets/react-gantt Example of using `locateTask` inside a DnD onDrop handler to add a task at the located row. ```jsx import { Gantt, locateTask } from '@svar-ui/react-gantt'; // inside a DnD onDrop handler: function handleDrop(ev, api) { const located = locateTask(ev, api); if (located) { api.exec('add-task', { task: { text: 'dropped', parent: located.id } }); } } ``` -------------------------------- ### Wrapping the Gantt with ContextMenu Source: https://github.com/svar-widgets/react-gantt Basic usage example wrapping a Gantt component inside ContextMenu to enable right-click context menu. ```jsx import { useState } from 'react'; import { Gantt, ContextMenu } from '@svar-ui/react-gantt'; export default function App() { const [api, setApi] = useState(); return ( ); } ``` -------------------------------- ### Import and render Gantt component with tasks Source: https://github.com/svar-widgets/react-gantt/blob/main/readme.md Import the Gantt component and its CSS, then define a tasks array with task and summary objects. The component renders the Gantt chart with the provided tasks. This is the basic setup for using SVAR React Gantt in a React application. ```jsx import { Gantt } from '@svar-ui/react-gantt'; import '@svar-ui/react-gantt/all.css'; export default function MyComponent() { const tasks = [ { id: 20, text: 'New Task', start: new Date(2024, 5, 11), end: new Date(2024, 6, 12), duration: 1, progress: 2, type: 'task', lazy: false, }, { id: 47, text: '[1] Master project', start: new Date(2024, 5, 12), end: new Date(2024, 7, 12), duration: 8, progress: 0, parent: 0, type: 'summary', }, ]; return ; } ``` -------------------------------- ### Willow theme usage example Source: https://github.com/svar-widgets/react-gantt Example of wrapping a Gantt component inside the Willow theme provider with fonts enabled. ```jsx ``` -------------------------------- ### Custom editor fields via getEditorItems + getEditorButtons Source: https://github.com/svar-widgets/react-gantt Builds a custom Editor by combining getEditorItems and getEditorButtons. The example extracts toolbar rows and items, then constructs editor items from keys. ```jsx import { getEditorItems, getEditorButtons, getDefaultColumns } from '@svar-ui/react-gantt'; const toolbarRows = getEditorButtons({ autoSave: false, resources: true, splitTasks: true }); const [closeBtn, spacer, deleteBtn, saveBtn] = toolbarRows[0].items; const tabs = toolbarRows[1]; const items = keys.map((key) => ({ ...getEditorItems({ resources: true, splitTasks: true }).find((op) => op.key === key), })); ``` -------------------------------- ### ConflictReport usage example Source: https://github.com/svar-widgets/react-gantt Example of rendering ConflictReport with an API instance and an onClose handler that logs when closed. ```jsx {api && console.log('closed')} />} ``` -------------------------------- ### ZoomConfig shape example Source: https://github.com/svar-widgets/react-gantt Configuration object for the `zoom` prop. `level` sets the initial zoom level; `levels` is an array of level configs, each with optional `minCellWidth`/`maxCellWidth` bounds and a `scales` array. If `levels` is absent, `prepareZoom` returns the config unchanged; otherwise each level's `scales` are localized via `prepareScales`. On active zoom, `normalizeZoom` derives the scale configuration, so `scales` need not be supplied alongside `zoom`. ```javascript zoom = { level: 3, levels: [ { minCellWidth: 200, // optional lower bound for this level's cell width maxCellWidth: 400, // optional upper bound scales: [{ unit: 'year', step: 1, format: '%Y' }, ...], }, // ... ], }; ``` -------------------------------- ### HeaderMenu Usage Example Source: https://github.com/svar-widgets/react-gantt Wraps a Gantt component with HeaderMenu, passing the api prop to enable right-click header menu detection. ```jsx ``` -------------------------------- ### getResourceCalendar(resource) Source: https://github.com/svar-widgets/react-gantt Gets the calendar for a resource. ```APIDOC ## getResourceCalendar(resource) ### Description Gets the calendar for a resource. ### Method Function ### Signature `getResourceCalendar(resource: Resource): Calendar` ### Parameters - **resource** (Resource) - Required - The resource object. ### Returns - **Calendar** - The calendar for the resource. ``` -------------------------------- ### Providing custom buttons Source: https://github.com/svar-widgets/react-gantt Example of defining custom toolbar items with id, text, handler, isDisabled, and isHidden callbacks, then passing them to the Toolbar via the items prop. ```JSX import { getToolbarButtons } from '@svar-ui/react-gantt'; const custom = [ { id: 'my-action', text: 'Copy', // localized handler: (item) => { // item.id === 'my-action' }, isDisabled: (task, state) => task.progress === 100, isHidden: (task, state) => !!task.parent, // hidden if any selected task has a parent }, ]; ``` -------------------------------- ### getHistory() Source: https://github.com/svar-widgets/react-gantt Gets the undo/redo history handle (null unless undo is enabled). ```APIDOC ## getHistory() ### Description Gets the undo/redo history handle (null unless undo is enabled). ### Method Function ### Signature `getHistory(): History | null` ### Returns - **History** or **null** - The history handle, or null if undo is disabled. ``` -------------------------------- ### getLinkValidator() Source: https://github.com/svar-widgets/react-gantt Gets the link (dependency) validator. ```APIDOC ## getLinkValidator() ### Description Gets the link (dependency) validator. ### Method Function ### Signature `getLinkValidator(): LinkValidator` ### Returns - **LinkValidator** - The link validator object. ``` -------------------------------- ### Custom resolver and filter example Source: https://github.com/svar-widgets/react-gantt Shows how to customize item resolution and filter menu items. The resolver returns a task to force it, true to use default lookup, or falsy to veto. The filter hides items based on a predicate. ```jsx { // return a task to force it, true to use default lookup, falsy/null to veto const task = api.getTask(id); return task && task.type === 'task' ? task : null; }} filter={(item, task) => !(item.id === 'split' && (task.id % 2 === 0))} onClick={(ev) => console.log('menu action', ev.action.id)} > ``` -------------------------------- ### getTaskResources(id) Source: https://github.com/svar-widgets/react-gantt Gets resources assigned to a task. ```APIDOC ## getTaskResources(id) ### Description Gets resources assigned to a task. ### Method Function ### Signature `getTaskResources(id: string): Resource[]` ### Parameters - **id** (string) - Required - The task id. ### Returns - **Resource[]** - Array of resources assigned to the task. ``` -------------------------------- ### Subscribe to events and read state Source: https://github.com/svar-widgets/react-gantt Use `api.on` to subscribe to events like `update-task` and `select-task`, and `api.getState()` to read the current state. The example logs task changes and selected task text. ```jsx init={(api) => { api.on('update-task', (ev) => { console.log('changed task', ev.id, ev.task); }); api.on('select-task', (ev) => { console.log('selected', ev.id, api.getTask(ev.id)?.text); }); const state = api.getState(); console.log('current tasks', state._tasks); }} ``` -------------------------------- ### Cancelling an action with intercept Source: https://github.com/svar-widgets/react-gantt Use `api.intercept` to block or allow actions. The example blocks dragging tasks onto the timeline (scale) but allows grid reordering, based on `ev.top` presence. ```jsx init={(api) => { // block dragging tasks onto the timeline (scale) but allow reordering in grid api.intercept('drag-task', (ev) => { if (typeof ev.top !== 'undefined') return orderAllowed; // grid reorder return allowDrag; // scale drag (ev.width/ev.left) }); }} ``` -------------------------------- ### Custom columns via getDefaultColumns Source: https://github.com/svar-widgets/react-gantt Shows how to build custom columns using getDefaultColumns with resources enabled, then pass them to the Gantt component. ```jsx import { getDefaultColumns } from '@svar-ui/react-gantt'; import { useMemo } from 'react'; export default function App() { const columns = useMemo(() => getDefaultColumns({ resources: true }), []); return ; } ``` -------------------------------- ### getMenuOptions({ splitTasks, taskTypes, summary, group }) Source: https://github.com/svar-widgets/react-gantt Builds ContextMenu options for the Gantt context menu. Accepts flags to conditionally include options. ```APIDOC ## Function: getMenuOptions ### Description Builds ContextMenu options for the Gantt context menu. Accepts flags to conditionally include options. ### Signature `getMenuOptions({ splitTasks, taskTypes, summary, group })` ### Parameters - **splitTasks** (boolean) - Optional - Include split task options. - **taskTypes** (array) - Optional - Task type definitions. - **summary** (boolean) - Optional - Include summary task options. - **group** (boolean) - Optional - Include group options. ### Returns - **Array** - Array of menu option descriptors. ``` -------------------------------- ### Basic Gantt initialization with tasks and scales Source: https://github.com/svar-widgets/react-gantt Initializes the Gantt component with a tasks array and two time scales (month and day). Requires importing '@svar-ui/react-gantt/all.css' for styling. The tasks include a summary task with a parent property. ```jsx import { useState } from 'react'; import { Gantt } from '@svar-ui/react-gantt'; import '@svar-ui/react-gantt/all.css'; export default function Project() { const tasks = [ { id: 20, text: 'New Task', start: new Date(2024, 5, 11), end: new Date(2024, 6, 12), duration: 1, progress: 2, type: 'task' }, { id: 47, text: '[1] Master project', start: new Date(2024, 5, 12), end: new Date(2024, 7, 12), duration: 8, progress: 0, parent: 0, type: 'summary' }, ]; return ; } ``` -------------------------------- ### getCalendar(id) Source: https://github.com/svar-widgets/react-gantt Gets a calendar by its id. ```APIDOC ## getCalendar(id) ### Description Gets a calendar by its id. ### Method Function ### Signature `getCalendar(id: string): Calendar` ### Parameters - **id** (string) - Required - The calendar id. ### Returns - **Calendar** - The calendar object. ``` -------------------------------- ### getResourceTasks(id) Source: https://github.com/svar-widgets/react-gantt Gets tasks assigned to a resource. ```APIDOC ## getResourceTasks(id) ### Description Gets tasks assigned to a resource. ### Method Function ### Signature `getResourceTasks(id: string): Task[]` ### Parameters - **id** (string) - Required - The resource id. ### Returns - **Task[]** - Array of tasks assigned to the resource. ``` -------------------------------- ### exec(action, payload) Source: https://github.com/svar-widgets/react-gantt Dispatches a store action by name. The action names observed in the source and demos include add-assignment, add-link, add-task, delete-assignment, delete-link, delete-task, drag-task, export-data, filter-tasks, hotkey, import-data, move-task, open-task, provide-data, redo, render-data, resize-chart, resize-grid, scroll-chart, select-task, set-columns, set-display-mode, show-editor, sort-resources, sort-tasks, undo, update-assignment, update-link, update-task, zoom-scale. ```APIDOC ## exec(action, payload) ### Description Dispatches a store action by name. The action names observed in the source and demos include add-assignment, add-link, add-task, delete-assignment, delete-link, delete-task, drag-task, export-data, filter-tasks, hotkey, import-data, move-task, open-task, provide-data, redo, render-data, resize-chart, resize-grid, scroll-chart, select-task, set-columns, set-display-mode, show-editor, sort-resources, sort-tasks, undo, update-assignment, update-link, update-task, zoom-scale. ### Method N/A (JavaScript method) ### Endpoint N/A ### Parameters - **action** (string) - Required - The name of the action to dispatch. - **payload** (object) - Optional - The payload to pass to the action. ### Response N/A ``` -------------------------------- ### getTaskCalendar(task) Source: https://github.com/svar-widgets/react-gantt Gets the calendar assigned to a task. ```APIDOC ## getTaskCalendar(task) ### Description Gets the calendar assigned to a task. ### Method Function ### Signature `getTaskCalendar(task: Task): Calendar` ### Parameters - **task** (Task) - Required - The task object. ### Returns - **Calendar** - The calendar assigned to the task. ``` -------------------------------- ### getDefaultColumns({ resources?, wbs? }) Source: https://github.com/svar-widgets/react-gantt Builds the default column set for the Gantt grid. Accepts optional flags for resources and WBS, and returns an array of column definitions. ```APIDOC ## Function: getDefaultColumns ### Description Builds the default column set for the Gantt grid. Accepts optional flags for resources and WBS, and returns an array of column definitions. ### Signature `getDefaultColumns({ resources?, wbs? })` ### Parameters - **resources** (boolean) - Optional - Whether to include resource columns. - **wbs** (boolean) - Optional - Whether to include WBS columns. ### Returns - **IGanttColumn[]** - Array of column definitions. ### Request Example ```jsx import { getDefaultColumns } from '@svar-ui/react-gantt'; import { useMemo } from 'react'; export default function App() { const columns = useMemo(() => getDefaultColumns({ resources: true }), []); return ; } ``` ``` -------------------------------- ### getToolbarButtons({ undo, splitTasks, group, conflicts }) Source: https://github.com/svar-widgets/react-gantt Builds Toolbar buttons for the main Gantt toolbar. Accepts flags to conditionally include buttons. ```APIDOC ## Function: getToolbarButtons ### Description Builds Toolbar buttons for the main Gantt toolbar. Accepts flags to conditionally include buttons. ### Signature `getToolbarButtons({ undo, splitTasks, group, conflicts })` ### Parameters - **undo** (boolean) - Optional - Include undo button. - **splitTasks** (boolean) - Optional - Include split task button. - **group** (boolean) - Optional - Include group button. - **conflicts** (boolean) - Optional - Include conflicts button. ### Returns - **Array** - Array of button descriptors. ``` -------------------------------- ### chart.js helper exports Source: https://github.com/svar-widgets/react-gantt Lists the exported helper functions from src/helpers/chart.js for unit start calculation and task lookup. ```javascript getUnitStart(value, unitSize) // Math.trunc(value / (unitSize||1)) * unitSize getTaskAtRow(tasks, y, cellHeight) // tasks[Math.floor(y / cellHeight)] ``` -------------------------------- ### IApi object construction in Gantt.jsx Source: https://github.com/svar-widgets/react-gantt Builds the forwarded ref and init(api) argument exposing store methods and event routing. Uses useMemo with dataStore and firstInRoute dependencies. Methods include getState, getReactiveState, getStores, exec, setNext, intercept, on, detach, getTask, getResource, serialize, getTable, getHistory, getCalendar, getTaskCalendar, getResourceCalendar, getTaskResources, getResourceTasks, and getLinkValidator. ```javascript const api = useMemo( () => ({ getState: dataStore.getState.bind(dataStore), getReactiveState: dataStore.getReactive.bind(dataStore), getStores: () => ({ data: dataStore }), exec: firstInRoute.exec, setNext: (ev) => { ... }, intercept: firstInRoute.intercept.bind(firstInRoute), on: firstInRoute.on.bind(firstInRoute), detach: firstInRoute.detach.bind(firstInRoute), getTask: (id) => dataStore.getTask(id), getResource: (id) => dataStore.getResource(id), serialize: (config) => dataStore.serialize(config), getTable: (waitRender, section = 'grid') => { ... }, getHistory: () => dataStore.getHistory(), getCalendar: (id) => dataStore.getCalendar(id), getTaskCalendar: (task) => dataStore.getTaskCalendar(task), getResourceCalendar: (resource) => dataStore.getResourceCalendar(resource), getTaskResources: (id) => dataStore.getTaskResources(id), getResourceTasks: (id) => dataStore.getResourceTasks(id), getLinkValidator: () => dataStore.getLinkValidator(), }), [dataStore, firstInRoute], ); ``` -------------------------------- ### Package exports configuration from package.json Source: https://github.com/svar-widgets/react-gantt Defines the package entry points for types, ESM, CommonJS, and CSS files. The root export supports both import and require, with style.css and all.css for styles. ```json "exports": { ".": { "types": "./types/index.d.ts", "import": "./dist/index.es.js", "require": "./dist/index.cjs.js", "default": "./dist/index.es.js" }, "./style.css": "./dist/index.css", "./all.css": "./dist-full/index.css" }, "types": "./types/index.d.ts", "main": "./dist/index.cjs.js", "module": "./dist/index.es.js" ``` -------------------------------- ### exec(action, payload) Source: https://github.com/svar-widgets/react-gantt Dispatches a named store action (e.g., 'select-task', 'update-task'). ```APIDOC ## exec(action, payload) ### Description Dispatches a named store action (e.g., 'select-task', 'update-task'). ### Method Function ### Signature `exec(action: string, payload?: any): void` ### Parameters - **action** (string) - Required - The name of the action to dispatch. - **payload** (any) - Optional - The payload to pass to the action. ``` -------------------------------- ### Using the ref Source: https://github.com/svar-widgets/react-gantt Access the API via a ref to call `exec` methods like `scroll-chart` and `select-task` from outside the component. The `Gantt` component accepts a `ref` and an `init` callback. ```jsx const apiRef = useRef(); const moveToTask = (id) => { apiRef.current.exec('scroll-chart', { ... }); apiRef.current.exec('select-task', { id, show: 'xy', focus: 'chart' }); }; ``` -------------------------------- ### setNext — backend provider chaining Source: https://github.com/svar-widgets/react-gantt Wires a `RestDataProvider` into the action chain so mutations are persisted. The `init` callback sets the provider, subscribes to `request-data`, and provides data via `exec('provide-data', ...)`. Requires `@svar-ui/gantt-data-provider` and `@svar-ui/react-gantt`. ```jsx import { useMemo, useState, useCallback } from 'react'; import { RestDataProvider } from '@svar-ui/gantt-data-provider'; import { Gantt, ContextMenu, Editor } from '@svar-ui/react-gantt'; export default function Backed() { const restProvider = useMemo( () => new RestDataProvider('https://gantt-backend.svar.dev'), [], ); const [api, setApi] = useState(); const init = useCallback((gApi) => { setApi(gApi); gApi.setNext(restProvider); gApi.on('request-data', (ev) => { restProvider.getData(ev.id).then(({ tasks, links }) => { gApi.exec('provide-data', { id: ev.id, data: { tasks, links } }); }); }); }, [restProvider]); return ( ); } ``` -------------------------------- ### on(action, fn) Source: https://github.com/svar-widgets/react-gantt Subscribes to an action event (post-handling). ```APIDOC ## on(action, fn) ### Description Subscribes to an action event (post-handling). ### Method Function ### Signature `on(action: string, fn: (payload: any) => void): void` ### Parameters - **action** (string) - Required - The action name to subscribe to. - **fn** (function) - Required - The callback function to execute. ``` -------------------------------- ### HeaderMenu Implementation Snippet Source: https://github.com/svar-widgets/react-gantt Shows the internal state initialization of HeaderMenu, tracking the target gantt section and table API. ```jsx const HeaderMenu = ({ children, columns = null, api }) => { const [targetSection, setTargetSection] = useState('grid'); const [tableAPI, setTableAPI] = useState(null); ... }; ``` -------------------------------- ### List of exec action names Source: https://github.com/svar-widgets/react-gantt Action names used with `exec(action, payload)` in this repo's source and demos. They cover tasks, links, assignments, sorting, filtering, display mode, undo/redo, and data import/export. ```text add-assignment add-link add-task delete-assignment delete-link delete-task drag-task export-data filter-tasks hotkey import-data move-task open-task provide-data redo render-data resize-chart resize-grid scroll-chart select-task set-columns set-display-mode show-editor sort-resources sort-tasks undo update-assignment update-link update-task zoom-scale ``` -------------------------------- ### ContextMenu implementation props (src/components/ContextMenu.jsx) Source: https://github.com/svar-widgets/react-gantt Implementation props read from the source file, showing the forwardRef signature. ```javascript const ContextMenu = forwardRef(function ContextMenu( { options: optionsInit = [], api = null, resolver = null, filter = null, at = 'point', children, onClick, css, }, ref, ) ``` -------------------------------- ### ContextMenu ref show method (useImperativeHandle) Source: https://github.com/svar-widgets/react-gantt The ref exposes a single show method that builds options and delegates to the underlying menu. ```javascript useImperativeHandle(ref, () => ({ show: (ev, obj) => { setMenuOptions(buildOptions()); if (menuRef.current && menuRef.current.show) { menuRef.current.show(ev, obj); } }, })); ``` -------------------------------- ### Capturing Gantt API via init prop with events Source: https://github.com/svar-widgets/react-gantt Uses the init prop to capture the Gantt API instance and register an event listener for 'update-task'. The callback logs the task id and task object when an update occurs. Requires useState and useCallback hooks. ```jsx import { useState, useCallback } from 'react'; import { Gantt } from '@svar-ui/react-gantt'; export default function WithApi() { const [api, setApi] = useState(); const init = useCallback((gApi) => { setApi(gApi); gApi.on('update-task', (ev) => { console.log('task updated', ev.id, ev.task); }); }, []); return ( ); } ``` -------------------------------- ### getReactiveState() Source: https://github.com/svar-widgets/react-gantt Accesses the reactive store, which supports subscriptions. ```APIDOC ## getReactiveState() ### Description Accesses the reactive store, which supports subscriptions. ### Method Function ### Signature `getReactiveState(): ReactiveStore` ### Returns - **ReactiveStore** - The reactive store object. ``` -------------------------------- ### Theme components: Material, Willow, WillowDark Source: https://github.com/svar-widgets/react-gantt Thin wrappers that mount the corresponding SVar core + grid theme and import the gantt CSS overrides. They can be used to wrap the application or mount the theme provider standalone. ```APIDOC ## Theme components: Material, Willow, WillowDark ### Description Thin wrappers that mount the corresponding SVar core + grid theme and import the gantt CSS overrides. They can be used to wrap the application or mount the theme provider standalone. ### Signatures ```ts export declare const Material: FC<{ fonts?: boolean; children?: ReactNode }>; export declare const Willow: FC<{ fonts?: boolean; children?: ReactNode }>; export declare const WillowDark: FC<{ fonts?: boolean; children?: ReactNode }>; ``` ### Parameters | Parameter | Type | Default | Description | |---|---|---|---| | `fonts` | `boolean` | `true` | Load the theme's font assets. | | `children` | `ReactNode` | — | Optional. When provided, render the app inside the theme provider (children may be a function for `Material`). Without children, mounts the theme provider standalone. | ### Usage ```jsx ``` ```jsx // orchestrate several themes / conditional import { Material, WillowDark } from '@svar-ui/react-gantt'; export default function App({ dark }) { return dark ? : ; } ``` ### Implementation notes - `Material` wraps `CoreMaterial` (from `@svar-ui/react-core`) plus `Material.css`. - `Willow` composes `CoreWillow` (`react-core`) with `GridWillow` (`react-grid`) and `Willow.css`. - `WillowDark` composes `WillowDarkCore` with `GridWillowDark` and `WillowDark.css`. - Without `children`, `Willow`/`WillowDark` mount both providers unwrapped as a fragment. ``` -------------------------------- ### serialize(config) Source: https://github.com/svar-widgets/react-gantt Serializes the store into a plain object shape. ```APIDOC ## serialize(config) ### Description Serializes the store into a plain object shape. ### Method Function ### Signature `serialize(config?: any): any` ### Parameters - **config** (any) - Optional - Configuration for serialization. ### Returns - **any** - The serialized store data. ``` -------------------------------- ### getEditorButtons({ resources, autoSave, splitTasks, deadlines, criticalPath, inactiveTasks, schedule }) Source: https://github.com/svar-widgets/react-gantt Builds the editor toolbar buttons used by the Editor for top/bottom bars. Returns rows with items arrays. ```APIDOC ## Function: getEditorButtons ### Description Builds the editor toolbar buttons used by the Editor for top/bottom bars. Returns rows with items arrays. ### Signature `getEditorButtons({ resources, autoSave, splitTasks, deadlines, criticalPath, inactiveTasks, schedule })` ### Parameters - **resources** (boolean) - Optional - Include resource-related buttons. - **autoSave** (boolean) - Optional - Include auto-save button. - **splitTasks** (boolean) - Optional - Include split task buttons. - **deadlines** (boolean) - Optional - Include deadline buttons. - **criticalPath** (boolean) - Optional - Include critical path buttons. - **inactiveTasks** (boolean) - Optional - Include inactive task buttons. - **schedule** (boolean) - Optional - Include schedule buttons. ### Returns - **Array** - Array of rows, each with an `items` array. ### Request Example ```jsx import { getEditorButtons } from '@svar-ui/react-gantt'; const toolbarRows = getEditorButtons({ autoSave: false, resources: true, splitTasks: true }); const [closeBtn, spacer, deleteBtn, saveBtn] = toolbarRows[0].items; const tabs = toolbarRows[1]; ``` ``` -------------------------------- ### Tooltip Implementation Props Source: https://github.com/svar-widgets/react-gantt Shows the destructured props of the GanttTooltip component, including defaults for at and overflow. ```javascript function GanttTooltip(props) { const { api, at = 'point', overflow = false, content: Content, resolver, ...restProps } = props; ... } ``` -------------------------------- ### getStores() Source: https://github.com/svar-widgets/react-gantt Returns the internal store map containing the data store. ```APIDOC ## getStores() ### Description Returns the internal store map containing the data store. ### Method Function ### Signature `getStores(): { data: DataStore }` ### Returns - **data** (DataStore) - The data store instance. ``` -------------------------------- ### Basic sidebar editor with ContextMenu Source: https://github.com/svar-widgets/react-gantt Registers editor items and renders an Editor when an API is available. Requires a ContextMenu wrapper and a Gantt with an initial task. ```jsx import { useState, useCallback } from 'react'; import { Gantt, Editor, ContextMenu } from '@svar-ui/react-gantt'; export default function App() { const [api, setApi] = useState(); return ( <> {api && } ); } ``` -------------------------------- ### Combined layout with Gantt and Editor Source: https://github.com/svar-widgets/react-gantt A typical combined layout from demos/cases/GanttBackend.jsx style, showing a Gantt with tasks, links, and scales wrapped in ContextMenu, and an Editor rendered when the API is set. ```jsx const [api, setApi] = useState(); return ( <> {api && } ); ``` -------------------------------- ### Toolbar implementation props (src/components/Toolbar.jsx) Source: https://github.com/svar-widgets/react-gantt Implementation signature of the Toolbar component, accepting an optional api and items array. ```JavaScript export default function Toolbar({ api = null, items = [] }) ``` -------------------------------- ### getResourceColumns() Source: https://github.com/svar-widgets/react-gantt Returns the default column set for the ResourceLoad left grid. Takes no arguments. ```APIDOC ## Function: getResourceColumns ### Description Returns the default column set for the ResourceLoad left grid. Takes no arguments. ### Signature `getResourceColumns()` ### Returns - **IGanttColumn[]** - Array of column definitions. ``` -------------------------------- ### getEditorItems({ unscheduledTasks, inactiveTasks, rollups, summary, taskTypes, resources, splitTasks, deadlines, schedule, criticalPath }) Source: https://github.com/svar-widgets/react-gantt Builds editor form-field items for the Editor component. Accepts reactive store flags to conditionally include fields. ```APIDOC ## Function: getEditorItems ### Description Builds editor form-field items for the Editor component. Accepts reactive store flags to conditionally include fields. ### Signature `getEditorItems({ unscheduledTasks, inactiveTasks, rollups, summary, taskTypes, resources, splitTasks, deadlines, schedule, criticalPath })` ### Parameters - **unscheduledTasks** (boolean) - Optional - Include unscheduled tasks. - **inactiveTasks** (boolean) - Optional - Include inactive tasks. - **rollups** (boolean) - Optional - Include rollups. - **summary** (boolean) - Optional - Include summary tasks. - **taskTypes** (array) - Optional - Task type definitions. - **resources** (boolean) - Optional - Include resource fields. - **splitTasks** (boolean) - Optional - Include split task fields. - **deadlines** (boolean) - Optional - Include deadline fields. - **schedule** (boolean) - Optional - Include schedule fields. - **criticalPath** (boolean) - Optional - Include critical path fields. ### Returns - **Array** - Array of editor item objects. ### Request Example ```jsx import { getEditorItems } from '@svar-ui/react-gantt'; const items = keys.map((key) => ({ ...getEditorItems({ resources: true, splitTasks: true }).find((op) => op.key === key), })); ``` ``` -------------------------------- ### version export from src/index.js Source: https://github.com/svar-widgets/react-gantt Exports the version constant from the source entry point. ```javascript export const version = pkg.version; ``` -------------------------------- ### getState() Source: https://github.com/svar-widgets/react-gantt Reads the current store state snapshot (reactive fields). ```APIDOC ## getState() ### Description Reads the current store state snapshot (reactive fields). ### Method Function ### Signature `getState(): State` ### Returns - **State** - The current store state snapshot. ``` -------------------------------- ### Tooltip Basic Usage Source: https://github.com/svar-widgets/react-gantt Wraps a Gantt component with Tooltip, passing the api prop to enable tooltips on tasks and links. ```jsx ``` -------------------------------- ### setNext(provider) Source: https://github.com/svar-widgets/react-gantt Wires a data provider (e.g., RestDataProvider) into the action chain so mutations are persisted. The provider must implement a `getData` method that returns a promise resolving to an object with `tasks` and `links` arrays. ```APIDOC ## setNext(provider) ### Description Wires a data provider (e.g., RestDataProvider) into the action chain so mutations are persisted. The provider must implement a `getData` method that returns a promise resolving to an object with `tasks` and `links` arrays. ### Method N/A (JavaScript method) ### Endpoint N/A ### Parameters - **provider** (object) - Required - The data provider instance. ### Response N/A ``` -------------------------------- ### getTable(waitRender, section?) Source: https://github.com/svar-widgets/react-gantt Resolves the grid table API for the specified section ('grid' or 'subGrid'). ```APIDOC ## getTable(waitRender, section?) ### Description Resolves the grid table API for the specified section ('grid' or 'subGrid'). ### Method Function ### Signature `getTable(waitRender?: boolean, section?: 'grid' | 'subGrid'): TableAPI | Promise` ### Parameters - **waitRender** (boolean) - Optional - If true, returns a Promise that resolves after render. - **section** (string) - Optional - The table section: 'grid' (default) or 'subGrid'. ### Returns - **TableAPI** or **Promise** - The table API object. ``` -------------------------------- ### version declaration Source: https://github.com/svar-widgets/react-gantt Declares the package version string constant. ```typescript export declare const version: string; ``` -------------------------------- ### getState() Source: https://github.com/svar-widgets/react-gantt Returns the current state of the Gantt store. The state object includes a `_tasks` property containing the current tasks. ```APIDOC ## getState() ### Description Returns the current state of the Gantt store. The state object includes a `_tasks` property containing the current tasks. ### Method N/A (JavaScript method) ### Endpoint N/A ### Parameters None ### Response - **state** (object) - The current state of the Gantt store, including `_tasks`. ``` -------------------------------- ### prepareConfig.js helper exports Source: https://github.com/svar-widgets/react-gantt Lists the exported helper functions from src/helpers/prepareConfig.js. These are internal and not part of the public API. ```javascript getUnitFormats(_) prepareScales(scales, calendarLocale) prepareFormats(calendarLocale, _) prepareColumns(columns, calendarLocale) prepareZoom(zoom, calendarLocale) ``` -------------------------------- ### Imperative Gantt API calls via ref Source: https://github.com/svar-widgets/react-gantt Accesses the Gantt API imperatively through a ref and calls the 'select-task' command when a button is clicked. The ref is attached to the Gantt component, and the exec method is used to select a task by id. ```jsx import { useRef } from 'react'; import { Gantt } from '@svar-ui/react-gantt'; export default function Imperative() { const apiRef = useRef(); const selectFirst = () => apiRef.current.exec('select-task', { id: 1 }); return ( <> ); } ``` -------------------------------- ### Gantt component implementation with default props Source: https://github.com/svar-widgets/react-gantt Implementation of the Gantt component using forwardRef, extracting named props with defaults and forwarding the rest as event-handler props. The ref exposes the public IApi. ```javascript const Gantt = forwardRef(function Gantt( { taskTemplate = null, markers = EMPTY_ARRAY, taskTypes = defaultTaskTypes, tasks = EMPTY_ARRAY, selected = EMPTY_ARRAY, activeTask = null, links = EMPTY_ARRAY, resources = null, assignments = EMPTY_ARRAY, scales = defaultScales, columns = null, start = null, end = null, lengthUnit = 'day', durationUnit = 'day', inclusiveEnd = false, cellWidth = 100, cellHeight = 38, scaleHeight = 36, gridWidth = null, subGridWidth = null, displayMode = 'all', readonly = false, cellBorders = 'full', zoom = false, baselines = false, rollups = false, highlightTime = null, init = null, autoScale = true, unscheduledTasks = false, inactiveTasks = false, placeholderRow = false, criticalPath = null, schedule = DEFAULT_SCHEDULE, // { type: 'forward' } projectStart = null, projectEnd = null, calendar = null, calendars = EMPTY_ARRAY, undo = false, splitTasks = false, summary = null, slack = false, groupBy = null, wbs = false, deadlines = false, progressLine = false, sCurve = false, ...restProps }, ref, ) ``` -------------------------------- ### Re-export statements from src/index.js Source: https://github.com/svar-widgets/react-gantt Lists the exact re-export statements from the package root. These symbols are re-exported verbatim from SVar dependencies. ```javascript export { defaultEditorItems, defaultToolbarButtons, defaultMenuOptions, defaultColumns, defaultTaskTypes, getDefaultColumns, getResourceColumns, getEditorItems, getToolbarButtons, getEditorButtons, getMenuOptions, registerScaleUnit, } from '@svar-ui/gantt-store'; export { registerEditorItem } from '@svar-ui/react-editor'; ``` -------------------------------- ### Constants: defaultEditorItems, defaultToolbarButtons, defaultMenuOptions, defaultColumns, defaultTaskTypes Source: https://github.com/svar-widgets/react-gantt Default configuration constants re-exported from the store. These are arrays of descriptors used as defaults for various Gantt components. ```APIDOC ## Constants ### Description Default configuration constants re-exported from the store. These are arrays of descriptors used as defaults for various Gantt components. ### Constants - **defaultEditorItems** (const array) - Default task edit-form fields. - **defaultToolbarButtons** (const array) - Default toolbar button descriptors. - **defaultMenuOptions** (const array) - Default context-menu option descriptors. - **defaultColumns** (const array) - Default grid columns. - **defaultTaskTypes** (const array) - Default task-type definitions. ### Request Example ```jsx import { defaultColumns } from '@svar-ui/react-gantt'; const columns = add ? defaultColumns : defaultColumns.filter((a) => a.id !== 'add-task'); ``` ``` -------------------------------- ### hotkeys.subscribe function Source: https://github.com/svar-widgets/react-gantt Subscribe to hotkeys. Returns an unsubscribe function. The provided callback receives a `t` instance with `add(key, handler)` and `limit(check)` methods. Keydown events build a key string and invoke matching handlers from the innermost scope, skipping inputs and calling `preventDefault()`. ```javascript export const hotkeys = { subscribe: (v) => { ... return unsubscribe; } }; ``` -------------------------------- ### IColumnConfig interface Source: https://github.com/svar-widgets/react-gantt Extends IGanttColumn with grid-level customizers for cell, header, and editor. ```typescript export interface IColumnConfig extends Omit { cell?: ITableColumn['cell']; header?: ITableColumn['header']; editor?: ITableColumn['editor']; } ``` -------------------------------- ### setNext(ev) Source: https://github.com/svar-widgets/react-gantt Sets the next handler in the event/persistence chain and returns the new tail router. ```APIDOC ## setNext(ev) ### Description Sets the next handler in the event/persistence chain and returns the new tail router. ### Method Function ### Signature `setNext(ev: any): Router` ### Parameters - **ev** (any) - Required - The next handler to set. ### Returns - **Router** - The new tail router. ```