UNPKG

locize

Version:

This package adds the incontext editor to your i18next setup.

28 lines (25 loc) 830 B
'use strict'; var postMessage = require('./postMessage.js'); var store = require('../store.js'); var highlightNode = require('../ui/highlightNode.js'); var previousMatches = []; function handler(payload) { var keys = payload.keys; var matchingItems = []; Object.values(store.store.data).forEach(function (item) { var matches = Object.values(item.keys).filter(function (k) { return keys.includes(k.qualifiedKey); }); if (matches.length) { matchingItems.push(item); } }); previousMatches.forEach(function (item) { highlightNode.resetHighlight(item, item.node, item.keys, false); }); matchingItems.forEach(function (item) { highlightNode.selectedHighlight(item, item.node, item.keys); }); previousMatches = matchingItems; } postMessage.api.addHandler('selectedKeys', handler);