@sci-grid/astro 1.0.1
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 +21 -0
- package/package.json +15 -0
- package/src/index.astro +50 -0
- package/src/index.test.ts +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SciGrid Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sci-grid/astro",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./src/index.astro",
|
|
6
|
+
"types": "./src/index.astro",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@sci-grid/core": "1.0.1"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"astro": "^4.0.0",
|
|
12
|
+
"vite": "^5.0.0",
|
|
13
|
+
"typescript": "^5.5.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.astro
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* SciGrid Astro Component
|
|
4
|
+
* Professional canvas-based grid for Astro.
|
|
5
|
+
* Note: Initialized via window events or automatic lookup.
|
|
6
|
+
*/
|
|
7
|
+
interface Props {
|
|
8
|
+
id?: string;
|
|
9
|
+
config?: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { id = "sci-grid-astro", config = {} } = Astro.props;
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<div
|
|
16
|
+
id={id}
|
|
17
|
+
class="sci-grid-astro-container"
|
|
18
|
+
data-config={JSON.stringify(config)}
|
|
19
|
+
style="width: 100%; height: 100%; min-height: 400px; position: relative;"
|
|
20
|
+
></div>
|
|
21
|
+
|
|
22
|
+
<script>
|
|
23
|
+
import { SciGrid } from '@sci-grid/core';
|
|
24
|
+
|
|
25
|
+
// Auto-initialize any grid that has a provider ready
|
|
26
|
+
const initGrids = () => {
|
|
27
|
+
document.querySelectorAll('.sci-grid-astro-container').forEach(el => {
|
|
28
|
+
const container = el as HTMLElement;
|
|
29
|
+
if (container.dataset.initialized) return;
|
|
30
|
+
|
|
31
|
+
const id = container.id;
|
|
32
|
+
const config = JSON.parse(container.dataset.config || '{}');
|
|
33
|
+
|
|
34
|
+
const setup = (e: any) => {
|
|
35
|
+
const { provider } = e.detail;
|
|
36
|
+
if (provider) {
|
|
37
|
+
new SciGrid(container, provider, config);
|
|
38
|
+
container.dataset.initialized = "true";
|
|
39
|
+
window.removeEventListener('scigrid-init-' + id, setup);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
window.addEventListener('scigrid-init-' + id, setup);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
initGrids();
|
|
48
|
+
// Support Astro View Transitions
|
|
49
|
+
document.addEventListener('astro:page-load', initGrids);
|
|
50
|
+
</script>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { SciGrid } from '@sci-grid/core';
|
|
3
|
+
|
|
4
|
+
// Behavioral test for Astro integration pattern
|
|
5
|
+
describe('SciGrid Astro Integration Pattern', () => {
|
|
6
|
+
let container: HTMLDivElement;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
container = document.createElement('div');
|
|
10
|
+
container.id = 'astro-grid';
|
|
11
|
+
document.body.appendChild(container);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should initialize when the custom event is dispatched', () => {
|
|
15
|
+
const id = 'astro-grid';
|
|
16
|
+
const mockProvider = {
|
|
17
|
+
getRowCount: () => 0,
|
|
18
|
+
getColumnCount: () => 0,
|
|
19
|
+
getCellData: () => '',
|
|
20
|
+
getHeader: () => ({ name: 'Test' })
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Simulate the logic inside the Astro <script> tag
|
|
24
|
+
window.addEventListener('scigrid-init-' + id, (e: any) => {
|
|
25
|
+
const { provider } = e.detail;
|
|
26
|
+
const el = document.getElementById(id);
|
|
27
|
+
if (el && provider) {
|
|
28
|
+
new SciGrid(el, provider, {});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Dispatch the event
|
|
33
|
+
window.dispatchEvent(new CustomEvent('scigrid-init-' + id, {
|
|
34
|
+
detail: { provider: mockProvider }
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
// Check if SciGrid initialized (it should have created a canvas)
|
|
38
|
+
const canvas = container.querySelector('canvas');
|
|
39
|
+
expect(canvas).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
});
|