(core) move client code to core

Summary:
This moves all client code to core, and makes minimal fix-ups to
get grist and grist-core to compile correctly.  The client works
in core, but I'm leaving clean-up around the build and bundles to
follow-up.

Test Plan: existing tests pass; server-dev bundle looks sane

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2627
This commit is contained in:
Paul Fitzpatrick
2020-10-02 11:10:00 -04:00
parent 5d60d51763
commit 1654a2681f
395 changed files with 52651 additions and 47 deletions

View File

@@ -0,0 +1,25 @@
import {reportError} from 'app/client/models/errors';
import {DomContents, onDisposeElem, replaceContent} from 'grainjs';
// grainjs annoyingly doesn't export browserGlobals tools, useful for testing in a simulated environment.
import {G} from 'grainjs/dist/cjs/lib/browserGlobals';
/**
* Insert DOM contents produced by a Promise. Until the Promise is fulfilled, nothing shows up.
* TODO: This would be a handy place to support options to show a loading spinner (perhaps
* showing up if the promise takes more than a bit to show).
*/
export function domAsync(promiseForDomContents: Promise<DomContents>, onError = reportError): DomContents {
const markerPre = G.document.createComment('a');
const markerPost = G.document.createComment('b');
// Function is added after the markers, to run once they have been attached to elem (the parent).
return [markerPre, markerPost, (elem: Node) => {
let disposed = false;
promiseForDomContents
.then((contents) => disposed || replaceContent(markerPre, markerPost, contents))
.catch(onError);
// If markerPost is disposed before the promise resolves, set insertContent to noop.
onDisposeElem(markerPost, () => { disposed = true; });
}];
}