{"version":3,"file":"order-options.cjs","names":["__"],"sources":["../../src/gallery/order-options.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\n\n/**\n * An ordering of gallery images: the field to order by and the direction.\n */\nexport type Order = {\n\torderby: string;\n\torder: string;\n};\n\n/**\n * The composite `\"orderby/order\"` select value for an order. A select needs one\n * string per option, so this format exists only at the select boundary; the\n * rest of the feature passes `Order` objects.\n *\n * @param order The order.\n * @return The select value.\n */\nexport function toOrderValue( order: Order ): string {\n\treturn `${ order.orderby }/${ order.order }`;\n}\n\n/**\n * Parses a composite `\"orderby/order\"` select value back into an order.\n *\n * @param value The select value.\n * @return The order.\n */\nexport function parseOrderValue( value: string ): Order {\n\tconst [ orderby, order ] = value.split( '/' );\n\treturn { orderby, order };\n}\n\n/**\n * Ordering options offered for gallery images. Each value is a composite\n * `orderby/order` string. The two modes share values and labels but differ\n * in their comparison logic:\n *\n * - A dynamic gallery passes `orderby/order` to the REST API in the editor (the\n *   `/wp/v2/media` collection params; see `dynamic-source.js`) and to a\n *   `WP_Query` on the front end (see `index.php`). Either way the database\n *   orders by post date or post title.\n * - A static gallery orders its inner image blocks client-side from the same\n *   attachment fields (see `order-images.js`). Dates compare the same way.\n *   Titles use a natural, case-insensitive compare, so `IMG_2` sorts before\n *   `IMG_10` where the database would put it after. The two title orders can\n *   therefore differ for numbered titles.\n *\n * `menu_order` is deliberately omitted — it isn't a valid REST `orderby`\n * value, so the editor preview couldn't reproduce it (see `dynamic-source.js`).\n */\nexport const ORDER_OPTIONS = [\n\t{ label: __( 'Newest to oldest' ), value: 'date/desc' },\n\t{ label: __( 'Oldest to newest' ), value: 'date/asc' },\n\t{\n\t\t/* translators: Label for ordering images by title in ascending order. */\n\t\tlabel: __( 'A → Z' ),\n\t\tvalue: 'title/asc',\n\t},\n\t{\n\t\t/* translators: Label for ordering images by title in descending order. */\n\t\tlabel: __( 'Z → A' ),\n\t\tvalue: 'title/desc',\n\t},\n];\n\n/**\n * The \"Random\" order. Unlike the orders above it isn't an `orderby`: it is the\n * gallery's `randomOrder` attribute, applied only on the front end by shuffling\n * the rendered images (see `index.php`), so the editor keeps showing the\n * underlying order. Offered as the last option of both modes' \"Order by\"\n * control, since it overrides whatever other order is in place.\n */\nexport const RANDOM_ORDER = 'random';\nexport const RANDOM_OPTION = { label: __( 'Random' ), value: RANDOM_ORDER };\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,SAAgB,aAAc,OAAuB;CACpD,OAAO,GAAI,MAAM,QAAS,GAAI,MAAM;AACrC;;;;;;;AAQA,SAAgB,gBAAiB,OAAuB;CACvD,MAAM,CAAE,SAAS,SAAU,MAAM,MAAO,GAAI;CAC5C,OAAO;EAAE;EAAS;CAAM;AACzB;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,gBAAgB;CAC5B;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,kBAAmB;EAAG,OAAO;CAAY;CACtD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,kBAAmB;EAAG,OAAO;CAAW;CACrD;EAEC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,OAAO;CACR;CACA;EAEC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,OAAO;CACR;AACD;;;;;;;;AASA,MAAa,eAAe;AAC5B,MAAa,gBAAgB;CAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,QAAS;CAAG,OAAO;AAAa"}