Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | 8x 26x 8x 53x 8x 8x 10x 10x 10x 10x 8x 39x 39x 39x 8x 8x 8x 28x 8x 42x 8x 8x 8x 8x 403x 403x 403x 403x 403x 8x 8x 8x | import { validProps } from '@appbaseio/reactivecore/lib/utils/constants'; import { helper } from '@appbaseio/reactivecore'; import connectToStore from './connector'; const { updateDefaultQuery: defaultQueryUtil, updateCustomQuery: customQueryUtil, isEqual, } = helper; // TODO // import { storeKey } from '@appbaseio/reactivecore'; export const connect = (...args) => connectToStore(...args); // connectToStore(...args, null, { // storeKey, // }); export const X_SEARCH_CLIENT = 'ReactiveSearch Vue'; export const composeThemeObject = (ownTheme = {}, userTheme = {}) => ({ typography: { ...ownTheme.typography, ...userTheme.typography, }, colors: { ...ownTheme.colors, ...userTheme.colors, }, component: { ...ownTheme.component, ...userTheme.component, }, }); /** * To determine wether an element is a function * @param {any} element */ export const isFunction = element => typeof element === 'function'; // parses current array (i.e. this.$props.value) for `onChange` callback for multi-* components export function parseValueArray(objectValues, currentValue) { let selectedValues; if (Array.isArray(objectValues)) { selectedValues = [...objectValues]; } else { const keys = Object.keys(objectValues); selectedValues = keys.map((key) => (objectValues[key] ? key : null)); } if (selectedValues.includes(currentValue)) { return selectedValues.filter(item => item !== currentValue); } return [...selectedValues, currentValue]; } /** * Extracts the render prop from props or slot and returns a valid JSX element * @param {Object} data * @param _ref */ export const getComponent = (data = {}, _ref = {}) => { const { render: renderScope } = _ref.$scopedSlots || {}; const { render: renderProp } = _ref.$props || {}; const render = renderScope || renderProp; Eif (render) return render(data); return null; }; /** * To determine whether a component has render prop or slot defined or not * @returns {Boolean} */ export const hasCustomRenderer = (_ref = {}) => { const { render: renderScope } = _ref.$scopedSlots || {}; const { render: renderProp } = _ref.$props || {}; return Boolean(renderScope || renderProp); }; export const getValidPropsKeys = (props = {}) => Object.keys(props).filter(i => validProps.includes(i)); export const isEvent = candidate => !!(candidate && candidate.stopPropagation && candidate.preventDefault); export const updateDefaultQuery = (componentId, setDefaultQuery, props, value) => { defaultQueryUtil(componentId, { ...props, setDefaultQuery }, value); }; export const updateCustomQuery = (componentId, setCustomQuery, props, value) => { customQueryUtil(componentId, { ...props, setCustomQuery }, value); }; /** * @param {Function} newVal * @param {Function} oldVal * @param {any} value * @param {Object} props */ export const isQueryIdentical = (newVal, oldVal, value, props) => { if (typeof newVal !== 'function' || typeof oldVal !== 'function') return true; // to not call original defaultQuery and customQuery, as here we are only comparing return isEqual(oldVal(value, props), newVal(value, props)); }; /** * Extracts the renderPopularSuggestions prop from props or slot and returns a valid JSX element * @param {Object} data * @param _ref */ export const getQuerySuggestionsComponent = (data = {}, _ref = {}) => { const { renderQuerySuggestions, renderPopularSuggestions } = _ref.$scopedSlots || _ref.$props; const render = renderPopularSuggestions || renderQuerySuggestions; if (render) return render(data); return null; }; /** * To determine whether a component has renderQuerySuggestions prop or slot defined or not * @returns {Boolean} */ export const hasQuerySuggestionsRenderer = (_ref = {}) => { const { renderQuerySuggestions, renderPopularSuggestions } = _ref.$scopedSlots || _ref.$props; return Boolean(renderPopularSuggestions) || Boolean(renderQuerySuggestions); }; /** * To get the camel case string from kebab case * @returns {string} */ export const getCamelCase = (str = '') => { const arr = str.split('-'); const capital = arr.map((item, index) => index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item, ); // ^-- change here. const capitalString = capital.join(''); return capitalString || ''; }; export const isEmpty = val => !(val && val.length && Object.keys(val).length); export function isNumeric(value) { return /^-?\d+$/.test(value); } // check if passed shortcut a key combination export function isHotkeyCombination(hotkey) { return typeof hotkey === 'string' && hotkey.indexOf('+') !== -1; } // used for getting correct string char from keycode passed // the below algebraic expression is used to get the correct ascii code out of the e.which || e.keycode returned value // since the keyboards doesn't understand ascii but scan codes and they differ for certain keys such as '/' // stackoverflow ref: https://stackoverflow.com/a/29811987/10822996 export function getCharFromCharCode(passedCharCode) { const which = passedCharCode; const chrCode = which - 48 * Math.floor(which / 48); return String.fromCharCode(which >= 96 ? chrCode : which); } // used for parsing focusshortcuts for keycodes passed as string, eg: 'ctrl+/' is same as 'ctrl+47' // returns focusShortcuts containing appropriate key charsas depicted on keyboards export function parseFocusShortcuts(focusShortcutsArray) { if (isEmpty(focusShortcutsArray)) return []; const parsedFocusShortcutsArray = []; focusShortcutsArray.forEach(element => { if (typeof element === 'string') { if (isHotkeyCombination(element)) { // splitting the combination into pieces const splitCombination = element.split('+'); const parsedSplitCombination = []; // parsedCombination would have all the keycodes converted into chars let parsedCombination = ''; for (let i = 0; i < splitCombination.length; i += 1) { if (isNumeric(splitCombination[i])) { parsedSplitCombination.push(getCharFromCharCode(+splitCombination[i])); } else { parsedSplitCombination.push(splitCombination[i]); } } parsedCombination = parsedSplitCombination.join('+'); parsedFocusShortcutsArray.push(parsedCombination); } else if (isNumeric(element)) { parsedFocusShortcutsArray.push(getCharFromCharCode(+element)); } else { // single char shortcut, eg: '/' parsedFocusShortcutsArray.push(element); } } else { // if not a string the the shortcut is assumed to be a keycode parsedFocusShortcutsArray.push(getCharFromCharCode(element)); } }); return parsedFocusShortcutsArray; } export const MODIFIER_KEYS = ['shift', 'ctrl', 'alt', 'control', 'option', 'cmd', 'command']; // filter out modifierkeys such as ctrl, alt, command, shift from focusShortcuts prop export function extractModifierKeysFromFocusShortcuts(focusShortcutsArray) { return focusShortcutsArray.filter(shortcutKey => MODIFIER_KEYS.includes(shortcutKey)); } export const debounce = (method, delay) => { clearTimeout(method._tId); // eslint-disable-next-line method._tId = setTimeout(() => { method(); }, delay); }; |