@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 3.53 kB
Source Map (JSON)
{
"version": 3,
"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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AAkBZ,SAAS,aAAc,OAAuB;AACpD,SAAO,GAAI,MAAM,OAAQ,IAAK,MAAM,KAAM;AAC3C;AAQO,SAAS,gBAAiB,OAAuB;AACvD,QAAM,CAAE,SAAS,KAAM,IAAI,MAAM,MAAO,GAAI;AAC5C,SAAO,EAAE,SAAS,MAAM;AACzB;AAoBO,IAAM,gBAAgB;AAAA,EAC5B,EAAE,WAAO,gBAAI,kBAAmB,GAAG,OAAO,YAAY;AAAA,EACtD,EAAE,WAAO,gBAAI,kBAAmB,GAAG,OAAO,WAAW;AAAA,EACrD;AAAA;AAAA,IAEC,WAAO,gBAAI,OAAQ;AAAA,IACnB,OAAO;AAAA,EACR;AAAA,EACA;AAAA;AAAA,IAEC,WAAO,gBAAI,OAAQ;AAAA,IACnB,OAAO;AAAA,EACR;AACD;AASO,IAAM,eAAe;AACrB,IAAM,gBAAgB,EAAE,WAAO,gBAAI,QAAS,GAAG,OAAO,aAAa;",
"names": []
}