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

feat: Package generation for JCR pages #459

Open
wants to merge 2 commits into
base: md2jcr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 31 additions & 20 deletions import.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<script src="./js/libs/vendors/exceljs/exceljs.min.js"></script>
<script src="./js/dist/helix-importer.js"></script>
<script src="./js/import/import.ui.js" type="module"></script>
<!-- TODO: fix this direct inclusion -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
</head>

<body class="tool loading">
Expand Down Expand Up @@ -60,11 +62,15 @@ <h3>Workbench</h3>
<sp-accordion>
<sp-accordion-item label="Import Options">
<div>
<sp-field-label for="import-file-url" required>Transformation file URL</sp-field-label>
<sp-textfield class="option-field" id="import-file-url" type="url" value="http://localhost:3001/tools/importer/import.js"></sp-textfield>
<sp-field-label for="import-file-url" required>Transformation file
URL</sp-field-label>
<sp-textfield class="option-field" id="import-file-url" type="url"
value="http://localhost:3001/tools/importer/import.js"></sp-textfield>

<sp-field-label for="import-pageload-timeout">Page load timeout</sp-field-label>
<sp-number-field class="option-field" id="import-pageload-timeout" value="100" min="0" step="100" format-options='{ "style": "unit", "unit": "millisecond", "unitDisplay": "short" }'></sp-number-field>
<sp-number-field class="option-field" id="import-pageload-timeout" value="100"
min="0" step="100"
format-options='{ "style": "unit", "unit": "millisecond", "unitDisplay": "short" }'></sp-number-field>

<div class="local-save">
<sp-checkbox class="option-field" id="import-local-docx" checked>
Expand All @@ -85,26 +91,29 @@ <h3>Workbench</h3>
Enable JavaScript
</sp-checkbox>
<sp-help-text variant="negative" icon>
Security risk: only enable Javascript execution when importing from trusted websites.
Security risk: only enable Javascript execution when importing from trusted
websites.
</sp-help-text>
<sp-checkbox class="option-field" id="import-scroll-to-bottom" checked>
Scroll to bottom
</sp-checkbox>

<sp-field-label for="import-custom-headers">Custom headers</sp-field-label>
<sp-textfield class="option-field" id="import-custom-headers" multiline placeholder="Define your custom headers as a JSON object with key/value (header name/header value)"></sp-textfield>
<sp-textfield class="option-field" id="import-custom-headers" multiline
placeholder="Define your custom headers as a JSON object with key/value (header name/header value)"></sp-textfield>
</div>
</sp-accordion-item>
</sp-accordion>

<div id="import-action-row">
<sp-button-group>
<sp-button id="import-doimport-button">Import</sp-button>
</sp-button-group>
<div id="transformation-file-default" class="hidden">
<sp-status-light size="s" variant="notice">The default transformation file is being used</sp-status-light>
<div id="import-action-row">
<sp-button-group>
<sp-button id="import-doimport-button">Import</sp-button>
</sp-button-group>
<div id="transformation-file-default" class="hidden">
<sp-status-light size="s" variant="notice">The default transformation file is being
used</sp-status-light>
</div>
</div>
</div>
</form>
<span id="folder-name"></span>
<div class="page-preview hidden">
Expand All @@ -127,16 +136,16 @@ <h3>Page preview</h3>
</sp-tab-panel>
<sp-tab-panel value="import-markdown">
<div data-panel="source">
<div class="code">
<textarea id="import-markdown-source" rows="4" cols="10"></textarea>
</div>
<div class="code">
<textarea id="import-markdown-source" rows="4" cols="10"></textarea>
</div>
</div>
</sp-tab-panel>
<sp-tab-panel value="import-html">
<div data-panel="source">
<div class="code">
<textarea id="import-transformed-html" rows="4" cols="10"></textarea>
</div>
<div class="code">
<textarea id="import-transformed-html" rows="4" cols="10"></textarea>
</div>
</div>
</sp-tab-panel>
<sp-tab-panel value="import-jcr">
Expand All @@ -148,7 +157,8 @@ <h3>Page preview</h3>
</sp-tab-panel>
</sp-tabs>
<sp-button-group>
<sp-button id="import-downloadImportReport" class="hidden">Download import report</sp-button>
<sp-button id="import-downloadImportReport" class="hidden">Download import
report</sp-button>
</sp-button-group>
</div>
</div>
Expand All @@ -158,4 +168,5 @@ <h3>Page preview</h3>
</sp-theme>
<script src="./js/swc_loader.js" type="module"></script>
</body>
</html>

</html>
21 changes: 20 additions & 1 deletion js/import/import.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
getProxyURLSetup,
loadDocument,
} from '../shared/document.js';
import { createJcrPackage } from '../shared/jcr/packaging.js';
import { getImageUrlMap } from '../shared/jcr/imageurl.mapping.js';

const PARENT_SELECTOR = '.import';

Expand Down Expand Up @@ -91,15 +93,32 @@ const postSuccessfulStep = async (results, originalURL) => {
files.push({ type: 'html', filename: `${path}.html`, data: `<html><head></head>${html}</html>` });
} else if (config.fields['import-local-md'] && md) {
files.push({ type: 'md', filename: `${path}.md`, data: md });
} else if (config.fields['import-jcr-package'] && jcr) {
}

// Save JCR pages
if (config.fields['import-jcr-package'] && jcr) {
jcrPages.push({
type: 'jcr',
path,
data: jcr,
url: originalURL,
});
}
if (jcrPages && jcrPages.length > 0) {
// get image mappings for JCR pages from the markdown content
const imageMappings = getImageUrlMap(md);

// create JCR package containing all JCR pages
await createJcrPackage(dirHandle, jcrPages, imageMappings, "xwalkdemo");

// Convert Map to plain object
const obj = Object.fromEntries(imageMappings);

// Save the object to a JSON file
saveFile(dirHandle, "jcr-image-mappings.json", JSON.stringify(obj, null, 2));
}

// save all other files (doc, html, md)
files.forEach((file) => {
try {
const filePath = files.length > 1 ? `/${file.type}${file.filename}` : file.filename;
Expand Down
46 changes: 46 additions & 0 deletions js/shared/component.loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

export const loadComponents = async (config) => {
const components = {};
if (config.origin) {
const [
componentModels, componentsDefinition, componentFilters,
] = await Promise.all([
fetch(`${config.origin}/component-models.json`).then((res) => {
if (!res.ok) {
throw new Error(`Failed to fetch component-models.json: ${res.status}`);
} else {
return res.text();
}
}),
fetch(`${config.origin}/component-definition.json`).then((res) => {
if (!res.ok) {
throw new Error(`Failed to fetch component-definition.json: ${res.status}`);
} else {
return res.text();
}
}),
fetch(`${config.origin}/component-filters.json`).then((res) => {
if (!res.ok) {
throw new Error(`Failed to fetch component-filters.json: ${res.status}`);
} else {
return res.text();
}
}),
]);
components.models = JSON.parse(componentModels);
components.definition = JSON.parse(componentsDefinition);
components.filters = JSON.parse(componentFilters);
}
return components;
};
Loading
Loading