@patternfly/quickstarts 2.2.2 → 2.2.3

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/dist/index.js CHANGED
@@ -2500,6 +2500,106 @@ const useLocalStorage = (key, initialValue) => {
2500
2500
  return [storedValue, setValue];
2501
2501
  };
2502
2502
 
2503
+ /* eslint-disable */
2504
+ // Brought in from dev to publish this with QS module
2505
+ // Dev now imports from here
2506
+ const ProcQuickStartParser = (quickStart, environmentVariables) => {
2507
+ var _a;
2508
+ const replaceEnvironmentVariables = (s) => s === null || s === void 0 ? void 0 : s.replace(/\${(\w+)}/, (substring, name) => {
2509
+ return environmentVariables ? ([name] ? environmentVariables[name] : substring) : substring;
2510
+ });
2511
+ quickStart.spec.tasks = (_a = quickStart.spec.tasks) === null || _a === void 0 ? void 0 : _a.map((task, index) => {
2512
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2513
+ let proc;
2514
+ let answer;
2515
+ if (typeof task === 'string') {
2516
+ proc = task;
2517
+ answer = {};
2518
+ }
2519
+ else {
2520
+ // @ts-ignore
2521
+ proc = task.proc;
2522
+ answer = task;
2523
+ // @ts-ignore
2524
+ delete task.proc;
2525
+ }
2526
+ let description = '', procedure, verification, title, summaryFailed, success, reviewFailed, prerequisites;
2527
+ if (proc) {
2528
+ const taskDOM = document.createElement('div');
2529
+ taskDOM.innerHTML = proc;
2530
+ // remove the screencapture images
2531
+ taskDOM.querySelectorAll('.imageblock.screencapture').forEach((node) => {
2532
+ var _a;
2533
+ (_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(node);
2534
+ });
2535
+ title = (_a = taskDOM
2536
+ .querySelector('h1:first-child,h2:first-child,h3:first-child,h4:first-child,h5:first-child')) === null || _a === void 0 ? void 0 : _a.innerHTML.trim();
2537
+ let sectionBody = taskDOM.querySelector('.sectionbody');
2538
+ if (!(sectionBody === null || sectionBody === void 0 ? void 0 : sectionBody.hasChildNodes())) {
2539
+ // possibly in other templates, where we want to look for article
2540
+ sectionBody = taskDOM.querySelector('article');
2541
+ }
2542
+ if (sectionBody) {
2543
+ for (let i = 0; i < sectionBody.children.length || 0; i++) {
2544
+ /**
2545
+ child typically looks like:
2546
+
2547
+ <div class="paragraph|olist|ulist|admonitionblock">
2548
+ <div class="title">Procedure|Prerequisites|Verification|Note|Warning</div>
2549
+ <ol|ul class="arabic">
2550
+ <li>
2551
+ <li>...
2552
+ </ol|ul>
2553
+ </div>
2554
+
2555
+ And the below code extracts the <ol> or <ul>
2556
+ Except for when there is no <div class="title|heading"/>, then the description is extracted
2557
+ in the else if below
2558
+ */
2559
+ const child = sectionBody.children.item(i);
2560
+ // find the title
2561
+ const sectionTitle = child === null || child === void 0 ? void 0 : child.querySelector('.heading,.title');
2562
+ // should this section be assigned to a specific section
2563
+ const sectionTitleText = (_b = sectionTitle === null || sectionTitle === void 0 ? void 0 : sectionTitle.textContent) === null || _b === void 0 ? void 0 : _b.trim();
2564
+ const isKnownSection = ['Procedure', 'Verification', 'Prerequisites'].includes((_c = sectionTitle === null || sectionTitle === void 0 ? void 0 : sectionTitle.textContent) === null || _c === void 0 ? void 0 : _c.trim());
2565
+ if (isKnownSection) {
2566
+ switch (sectionTitleText) {
2567
+ case 'Procedure':
2568
+ procedure = (_d = child === null || child === void 0 ? void 0 : child.querySelector(':not(.heading):not(.title)')) === null || _d === void 0 ? void 0 : _d.outerHTML.trim();
2569
+ break;
2570
+ case 'Verification':
2571
+ verification = (_e = child === null || child === void 0 ? void 0 : child.querySelector(':not(.heading):not(.title)')) === null || _e === void 0 ? void 0 : _e.outerHTML.trim();
2572
+ break;
2573
+ case 'Prerequisites':
2574
+ prerequisites = (_f = child === null || child === void 0 ? void 0 : child.querySelector(':not(.heading):not(.title)')) === null || _f === void 0 ? void 0 : _f.outerHTML.trim();
2575
+ break;
2576
+ }
2577
+ }
2578
+ else if (!procedure) {
2579
+ // Otherwise if it comes before a procedure it's part of the description
2580
+ description = description + (child === null || child === void 0 ? void 0 : child.outerHTML.trim());
2581
+ }
2582
+ }
2583
+ }
2584
+ success = (_g = taskDOM.querySelector('.qs-summary.success')) === null || _g === void 0 ? void 0 : _g.innerHTML.trim();
2585
+ reviewFailed = (_h = taskDOM.querySelector('.qs-review.failed')) === null || _h === void 0 ? void 0 : _h.innerHTML.trim();
2586
+ summaryFailed = (_j = taskDOM.querySelector('.qs-summary.failed')) === null || _j === void 0 ? void 0 : _j.innerHTML.trim();
2587
+ }
2588
+ answer.title = replaceEnvironmentVariables(answer.title || title);
2589
+ answer.description = replaceEnvironmentVariables(answer.description || `${description} ${prerequisites || ''} ${procedure}`);
2590
+ answer.review = answer.review || {};
2591
+ answer.review.instructions = replaceEnvironmentVariables(((_k = answer.review) === null || _k === void 0 ? void 0 : _k.instructions) || verification || 'Have you completed these steps?');
2592
+ answer.review.failedTaskHelp = replaceEnvironmentVariables(answer.review.failedTaskHelp ||
2593
+ reviewFailed ||
2594
+ 'This task isn’t verified yet. Try the task again.');
2595
+ answer.summary = answer.summary || {};
2596
+ answer.summary.success = replaceEnvironmentVariables(answer.summary.success || success || 'You have completed this task!');
2597
+ answer.summary.failed = replaceEnvironmentVariables(answer.summary.failed || summaryFailed || 'Try the steps again.');
2598
+ return answer;
2599
+ });
2600
+ return quickStart;
2601
+ };
2602
+
2503
2603
  exports.Box = Box;
2504
2604
  exports.CamelCaseWrap = CamelCaseWrap;
2505
2605
  exports.EmptyBox = EmptyBox;
@@ -2510,6 +2610,7 @@ exports.HelpTopicContextDefaults = HelpTopicContextDefaults;
2510
2610
  exports.HelpTopicDrawer = HelpTopicDrawer;
2511
2611
  exports.Loading = Loading;
2512
2612
  exports.LoadingBox = LoadingBox;
2613
+ exports.ProcQuickStartParser = ProcQuickStartParser;
2513
2614
  exports.QUICKSTART_ID_FILTER_KEY = QUICKSTART_ID_FILTER_KEY;
2514
2615
  exports.QUICKSTART_SEARCH_FILTER_KEY = QUICKSTART_SEARCH_FILTER_KEY;
2515
2616
  exports.QUICKSTART_STATUS_FILTER_KEY = QUICKSTART_STATUS_FILTER_KEY;