CoreFiles by mySites.guru
positioning.es6.js73 lines, 1,922 bytes, from Joomla_6.1.2-Stable-Full_Package.zip
Raw History Compare with 6.1.1
md5
678be5205c2be40362e79b0b9c8429b5
sha1
2f4787546b5410cf52c13fab0bbc2d6eb177e798
sha256
d9c04e85d6bac38d99d25da43bcdb68dbf6b89b5dec5c6287d026d04c9623fa3
import { getColorForStage } from './utils.es6.js';

/**
 * Calculate and return positioned stage nodes in a grid layout.
 * @param {Array<Object>} stages - Array of stage objects.
 * @param {Object} options - Grid layout options (gapX, gapY, paddingX, paddingY).
 * @returns {Array<Object>} Array of positioned node configs.
 */
export function generatePositionedNodes(stages, options = {}) {
  const {
    gapX = 400,
    gapY = 300,
    paddingX = 100,
    paddingY = 100,
  } = options;

  const columns = Math.min(4, Math.ceil(Math.sqrt(stages?.length || 0)) + 1);

  return stages.map((stage, index) => {
    const col = index % columns;
    const row = Math.floor(index / columns);

    const position = stage?.position || {
      x: col * gapX + paddingX,
      y: row * gapY + paddingY,
    };

    return {
      id: String(stage.id),
      type: 'stage',
      position,
      data: {
        stage: {
          ...stage,
          color: getColorForStage(stage),
        },
        isSelected: false,
        onSelect: () => {},
        onEdit: () => {},
        onDelete: () => {},
      },
      draggable: true,
    };
  });
}

/**
 * Create special static nodes like "from_any" node.
 * @param {String} id - The ID of the special node
 * @param {Object} position - The position of the special node
 * @param {String} color - The color of the special node
 * @param {String} label - The label of the special node
 * @param {Function} onSelect - The function to call when the special node is selected
 * @param {Boolean} draggable - Whether the special node is draggable
 */
export function createSpecialNode(id, position, color, label, onSelect = () => {}, draggable = false) {
  return {
    id,
    type: 'stage',
    position,
    data: {
      stage: {
        id,
        title: label,
        published: true,
        color,
      },
      isSpecial: true,
      onSelect,
    },
    draggable,
  };
}

The same content is in 18 releases, Joomla 6.1.0-beta1 to 6.1.4. See them all, or every version of this file.