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

Displaying TS code examples in the docs #10966

Open
wants to merge 188 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
25d625b
init
Oct 11, 2023
86657a8
Merge branch 'feature/docs-redesign' of https://github.com/sl01k/hand…
evanSe Dec 20, 2023
d6c29b5
white space
sl01k Feb 28, 2024
f596e42
classic
sl01k Mar 1, 2024
2c6bc60
classic
sl01k Mar 1, 2024
f68feee
dosc dev
sl01k Mar 8, 2024
4960c1f
styling v0.1
sl01k Mar 13, 2024
d79a08e
frontend rwd
sl01k Mar 15, 2024
9d2a959
styleing
sl01k Mar 20, 2024
990ea6a
search fix
sl01k Mar 20, 2024
215e27b
sync
sl01k Mar 22, 2024
442b22c
vue styles leak fix
sl01k Mar 27, 2024
702ab13
Add algolia search to documentation
adrianspdev Mar 27, 2024
28f6ee4
Merge branch 'develop' into feature/dev-issue-1780
adrianspdev Mar 27, 2024
0f9a19b
add missing docsearch env error, and remove old search box component
adrianspdev Mar 27, 2024
46d7dd3
add lint fix
adrianspdev Mar 27, 2024
d0cca28
fix search box results styles
adrianspdev Mar 27, 2024
b48f32f
scss
sl01k Mar 27, 2024
75aca1c
scss
sl01k Mar 28, 2024
3af0905
add clear input after redirect, add fixes from qa comments
adrianspdev Mar 29, 2024
ed5f38b
scss
sl01k Mar 29, 2024
4140685
scss
sl01k Mar 29, 2024
ed049e2
scss update
sl01k Mar 29, 2024
d30042b
update review v2
sl01k Apr 3, 2024
e91b088
css bg / code colors
sl01k Apr 3, 2024
56dd896
Merge branch 'develop' into feature/dev-issue-1780
evanSe Apr 5, 2024
edee381
Merge branch 'develop' into docs-redesign-v2
evanSe Apr 5, 2024
71bb724
Merge branch 'feature/dev-issue-1780' into docs-redesign-v2
evanSe Apr 5, 2024
30e093a
fix
evanSe Apr 5, 2024
dcee289
review 2 part 1 - frontend
sl01k Apr 5, 2024
308aee0
sync
sl01k Apr 10, 2024
72795ba
visial update review 2
sl01k Apr 10, 2024
aed1a23
hotfix RWD
sl01k Apr 10, 2024
c580b94
sync
sl01k Apr 10, 2024
03a2da9
Update algolia docsearch to v3
adrianspdev Apr 11, 2024
ae49b09
fix lint
adrianspdev Apr 11, 2024
4f50dcc
update lock
evanSe Apr 11, 2024
8e1c879
adjust z-index
evanSe Apr 11, 2024
d757311
review 10.04
sl01k Apr 12, 2024
5e5929e
code runner
sl01k Apr 12, 2024
9d353f3
hotfix
sl01k Apr 12, 2024
607ee0a
front update
sl01k Apr 17, 2024
55e6eba
feat: show examples inline
evanSe Apr 17, 2024
d34bdf0
sync
sl01k Apr 17, 2024
b8c4914
Make the Vue/Vue3 wrappers' `simpleEqual` helper correctly recognize …
jansiegel Apr 8, 2024
623413b
Revert "Generate canonical links inline (#10879)" (#10898)
budnix Apr 8, 2024
09070df
1836 automate more e2e scenarios (#10901)
magierg Apr 8, 2024
6842a47
Fix datepicker position (#10892)
budnix Apr 9, 2024
8d6fb22
update dependencies (#10889)
evanSe Apr 9, 2024
984569d
Fix date picker position in overlays (#10905)
budnix Apr 10, 2024
3e7c888
Rollup interop fix (#10908)
evanSe Apr 11, 2024
366e61c
Generate canonicals inline (#10900)
budnix Apr 11, 2024
56b5417
Add fix for react only links (#10895)
adrianspdev Apr 12, 2024
ec23bda
Add stackblitz improvements and codesanbox fixes (#10891)
adrianspdev Apr 15, 2024
5211f6f
14.3.0
jansiegel Apr 9, 2024
71b532a
Regenerate package-lock with .
jansiegel Apr 9, 2024
30bfb07
Fix the audit error.
jansiegel Apr 9, 2024
e44f0be
14.3.0
jansiegel Apr 10, 2024
1ea6816
14.3.0
jansiegel Apr 11, 2024
9cbcb2b
update changelog and release notes (#10916)
evanSe Apr 16, 2024
94d3eb8
sync
sl01k Apr 17, 2024
718b38a
Merge branch 'docs-redesign-v2' of https://github.com/handsontable/ha…
sl01k Apr 17, 2024
0310207
favicon
sl01k Apr 17, 2024
e8be956
docs frontend update - examples / algolia / roadmap
sl01k Apr 17, 2024
919e6c5
Fix links in right-hand side menu and remove smooth scroll effect (#1…
adrianspdev Apr 18, 2024
1001887
Add breadcrumbs to documentation (#10907)
adrianspdev Apr 18, 2024
f35d948
Add docs github stars counter (#10899)
adrianspdev Apr 18, 2024
eb14bfb
Add version ticker component (#10913)
adrianspdev Apr 18, 2024
cd45de1
docs update
sl01k Apr 19, 2024
20cb14b
docs update
sl01k Apr 19, 2024
4b60eea
css hotfix
sl01k Apr 22, 2024
cde011f
add docs fixes round 2
adrianspdev Apr 22, 2024
ad83bf6
Wrap headers in ahref (#10927)
adrianspdev Apr 23, 2024
6c2afad
installation page & lint fix
sl01k Apr 23, 2024
b07b36a
Add right hand menu and toggle source code improvement
adrianspdev Apr 23, 2024
4266ca0
Fix demo disappearing on tab changes
adrianspdev Apr 23, 2024
1c8fc42
installation page fix
sl01k Apr 23, 2024
26a1e4e
Add TOC active element improvement and lint fixes
adrianspdev Apr 23, 2024
72f5260
Merge branch 'develop' into docs-redesign-v2
evanSe Apr 25, 2024
1c16014
Add structured data to docs (#10880)
adrianspdev Apr 25, 2024
9ae8e9d
sync
sl01k Apr 25, 2024
189d5ba
Merge branch 'docs-redesign-v2' of https://github.com/handsontable/ha…
sl01k Apr 25, 2024
732c58d
update theme
sl01k Apr 25, 2024
fc2d8bb
fix lint
adrianspdev Apr 26, 2024
c73e6e2
Merge branch 'develop' into docs-redesign-v2
evanSe Apr 26, 2024
9bc20ee
ally issues, light theme upgrade, demos fix
sl01k Apr 26, 2024
edc4000
Merge branch 'docs-redesign-v2' of https://github.com/handsontable/ha…
sl01k Apr 26, 2024
d08887b
DM link color ally
sl01k Apr 29, 2024
7d54b7e
tabs styling
sl01k Apr 29, 2024
765234a
hotfix
sl01k Apr 29, 2024
e7da1fc
fix lockfile
evanSe May 6, 2024
f972af2
update lock
evanSe May 6, 2024
377779e
fix example checker
evanSe May 6, 2024
104ad04
update cases
evanSe May 6, 2024
9eb3105
Add docs redesign fixes round 3 (#10960)
adrianspdev May 6, 2024
fa2a0f3
Add lighthouse fixes and clear console errors (#10953)
adrianspdev May 6, 2024
007cc85
Add reset demo button functionality and fix test cases (#10946)
adrianspdev May 6, 2024
da0cccc
fix docs build
adrianspdev May 7, 2024
8b8b80f
update expected count
evanSe May 7, 2024
a40a77f
update lock
evanSe May 7, 2024
e0a07ba
fix locks
evanSe May 7, 2024
5c733a9
bump up waiting time
evanSe May 7, 2024
d745442
update test case
evanSe May 7, 2024
000fab2
update selector
evanSe May 7, 2024
abfac60
update cases
evanSe May 8, 2024
e7ff94c
introduction page update
sl01k May 8, 2024
4f9ced5
Merge branch 'docs-redesign-v2' of https://github.com/handsontable/ha…
sl01k May 8, 2024
a3100f3
update cases
evanSe May 8, 2024
9729748
fix cases
evanSe May 8, 2024
92ee00b
fix lint issues
adrianspdev May 8, 2024
d22bab9
SPIKE - add script that compiles an example TS file to JS
sequba May 8, 2024
cd4b017
Adjust the start script to make it work in Windows env
sequba May 8, 2024
2b823e5
Extend the base eslintrc in the eslintrc for example files
sequba May 8, 2024
eb10648
Add a bash script that generates the JS files for all the TS example …
sequba May 9, 2024
195a411
Add generate-js-examples step to the npm scripts
sequba May 9, 2024
839a0b2
Make the generate-js-examples script apply only for the vanilla js ex…
sequba May 14, 2024
1a1aade
Renamed all js examples to *.ts without changing the content
sequba May 14, 2024
4816454
Add typings for data array in the examples (array of arrays)
sequba May 14, 2024
a7512e9
Add typings for HOT instance in all TS examples
sequba May 14, 2024
23ba25b
Add typings for data array in the examples (array of objects)
sequba May 14, 2024
ab45ef0
Improve reporting in the generate-js-examples script
sequba May 14, 2024
d4b2013
Add typings for the HOT instance in the examples
sequba May 14, 2024
e4a2747
Improve typings in docs/content/guides/accessories-and-menus/context-…
sequba May 14, 2024
5e6fd70
Improve typings in docs/content/guides/accessories-and-menus/export-t…
sequba May 14, 2024
a037c86
Add typing for .getPlugin statements
sequba May 14, 2024
f5fbeee
Change typing for HOT instance from Handsontable to Core
sequba May 14, 2024
530c512
Add typings for custom renderers in the ts examples
sequba May 14, 2024
78e8357
Add missing import statements
sequba May 14, 2024
a5ae697
Improve typings for arrays
sequba May 14, 2024
b5f2b19
replace Core type
adrianspdev May 15, 2024
247f43a
add lint rules
adrianspdev May 15, 2024
9eeae74
update lint
adrianspdev May 15, 2024
8af9e2b
update ts examples
adrianspdev May 15, 2024
1578442
Newline at the end of file gitignore
sequba May 15, 2024
92392e9
Remove unused vars in docs/content/guides/getting-started
sequba May 15, 2024
1eefab1
Remove unused 'const hot' variables
sequba May 15, 2024
4041851
Fix type error for html containers for the HOT instance
sequba May 15, 2024
0c8c83b
Fix typings in docs/content/guides/rows/row-prepopulating/javascript/…
sequba May 15, 2024
6898d65
Make all HOT instances variables names consistently 'hot'
sequba May 15, 2024
1e8dd07
add ts fixes and cleanup
adrianspdev May 16, 2024
801ff9c
Improve typings in docs/content/guides/getting-started/binding-to-data
sequba May 16, 2024
5621ca6
Merge branch 'feature/dev-issue-1867' of github.com:handsontable/hand…
sequba May 16, 2024
7e00493
Improve typings for cells() function in HOT configuration
sequba May 16, 2024
eb75033
Fix docs/content/guides/columns/column-filter/javascript/exampleFilte…
sequba May 16, 2024
7e8a66c
Fix typings for docs/content/guides/getting-started/demo/javascript/e…
sequba May 16, 2024
cf44725
fix example
adrianspdev May 16, 2024
c6543d0
Fix type-null-checking in HTML elements
sequba May 16, 2024
8001b7c
Merge branch 'feature/dev-issue-1867' of github.com:handsontable/hand…
sequba May 16, 2024
44c24c0
Fix typing for HTMLInputElement vars
sequba May 16, 2024
383e396
Fix docs/content/guides/optimization/batch-operations/javascript/exam…
sequba May 16, 2024
88f27c8
Fix typings in dir docs/content/guides/cell-functions
sequba May 16, 2024
65ae825
Fix typings in dir docs/content/guides/columns
sequba May 16, 2024
2c68ce2
Fix typings in dir docs/content/guides/cell-features
sequba May 16, 2024
b3a0b32
Fix typings in dir docs/content/guides/cell-types
sequba May 16, 2024
0b134f0
Fix typings in dir docs/content/guides/formulas
sequba May 16, 2024
ff7c7b3
Fix typings in dir docs/content/guides/navigation
sequba May 16, 2024
8f60aa6
Fix typings in dir docs/content/guides/accessories-and-menus
sequba May 16, 2024
c4bd257
Improve typings for docs/content/guides/getting-started/binding-to-da…
sequba May 16, 2024
5b93d19
add typescript tab to examples
adrianspdev May 17, 2024
ceefb22
Merge branch 'develop' of github.com:handsontable/handsontable into f…
sequba May 21, 2024
4dea4ab
Revert unnecessary changes
sequba May 21, 2024
a2c0f13
Revert unnecessary changes
sequba May 21, 2024
c2fc20b
Revert unnecessary changes
sequba May 21, 2024
68265ca
Make generate-js-examples script re-generate files even when exist
sequba May 21, 2024
4f0f39b
Make sure generate-js-examples.sh is run in bash shell
sequba May 22, 2024
2c32dbf
Merge branch 'feature/dev-issue-1867-without-1905' of github.com:hand…
sequba May 22, 2024
450f8d6
Fix merge errors in docs/content/guides/cell-types/dropdown-cell-type…
sequba May 22, 2024
cb74696
Add @[code] tag with TS example to all guides
sequba May 23, 2024
5b19c40
Fix file content/guides/accessories-and-menus/context-menu/context-me…
sequba May 23, 2024
aefd67d
Update tags for the code examples in the guides that include a TS ver…
sequba May 23, 2024
34f89ca
Fix typo in example tags in the guides
sequba May 23, 2024
7d97b5c
Add tags for examples with ':hot-lang'
sequba May 23, 2024
0c0ecad
Add tags for examples with ':hot-numbro'
sequba May 23, 2024
cdadb5c
Fix example-without-tabs
sequba May 23, 2024
3f3b649
Fix /column-summary.md and binding-to-data.md
sequba May 23, 2024
d664778
Fix binding-to-data.md
sequba May 23, 2024
48ed1f3
Merge branch 'develop' into feature/dev-issue-1867
adrianspdev Jun 6, 2024
f312564
add TS/JS switcher
adrianspdev Jun 11, 2024
53507bc
add sandbox lang support
adrianspdev Jun 13, 2024
7a562f2
Merge branch 'develop' of github.com-htable:handsontable/handsontable…
adrianspdev Jun 13, 2024
99e14a0
add scripts to package.json, fix lint and update readme file
adrianspdev Jun 13, 2024
3c46c41
Update docs/README.md
adrianspdev Jun 13, 2024
78cd3a1
Update docs/package.json
adrianspdev Jun 13, 2024
46629b9
Update docs/package.json
adrianspdev Jun 13, 2024
753ee58
update docs getting started
adrianspdev Jun 13, 2024
2c7fc40
fix examples
adrianspdev Jun 13, 2024
238af01
fix autocomplete examples
adrianspdev Jun 13, 2024
cbfc736
fix autocomplete cell type
adrianspdev Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/.vuepress/code-structure-builder/buildJavascriptBody.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const buildJavascriptBody = ({ id, html, js, css, version, hyperformulaVersion, sandbox }) => {
const buildJavascriptBody = ({ id, html, js, css, version, hyperformulaVersion, sandbox, lang }) => {
if (sandbox === 'stackblitz') {
return {
files: {
Expand Down Expand Up @@ -29,7 +29,7 @@ const buildJavascriptBody = ({ id, html, js, css, version, hyperformulaVersion,
'styles.css': {
content: css
},
'index.js': {
[`index.${lang}`]: {
content: `import './styles.css'
${js}`
},
Expand Down Expand Up @@ -73,14 +73,14 @@ ${js}`

<body>
${html || `<div id="${id}"></div>`}
<script src="src/index.js"></script>
<script src="src/index.${lang}"></script>
</body>
</html>`
},
'src/styles.css': {
content: css
},
'src/index.js': {
[`src/index.${lang}`]: {
content: js.replace('import { HyperFormula } from \'hyperformula\';', '')
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/code-structure-builder/getBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const { buildReactBody } = require('./buildReactBody');
const { buildVue3Body } = require('./buildVue3Body');
const { buildVueBody } = require('./buildVueBody');

const getBody = (id, html, js, css, docsVersion, preset, sandbox) => {
const getBody = ({ id, html, js, css, docsVersion, preset, sandbox, lang }) => {
const version = formatVersion(docsVersion);
const hyperformulaVersion = '^2.4.0';

if (/hot(-.*)?/.test(preset)) {
return buildJavascriptBody({ id, html, js, css, version, hyperformulaVersion, sandbox });
return buildJavascriptBody({ id, html, js, css, version, hyperformulaVersion, sandbox, lang });
} else if (/react(-.*)?/.test(preset)) {
return buildReactBody({ js, css, version, hyperformulaVersion, preset, sandbox });
} else if (/vue3(-.*)?/.test(preset)) {
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/containers/examples/codesandbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { getParameters } = require('codesandbox/lib/api/define');
const { getBody } = require('../../code-structure-builder/getBody');

const codesandbox = (id, html, js, css, docsVersion, preset) => {
const body = getBody(id, html, js, css, docsVersion, preset);
const codesandbox = (id, html, js, css, docsVersion, preset, lang) => {
const body = getBody({ id, html, js, css, docsVersion, preset, lang });
const parameters = getParameters(body);

return `
Expand Down
233 changes: 132 additions & 101 deletions docs/.vuepress/containers/examples/examples.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Matches into: `example #ID .class :preset --css 2 --html 0 --js 1 --no-edit`.
* Matches into: `example #ID .class :preset --css 2 --html 0 --js 1 --ts 3 --no-edit`.
*
* @type {RegExp}
*/
const EXAMPLE_REGEX = /^(example)\s*(#\S*|)\s*(\.\S*|)\s*(:\S*|)\s*([\S|\s]*)$/;

const Token = require('markdown-it/lib/token');
const { buildCode } = require('./code-builder');
const { addCodeForPreset } = require('./add-code-for-preset');
const { codesandbox } = require('./codesandbox');
Expand All @@ -14,45 +14,84 @@ const { stackblitz } = require('./stackblitz');
const tab = (tabName, token, id) => {
if (!token) return [];

const openTSDivToken = new Token('html_block', '', 1);
const closeDivToken = new Token('html_block', '', -1);

openTSDivToken.content = `<tab id="${tabName.toLowerCase()}-tab-${id}" name="${tabName}">`;
closeDivToken.content = '</tab>';

return [
{
type: 'html_block',
tag: '',
attrs: null,
map: [],
nesting: 0,
level: 1,
children: null,
content: `<tab id="${tabName.toLowerCase()}-tab-${id}" name="${tabName}">`,
markup: '',
info: '',
meta: null,
block: true,
hidden: false,
},
openTSDivToken,
token,
{
type: 'html_block',
tag: '',
attrs: null,
map: [],
nesting: 0,
level: 1,
children: null,
content: '</tab>',
markup: '',
info: '',
meta: null,
block: true,
hidden: false,
},
closeDivToken
];
};

const parsePreview = (content, base) => {
if (!content) return '';

return content
.replaceAll('{{$basePath}}', base)
// Remove the all "/* start:skip-in-compilation */" and "/* end:skip-in-compilation */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-compilation(\s+)?\*\/\n/gm, '')
// Remove the code between "/* start:skip-in-preview */" and "/* end:skip-in-preview */" expressions
.replace(/\/\*(\s+)?start:skip-in-preview(\s+)?\*\/\n.*?\/\*(\s+)?end:skip-in-preview(\s+)?\*\/\n/msg, '')
// Remove /* end-file */
.replace(/\/\* end-file \*\//gm, '')
.trim();
};

const parseCode = (content) => {
if (!content) return '';

return content
// Remove the all "/* start:skip-in-preview */" and "/* end:skip-in-preview */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-preview(\s+)?\*\/\n/gm, '')
// Remove the code between "/* start:skip-in-compilation */" and "/* end:skip-in-compilation */" expressions
// eslint-disable-next-line max-len
.replace(/\/\*(\s+)?start:skip-in-compilation(\s+)?\*\/\n.*?\/\*(\s+)?end:skip-in-compilation(\s+)?\*\/\n/msg, '')
// Remove /* end-file */
.replace(/\/\* end-file \*\//gm, '');
};

const parseCodeSandbox = (content) => {
if (!content) return '';

return content
// Remove the all "/* start:skip-in-preview */" and "/* end:skip-in-preview */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-preview(\s+)?\*\/\n/gm, '')
// Remove the all "/* start:skip-in-compilation */" and "/* end:skip-in-compilation */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-compilation(\s+)?\*\/\n/gm, '');
};

const getCodeToken = (jsToken, tsToken) => {
const code = new Token('inline', '', 1);
const openJSDivToken = new Token('container_div_open', 'div', 1);
const openTSDivToken = new Token('container_div_open', 'div', 1);
const closeDivToken = new Token('container_div_close', 'div', -1);

openJSDivToken.attrSet('class', 'tab-content-js hideElement');
openTSDivToken.attrSet('class', 'tab-content-ts');

code.children = [
openJSDivToken,
jsToken,
closeDivToken
];

if (tsToken) {
code.children.push(openTSDivToken);
code.children.push(tsToken);
code.children.push(closeDivToken);
}

return code;
};

module.exports = function(docsVersion, base) {
return {
type: 'example',
render(tokens, index, opts, env) {
render(tokens, index, _opts, env) {
const token = tokens[index];
const m = token.info.trim().match(EXAMPLE_REGEX);

Expand All @@ -79,72 +118,54 @@ module.exports = function(docsVersion, base) {
const cssContent = cssToken ? cssToken.content : '';

const jsPos = args.match(/--js (\d*)/)?.[1] || 1;
const jsIndex = index + Number.parseInt(jsPos, 10);
const jsToken = tokens[jsIndex];

jsToken.content = jsToken.content.replaceAll('{{$basePath}}', base);

const codeToCompile = jsToken.content
// Remove the all "/* start:skip-in-preview */" and "/* end:skip-in-preview */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-preview(\s+)?\*\/\n/gm, '')
// Remove the code between "/* start:skip-in-compilation */" and "/* end:skip-in-compilation */" expressions
// eslint-disable-next-line max-len
.replace(/\/\*(\s+)?start:skip-in-compilation(\s+)?\*\/\n.*?\/\*(\s+)?end:skip-in-compilation(\s+)?\*\/\n/msg, '')
// Remove /* end-file */
.replace(/\/\* end-file \*\//gm, '');

const codeToPreview = jsToken.content
// Remove the all "/* start:skip-in-compilation */" and "/* end:skip-in-compilation */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-compilation(\s+)?\*\/\n/gm, '')
// Remove the code between "/* start:skip-in-preview */" and "/* end:skip-in-preview */" expressions
.replace(/\/\*(\s+)?start:skip-in-preview(\s+)?\*\/\n.*?\/\*(\s+)?end:skip-in-preview(\s+)?\*\/\n/msg, '')
// Remove /* end-file */
.replace(/\/\* end-file \*\//gm, '')
.trim();

const codeToCompileSandbox = jsToken.content
// Remove the all "/* start:skip-in-preview */" and "/* end:skip-in-preview */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-preview(\s+)?\*\/\n/gm, '')
// Remove the all "/* start:skip-in-compilation */" and "/* end:skip-in-compilation */" comments
.replace(/\/\*(\s+)?(start|end):skip-in-compilation(\s+)?\*\/\n/gm, '');

jsToken.content = codeToPreview;
const jsIndex = jsPos ? index + Number.parseInt(jsPos, 10) : 0;
const jsToken = jsPos ? tokens[jsIndex] : undefined;

const activeTab = `${args.match(/--tab (code|html|css|preview)/)?.[1] ?? 'preview'}-tab-${id}`;
const noEdit = !!args.match(/--no-edit/)?.[0];
const tsPos = args.match(/--ts (\d*)/)?.[1];
const tsIndex = tsPos ? index + Number.parseInt(tsPos, 10) : 0;
const tsToken = tsPos ? tokens[tsIndex] : undefined;

const codeForPreset = addCodeForPreset(codeToCompile, preset, id);
// Parse code
const codeToCompile = parseCode(jsToken.content);
const tsCodeToCompile = parseCode(tsToken?.content);
const codeToCompileSandbox = parseCodeSandbox(jsToken.content);
const tsCodeToCompileSandbox = parseCodeSandbox(tsToken?.content);
const codeToPreview = parsePreview(jsToken.content, base);
const tsCodeToPreview = parsePreview(tsToken?.content, base);

const code = buildCode(
id + (preset.includes('angular') ? '.ts' : '.jsx'),
codeForPreset,
env.relativePath
);
const encodedCode = encodeURI(
`useHandsontable('${docsVersion}', function(){${code}}, '${preset}')`
);
// Replace token content
if (jsToken) jsToken.content = codeToPreview;

if (tsToken) tsToken.content = tsCodeToPreview;

[htmlIndex, jsIndex, cssIndex].filter(x => !!x).sort().reverse().forEach((x) => {
[htmlIndex, jsIndex, tsIndex, cssIndex].filter(x => !!x).sort().reverse().forEach((x) => {
tokens.splice(x, 1);
});

const newTokens = [
...tab('Code', jsToken, id),
...tab('Code', tsToken ? getCodeToken(jsToken, tsToken) : jsToken, id),
...tab('HTML', htmlToken, id),
...tab('CSS', cssToken, id),
];

tokens.splice(index + 1, 0, ...newTokens);
const isAngular = /angular(-.*)?/.test(preset);
const isRTL = /layoutDirection(.*)'rtl'/.test(codeToCompile) || /dir="rtl"/.test(htmlContent);
const isReact = /react(-.*)?/.test(preset);

const displayJsFiddle = Boolean(!noEdit && !isAngular);

const codeForPreset = addCodeForPreset(codeToCompile, preset, id);
const code = buildCode(
id + (preset.includes('angular') ? '.ts' : '.jsx'),
codeForPreset,
env.relativePath
);
const encodedCode = encodeURI(
`useHandsontable('${docsVersion}', function(){${code}}, '${preset}')`
);
const activeTab = `${args.match(/--tab (code|html|css|preview)/)?.[1] ?? 'preview'}-tab-${id}`;
const noEdit = !!args.match(/--no-edit/)?.[0];
const isRTL = /layoutDirection(.*)'rtl'/.test(codeToCompile) || /dir="rtl"/.test(htmlContent);
const isActive = `$parent.$parent.isScriptLoaderActivated('${id}')`;

return `
<div class="example-container" >
<div class="example-container">
<template v-if="${isActive}">
<style v-pre>${cssContent}</style>
<div v-pre>${htmlContentRoot}</div>
Expand All @@ -157,31 +178,41 @@ module.exports = function(docsVersion, base) {
<i class="ico i-code"></i>Source code
</button>
<div class="example-controls">
${Boolean(!noEdit) && stackblitz(
id,
htmlContent,
codeToCompileSandbox,
cssContent,
docsVersion,
preset
)}
${!noEdit && !isReact
? codesandbox(
id,
htmlContent,
codeToCompileSandbox,
cssContent,
docsVersion,
preset
) : ''}
${displayJsFiddle ? jsfiddle(id, htmlContent, codeForPreset, cssContent, docsVersion, preset) : ''}
<button
<div class="examples-buttons examples-js${tsToken ? ' hideElement' : ''}">
${!noEdit
? stackblitz(id, htmlContent, codeToCompileSandbox, cssContent, docsVersion, preset, 'js')
: ''}
${!noEdit
? codesandbox(id, htmlContent, codeToCompileSandbox, cssContent, docsVersion, preset, 'js')
: ''}
${!noEdit
? jsfiddle(id, htmlContent, codeForPreset, cssContent, docsVersion, preset, 'js')
: ''}
</div>
${tsToken ? `
<div class="examples-buttons examples-ts">
${!noEdit
? stackblitz(id, htmlContent, tsCodeToCompileSandbox, cssContent, docsVersion, preset, 'ts')
: ''}
${!noEdit
? codesandbox(id, htmlContent, tsCodeToCompileSandbox, cssContent, docsVersion, preset, 'ts')
: ''}
${!noEdit
? jsfiddle(id, htmlContent, tsCodeToCompile, cssContent, docsVersion, preset, 'ts')
: ''}
</div>
` : ''}
<button
aria-label="Reset the demo"
@click="$parent.$parent.resetDemo('${id}')"
:disabled="$parent.$parent.isButtonInactive"
>
<i class="ico i-refresh"></i>
</button>
<select class="selected-lang" value="ts" hidden>
<option value="ts">ts</option>
<option value="js">js</option>
</select>
</div>
</div>
<div class="example-container-code">
Expand Down
6 changes: 3 additions & 3 deletions docs/.vuepress/containers/examples/jsfiddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const JSFIDDLE_ENDPOINT = 'https://jsfiddle.net/api/post/library/pure/';

const { getDependencies } = require('../../handsontable-manager');

const jsfiddle = (id, html, code, css, version, preset) => {
const jsfiddle = (_id, html, code, css, version, preset, lang) => {
const isBabelPanel = preset.includes('react') || preset.includes('vue') || preset.includes('hot');
const isAngularPanel = preset.includes('angular');
const imports = getDependencies(version, preset).reduce(
Expand All @@ -29,8 +29,8 @@ ${html}
</textarea>
<textarea class="hidden" name="css" readOnly v-pre>${css}</textarea>
<input type="hidden" name="panel_css" value="1" readOnly> <!-- enables SCSS panel -->
${isBabelPanel ? '<input type="hidden" name="panel_js" value="3" readOnly>' : ''}
${isAngularPanel ? '<input type="hidden" name="panel_js" value="4" readOnly>' : ''}
${isBabelPanel && lang === 'js' ? '<input type="hidden" name="panel_js" value="3" readOnly>' : ''}
${isAngularPanel || lang === 'ts' ? '<input type="hidden" name="panel_js" value="4" readOnly>' : ''}

<div class="js-fiddle-link">
<button type="submit" aria-label="Edit in JSFiddle">
Expand Down
8 changes: 5 additions & 3 deletions docs/.vuepress/containers/examples/stackblitz.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { getBody } = require('../../code-structure-builder/getBody');

const stackblitz = (id, html, js, css, docsVersion, preset) => {
const body = getBody(id, html, js, css, docsVersion, preset, 'stackblitz');
const stackblitz = (id, html, js, css, docsVersion, preset, lang) => {
const body = getBody({ id, html, js, css, docsVersion, preset, sandbox: 'stackblitz', lang });

const projects = body?.files
? Object.entries(body?.files).map(([key, value]) => (
Expand All @@ -16,7 +16,9 @@ const stackblitz = (id, html, js, css, docsVersion, preset) => {
const getTemplate = () => {
if (preset.includes('react')) return 'create-react-app';

if (preset.includes('hot')) return 'javascript';
if (preset.includes('hot') && lang === 'js') return 'javascript';

if (preset.includes('hot') && lang === 'ts') return 'typescript';

return 'node';
};
Expand Down