{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages-default-tasks",
  "title": "Default task hooks",
  "description": "The create, change and decision tasks and the attachment upload and removal commands the page blocks submit with: `@registrystack/app-runtime`'s own hooks, each attempt handed on as `reference`. The request attachment commands aim at the request the current route names.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0"
  ],
  "registryDependencies": [
    "@registrystack/pages-change-request-form",
    "@registrystack/pages-create-record",
    "@registrystack/pages-record",
    "@registrystack/pages-record-attachments",
    "@registrystack/pages-register-routes",
    "@registrystack/pages-request-detail",
    "@registrystack/request-attachment-slots",
    "@registrystack/shell-routing"
  ],
  "files": [
    {
      "path": "pages/default-tasks.tsx",
      "content": "import {\n  useAttachmentRemoval,\n  useAttachmentUpload,\n  useRecordTask,\n  useRequestWrite,\n  withReference,\n} from \"@registrystack/app-runtime/react\";\nimport type { ChangeRequestTask } from \"@/blocks/pages/change-request-form-page\";\nimport type { CreateRecordTask } from \"@/blocks/pages/create-record-page\";\nimport type { RemovalOutcome } from \"@/blocks/pages/record-attachments\";\nimport { routedRequest, useRegister } from \"@/blocks/pages/record\";\nimport {\n  matchRegisterRoute,\n  useRegisterRoutes,\n} from \"@/blocks/pages/register-routes\";\nimport type { RequestDecisionTask } from \"@/blocks/pages/request-detail-page\";\nimport type { UploadOutcome } from \"@/blocks/request/attachment-slots\";\nimport { splitRoute, useRoute } from \"@/blocks/shell/routing\";\n\n/**\n * The commands the default pages submit with: `@registrystack/app-runtime`'s\n * own hooks, each result handed on under the `reference` name the page blocks\n * read. A page block never keeps or compares an attempt itself, only shows\n * the one its caller hands it.\n */\n\n/** The create task on a record's creation form. */\nexport function useCreateTask(): CreateRecordTask {\n  return withReference(useRecordTask());\n}\n\n/** The change task on a record's change request form, over the same record task. */\nexport function useChangeTask(): ChangeRequestTask {\n  return withReference(useRecordTask());\n}\n\n/**\n * The decision task on a request's own page, aimed at the request the route names: an\n * apply is a command on that request, and any other decision is a record task.\n */\nexport function useRequestTask(): RequestDecisionTask {\n  const entity = useRoutedRequestId();\n  return withReference(useRequestWrite(entity, useCurrentRequestId()));\n}\n\n/**\n * The id of the request the current route names, or \"\" off a request route.\n * `RequestDetailPage` calls `useUpload`/`useRemoval` with only a slot, never\n * the request id itself, so a hook wired onto the whole app reads it from the\n * route the same way the page's own id prop was resolved.\n */\nfunction useCurrentRequestId(): string {\n  const routes = useRegisterRoutes();\n  const { path } = splitRoute(useRoute());\n  const match = matchRegisterRoute(routes, path);\n  return match.kind === \"request\" ? match.id : \"\";\n}\n\n/** The id of the request entity the current route names, or the followed one, or \"\". */\nfunction useRoutedRequestId(): string {\n  const entities = useRegister().entities;\n  const { query } = splitRoute(useRoute());\n  return (\n    (entities && (routedRequest(entities, query) ?? entities.request))?.id ?? \"\"\n  );\n}\n\n/** An upload command for one slot of any record, aimed by entity and id. */\nexport function useRecordUpload(\n  entity: string,\n  id: string,\n  slot: string,\n): UploadOutcome {\n  return withReference(useAttachmentUpload(entity, id, slot));\n}\n\n/** A removal command for one slot of any record, aimed by entity and id. */\nexport function useRecordRemoval(\n  entity: string,\n  id: string,\n  slot: string,\n): RemovalOutcome {\n  return withReference(useAttachmentRemoval(entity, id, slot));\n}\n\n/** The upload command for a request's attachment slots, aimed at the request the route names. */\nexport function useUpload(slot: string): UploadOutcome {\n  const requestEntityId = useRoutedRequestId();\n  return useRecordUpload(requestEntityId, useCurrentRequestId(), slot);\n}\n\n/** The removal command for a request's attachment slots, aimed at the request the route names. */\nexport function useRemoval(slot: string): RemovalOutcome {\n  const requestEntityId = useRoutedRequestId();\n  return useRecordRemoval(requestEntityId, useCurrentRequestId(), slot);\n}\n",
      "type": "registry:block",
      "target": "@components/pages/default-tasks.tsx"
    }
  ],
  "type": "registry:block"
}