{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lib-content",
  "title": "Block content",
  "description": "Supplies the generic wording every block reads through a React context, so an adopter can override labels, hints and messages from one place without editing block source.",
  "registryDependencies": [
    "@registrystack/lib-format"
  ],
  "files": [
    {
      "path": "lib/content.tsx",
      "content": "import { createContext, useContext, useMemo } from \"react\";\nimport { fillNodes } from \"@/blocks/lib/format\";\n\n/**\n * The wording an app sets, by area. Each area's hook reads its own entry and\n * falls back to its defaults; `ContentProvider` is the one place that fills\n * this in.\n */\nexport const ContentContext = createContext<Record<string, unknown>>({});\n\n/**\n * The texts the session's UI model sets for the kit's wording, by message id\n * (`<area>.<key>`), in the session's language. They stand over the app's own\n * wording; `ContentProvider` fills this in from the model.\n */\nexport const MessagesContext = createContext<Readonly<Record<string, string>>>(\n  {},\n);\n\n/**\n * The locale blocks format dates, numbers and lists in: the session's language\n * as `ModelMessages` sets it, else the kit's English, which is British English.\n */\nexport const LocaleContext = createContext(\"en-GB\");\n\n/** The locale to pass a formatter, so its dates and numbers read like the words around them. */\nexport function useLocale(): string {\n  return useContext(LocaleContext);\n}\n\n/**\n * `node` with the text at `path` replaced, or added under a map of words\n * (an object of words below the area's own), copying only the objects along\n * the path. The rest of a path a map does not divide is one key, since the\n * ids an app chooses, such as a file type, may hold dots.\n */\nfunction withText(\n  node: unknown,\n  path: string[],\n  text: string,\n  depth = 0,\n): unknown {\n  if (!node || typeof node !== \"object\") return node;\n  const record = node as Record<string, unknown>;\n  const [key, ...rest] = path;\n  const child = record[key!];\n  if (rest.length && Object.hasOwn(record, key!) && typeof child === \"object\") {\n    const next = withText(child, rest, text, depth + 1);\n    return next === child ? node : { ...record, [key!]: next };\n  }\n  const whole = path.join(\".\");\n  const words =\n    depth > 0 &&\n    Object.values(record).every((value) => typeof value === \"string\");\n  if (\n    record[whole] === text ||\n    (Object.hasOwn(record, whole) ? typeof record[whole] !== \"string\" : !words)\n  )\n    return node;\n  return { ...record, [whole]: text };\n}\n\n/**\n * An area's wording with the model's texts set over it. Only the ids under\n * the area apply, and only to words that are text or to a key of a map of\n * words; the wording given is not changed, and is returned as it is when no\n * text applies.\n */\nexport function withMessages<T>(\n  area: string,\n  content: T,\n  messages: Readonly<Record<string, string>>,\n): T {\n  const prefix = `${area}.`;\n  return Object.entries(messages)\n    .filter(([id]) => id.startsWith(prefix))\n    .reduce(\n      (words, [id, text]) =>\n        withText(words, id.slice(prefix.length).split(\".\"), text) as T,\n      content,\n    );\n}\n\n/** One area's wording from the nearest `ContentProvider`, else its `defaults`, under the model's texts. */\nexport function useContentArea<T>(area: string, defaults: T): T {\n  const content = (useContext(ContentContext)[area] as T | undefined) ?? defaults;\n  const messages = useContext(MessagesContext);\n  return useMemo(\n    () => withMessages(area, content, messages),\n    [area, content, messages],\n  );\n}\n\n/**\n * The words blocks show on their own: generic defaults an app replaces with\n * its own content through `ContentProvider`.\n */\nexport interface BlockContent {\n  notRecorded: string;\n  /** The heading that opens a quantity's unit scheme. */\n  quantityUnitStandard: string;\n  /** The heading that opens the full URI behind a value read as words. */\n  fullIdentifier: string;\n  yes: string;\n  no: string;\n  notSupplied: string;\n  /** A label and its value read on one line, as in \"Receipt: R-1\". */\n  labelled: string;\n  /** `labelled` as a sentence of its own. */\n  labelledSentence: string;\n  optional: string;\n  selectOption: string;\n  errorPrefix: string;\n  /** Shown while a block waits on data it cannot yet render. */\n  loading: string;\n  /** The hint of a checkbox group whose field carries none. */\n  choicesHint: string;\n  /** The words for a recorded blank answer, by field id. */\n  blankValues: Readonly<Record<string, string>>;\n  /** Words for coded values, by code, before the words a field model carries. */\n  terms: Readonly<Record<string, string>>;\n\n  // Record blocks: a list's search and paging, a table's row action, a\n  // form's validation banner. Generic defaults; an app's own wording (which\n  // may name its register) reaches these through `blockContentOf`.\n  search: string;\n  clearSearch: string;\n  /** A filter select's choice that applies no filter. */\n  filterAll: string;\n  previous: string;\n  next: string;\n  page: string;\n  viewRecord: string;\n  actions: string;\n  validationTitle: string;\n  requiredError: string;\n  /** The check message for one field, by field id, before the generic wording below. */\n  fieldErrors: Readonly<Record<string, string>>;\n  dateError: string;\n  invalidError: string;\n  /** A decimal answer with more places than the registry keeps; `{places}` is how many it keeps. */\n  decimalPlacesError: string;\n  /** A decimal answer the registry keeps without places. */\n  wholeNumberError: string;\n  /** A number below its declared minimum, `{limit}`. */\n  minimumError: string;\n  /** A number above its declared maximum, `{limit}`. */\n  maximumError: string;\n  /** Coordinate labels for a CRS84 point, whose order is longitude then latitude. */\n  longitudeLabel: string;\n  latitudeLabel: string;\n\n  // Request blocks: a command's outcome, a decision, a change comparison,\n  // reviewer notes, verified prefill and supporting documents. Generic\n  // defaults; wording that names the register (a decision's own body text, a\n  // recovery notice's product name, the \"before\"/\"after\" column headings)\n  // reaches these blocks as required props instead, supplied by the app.\n  saving: string;\n  unknownTitle: string;\n  unknownBody: string;\n  retryRefused: string;\n  receipt: string;\n  /** Why a confirmed write keeps its exact registry reference. */\n  receiptHelp: string;\n  exactRetry: string;\n  reconcile: string;\n  confirmed: string;\n  openRequest: string;\n  decisionCheckHeading: string;\n  decisionChange: string;\n  decisionContinue: string;\n  decisionReasonLabel: string;\n  decisionReasonAudience: string;\n  decisionReasonHint: string;\n  noActions: string;\n  staleDecidedTitle: string;\n  staleDecidedBody: string;\n  reloadRequest: string;\n  /** The comparison shown when a save is refused because the record changed since it was read. */\n  conflictTitle: string;\n  conflictBody: string;\n  conflictFieldColumn: string;\n  conflictStartedColumn: string;\n  conflictMineColumn: string;\n  conflictLatestColumn: string;\n  /** Said in words on a field both the person and the registry changed to different values. */\n  conflictBothChanged: string;\n  conflictKeepMine: string;\n  conflictTakeLatest: string;\n  conflictKept: string;\n  conflictTaken: string;\n  decidedTitle: string;\n  /** Announced to assistive technology once a decision is confirmed; the decision's own body text is the caller's, since it may name what the decision changes. */\n  decisionAnnounced: string;\n  proposedHeading: string;\n  fieldColumn: string;\n  currentColumn: string;\n  proposedColumn: string;\n  changedMarker: string;\n  showUnchanged: string;\n  hideUnchanged: string;\n  currentUnavailable: string;\n  /** The comparison of an applied request: what the record held before it, and what it wrote. */\n  appliedChangesHeading: string;\n  beforeColumn: string;\n  afterColumn: string;\n  /** Where the record history this session reads does not hold the values before an applied request. */\n  beforeUnavailable: string;\n  whyAskedHeading: string;\n  /** `whyAskedHeading` on a holder's own request. */\n  holderWhyAskedHeading: string;\n  changeAnswer: string;\n  prefillVerified: string;\n  prefillChanged: string;\n  prefillInvalid: string;\n  prefillLoading: string;\n  prefillProposed: string;\n  acceptPrefill: string;\n  prefillUnavailable: string;\n  prefillUncertain: string;\n  prefillDenied: string;\n  prefillExpired: string;\n  /**\n   * A verified answer's line: `{label}` is `prefillProposed` or\n   * `prefillVerified`, `{answer}` is yes or no, and `{source}` and `{date}`\n   * say who verified it and when.\n   */\n  prefillAnswerLine: string;\n  /** A draft's retained evidence: its answer, and when it was verified. */\n  prefillDraftLine: string;\n  /** A submitted request's retained evidence, under the `prefillVerified` heading. */\n  prefillSummaryLine: string;\n  getVerifiedInformation: string;\n  revisionNoNote: string;\n  /** What an officer reads when the reviewer left the requester no note. */\n  requesterNoNote: string;\n  undisclosedRevisionReason: string;\n  attachmentsHeading: string;\n  attachmentReadiness: string;\n  attachmentNone: string;\n  attachmentRequired: string;\n  attachmentRemove: string;\n  attachmentChoose: string;\n  attachmentChooseReplacement: string;\n  attachmentAllowed: string;\n  attachmentUpload: string;\n  attachmentReplace: string;\n  attachmentWrongType: string;\n  attachmentTooLarge: string;\n  attachmentDownload: string;\n  attachmentNotRetainedTitle: string;\n  attachmentNotRetained: string;\n  /** Shown when an uploaded file is empty even though its declared type is accepted. */\n  attachmentEmpty: string;\n  /** Shown when an uploaded file's bytes do not match its declared type. */\n  attachmentContentMismatch: string;\n  attachmentStopWaiting: string;\n  attachmentFileLost: string;\n  attachmentFileLine: string;\n  attachmentFileLineUndated: string;\n  fileSizeKilobytes: string;\n  fileSizeMegabytes: string;\n  /** \"View {document}\", the document's own name filled in by the caller. */\n  documentView: string;\n  documentSelected: string;\n  documentSelectedReplacement: string;\n\n  // Repeatable groups: the words for adding and removing an item, and for\n  // naming one item by its position among the others. Optional: an app that\n  // builds its BlockContent from its own content type may not carry these\n  // yet, so the group control falls back to its own default wording.\n  addGroupItem?: string;\n  /** `{index}`: the item's position, from 1. */\n  removeGroupItem?: string;\n  /** `{index}`: the item's position, from 1. */\n  groupItemLegend?: string;\n  /** A repeatable group read in a link or a line of text, by its `{count}` of items. */\n  groupEntryCount?: string;\n  /**\n   * Shown in place of a reference to a record that cannot be read or named.\n   * Optional for the same reason; the reference value falls back to its own\n   * default wording.\n   */\n  referenceUnavailable?: string;\n  /** Under a reference picker that found no record to offer. */\n  referenceNoMatch?: string;\n  /** Under a reference picker whose records could not be read. */\n  referenceLoadFailed?: string;\n  /** The button that clears a chosen record so another can be picked. */\n  referenceChange?: string;\n  /** The first option of a reference picker that lists records to choose from. */\n  referenceChoose?: string;\n  /**\n   * A record offered in a reference picker's list, by its `{title}` and the\n   * `{detail}` that tells it apart from records with the same title.\n   */\n  referenceOption?: string;\n  /** Loads the next authorized page of records in a reference picker. */\n  referenceMore?: string;\n  /** Restarts a paged reference picker at its authorized first page. */\n  referenceRestart?: string;\n  /** Finds one authorized record by an exact identifier. */\n  referenceFind?: string;\n  /** Explains that an exact lookup must succeed before its record can be chosen. */\n  referenceLookupHint?: string;\n  /** A neutral result for a missing, unreadable or refused exact record lookup. */\n  referenceLookupUnavailable?: string;\n  /** Names the identifier input of a reference picker that also offers lookup selectors. */\n  referenceIdentifier?: string;\n  /** Opens the identifier input of a reference picker that also offers lookup selectors, as a separate way in. */\n  referenceIdentifierOther?: string;\n  /** Sends a reference lookup again after the service did not answer it. */\n  referenceRetry?: string;\n  /** Shown when this session can neither list nor look up the target. */\n  referenceSelectionUnavailable?: string;\n}\n\nexport const blockContent: BlockContent = {\n  notRecorded: \"Not recorded\",\n  quantityUnitStandard: \"Unit standard\",\n  fullIdentifier: \"Full identifier\",\n  yes: \"Yes\",\n  no: \"No\",\n  notSupplied: \"Not supplied\",\n  labelled: \"{label}: {value}\",\n  labelledSentence: \"{label}: {value}.\",\n  optional: \"optional\",\n  selectOption: \"Choose an option\",\n  errorPrefix: \"Error:\",\n  loading: \"Loading…\",\n  choicesHint: \"Select all that apply.\",\n  blankValues: {},\n  terms: {},\n\n  search: \"Search\",\n  clearSearch: \"Clear search\",\n  filterAll: \"All\",\n  previous: \"Previous\",\n  next: \"Next\",\n  page: \"Page\",\n  viewRecord: \"View record\",\n  actions: \"Actions\",\n  validationTitle: \"Check the information you entered\",\n  requiredError: \"Enter a value for this field.\",\n  fieldErrors: {},\n  dateError: \"Enter a valid date.\",\n  invalidError: \"Enter a valid value.\",\n  decimalPlacesError:\n    \"Enter a number with no more than {places, plural, one {# decimal place} other {# decimal places}}.\",\n  wholeNumberError: \"Enter a whole number.\",\n  minimumError: \"Enter {limit} or more.\",\n  maximumError: \"Enter {limit} or less.\",\n  longitudeLabel: \"Longitude\",\n  latitudeLabel: \"Latitude\",\n\n  saving: \"Sending…\",\n  unknownTitle: \"We could not confirm the result\",\n  unknownBody:\n    \"Your request may have reached the registry. Do not start a replacement submission. You can retry this exact submission while its original session and authority remain available.\",\n  retryRefused:\n    \"The service refused this retry. The earlier submission outcome is still not confirmed.\",\n  receipt: \"Support reference\",\n  receiptHelp:\n    \"Keep this reference if you need help finding this change in the registry.\",\n  exactRetry: \"Retry this exact submission\",\n  reconcile: \"Check current records\",\n  confirmed: \"Confirmed by the registry\",\n  openRequest: \"Open request\",\n  decisionCheckHeading: \"Check before you continue\",\n  decisionChange: \"Back to the request\",\n  decisionContinue: \"Continue\",\n  decisionReasonLabel: \"Reason\",\n  decisionReasonAudience: \"The subject reads this.\",\n  decisionReasonHint:\n    \"Say what is wrong with the request and what the subject needs to change or provide, in words they will understand.\",\n  noActions: \"There are no actions available to your account for this request.\",\n  staleDecidedTitle: \"This request was decided while you had it open\",\n  staleDecidedBody:\n    \"Another reviewer has recorded a decision. Check what changed, then reload this request.\",\n  reloadRequest: \"Reload this request\",\n  conflictTitle: \"This record changed while you had it open\",\n  conflictBody:\n    \"Nothing was saved. Compare what you began with, what you entered and what the registry holds now, then choose which to keep. Your entry is not combined with the latest.\",\n  conflictFieldColumn: \"Field\",\n  conflictStartedColumn: \"What you began with\",\n  conflictMineColumn: \"What you entered\",\n  conflictLatestColumn: \"What it is now\",\n  conflictBothChanged: \"Changed by both\",\n  conflictKeepMine: \"Keep my entry\",\n  conflictTakeLatest: \"Take the latest\",\n  conflictKept: \"Your entry is kept. Save it again to send it against the latest version.\",\n  conflictTaken: \"The latest values replace your entry. Review them, then save.\",\n  decidedTitle: \"Request updated\",\n  decisionAnnounced: \"The request was updated.\",\n  proposedHeading: \"What is proposed\",\n  fieldColumn: \"Field\",\n  currentColumn: \"Current\",\n  proposedColumn: \"Proposed\",\n  changedMarker: \"Changed\",\n  showUnchanged: \"Show unchanged fields ({count})\",\n  hideUnchanged: \"Hide unchanged fields\",\n  currentUnavailable:\n    \"The recorded values at the time of this decision are not held with the request.\",\n  appliedChangesHeading: \"What changed\",\n  beforeColumn: \"Before\",\n  afterColumn: \"After\",\n  beforeUnavailable:\n    \"The values before this change are not in the record history you can read.\",\n  whyAskedHeading: \"Reason given\",\n  holderWhyAskedHeading: \"Why you asked\",\n  changeAnswer: \"Change {field}\",\n  prefillVerified: \"Verified source answer\",\n  prefillChanged: \"Changed after verification\",\n  prefillInvalid:\n    \"The retained evidence could not be re-verified. Treat this answer as unverified.\",\n  prefillLoading: \"Requesting verified information…\",\n  prefillProposed: \"Proposed verified answer\",\n  acceptPrefill: \"Use this answer\",\n  prefillUnavailable:\n    \"Verified information is unavailable. Enter your answer yourself or attach a supporting document.\",\n  prefillUncertain:\n    \"The request outcome is uncertain. Retrying this reference will not request the information again. You can enter it yourself.\",\n  prefillDenied:\n    \"The provider could not release this information. Enter it yourself or attach a document.\",\n  prefillExpired:\n    \"This verified answer has expired. Request it again or enter your answer yourself.\",\n  prefillAnswerLine: \"{label}: {answer}. {source}, {date}.\",\n  prefillDraftLine: \"{label}: {answer}. {date}.\",\n  prefillSummaryLine: \"{answer}. {source}, {date}.\",\n  getVerifiedInformation: \"Get verified information\",\n  revisionNoNote: \"The reviewer did not leave a note for you.\",\n  requesterNoNote: \"The reviewer did not leave a note for the requester.\",\n  undisclosedRevisionReason: \"The reviewer reason is not available to this account.\",\n  attachmentsHeading: \"Supporting documents\",\n  attachmentReadiness: \"{ready} of {total} required documents ready\",\n  attachmentNone: \"No document attached.\",\n  attachmentRequired: \"Needed before the request can be submitted.\",\n  attachmentRemove: \"Remove document\",\n  attachmentChoose: \"Choose a file\",\n  attachmentChooseReplacement: \"Choose a replacement file\",\n  attachmentAllowed: \"{types}, up to {size}.\",\n  attachmentUpload: \"Add document\",\n  attachmentReplace: \"Replace document\",\n  attachmentWrongType: \"This file is not a {types}. Choose another file.\",\n  attachmentTooLarge: \"This file is {size}. Choose one up to {limit}.\",\n  attachmentDownload: \"Download {document}\",\n  attachmentNotRetainedTitle: \"The file was not sent\",\n  attachmentNotRetained:\n    \"This browser could not keep a copy of the file for an exact retry, so it was not sent. Free some browser storage or use another browser, then try again.\",\n  attachmentEmpty: \"This file is empty. Choose another file.\",\n  attachmentContentMismatch:\n    \"This file's contents do not match its type. Choose another file.\",\n  attachmentStopWaiting:\n    \"I have checked the documents; stop waiting for this upload\",\n  attachmentFileLost:\n    \"This browser no longer holds the exact file, so it cannot be sent again. Check the documents on this request before adding it again.\",\n  attachmentFileLine: \"{type}, {size}, added {date}\",\n  attachmentFileLineUndated: \"{type}, {size}\",\n  fileSizeKilobytes: \"{size} KB\",\n  fileSizeMegabytes: \"{size} MB\",\n  documentView: \"View {document}\",\n  documentSelected:\n    \"Selected: {name} ({type}, {size}). Choose Add document to save it.\",\n  documentSelectedReplacement:\n    \"Selected: {name} ({type}, {size}). Choose Replace document to save it.\",\n\n  addGroupItem: \"Add item\",\n  removeGroupItem: \"Remove item {index}\",\n  groupItemLegend: \"Item {index}\",\n  groupEntryCount: \"{count, plural, one {# item} other {# items}}\",\n  referenceUnavailable: \"A record that could not be read\",\n  referenceNoMatch: \"No matching records\",\n  referenceLoadFailed: \"The records could not be read\",\n  referenceChange: \"Choose a different record\",\n  referenceChoose: \"Choose a record\",\n  referenceOption: \"{title} ({detail})\",\n  referenceMore: \"Show more records\",\n  referenceRestart: \"Start choices again\",\n  referenceFind: \"Find record\",\n  referenceLookupHint:\n    \"Enter the record identifier, then find the record before choosing it.\",\n  referenceLookupUnavailable: \"No record is available for that identifier.\",\n  referenceIdentifier: \"Record identifier\",\n  referenceIdentifierOther: \"Or, if you have the record identifier\",\n  referenceRetry: \"Try again\",\n  referenceSelectionUnavailable:\n    \"No records are available to choose with this account.\",\n};\n\nexport function useBlockContent(): BlockContent {\n  return useContentArea(\"block\", blockContent);\n}\n\n/**\n * A confirmed write's exact registry reference, kept as secondary support\n * detail: small and muted, but shown beside its label with what it is for, as\n * an unconfirmed write's reference is.\n */\nexport function ConfirmedReceipt({ receipt }: { receipt: string }) {\n  const c = useBlockContent();\n  const locale = useLocale();\n  return (\n    <div className=\"reference\">\n      <p>\n        {fillNodes(\n          c.labelled,\n          {\n            label: c.receipt,\n            value: <span className=\"font-mono\">{receipt}</span>,\n          },\n          locale,\n        )}\n      </p>\n      <p>{c.receiptHelp}</p>\n    </div>\n  );\n}\n",
      "type": "registry:lib",
      "target": "@lib/content.tsx"
    }
  ],
  "type": "registry:lib"
}