-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge refs/heads/master into np/focus
- Loading branch information
Showing
77 changed files
with
9,681 additions
and
6,688 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
`@cognite/reveal` supports `Node16` [module resolution](https://www.typescriptlang.org/tsconfig#moduleResolution), and if enabled in the consuming application will expose three modules: | ||
- [@cognite/reveal](/api/modules/cognite_reveal.md) is the main module and has the main entry point of Reveal, [`Cognite3DViewer`](/api/classes/cognite_reveal.Cognite3DViewer.md). CAD models are represented by [`CogniteCadModel`](/api/classes/cognite_reveal.CogniteCadModel.md) and points clouds by [`CognitePointCloudModel`](/api/classes/cognite_reveal.CognitePointCloudModel.md). | ||
- [@congite/reveal/tools](/api/modules/cognite_reveal_tools.md) contains a set of tools, e.g. [`AxisViewTool`](/api/classes/cognite_reveal_tools.AxisViewTool.md), [`TimelineTool`](/api/classes/cognite_reveal_tools.TimelineTool.md), and [`HtmlOverlayTool`](/api/classes/cognite_reveal_tools.HtmlOverlayTool.md) that works with `Cognite3DViewer`. | ||
- [@cognite/reveal/extensions/datasource](/api/modules/cognite_reveal_extensions_datasource.md) allows providing custom data sources for geometry and model metadata. | ||
- [@cognite/reveal](/api/@cognite/reveal/index.md) is the main module and has the main entry point of Reveal, [`Cognite3DViewer`](/api/@cognite/reveal/classes/Cognite3DViewer.md). CAD models are represented by [`CogniteCadModel`](/api/@cognite/reveal/classes/CogniteCadModel.md) and points clouds by [`CognitePointCloudModel`](/api/@cognite/reveal/classes/CognitePointCloudModel.md). | ||
- [@congite/reveal/tools](/api/@cognite/reveal/tools/index.md) contains a set of tools, e.g. [`AxisViewTool`](/api/@cognite/reveal/tools/classes/AxisViewTool.md), [`TimelineTool`](/api/@cognite/reveal/tools/classes/TimelineTool.md), and [`HtmlOverlayTool`](/api/@cognite/reveal/tools/classes/HtmlOverlayTool.md) that works with `Cognite3DViewer`. | ||
- [@cognite/reveal/extensions/datasource](/api/@cognite/reveal/extensions/datasource/index.md) allows providing custom data sources for geometry and model metadata. | ||
|
||
:::note | ||
If the consuming application does not enable `Node16` module resolution, then all types must be imported from `@cognite/reveal`. | ||
::: | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 89 additions & 65 deletions
154
documentation/src/plugins/remark-runnable-reveal-demo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,97 @@ | ||
const transformNode = (node) => { | ||
const code = node.value | ||
.trim() | ||
// allows new lines in jsx snippets | ||
.replace(/(\r\n|\n|\r)/gm, '\n') | ||
// handles backtick usage in jsx snippets | ||
.replace(/`/gm, '\\`') | ||
.replace(/\$/gm, '\\$'); | ||
import { is } from "unist-util-is"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
return [ | ||
{ | ||
type: 'jsx', | ||
value: '<LiveCodeSnippet>{`' + code + '`}</LiveCodeSnippet>', | ||
}, | ||
]; | ||
}; | ||
/** | ||
* adapted from https://github.com/mrazauskas/docusaurus-remark-plugin-tab-blocks/blob/b7dab1533dc422df00ce965a87fef840a62255bb/index.js | ||
*/ | ||
|
||
function getImportNodes(metaString) { | ||
|
||
const docsPath = getDocsPath(metaString); | ||
|
||
const versionedImportNode = { | ||
runnable: { | ||
type: 'import', | ||
value: | ||
"import { LiveCodeSnippet } from '@site/docs/components/LiveCodeSnippet';", | ||
}, | ||
'runnable-1x': { | ||
type: 'import', | ||
value: | ||
"import { LiveCodeSnippet } from '@site/versioned_docs/version-1.x/components/LiveCodeSnippet';", | ||
}, | ||
'runnable-2x': { | ||
type: 'import', | ||
value: | ||
"import { LiveCodeSnippet } from '@site/versioned_docs/version-2.x/components/LiveCodeSnippet';", | ||
}, | ||
'runnable-3x': { | ||
type: 'import', | ||
value: | ||
"import { LiveCodeSnippet } from '@site/versioned_docs/version-3.x/components/LiveCodeSnippet';", | ||
}, | ||
'runnable-4x': { | ||
type: 'import', | ||
value: | ||
"import { LiveCodeSnippet } from '@site/versioned_docs/version-4.x/components/LiveCodeSnippet';", | ||
if (docsPath === undefined) { | ||
return undefined; | ||
} | ||
}; | ||
|
||
module.exports = () => { | ||
let transformed = false; | ||
let importNode; | ||
const transformer = (node) => { | ||
if (node.type === 'code' && versionedImportNode[node.meta]) { | ||
transformed = true; | ||
importNode = versionedImportNode[node.meta]; | ||
return transformNode(node); | ||
return { | ||
data: { | ||
estree: { | ||
body: [ | ||
{ | ||
source: { | ||
raw: `'@site/${docsPath}/components/LiveCodeSnippet'`, | ||
type: "Literal", | ||
value: `@site/${docsPath}/components/LiveCodeSnippet`, | ||
}, | ||
specifiers: [ | ||
{ | ||
local: { name: "LiveCodeSnippet", type: "Identifier" }, | ||
type: "ImportDefaultSpecifier", | ||
}, | ||
], | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
type: "Program", | ||
}, | ||
}, | ||
type: "mdxjsEsm", | ||
value: `import LiveCodeSnippet from '@site/${docsPath}/components/LiveCodeSnippet';`, | ||
}; | ||
|
||
function getDocsPath(metaString) { | ||
switch(metaString) { | ||
case 'runnable': return 'docs'; | ||
case 'runnable-1x': return 'versioned_docs/version-1.x'; | ||
case 'runnable-2x': return 'versioned_docs/version-2.x'; | ||
case 'runnable-3x': return 'versioned_docs/version-3.x'; | ||
case 'runnable-4x': return 'versioned_docs/version-4.x'; | ||
default: return undefined; | ||
} | ||
if (Array.isArray(node.children)) { | ||
let index = 0; | ||
while (index < node.children.length) { | ||
const result = transformer(node.children[index]); | ||
if (result) { | ||
node.children.splice(index, 1, ...result); | ||
index += result.length; | ||
} else { | ||
index += 1; | ||
} | ||
} | ||
} | ||
|
||
function createSnippet(codeNode) { | ||
return { | ||
type: 'mdxJsxFlowElement', | ||
name: 'LiveCodeSnippet', | ||
attributes: [], | ||
children: [{ type: 'text', value: codeNode.value }] | ||
}; | ||
} | ||
|
||
function resolveConfig(options) { | ||
return { | ||
groupId: options.groupId, | ||
labels: new Map([ | ||
["js", "JavaScript"], | ||
["ts", "TypeScript"], | ||
...(options.labels || []), | ||
]), | ||
sync: options.sync ?? true, | ||
}; | ||
} | ||
|
||
function plugin(options = {}) { | ||
const config = resolveConfig(options); | ||
|
||
return function transformer(tree) { | ||
let importNodes = undefined; | ||
|
||
visit(tree, ['code', 'mdxjsEsm'], (node, index, parent) => { | ||
if (!node.meta?.includes('runnable')) { | ||
return; | ||
} | ||
|
||
importNodes = getImportNodes(node.meta); | ||
|
||
parent.children[index] = createSnippet(node); | ||
}); | ||
|
||
if (importNodes !== undefined) { | ||
tree.children.unshift(importNodes); | ||
} | ||
if (node.type === 'root' && transformed) { | ||
node.children.unshift(importNode); | ||
} | ||
return null; | ||
}; | ||
return transformer; | ||
}; | ||
} | ||
|
||
export default plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.