Co-authored-by: Oleksii Kadurin <ovkadurin@gmail.com>; Thijs Louisse <Thijs.Louisse@ing.com>
275 lines
9.7 KiB
Diff
275 lines
9.7 KiB
Diff
diff --git a/node_modules/@mdjs/core/src/mdjsParse.js b/node_modules/@mdjs/core/src/mdjsParse.js
|
|
index 730e32a..5d6f3f5 100644
|
|
--- a/node_modules/@mdjs/core/src/mdjsParse.js
|
|
+++ b/node_modules/@mdjs/core/src/mdjsParse.js
|
|
@@ -5,13 +5,12 @@ import { remove } from 'unist-util-remove';
|
|
/** @typedef {import('unist').Node} Node */
|
|
|
|
export function mdjsParse() {
|
|
- let jsCode = '';
|
|
-
|
|
/**
|
|
* @param {Node} tree
|
|
* @param {VFileOptions} file
|
|
*/
|
|
function transformer(tree, file) {
|
|
+ let jsCode = '';
|
|
visit(
|
|
tree,
|
|
'code',
|
|
diff --git a/node_modules/@mdjs/core/src/mdjsSetupCode.js b/node_modules/@mdjs/core/src/mdjsSetupCode.js
|
|
index 02a7c56..db3e466 100644
|
|
--- a/node_modules/@mdjs/core/src/mdjsSetupCode.js
|
|
+++ b/node_modules/@mdjs/core/src/mdjsSetupCode.js
|
|
@@ -76,10 +76,6 @@ export function mdjsSetupCode({
|
|
` Object.assign(storyEl, ${JSON.stringify(simulationSettings)});`,
|
|
' }',
|
|
`};`,
|
|
- 'if (needsMdjsElements) {',
|
|
- ` if (!customElements.get('mdjs-preview')) { import('@mdjs/mdjs-preview/define'); }`,
|
|
- ` if (!customElements.get('mdjs-story')) { import('@mdjs/mdjs-story/define'); }`,
|
|
- '}',
|
|
].join('\n');
|
|
}
|
|
|
|
diff --git a/node_modules/@mdjs/core/src/mdjsStoryParse.js b/node_modules/@mdjs/core/src/mdjsStoryParse.js
|
|
index fe734a3..3ddd3a1 100644
|
|
--- a/node_modules/@mdjs/core/src/mdjsStoryParse.js
|
|
+++ b/node_modules/@mdjs/core/src/mdjsStoryParse.js
|
|
@@ -54,132 +54,130 @@ export function mdjsStoryParse({
|
|
storyTag = defaultStoryTag,
|
|
previewStoryTag = defaultPreviewStoryTag,
|
|
} = {}) {
|
|
- /** @type {Story[]} */
|
|
- const stories = [];
|
|
- let htmlIndex = 0;
|
|
-
|
|
- /* eslint-disable no-param-reassign */
|
|
-
|
|
/**
|
|
- * @param {UnistNode} _node
|
|
- * @param {number} index
|
|
- * @param {UnistParent} parent
|
|
+ * @param {Node} tree
|
|
+ * @param {VFileOptions} file
|
|
*/
|
|
- const nodeCodeVisitor = (_node, index, parent) => {
|
|
- let node = /** @type {UnistNode & {[key: string]: unknown}} */ (_node);
|
|
- if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
|
|
- const storyData = extractStoryData(node.value);
|
|
- node.type = 'html';
|
|
- node.value = storyTag(storyData.name);
|
|
- stories.push(storyData);
|
|
- }
|
|
- if (node.lang === 'js' && node.meta === 'preview-story' && typeof node.value === 'string') {
|
|
- const storyData = extractStoryData(node.value);
|
|
- const newValue = previewStoryTag(storyData.name);
|
|
- if (newValue.includes('[[CODE SLOT]]')) {
|
|
- const tagParts = newValue.split('[[CODE SLOT]]');
|
|
-
|
|
- const inside = [node];
|
|
- let skipAmount = 1;
|
|
+ async function transformer(tree, file) {
|
|
+ /** @type {Story[]} */
|
|
+ const stories = [];
|
|
+ let htmlIndex = 0;
|
|
+
|
|
+ /**
|
|
+ * @param {UnistNode} _node
|
|
+ * @param {number} index
|
|
+ * @param {UnistParent} parent
|
|
+ */
|
|
+ const nodeCodeVisitor = (_node, index, parent) => {
|
|
+ let node = /** @type {UnistNode & {[key: string]: unknown}} */ (_node);
|
|
+ if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
|
|
+ const storyData = extractStoryData(node.value);
|
|
+ node.type = 'html';
|
|
+ node.value = storyTag(storyData.name);
|
|
+ stories.push(storyData);
|
|
+ }
|
|
+ if (node.lang === 'js' && node.meta === 'preview-story' && typeof node.value === 'string') {
|
|
+ const storyData = extractStoryData(node.value);
|
|
+ const newValue = previewStoryTag(storyData.name);
|
|
+ if (newValue.includes('[[CODE SLOT]]')) {
|
|
+ const tagParts = newValue.split('[[CODE SLOT]]');
|
|
|
|
- const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
- parent.children[index + 1]
|
|
- );
|
|
- if (next && next.type === 'code' && next.meta === 'story-code') {
|
|
- inside.push(next);
|
|
- skipAmount += 1;
|
|
+ const inside = [node];
|
|
+ let skipAmount = 1;
|
|
|
|
- const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
- parent.children[index + 2]
|
|
+ const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
+ parent.children[index + 1]
|
|
);
|
|
- if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
|
- inside.push(next2);
|
|
+ if (next && next.type === 'code' && next.meta === 'story-code') {
|
|
+ inside.push(next);
|
|
skipAmount += 1;
|
|
+
|
|
+ const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
+ parent.children[index + 2]
|
|
+ );
|
|
+ if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
|
+ inside.push(next2);
|
|
+ skipAmount += 1;
|
|
+ }
|
|
}
|
|
+
|
|
+ node = {
|
|
+ type: 'root',
|
|
+ children: [
|
|
+ { type: 'html', value: tagParts[0] },
|
|
+ { type: 'text', value: '\n\n' },
|
|
+ ...inside,
|
|
+ { type: 'text', value: '\n\n' },
|
|
+ { type: 'html', value: tagParts[1] },
|
|
+ ],
|
|
+ };
|
|
+ parent.children.splice(index, skipAmount, node);
|
|
+ } else {
|
|
+ node.type = 'html';
|
|
+ node.value = previewStoryTag(storyData.name);
|
|
}
|
|
|
|
- node = {
|
|
- type: 'root',
|
|
- children: [
|
|
- { type: 'html', value: tagParts[0] },
|
|
- { type: 'text', value: '\n\n' },
|
|
- ...inside,
|
|
- { type: 'text', value: '\n\n' },
|
|
- { type: 'html', value: tagParts[1] },
|
|
- ],
|
|
- };
|
|
- parent.children.splice(index, skipAmount, node);
|
|
- } else {
|
|
- node.type = 'html';
|
|
- node.value = previewStoryTag(storyData.name);
|
|
+ stories.push(storyData);
|
|
}
|
|
|
|
- stories.push(storyData);
|
|
- }
|
|
-
|
|
- if (node.lang === 'html' && node.meta === 'story') {
|
|
- const storyData = extractStoryData(
|
|
- `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
|
|
- { type: 'html' },
|
|
- );
|
|
- node.type = 'html';
|
|
- node.value = storyTag(storyData.name);
|
|
- stories.push(storyData);
|
|
- htmlIndex += 1;
|
|
- }
|
|
- if (node.lang === 'html' && node.meta === 'preview-story') {
|
|
- const storyData = extractStoryData(
|
|
- `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
|
|
- { type: 'html' },
|
|
- );
|
|
-
|
|
- const newValue = previewStoryTag(storyData.name);
|
|
- if (newValue.includes('[[CODE SLOT]]')) {
|
|
- const tagParts = newValue.split('[[CODE SLOT]]');
|
|
- const inside = [node];
|
|
- let skipAmount = 1;
|
|
- const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
- parent.children[index + 1]
|
|
+ if (node.lang === 'html' && node.meta === 'story') {
|
|
+ const storyData = extractStoryData(
|
|
+ `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
|
|
+ { type: 'html' },
|
|
+ );
|
|
+ node.type = 'html';
|
|
+ node.value = storyTag(storyData.name);
|
|
+ stories.push(storyData);
|
|
+ htmlIndex += 1;
|
|
+ }
|
|
+ if (node.lang === 'html' && node.meta === 'preview-story') {
|
|
+ const storyData = extractStoryData(
|
|
+ `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
|
|
+ { type: 'html' },
|
|
);
|
|
- if (next && next.type === 'code' && next.meta === 'story-code') {
|
|
- inside.push(next);
|
|
- skipAmount += 1;
|
|
|
|
- const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
- parent.children[index + 2]
|
|
+ const newValue = previewStoryTag(storyData.name);
|
|
+ if (newValue.includes('[[CODE SLOT]]')) {
|
|
+ const tagParts = newValue.split('[[CODE SLOT]]');
|
|
+ const inside = [node];
|
|
+ let skipAmount = 1;
|
|
+ const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
+ parent.children[index + 1]
|
|
);
|
|
- if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
|
- inside.push(next2);
|
|
+ if (next && next.type === 'code' && next.meta === 'story-code') {
|
|
+ inside.push(next);
|
|
skipAmount += 1;
|
|
+
|
|
+ const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
|
+ parent.children[index + 2]
|
|
+ );
|
|
+ if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
|
+ inside.push(next2);
|
|
+ skipAmount += 1;
|
|
+ }
|
|
}
|
|
+
|
|
+ node = {
|
|
+ type: 'root',
|
|
+ children: [
|
|
+ { type: 'html', value: tagParts[0] },
|
|
+ { type: 'text', value: '\n\n' },
|
|
+ ...inside,
|
|
+ { type: 'text', value: '\n\n' },
|
|
+ { type: 'html', value: tagParts[1] },
|
|
+ ],
|
|
+ };
|
|
+ parent.children.splice(index, skipAmount, node);
|
|
+ } else {
|
|
+ node.type = 'html';
|
|
+ node.value = previewStoryTag(storyData.name);
|
|
}
|
|
|
|
- node = {
|
|
- type: 'root',
|
|
- children: [
|
|
- { type: 'html', value: tagParts[0] },
|
|
- { type: 'text', value: '\n\n' },
|
|
- ...inside,
|
|
- { type: 'text', value: '\n\n' },
|
|
- { type: 'html', value: tagParts[1] },
|
|
- ],
|
|
- };
|
|
- parent.children.splice(index, skipAmount, node);
|
|
- } else {
|
|
- node.type = 'html';
|
|
- node.value = previewStoryTag(storyData.name);
|
|
+ stories.push(storyData);
|
|
+ htmlIndex += 1;
|
|
}
|
|
+ };
|
|
|
|
- stories.push(storyData);
|
|
- htmlIndex += 1;
|
|
- }
|
|
- };
|
|
-
|
|
- /**
|
|
- * @param {Node} tree
|
|
- * @param {VFileOptions} file
|
|
- */
|
|
- async function transformer(tree, file) {
|
|
// unifiedjs expects node changes to be made on the given node...
|
|
await init;
|
|
// @ts-ignore
|