UNPKG

svelte-parse

Version:

An increidbly relaxed svelte-parser

1,320 lines (1,319 loc) 135 kB
{ "type": "root", "children": [ { "type": "svelteScript", "tagName": "script", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n import { beforeUpdate, createEventDispatcher, onMount } from 'svelte';\n import { classnames } from '../../helpers/classnames';\n import orderBy from 'lodash/orderBy';\n import Pagination from '../Pagination/Pagination.svelte';\n import Spinner from '../Spinner/Spinner.svelte';\n\n const dispatch = createEventDispatcher();\n\n let tableData = undefined;\n\n export let isLoading = false;\n export let hasBorder = false;\n export let isRowClickable = false;\n export let activeSort = undefined;\n export let activeSortDirection = undefined;\n export let currentPage = 1;\n export let pageSize = 10;\n export let isDynamic = false;\n export let columns = [];\n export let showHeader = true;\n export let noResultsMessage = 'No results available';\n export let hasPagination = false;\n export let itemTotal = 0;\n export let data = [];\n export let rowCssClass = () => {};\n\n let ClassNames;\n\n $: {\n ClassNames = classnames({\n hasBorder,\n isLoading,\n isRowClickable,\n noHeader: !showHeader\n });\n }\n\n $: {\n if(data) {\n tableData = data;\n }\n }\n\n $: {\n itemTotal = isDynamic ? itemTotal : data.length;\n }\n\n let Data;\n\n $: {\n if (!tableData) {\n Data = [];\n } else if (isDynamic) {\n Data = tableData;\n } else {\n let processedData = tableData;\n\n if (activeSort) {\n processedData = orderBy(tableData, activeSort, activeSortDirection);\n }\n\n const currentPageSize = pageSize || processedData.length;\n\n Data = processedData.slice((currentPage * currentPageSize) - currentPageSize, currentPage * currentPageSize);\n }\n }\n\n export function sort(selectedHeaderItem) {\n const currentActiveSort = activeSort;\n const currentDirection = activeSortDirection;\n const dataLookup = typeof selectedHeaderItem.cell === 'string' ? selectedHeaderItem.cell : '';\n const selectedSort = typeof selectedHeaderItem.sort === 'boolean' ? dataLookup : selectedHeaderItem.sort;\n\n let newActiveSort = null;\n let newSortDirection = null;\n\n if (currentActiveSort !== selectedSort) {\n newActiveSort = selectedSort;\n newSortDirection = 'asc';\n } else {\n\n if (!currentDirection) {\n newSortDirection = 'asc';\n } else if (currentDirection === 'asc') {\n newSortDirection = 'desc';\n } else {\n newSortDirection = null;\n }\n\n newActiveSort = newSortDirection ? currentActiveSort : null;\n }\n\n activeSort = newActiveSort, activeSortDirection = newSortDirection;\n\n onChange();\n }\n\n function onChange() {\n dispatch('change', {\n currentPage,\n pageSize,\n activeSort,\n activeSortDirection\n });\n }\n\n function onRowClick(rowItem) {\n dispatch('rowClick', rowItem);\n }\n\n function colWidth(col) {\n return col.width ? `width:${col.width};min-width:${col.width};` : '';\n }\n\n function cellAlign(cell) {\n return cell.align ? `text-align:${cell.align};` : '';\n }\n\n function sortClassNames(sort, lookup, activeSort, activeSortDirection) {\n const dataLookup = typeof lookup === 'string' ? lookup : '';\n const actualSort = typeof sort === 'boolean' ? dataLookup : sort;\n\n return classnames({\n 'sort-asc': actualSort === activeSort && activeSortDirection === 'asc',\n 'sort-desc': actualSort === activeSort && activeSortDirection === 'desc'\n });\n }\n\n\n let previous = false;\n let data_prev = undefined;\n\n onMount(() => {\n isRowClickable = !!arguments[0].$$.callbacks.rowClick;\n });\n", "position": { "start": { "line": 1, "column": 9, "offset": 8 }, "end": { "line": 137, "column": 1, "offset": 3486 } } } ], "position": { "start": { "line": 1, "column": 1, "offset": 0 }, "end": { "line": 137, "column": 10, "offset": 3495 } } }, { "type": "text", "value": "\n\n", "position": { "start": { "line": 137, "column": 10, "offset": 3495 }, "end": { "line": 139, "column": 1, "offset": 3497 } } }, { "type": "svelteStyle", "tagName": "style", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n .wrapper {\n position: relative;\n }\n\n .table.hasBorder {\n border: 1px solid #EBEDEF;\n border-radius: 4px;\n }\n\n .isLoading {\n min-height: 150px;\n opacity: 0.6;\n }\n\n .loader {\n cursor: wait;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n }\n\n .loader_spinner {\n color: var(--green_4, #51ce6c);\n width: 25px;\n height: 25px;\n position: absolute;\n top: 50%;\n left: 50%;\n margin: -25px 0 0 -25px;\n }\n\n .pagination {\n padding: 20px 0;\n }\n\n table {\n border: none;\n border-collapse: collapse;\n table-layout: fixed;\n width: 100%;\n }\n\n table thead th {\n border-bottom: 1px solid var(--neutral_0);\n box-sizing: border-box;\n color: var(--neutral_6);\n font-size: 12px;\n font-weight: 600;\n padding: 15px 28px;\n text-align: left;\n white-space: nowrap;\n }\n\n .sort {\n display: inline-block;\n cursor: pointer;\n -webkit-touch-callout: none;\n user-select: none;\n position: relative;\n }\n\n .sort::after,\n .sort::before {\n border-width: 3px;\n border-style: solid;\n display: block;\n height: 0;\n position: absolute;\n right: -11px;\n width: 0;\n content: \" \";\n }\n\n .sort::before {\n border-color: transparent transparent rgba(0, 0, 0, 0.2);\n bottom: 8px;\n }\n\n .sort:hover::before {\n border-color: transparent transparent rgba(0, 0, 0, 0.3);\n }\n\n .sort.sort-asc::before {\n border-color: transparent transparent rgba(0, 0, 0, 0.6);\n }\n\n .sort::after {\n border-color: rgba(0, 0, 0, 0.2) transparent transparent;\n bottom: 0;\n }\n\n .sort:hover::after {\n border-color: rgba(0, 0, 0, 0.3) transparent transparent;\n }\n\n .sort.sort-desc::after {\n border-color: rgba(0, 0, 0, 0.6) transparent transparent;\n }\n\n .isRowClickable tbody tr:not(.noResultsMessage) {\n cursor: pointer;\n transition: all 0.15s;\n }\n\n .isRowClickable tbody tr:not(.noResultsMessage):hover {\n background-color: var(--blue_0);\n }\n\n table tbody td {\n color: var(--neutral_6);\n border-bottom: 1px solid var(--neutral_0);\n box-sizing: border-box;\n font-size: 13px;\n padding: 18px 28px;\n text-align: left;\n vertical-align: middle;\n }\n\n .hasBorder tr:last-of-type td {\n border-bottom: none;\n }\n\n .hasBorder thead tr:first-child th:first-child,\n .hasBorder.noHeader tbody tr:first-child td:first-child {\n border-top-left-radius: 4px;\n }\n\n .hasBorder thead tr:first-child th:last-child,\n .hasBorder.noHeader tbody tr:first-child td:last-child {\n border-top-right-radius: 4px;\n }\n\n .hasBorder tbody tr:last-child td:first-child {\n border-bottom-left-radius: 4px;\n }\n\n .hasBorder tbody tr:last-child td:last-child {\n border-bottom-right-radius: 4px;\n }\n", "position": { "start": { "line": 139, "column": 8, "offset": 3504 }, "end": { "line": 281, "column": 1, "offset": 6247 } } } ], "position": { "start": { "line": 139, "column": 1, "offset": 3497 }, "end": { "line": 281, "column": 9, "offset": 6255 } } }, { "type": "text", "value": "\n\n\n", "position": { "start": { "line": 281, "column": 9, "offset": 6255 }, "end": { "line": 284, "column": 1, "offset": 6258 } } }, { "type": "svelteElement", "tagName": "div", "properties": [ { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "wrapper", "position": { "start": { "line": 284, "column": 13, "offset": 6270 }, "end": { "line": 284, "column": 21, "offset": 6278 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 284, "column": 6, "offset": 6263 }, "end": { "line": 284, "column": 21, "offset": 6278 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 284, "column": 22, "offset": 6279 }, "end": { "line": 285, "column": 3, "offset": 6282 } } }, { "type": "svelteElement", "tagName": "div", "properties": [ { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "table", "position": { "start": { "line": 285, "column": 15, "offset": 6294 }, "end": {} } }, { "type": "text", "value": " ", "position": { "start": { "line": 285, "column": 20, "offset": 6299 }, "end": { "line": 285, "column": 21, "offset": 6300 } } }, { "type": "svelteDynamicContent", "position": { "start": { "line": 285, "column": 21, "offset": 6300 }, "end": { "line": 285, "column": 35, "offset": 6314 } }, "expression": { "type": "svelteExpression", "value": " ClassNames ", "position": { "start": { "line": 285, "column": 22, "offset": 6301 }, "end": { "line": 285, "column": 34, "offset": 6313 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 285, "column": 8, "offset": 6287 }, "end": { "line": 285, "column": 36, "offset": 6315 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 285, "column": 37, "offset": 6316 }, "end": { "line": 286, "column": 5, "offset": 6321 } } }, { "type": "svelteElement", "tagName": "table", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n\n ", "position": { "start": { "line": 286, "column": 12, "offset": 6328 }, "end": { "line": 288, "column": 7, "offset": 6336 } } }, { "type": "svelteElement", "tagName": "colgroup", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 288, "column": 17, "offset": 6346 }, "end": { "line": 289, "column": 9, "offset": 6355 } } }, { "type": "svelteBranchingBlock", "name": "each", "branches": [ { "type": "svelteBranch", "name": "each", "expression": { "type": "svelteExpression", "value": "columns as col ", "position": { "start": { "line": 289, "column": 17, "offset": 6363 }, "end": { "line": 289, "column": 32, "offset": 6378 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 289, "column": 33, "offset": 6379 }, "end": { "line": 290, "column": 9, "offset": 6388 } } }, { "type": "svelteElement", "tagName": "col", "properties": [ { "type": "svelteProperty", "name": "style", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 290, "column": 21, "offset": 6400 }, "end": { "line": 290, "column": 38, "offset": 6417 } }, "expression": { "type": "svelteExpression", "value": " colWidth(col) ", "position": { "start": { "line": 290, "column": 22, "offset": 6401 }, "end": { "line": 290, "column": 37, "offset": 6416 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 290, "column": 14, "offset": 6393 }, "end": { "line": 290, "column": 39, "offset": 6418 } } } ], "selfClosing": true, "children": [], "position": { "start": { "line": 290, "column": 9, "offset": 6388 }, "end": { "line": 290, "column": 42, "offset": 6421 } } }, { "type": "text", "value": "\n ", "position": { "start": { "line": 290, "column": 42, "offset": 6421 }, "end": { "line": 291, "column": 9, "offset": 6430 } } } ], "position": { "start": { "line": 289, "column": 9, "offset": 6355 }, "end": { "line": 291, "column": 9, "offset": 6430 } } } ], "position": { "start": { "line": 289, "column": 9, "offset": 6355 }, "end": { "line": 291, "column": 18, "offset": 6439 } } }, { "type": "text", "value": "\n ", "position": { "start": { "line": 291, "column": 18, "offset": 6439 }, "end": { "line": 292, "column": 7, "offset": 6446 } } } ], "position": { "start": { "line": 288, "column": 7, "offset": 6336 }, "end": { "line": 292, "column": 18, "offset": 6457 } } }, { "type": "text", "value": "\n\n ", "position": { "start": { "line": 292, "column": 18, "offset": 6457 }, "end": { "line": 294, "column": 7, "offset": 6465 } } }, { "type": "svelteBranchingBlock", "name": "if", "branches": [ { "type": "svelteBranch", "name": "if", "expression": { "type": "svelteExpression", "value": "showHeader ", "position": { "start": { "line": 294, "column": 13, "offset": 6471 }, "end": { "line": 294, "column": 24, "offset": 6482 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 294, "column": 25, "offset": 6483 }, "end": { "line": 295, "column": 7, "offset": 6490 } } }, { "type": "svelteElement", "tagName": "thead", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 295, "column": 14, "offset": 6497 }, "end": { "line": 296, "column": 9, "offset": 6506 } } }, { "type": "svelteElement", "tagName": "tr", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 296, "column": 13, "offset": 6510 }, "end": { "line": 297, "column": 11, "offset": 6521 } } }, { "type": "svelteBranchingBlock", "name": "each", "branches": [ { "type": "svelteBranch", "name": "each", "expression": { "type": "svelteExpression", "value": "columns as headerItem ", "position": { "start": { "line": 297, "column": 19, "offset": 6529 }, "end": { "line": 297, "column": 41, "offset": 6551 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 297, "column": 42, "offset": 6552 }, "end": { "line": 298, "column": 11, "offset": 6563 } } }, { "type": "svelteElement", "tagName": "th", "properties": [ { "type": "svelteProperty", "name": "style", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 298, "column": 22, "offset": 6574 }, "end": { "line": 298, "column": 47, "offset": 6599 } }, "expression": { "type": "svelteExpression", "value": " cellAlign(headerItem) ", "position": { "start": { "line": 298, "column": 23, "offset": 6575 }, "end": { "line": 298, "column": 46, "offset": 6598 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 298, "column": 15, "offset": 6567 }, "end": { "line": 298, "column": 48, "offset": 6600 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 298, "column": 49, "offset": 6601 }, "end": { "line": 299, "column": 13, "offset": 6614 } } }, { "type": "svelteBranchingBlock", "name": "if", "branches": [ { "type": "svelteBranch", "name": "if", "expression": { "type": "svelteExpression", "value": "headerItem.sort ", "position": { "start": { "line": 299, "column": 19, "offset": 6620 }, "end": { "line": 299, "column": 35, "offset": 6636 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 299, "column": 36, "offset": 6637 }, "end": { "line": 300, "column": 13, "offset": 6650 } } }, { "type": "svelteElement", "tagName": "span", "properties": [ { "type": "svelteDirective", "name": "on", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 300, "column": 29, "offset": 6666 }, "end": { "line": 300, "column": 53, "offset": 6690 } }, "expression": { "type": "svelteExpression", "value": "() => sort(headerItem)", "position": { "start": { "line": 300, "column": 30, "offset": 6667 }, "end": { "line": 300, "column": 52, "offset": 6689 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 300, "column": 19, "offset": 6656 }, "end": { "line": 300, "column": 54, "offset": 6691 } }, "specifier": "click" }, { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "sort", "position": { "start": { "line": 301, "column": 22, "offset": 6713 }, "end": {} } }, { "type": "text", "value": " ", "position": { "start": { "line": 301, "column": 26, "offset": 6717 }, "end": { "line": 301, "column": 27, "offset": 6718 } } }, { "type": "svelteDynamicContent", "position": { "start": { "line": 301, "column": 27, "offset": 6718 }, "end": { "line": 301, "column": 112, "offset": 6803 } }, "expression": { "type": "svelteExpression", "value": " sortClassNames(headerItem.sort, headerItem.cell, activeSort, activeSortDirection) ", "position": { "start": { "line": 301, "column": 28, "offset": 6719 }, "end": { "line": 301, "column": 111, "offset": 6802 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 301, "column": 15, "offset": 6706 }, "end": { "line": 301, "column": 113, "offset": 6804 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 301, "column": 114, "offset": 6805 }, "end": { "line": 302, "column": 15, "offset": 6820 } } }, { "type": "svelteBranchingBlock", "name": "if", "branches": [ { "type": "svelteBranch", "name": "if", "expression": { "type": "svelteExpression", "value": "headerItem.title.component ", "position": { "start": { "line": 302, "column": 21, "offset": 6826 }, "end": { "line": 302, "column": 48, "offset": 6853 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 302, "column": 49, "offset": 6854 }, "end": { "line": 303, "column": 15, "offset": 6869 } } }, { "type": "svelteMeta", "tagName": "component", "properties": [ { "type": "svelteProperty", "name": "this", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 303, "column": 38, "offset": 6892 }, "end": { "line": 303, "column": 66, "offset": 6920 } }, "expression": { "type": "svelteExpression", "value": "headerItem.title.component", "position": { "start": { "line": 303, "column": 39, "offset": 6893 }, "end": { "line": 303, "column": 65, "offset": 6919 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 303, "column": 33, "offset": 6887 }, "end": { "line": 303, "column": 66, "offset": 6920 } } }, { "type": "svelteProperty", "name": "...headerItem.title.props", "value": [ { "type": "svelteDynamicContent", "expression": { "type": "svelteExpression", "value": "...headerItem.title.props", "position": { "start": { "line": 303, "column": 68, "offset": 6922 }, "end": { "line": 303, "column": 93, "offset": 6947 } } }, "position": { "start": { "line": 303, "column": 67, "offset": 6921 }, "end": { "line": 303, "column": 93, "offset": 6947 } } } ], "modifiers": [], "shorthand": "expression", "position": { "start": { "line": 303, "column": 67, "offset": 6921 }, "end": { "line": 303, "column": 93, "offset": 6947 } } } ], "selfClosing": true, "children": [], "position": { "start": { "line": 303, "column": 15, "offset": 6869 }, "end": { "line": 303, "column": 97, "offset": 6951 } } }, { "type": "text", "value": "\n ", "position": { "start": { "line": 303, "column": 97, "offset": 6951 }, "end": { "line": 304, "column": 15, "offset": 6966 } } } ], "position": { "start": { "line": 302, "column": 15, "offset": 6820 }, "end": { "line": 304, "column": 15, "offset": 6966 } } }, { "type": "svelteBranch", "name": "else", "expression": { "type": "svelteExpression", "value": "", "position": { "start": { "line": 304, "column": 23, "offset": 6974 }, "end": { "line": 304, "column": 23, "offset": 6974 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 304, "column": 24, "offset": 6975 }, "end": { "line": 305, "column": 15, "offset": 6990 } } }, { "type": "svelteVoidBlock", "name": "html", "expression": { "type": "svelteExpression", "value": "headerItem.title ", "position": { "start": { "line": 305, "column": 23, "offset": 6998 }, "end": { "line": 305, "column": 40, "offset": 7015 } } }, "position": { "start": { "line": 305, "column": 15, "offset": 6990 }, "end": { "line": 305, "column": 41, "offset": 7016 } } }, { "type": "text", "value": "\n ", "position": { "start": { "line": 305, "column": 41, "offset": 7016 }, "end": { "line": 306, "column": 15, "offset": 7031 } } } ], "position": { "start": { "line": 304, "column": 15, "offset": 6966 }, "end": { "line": 306, "column": 15, "offset": 7031 } } } ], "position": { "start": { "line": 302, "column": 15, "offset": 6820 }, "end": { "line": 306, "column": 22, "offset": 7038 } } }, { "type": "text", "value": "\n ", "position": { "start": { "line": 306, "column": 22, "offset": 7038 }, "end": { "line": 307, "column": 13, "offset": 7051 } } } ], "position": { "start": { "line": 300, "column": 13, "offset": 6650 }, "end": { "line": 307, "column": 20, "offset": 7058 } } }, { "type": "text", "value": "\n ", "position": { "start": { "line": 307, "column": 20, "offset": 7058 }, "end": { "line": 308, "column": 13, "offset": 7071 } } } ], "position": { "start": { "line": 299, "column": 13, "offset": 6614 }, "end": { "line": 308, "column": 13, "offset": 7071 } } }, { "type": "svelteBranch", "name": "else", "expression": { "type": "svelteExpression", "value": "", "position": { "start": { "line": 308, "column": 21, "offset": 7079 }, "end": { "line": 308, "column": 21, "offset": 7079 } } }, "children": [ { "type": "text", "value": "\n ", "position": { "start": { "line": 308, "column": 22, "offset": 7080 }, "end": { "line": 309, "column": 13, "offset": 7093 } } }, { "type": "svelteBranchingBlock", "name": "if", "branches": [ { "type": "svelteBranch", "name": "if", "expression": { "type": "svelteExpression", "value": "headerItem.title.component ", "position": { "start": { "line": 309, "column": 19,