{
  "version": 3,
  "sources": ["row_rename_commit.js"],
  "sourcesContent": ["/*\n * static/js/row_rename_commit.js \u2014 committing a UGC row's inline rename to\n * the server (SNOW-711).\n *\n * The server half of static/js/inline_rename.js. That module owns the\n * INTERACTION \u2014 the pencil reveals the editor, Enter or blur commits,\n * Escape cancels, an emptied field leaves the title alone \u2014 and calls back\n * once with a name worth writing. This module owns what three surfaces then\n * do with that name, which had been the same twenty lines in each of them:\n *\n *   1. read the row's own uuid off the pencil (the delegated handler needs\n *      no closure over the rendered row);\n *   2. POST it to a `__UUID__`-templated rename URL as a form-encoded\n *      `name`, with `HX-Request` \u2014 every one of those endpoints is\n *      @require_htmx and this is a plain fetch \u2014 and the CSRF token the\n *      calling surface can reach;\n *   3. hand the response back to the caller, which is the ONLY part that\n *      differs.\n *\n * WHY THE CALLERS STILL DIFFER AT STEP 3. The map panels\n * (static/js/favourites.js, static/js/routes.js) throw the response away\n * and re-read their list: favourite_rename and route_rename answer with the\n * ACCOUNT page's row, which carries a disclosure the map row does not, so\n * it cannot be swapped into a map panel. The account page\n * (static/js/account_favourites.js) swaps that same response straight into\n * the row it came from, because there it is exactly the right shape. The\n * refetch on the map is therefore not something this extraction removes \u2014\n * see routes.js's own note on why teaching those endpoints a `?variant=`\n * parameter is the wrong trade.\n *\n * ONLINE-ONLY, on every caller. Creates are queued for offline replay\n * (window.pwaMutationQueue); edits to an existing row are not, and this\n * module deliberately does not change that.\n *\n * No user-facing strings: a failed commit is reported by the caller, in\n * the idiom of its own surface (a map toast, the account page's HTMX error\n * banner). See docs/i18n.md for why a string built here could not be\n * translated.\n */\n\n(function rowRenameCommitInit() {\n  'use strict';\n\n  /**\n   * Handle a click that may start and commit a row's inline rename.\n   *\n   * Shaped to be called from a surface's own delegated click listener and\n   * to answer the question that listener asks next: \"was this a rename, or\n   * should I keep testing?\" A click that is not on a pencil returns false\n   * and is left entirely alone.\n   *\n   * A misconfigured or unidentifiable row returns TRUE without writing: the\n   * click WAS a rename, it simply cannot be served, and reporting it as\n   * \"not a rename\" would send it on to the caller's add-CTA test.\n   *\n   * @param {MouseEvent} event The click.\n   * @param {{\n   *   uuidAttribute: string,\n   *   urlTemplate: string,\n   *   csrfToken: function(): string,\n   *   onCommitted: function(Response, HTMLElement): void,\n   *   onFailed: function(): void,\n   * }} options\n   *   `uuidAttribute` is the panel's own hook on the pencil\n   *   (`data-favourite-rename`, `data-route-rename`) carrying the row's\n   *   uuid; `urlTemplate` is the rename endpoint with `__UUID__` where the\n   *   uuid goes; `csrfToken` is called at commit time, not at bind time,\n   *   because the element carrying the token may have been re-rendered\n   *   since; `onCommitted` receives the unread Response and the row it\n   *   belongs to; `onFailed` covers a non-2xx, a dropped request, and a\n   *   throw out of `onCommitted` alike \u2014 all three leave the row showing\n   *   something the server did not agree to.\n   * @returns {boolean} Whether this click was a rename.\n   */\n  function handleClick(event, options) {\n    var row = window.pwaInlineRename && window.pwaInlineRename.rowFor(event.target);\n    if (!row) return false;\n    if (!options || !options.urlTemplate) return true;\n\n    var button = row.querySelector('[' + options.uuidAttribute + ']');\n    var uuid = button ? button.getAttribute(options.uuidAttribute) : '';\n    if (!uuid) return true;\n\n    window.pwaInlineRename.begin(row, function (name) {\n      fetch(options.urlTemplate.replace('__UUID__', uuid), {\n        method: 'POST',\n        headers: {\n          'HX-Request': 'true',\n          'X-CSRFToken': options.csrfToken ? options.csrfToken() : '',\n          'Content-Type': 'application/x-www-form-urlencoded',\n        },\n        body: new URLSearchParams({ name: name }).toString(),\n      })\n        .then(function (resp) {\n          if (!resp.ok) throw new Error('rename failed');\n          if (options.onCommitted) return options.onCommitted(resp, row);\n          return undefined;\n        })\n        .catch(function () {\n          if (options.onFailed) options.onFailed();\n        });\n    });\n    return true;\n  }\n\n  window.pwaRowRenameCommit = Object.freeze({\n    handleClick: handleClick,\n  });\n})();\n"],
  "mappings": "CAwCC,UAA+B,CAC9B,aAiCA,SAASA,EAAYC,EAAOC,EAAS,CACnC,IAAIC,EAAM,OAAO,iBAAmB,OAAO,gBAAgB,OAAOF,EAAM,MAAM,EAC9E,GAAI,CAACE,EAAK,MAAO,GACjB,GAAI,CAACD,GAAW,CAACA,EAAQ,YAAa,MAAO,GAE7C,IAAIE,EAASD,EAAI,cAAc,IAAMD,EAAQ,cAAgB,GAAG,EAC5DG,EAAOD,EAASA,EAAO,aAAaF,EAAQ,aAAa,EAAI,GACjE,OAAKG,GAEL,OAAO,gBAAgB,MAAMF,EAAK,SAAUG,EAAM,CAChD,MAAMJ,EAAQ,YAAY,QAAQ,WAAYG,CAAI,EAAG,CACnD,OAAQ,OACR,QAAS,CACP,aAAc,OACd,cAAeH,EAAQ,UAAYA,EAAQ,UAAU,EAAI,GACzD,eAAgB,mCAClB,EACA,KAAM,IAAI,gBAAgB,CAAE,KAAMI,CAAK,CAAC,EAAE,SAAS,CACrD,CAAC,EACE,KAAK,SAAUC,EAAM,CACpB,GAAI,CAACA,EAAK,GAAI,MAAM,IAAI,MAAM,eAAe,EAC7C,GAAIL,EAAQ,YAAa,OAAOA,EAAQ,YAAYK,EAAMJ,CAAG,CAE/D,CAAC,EACA,MAAM,UAAY,CACbD,EAAQ,UAAUA,EAAQ,SAAS,CACzC,CAAC,CACL,CAAC,EACM,EACT,CAEA,OAAO,mBAAqB,OAAO,OAAO,CACxC,YAAaF,CACf,CAAC,CACH,GAAG",
  "names": ["handleClick", "event", "options", "row", "button", "uuid", "name", "resp"]
}
