///
/**
* Location Module - Pattern for places/venues
*
* A composable pattern that can be used standalone or embedded in containers
* like Record. Stores location name, address, and optional coordinates.
*/
import { computed, type Default, NAME, recipe, UI } from "commontools";
import type { ModuleMetadata } from "./container-protocol.ts";
// ===== Self-Describing Metadata =====
export const MODULE_METADATA: ModuleMetadata = {
type: "location",
label: "Location",
icon: "\u{1F5FA}", // world map emoji
schema: {
locationName: { type: "string", description: "Location name" },
locationAddress: { type: "string", description: "Full address" },
coordinates: { type: "string", description: "Coordinates (lat,lng)" },
},
fieldMapping: ["locationName", "locationAddress", "coordinates"],
};
// ===== Types =====
export interface LocationModuleInput {
/** Location name (e.g., venue, landmark) */
locationName: Default;
/** Full address */
locationAddress: Default;
/** Coordinates in lat,lng format */
coordinates: Default;
}
// ===== The Pattern =====
export const LocationModule = recipe(
"LocationModule",
({ locationName, locationAddress, coordinates }) => {
const displayText = computed(() =>
locationName || locationAddress || "Not set"
);
return {
[NAME]: computed(() =>
`${MODULE_METADATA.icon} Location: ${displayText}`
),
[UI]: (
),
locationName,
locationAddress,
coordinates,
};
},
);
export default LocationModule;