@sqlrooms/mosaic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/dist/VgPlotChart.d.ts +15 -0
- package/dist/VgPlotChart.d.ts.map +1 -0
- package/dist/VgPlotChart.js +24 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/use-mosaic.d.ts +16 -0
- package/dist/use-mosaic.d.ts.map +1 -0
- package/dist/use-mosaic.js +35 -0
- package/package.json +39 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Ilya Boyandin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Spec } from '@uwdata/mosaic-spec';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
type VgPlotChartProps = {
|
|
4
|
+
spec: Spec;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Renders a Vega-Lite chart using the Mosaic library.
|
|
8
|
+
*
|
|
9
|
+
* @param {VgPlotChartProps} props - The component props.
|
|
10
|
+
* @param {Spec} props.spec - The Vega-Lite specification for the chart.
|
|
11
|
+
* @returns {React.ReactElement} The rendered chart component.
|
|
12
|
+
*/
|
|
13
|
+
export declare const VgPlotChart: FC<VgPlotChartProps>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=VgPlotChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VgPlotChart.d.ts","sourceRoot":"","sources":["../src/VgPlotChart.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsB,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAC,EAAE,EAAoB,MAAM,OAAO,CAAC;AAE5C,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AACF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAe5C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { astToDOM, parseSpec } from '@uwdata/mosaic-spec';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* Renders a Vega-Lite chart using the Mosaic library.
|
|
6
|
+
*
|
|
7
|
+
* @param {VgPlotChartProps} props - The component props.
|
|
8
|
+
* @param {Spec} props.spec - The Vega-Lite specification for the chart.
|
|
9
|
+
* @returns {React.ReactElement} The rendered chart component.
|
|
10
|
+
*/
|
|
11
|
+
export const VgPlotChart = ({ spec }) => {
|
|
12
|
+
const containerRef = useRef(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
(async () => {
|
|
15
|
+
if (containerRef.current) {
|
|
16
|
+
const ast = await parseSpec(spec);
|
|
17
|
+
const { element, // root DOM element of the application
|
|
18
|
+
} = await astToDOM(ast);
|
|
19
|
+
containerRef.current?.replaceChildren(element);
|
|
20
|
+
}
|
|
21
|
+
})();
|
|
22
|
+
}, [spec, containerRef]);
|
|
23
|
+
return _jsx("div", { ref: containerRef });
|
|
24
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAC,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves a Mosaic connector for the DuckDB database.
|
|
3
|
+
*
|
|
4
|
+
* @returns {Promise<MosaicConnector>} The Mosaic connector for the DuckDB database.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getMosaicConnector(): Promise<(db?: any) => any>;
|
|
7
|
+
/**
|
|
8
|
+
* Hook to manage the Mosaic connector.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Object} An object containing the Mosaic connector and a loading state.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useMosaic(): {
|
|
13
|
+
isMosaicLoading: boolean;
|
|
14
|
+
mosaicConnector: ((db?: any) => any) | undefined;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=use-mosaic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mosaic.d.ts","sourceRoot":"","sources":["../src/use-mosaic.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAsB,kBAAkB,+BAYvC;AAED;;;;GAIG;AACH,wBAAgB,SAAS;;;EASxB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getDuckDb } from '@sqlrooms/duckdb';
|
|
2
|
+
import { coordinator, wasmConnector } from '@uwdata/mosaic-core';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
let connector;
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a Mosaic connector for the DuckDB database.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<MosaicConnector>} The Mosaic connector for the DuckDB database.
|
|
9
|
+
*/
|
|
10
|
+
export async function getMosaicConnector() {
|
|
11
|
+
if (connector) {
|
|
12
|
+
return connector;
|
|
13
|
+
}
|
|
14
|
+
const duckDb = await getDuckDb();
|
|
15
|
+
connector = await coordinator().databaseConnector(wasmConnector({
|
|
16
|
+
duckDb: duckDb.db,
|
|
17
|
+
connection: duckDb.conn,
|
|
18
|
+
}));
|
|
19
|
+
return connector;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Hook to manage the Mosaic connector.
|
|
23
|
+
*
|
|
24
|
+
* @returns {Object} An object containing the Mosaic connector and a loading state.
|
|
25
|
+
*/
|
|
26
|
+
export function useMosaic() {
|
|
27
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
28
|
+
const [connector, setConnector] = useState();
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
getMosaicConnector()
|
|
31
|
+
.then(setConnector)
|
|
32
|
+
.finally(() => setIsLoading(false));
|
|
33
|
+
}, []);
|
|
34
|
+
return { isMosaicLoading: isLoading, mosaicConnector: connector };
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sqlrooms/mosaic",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"private": false,
|
|
9
|
+
"author": "Ilya Boyandin <ilya@boyandin.me>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/sqlrooms/sqlrooms.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/provider": "^1.0.7",
|
|
23
|
+
"@sqlrooms/duckdb": "0.1.0",
|
|
24
|
+
"@uwdata/mosaic-core": "^0.12.2",
|
|
25
|
+
"@uwdata/mosaic-spec": "^0.12.2",
|
|
26
|
+
"@uwdata/vgplot": "^0.12.2"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "*",
|
|
30
|
+
"react-dom": "*"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "tsc -w",
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"lint": "eslint .",
|
|
36
|
+
"typedoc": "typedoc"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "2d44f6636dbd53d18c32a422351e93caa182ada6"
|
|
39
|
+
}
|