gristlabs_grist-core/test/fixtures/sites/readout/page.js
George Gevoian f38df564a9 (core) Add Command API to Grist Plugin API
Summary:
The new Command API provides limited access to Grist Commands from within cusotm
widgets. This includes the ability to perform undo and redo, which is bound to
the same keyboard shortcut as Grist by default.

Test Plan: Browser tests.

Reviewers: jarek

Reviewed By: jarek

Subscribers: paulfitz, jarek

Differential Revision: https://phab.getgrist.com/D4050
2023-09-27 13:25:18 -04:00

39 lines
1.1 KiB
JavaScript

/* global document, grist, window */
function readDoc() {
const fetchTable = grist.docApi.fetchSelectedTable();
const placeholder = document.getElementById('placeholder');
const fallback = setTimeout(() => {
placeholder.innerHTML = '<div id="output">no joy</div>';
}, 1000);
fetchTable
.then(table => {
clearTimeout(fallback);
placeholder.innerHTML = `<div id="output">${JSON.stringify(table)}</div>`;
});
}
function setup() {
grist.ready();
grist.on('message', function(e) {
if ('options' in e) return;
document.getElementById('rowId').innerHTML = e.rowId || '';
document.getElementById('tableId').innerHTML = e.tableId || '';
readDoc();
});
grist.onRecord(function(rec) {
document.getElementById('record').innerHTML = JSON.stringify(rec);
});
grist.onRecords(function(recs) {
document.getElementById('records').innerHTML = JSON.stringify(recs);
});
grist.onNewRecord(function(rec) {
document.getElementById('record').innerHTML = 'new';
});
grist.enableKeyboardShortcuts();
}
window.onload = setup;