Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created for spline-fragment #1317

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions blocks/spline-viewer/spline-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getFragmentFromFile } from '../../scripts/scripts.js';

export default async function decorate(block) {
try {
// get the content
const fragment = await getFragmentFromFile('/fragments/spline.html');
block.innerHTML = '';
const parser = new DOMParser();
const fragmentHtml = parser.parseFromString(fragment, 'text/html');
[...fragmentHtml.body.children].forEach((item) => {
block.append(item);
});
} catch (e) {
block.textContent = '';
// eslint-disable-next-line no-console
console.warn(`cannot load snippet at ${e}`);
}
}
2 changes: 2 additions & 0 deletions fragments/spline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script type="module" src="https://unpkg.com/@splinetool/[email protected]/build/spline-viewer.js"></script>
<spline-viewer url="https://prod.spline.design/UBAIdqMtOkuDExkL/scene.splinecode"></spline-viewer>
2 changes: 2 additions & 0 deletions tools/importer/transformers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import workflowCarousel from './workflowCarousel.js';
import embedScript from './embedScript.js';
import callToActionText from './callToActionText.js';
import productNotFound from './product-not-found.js';
import splineViewer from './spline-viewer.js';

// eslint-disable-next-line import/prefer-default-export
export const transformers = [
Expand Down Expand Up @@ -93,6 +94,7 @@ export const transformers = [
embedScript,
callToActionText,
productNotFound,
splineViewer,
];

export const asyncTransformers = [
Expand Down
10 changes: 10 additions & 0 deletions tools/importer/transformers/spline-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global WebImporter */
const splineViewer = (main, document) => {
const splineViewerEl = main.querySelector('div#spline-viewer');
if (splineViewerEl) {
const block = [['Spline Viewer'], ['']];
const table = WebImporter.DOMUtils.createTable(block, document);
splineViewerEl.replaceWith(table);
}
};
export default splineViewer;
Loading