- ✅ Ticket 1.1: Estructura Clean Architecture en backend - ✅ Ticket 1.2: Schemas Zod compartidos - ✅ Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares) - ✅ Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares) - ✅ Ticket 1.5: Eliminación de duplicidades (~50 líneas) Cambios principales: - Creada estructura Clean Architecture en backend/src/ - Schemas Zod compartidos en backend/src/shared/schemas/ - Refactorización modular de drugs y procedures - Utilidades genéricas en src/utils/ (filter, validation) - Eliminados scripts obsoletos y documentación antigua - Corregidos errores: QueryClient, import test-error-handling - Build verificado y funcionando correctamente
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
/**
|
|
* @import {Element, ElementContent, Properties} from 'hast'
|
|
* @import {Parents, TableRow} from 'mdast'
|
|
* @import {State} from '../state.js'
|
|
*/
|
|
|
|
/**
|
|
* Turn an mdast `tableRow` node into hast.
|
|
*
|
|
* @param {State} state
|
|
* Info passed around.
|
|
* @param {TableRow} node
|
|
* mdast node.
|
|
* @param {Parents | undefined} parent
|
|
* Parent of `node`.
|
|
* @returns {Element}
|
|
* hast node.
|
|
*/
|
|
export function tableRow(state, node, parent) {
|
|
const siblings = parent ? parent.children : undefined
|
|
// Generate a body row when without parent.
|
|
const rowIndex = siblings ? siblings.indexOf(node) : 1
|
|
const tagName = rowIndex === 0 ? 'th' : 'td'
|
|
// To do: option to use `style`?
|
|
const align = parent && parent.type === 'table' ? parent.align : undefined
|
|
const length = align ? align.length : node.children.length
|
|
let cellIndex = -1
|
|
/** @type {Array<ElementContent>} */
|
|
const cells = []
|
|
|
|
while (++cellIndex < length) {
|
|
// Note: can also be undefined.
|
|
const cell = node.children[cellIndex]
|
|
/** @type {Properties} */
|
|
const properties = {}
|
|
const alignValue = align ? align[cellIndex] : undefined
|
|
|
|
if (alignValue) {
|
|
properties.align = alignValue
|
|
}
|
|
|
|
/** @type {Element} */
|
|
let result = {type: 'element', tagName, properties, children: []}
|
|
|
|
if (cell) {
|
|
result.children = state.all(cell)
|
|
state.patch(cell, result)
|
|
result = state.applyData(cell, result)
|
|
}
|
|
|
|
cells.push(result)
|
|
}
|
|
|
|
/** @type {Element} */
|
|
const result = {
|
|
type: 'element',
|
|
tagName: 'tr',
|
|
properties: {},
|
|
children: state.wrap(cells, true)
|
|
}
|
|
state.patch(node, result)
|
|
return state.applyData(node, result)
|
|
}
|