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

TS code examples #10990

Merged
merged 62 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
f252fcb
SPIKE - add script that compiles an example TS file to JS
sequba May 8, 2024
2ed5920
Adjust the start script to make it work in Windows env
sequba May 8, 2024
83761ec
Extend the base eslintrc in the eslintrc for example files
sequba May 8, 2024
38cf5da
Add a bash script that generates the JS files for all the TS example …
sequba May 9, 2024
4c9f7b0
Add generate-js-examples step to the npm scripts
sequba May 9, 2024
65481d5
Make the generate-js-examples script apply only for the vanilla js ex…
sequba May 14, 2024
b0f6f60
Renamed all js examples to *.ts without changing the content
sequba May 14, 2024
8ca474e
Add typings for data array in the examples (array of arrays)
sequba May 14, 2024
08921ce
Add typings for HOT instance in all TS examples
sequba May 14, 2024
e38a937
Add typings for data array in the examples (array of objects)
sequba May 14, 2024
e1eb8d4
Improve reporting in the generate-js-examples script
sequba May 14, 2024
1ac192f
Add typings for the HOT instance in the examples
sequba May 14, 2024
59d5d0d
Improve typings in docs/content/guides/accessories-and-menus/context-…
sequba May 14, 2024
f13461e
Improve typings in docs/content/guides/accessories-and-menus/export-t…
sequba May 14, 2024
3f7da28
Add typing for .getPlugin statements
sequba May 14, 2024
786dbc6
Change typing for HOT instance from Handsontable to Core
sequba May 14, 2024
84b938a
Add typings for custom renderers in the ts examples
sequba May 14, 2024
4186dbd
Add missing import statements
sequba May 14, 2024
2b226f8
Improve typings for arrays
sequba May 14, 2024
e051d7c
replace Core type
adrianspdev May 15, 2024
cc8d6c0
add lint rules
adrianspdev May 15, 2024
ea9381d
update lint
adrianspdev May 15, 2024
6b63877
update ts examples
adrianspdev May 15, 2024
77a9346
Newline at the end of file gitignore
sequba May 15, 2024
effdf19
Remove unused vars in docs/content/guides/getting-started
sequba May 15, 2024
80319f0
Remove unused 'const hot' variables
sequba May 15, 2024
f6bfba0
Fix type error for html containers for the HOT instance
sequba May 15, 2024
4a10337
Fix typings in docs/content/guides/rows/row-prepopulating/javascript/…
sequba May 15, 2024
bce21f4
Make all HOT instances variables names consistently 'hot'
sequba May 15, 2024
3d42101
Improve typings in docs/content/guides/getting-started/binding-to-data
sequba May 16, 2024
2ec518f
add ts fixes and cleanup
adrianspdev May 16, 2024
63d853f
Improve typings for cells() function in HOT configuration
sequba May 16, 2024
8311961
Fix docs/content/guides/columns/column-filter/javascript/exampleFilte…
sequba May 16, 2024
c7a70d5
Fix typings for docs/content/guides/getting-started/demo/javascript/e…
sequba May 16, 2024
497478b
Fix type-null-checking in HTML elements
sequba May 16, 2024
56296a0
fix example
adrianspdev May 16, 2024
d30b0df
Fix typing for HTMLInputElement vars
sequba May 16, 2024
e50288e
Fix docs/content/guides/optimization/batch-operations/javascript/exam…
sequba May 16, 2024
f7b2072
Fix typings in dir docs/content/guides/cell-functions
sequba May 16, 2024
ab4b981
Fix typings in dir docs/content/guides/columns
sequba May 16, 2024
cabb3e7
Fix typings in dir docs/content/guides/cell-features
sequba May 16, 2024
58ecdc5
Fix typings in dir docs/content/guides/cell-types
sequba May 16, 2024
e62ea65
Fix typings in dir docs/content/guides/formulas
sequba May 16, 2024
cc876f9
Fix typings in dir docs/content/guides/navigation
sequba May 16, 2024
6d4f2a9
Fix typings in dir docs/content/guides/accessories-and-menus
sequba May 16, 2024
1719711
Improve typings for docs/content/guides/getting-started/binding-to-da…
sequba May 16, 2024
85642d0
Revert unnecessary changes
sequba May 21, 2024
89be613
Revert unnecessary changes
sequba May 21, 2024
2fb9000
Make generate-js-examples script re-generate files even when exist
sequba May 21, 2024
a949306
Make sure generate-js-examples.sh is run in bash shell
sequba May 22, 2024
67838e4
Remove generate-js-examples script from the docs:start pipeline
sequba May 29, 2024
27ac72d
Make generate-js-examples script run jobs in parallel to speed things up
sequba May 29, 2024
91c1168
Improve the dev experience with the generate-js-examples script
sequba May 29, 2024
c9fb46c
Fix merge errors
sequba May 29, 2024
9208926
Fix merge errors
sequba May 29, 2024
d65a525
Make generat-js-examples script work in zsh env (MacOS)
sequba Jun 5, 2024
9830081
Fix/docs visual cache logic (#11014)
magierg Jun 11, 2024
154e6e4
fix lock
evanSe Jun 11, 2024
7612760
resolve docs lock
evanSe Jun 11, 2024
ea54356
update locks
evanSe Jun 11, 2024
e81bc7b
Merge branch 'develop' into feature/dev-issue-1867-without-1905
evanSe Jun 11, 2024
fdf2eb9
Merge branch 'develop' into feature/dev-issue-1867-without-1905
evanSe Jun 11, 2024
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
22 changes: 18 additions & 4 deletions .github/workflows/docs-visual-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defaults:
jobs:
run-tests:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 60
env: # Or as an environment variable
PASS_COOKIE: ${{ secrets.PassCookie }}
steps:
Expand Down Expand Up @@ -55,6 +55,11 @@ jobs:
if: ${{inputs.test_env == 'http://localhost:8080/docs'}}
run: |
npm run docs:api

- name: Build documentation
if: ${{inputs.test_env == 'http://localhost:8080/docs'}}
run: |
npm run docs:build

- name: Set up cache
id: cache
Expand All @@ -63,13 +68,22 @@ jobs:
key: plawyright-cache/${{github.repository}}/${{github.ref}}
restore-keys: plawyright-cache/${{github.repository}}/refs/heads/develop
path: '**/test-artifacts/**'


- name: Check if cache was restored
id: check-cache
run: |
if [[ -n "$(find . -name 'test-artifacts' -type d -not -path '*/node_modules/*' -print0 | xargs -0 -I {} find {} -type f -print -quit)" ]]; then
echo "cache-restored=true" >> $GITHUB_ENV
else
echo "cache-restored=false" >> $GITHUB_ENV
fi

- name: Initialize snapshots
if: ${{steps.cache.outputs.cache-hit != 'true' || inputs.update-snapshots == 'true'}}
if: ${{env.cache-restored != 'true' || github.event.inputs.update-snapshots == 'true'}}
run: BASE_URL=${{ inputs.test_env }} npx playwright test --update-snapshots

- name: Test
if: ${{steps.cache.outputs.cache-hit == 'true' || inputs.update-snapshots != 'true'}}
if: ${{env.cache-restored == 'true' || github.event.inputs.update-snapshots != 'true'}}
run: BASE_URL=${{ inputs.test_env }} npx playwright test

- name: Upload test report
Expand Down
5 changes: 4 additions & 1 deletion docs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ module.exports = {
parser: 'babel-eslint',
sourceType: 'module'
},
ignorePatterns: ['**/guides/**/*.js'],
ignorePatterns: [
'**/guides/**/*.js',
'**/guides/**/*.ts'
],
rules: {
'no-restricted-globals': 'off',
'import/no-unresolved': 'off'
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ report-check-links.xlsx
/playwright-report/
/blob-report/
/playwright/.cache/
/content/guides/**/javascript/**/*.js
34 changes: 34 additions & 0 deletions docs/.vuepress/tools/generate-js-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/bash
evanSe marked this conversation as resolved.
Show resolved Hide resolved

# This script generates the JS files for all the TS code examples. It skips the examples that already have a JS file.

jobs_limit=16

generate_single_file() {
ts_filename="$1"
js_filename="${ts_filename%.*}.js"

tsc --target esnext --skipLibCheck $ts_filename > /dev/null

if [ -f "$js_filename" ]; then
eslint --fix --no-ignore -c eslintrc.examples.js $js_filename > /dev/null
echo "Generated $js_filename"
else
echo "Failed to generate $js_filename"
fi
}

echo "Running $jobs_limit jobs in parallel..."

find content/guides -wholename "*/javascript/*.ts" -print0 | while read -d $'\0' ts_filename; do
while test "$(jobs | wc -l)" -ge "$jobs_limit"; do
sleep 1
done

generate_single_file "$ts_filename" &
done

wait
echo "Waiting for the result of all jobs..."
sleep 20
echo "All jobs finished"
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';

/* start:skip-in-preview */
interface Product {
companyName: string;
productName: string;
sellDate: string;
inStock: boolean;
qty: number;
orderId: string;
country: string;
}

/* start:skip-in-preview */
const data = [
const data: Product[] = [
{
companyName: 'Hodkiewicz - Hintz',
productName: 'Rustic Soft Ball',
Expand Down Expand Up @@ -463,7 +475,7 @@ const data = [
},
];

const countries = data.reduce((acc, curr) => {
const countries = data.reduce<string[]>((acc, curr) => {
if (acc.includes(curr.country)) {
return acc;
}
Expand All @@ -474,10 +486,10 @@ const countries = data.reduce((acc, curr) => {
/* end:skip-in-preview */

// Get the DOM element with the ID 'example1' where the Handsontable will be rendered
const app = document.getElementById('example1');
const app = document.getElementById('example1')!;

// Define configuration options for the Handsontable
const hotOptions = {
const hotOptions: Handsontable.GridSettings = {
data,
height: 464,
colWidths: [140, 165, 100, 100, 100, 110, 178],
Expand Down Expand Up @@ -533,116 +545,116 @@ const hotOptions = {
};

// Initialize the Handsontable instance with the specified configuration options
let hotInstance = new Handsontable(app, hotOptions);
let hot = new Handsontable(app, hotOptions);

// Helper function to set up checkbox event handling
const setupCheckbox = (element, callback) =>
element.addEventListener('click', clickEvent => callback(element.checked));
const setupCheckbox = (element: HTMLInputElement, callback: (val: boolean) => void) =>
element.addEventListener('click', () => callback(element.checked));

// Set up event listeners for various checkboxes to update Handsontable settings.
// This allows us to change the Handsontable settings from the UI, showcasing
// the flexibility of Handsontable in configuring according to your needs.

// Checkbox: Enable/Disable Tab Navigation
setupCheckbox(document.querySelector('#enable-tab-navigation'), (checked) => {
setupCheckbox(document.querySelector('#enable-tab-navigation') as HTMLInputElement, (checked) => {
hotOptions.tabNavigation = checked;
hotInstance.updateSettings({
hot.updateSettings({
tabNavigation: hotOptions.tabNavigation,
});
console.log(
'Updated setting: tabNavigation to',
hotInstance.getSettings().tabNavigation
hot.getSettings().tabNavigation
);
});

// Checkbox: Enable/Disable Header Navigation
setupCheckbox(
document.querySelector('#enable-header-navigation'),
document.querySelector('#enable-header-navigation') as HTMLInputElement,
(checked) => {
hotOptions.navigableHeaders = checked;
hotInstance.updateSettings({
hot.updateSettings({
navigableHeaders: hotOptions.navigableHeaders,
});
console.log(
'Updated setting: navigableHeaders to',
hotInstance.getSettings().navigableHeaders
hot.getSettings().navigableHeaders
);
}
);

// Checkbox: Enable/Disable Cell Virtualization
setupCheckbox(
document.querySelector('#enable-cell-virtualization'),
document.querySelector('#enable-cell-virtualization') as HTMLInputElement,
(checked) => {
hotInstance.destroy();
hotInstance = new Handsontable(document.getElementById('example1'), {
hot.destroy();
hot = new Handsontable(document.getElementById('example1')!, {
...hotOptions,
renderAllRows: !checked,
renderAllColumns: !checked,
});
console.log('Updated virtualization settings:', {
renderAllRows: hotInstance.getSettings().renderAllRows,
renderAllColumns: hotInstance.getSettings().renderAllColumns,
renderAllRows: hot.getSettings().renderAllRows,
renderAllColumns: hot.getSettings().renderAllColumns,
});
}
);

// Checkbox: Enable/Disable Cell Enter Editing
setupCheckbox(
document.querySelector('#enable-cell-enter-editing'),
document.querySelector('#enable-cell-enter-editing') as HTMLInputElement,
(checked) => {
hotOptions.enterBeginsEditing = checked;
hotInstance.updateSettings({
hot.updateSettings({
enterBeginsEditing: hotOptions.enterBeginsEditing,
});
console.log(
'Updated setting: enable-cell-enter-editing to',
hotInstance.getSettings().enterBeginsEditing
hot.getSettings().enterBeginsEditing
);
}
);

// Checkbox: Enable/Disable Arrow Navigation for First/Last Row
setupCheckbox(
document.querySelector('#enable-arrow-rl-first-last-column'),
document.querySelector('#enable-arrow-rl-first-last-column') as HTMLInputElement,
(checked) => {
hotOptions.autoWrapRow = checked;
hotInstance.updateSettings({
hot.updateSettings({
autoWrapRow: hotOptions.autoWrapRow,
});
console.log(
'Updated setting: autoWrapRow to',
hotInstance.getSettings().autoWrapRow
hot.getSettings().autoWrapRow
);
}
);

// Checkbox: Enable/Disable Arrow Navigation for First/Last Column
setupCheckbox(
document.querySelector('#enable-arrow-td-first-last-column'),
document.querySelector('#enable-arrow-td-first-last-column') as HTMLInputElement,
(checked) => {
hotOptions.autoWrapCol = checked;
hotInstance.updateSettings({
hot.updateSettings({
autoWrapCol: hotOptions.autoWrapCol,
});
console.log(
'Updated setting: autoWrapCol to',
hotInstance.getSettings().autoWrapCol
hot.getSettings().autoWrapCol
);
}
);

// Checkbox: Enable/Disable Enter Key Focus for Editing
setupCheckbox(
document.querySelector('#enable-enter-focus-editing'),
document.querySelector('#enable-enter-focus-editing') as HTMLInputElement,
(checked) => {
hotOptions.enterMoves = checked ? { col: 0, row: 1 } : { col: 0, row: 0 };
hotInstance.updateSettings({
hot.updateSettings({
enterMoves: hotOptions.enterMoves,
});
console.log(
'Updated setting: enterMoves to',
hotInstance.getSettings().enterMoves
hot.getSettings().enterMoves
);
}
);
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';

const container = document.querySelector('#example1');
const hot = new Handsontable(container, {
const container = document.querySelector('#example1')!;

new Handsontable(container, {
data: [
['', 'Tesla', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
['2017', 10, 11, 12, 13, 15, 16],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';

const container = document.querySelector('#example2');
const hot = new Handsontable(container, {
const container = document.querySelector('#example2')!;

new Handsontable(container, {
data: [
['', 'Tesla', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
['2017', 10, 11, 12, 13, 15, 16],
Expand Down

This file was deleted.

Loading
Loading