= getEntriesIndexes(mapEntries, max, isInterestingEntry); if (indexes.length < max && indexes.length < mapEntries.length) { // There are not enough entries yet, so we add uninteresting entries. indexes = indexes.concat( getEntriesIndexes(mapEntries, max - indexes.length, (t, value, name) => { return !isInterestingEntry(t, value, name); }) ); } const entries = getEntries(props, mapEntries, indexes); if (entries.length < getLength(object)) { // There are some undisplayed entries. Then display "…". entries.push(ellipsisElement); } return entries; } /** * Get entries ordered by index. * * @param {object} props Component props. * @param {Array} entries Entries array. * @param {Array} indexes Indexes of entries. * @return {Array} Array of PropRep. */ function getEntries(props, entries, indexes) { const { onDOMNodeMouseOver, onDOMNodeMouseOut, onInspectIconClick } = props; // Make indexes ordered by ascending. indexes.sort(function (a, b) { return a - b; }); return indexes.map(index => { const [key, entryValue] = entries[index]; const value = entryValue.value !== undefined ? entryValue.value : entryValue; return PropRep({ ...props, name: key && key.getGrip ? key.getGrip() : key, equal: " \u2192 ", object: value && value.getGrip ? value.getGrip() : value, mode: MODE.TINY, onDOMNodeMouseOver, onDOMNodeMouseOut, onInspectIconClick, }); }); } /** * Get the indexes of entries in the map. * * @param {Array} entries Entries array. * @param {number} max The maximum length of indexes array. * @param {Function} filter Filter the entry you want. * @return {Array} Indexes of filtered entries in the map. */ function getEntriesIndexes(entries, max, filter) { return entries.reduce((indexes, [key, entry], i) => { if (indexes.length < max) { const value = entry && entry.value !== undefined ? entry.value : entry; // Type is specified in grip's "class" field and for primitive // values use typeof. const type = ( value && value.class ? value.class : typeof value ).toLowerCase(); if (filter(type, value, key)) { indexes.push(i); } } return indexes; }, []); } function getLength(grip) { return grip.preview.size || 0; } function supportsObject(grip) { return grip?.preview?.kind == "MapLike"; } const maxLengthMap = new Map(); maxLengthMap.set(MODE.SHORT, 3); maxLengthMap.set(MODE.LONG, 10); const rep = wrapRender(GripMap); // Exports from this module export { rep, supportsObject, maxLengthMap, getLength }; PK