Merge pull request #5287 from tmaestrini/5253-hacktoberfest-upgrade-page-navigator

This commit is contained in:
Hugo Bernier 2024-10-12 12:57:19 -07:00 committed by GitHub
commit 139d16e414
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 43068 additions and 22926 deletions

View File

@ -1,7 +1,7 @@
// For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer // For more information on how to run this SPFx project in a VS Code Remote Container, please visit https://aka.ms/spfx-devcontainer
{ {
"name": "SPFx 1.14.0", "name": "SPFx 1.20.0",
"image": "docker.io/m365pnp/spfx:1.14.0", "image": "docker.io/m365pnp/spfx:1.20.0",
// Set *default* container specific settings.json values on container create. // Set *default* container specific settings.json values on container create.
"settings": {}, "settings": {},
// Add the IDs of extensions you want installed when the container is created. // Add the IDs of extensions you want installed when the container is created.

View File

@ -0,0 +1,319 @@
require('@rushstack/eslint-config/patch/modern-module-resolution');
module.exports = {
extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'],
parserOptions: { tsconfigRootDir: __dirname },
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
'parserOptions': {
'project': './tsconfig.json',
'ecmaVersion': 2018,
'sourceType': 'module'
},
rules: {
// Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null. https://www.npmjs.com/package/@rushstack/eslint-plugin
'@rushstack/no-new-null': 1,
// Require Jest module mocking APIs to be called before any other statements in their code block. https://www.npmjs.com/package/@rushstack/eslint-plugin
'@rushstack/hoist-jest-mock': 1,
// Require regular expressions to be constructed from string constants rather than dynamically building strings at runtime. https://www.npmjs.com/package/@rushstack/eslint-plugin-security
'@rushstack/security/no-unsafe-regexp': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/adjacent-overload-signatures': 1,
// RATIONALE: Code is more readable when the type of every variable is immediately obvious.
// Even if the compiler may be able to infer a type, this inference will be unavailable
// to a person who is reviewing a GitHub diff. This rule makes writing code harder,
// but writing code is a much less important activity than reading it.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/explicit-function-return-type': [
1,
{
'allowExpressions': true,
'allowTypedFunctionExpressions': true,
'allowHigherOrderFunctions': false
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Rationale to disable: although this is a recommended rule, it is up to dev to select coding style.
// Set to 1 (warning) or 2 (error) to enable.
'@typescript-eslint/explicit-member-accessibility': 0,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-array-constructor': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
//
// RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript.
// This rule should be suppressed only in very special cases such as JSON.stringify()
// where the type really can be anything. Even if the type is flexible, another type
// may be more appropriate such as "unknown", "{}", or "Record<k,V>".
'@typescript-eslint/no-explicit-any': 1,
// RATIONALE: The #1 rule of promises is that every promise chain must be terminated by a catch()
// handler. Thus wherever a Promise arises, the code must either append a catch handler,
// or else return the object to a caller (who assumes this responsibility). Unterminated
// promise chains are a serious issue. Besides causing errors to be silently ignored,
// they can also cause a NodeJS process to terminate unexpectedly.
'@typescript-eslint/no-floating-promises': 2,
// RATIONALE: Catches a common coding mistake.
'@typescript-eslint/no-for-in-array': 2,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-misused-new': 2,
// RATIONALE: The "namespace" keyword is not recommended for organizing code because JavaScript lacks
// a "using" statement to traverse namespaces. Nested namespaces prevent certain bundler
// optimizations. If you are declaring loose functions/variables, it's better to make them
// static members of a class, since classes support property getters and their private
// members are accessible by unit tests. Also, the exercise of choosing a meaningful
// class name tends to produce more discoverable APIs: for example, search+replacing
// the function "reverse()" is likely to return many false matches, whereas if we always
// write "Text.reverse()" is more unique. For large scale organization, it's recommended
// to decompose your code into separate NPM packages, which ensures that component
// dependencies are tracked more conscientiously.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-namespace': [
1,
{
'allowDeclarations': false,
'allowDefinitionFiles': false
}
],
// RATIONALE: Parameter properties provide a shorthand such as "constructor(public title: string)"
// that avoids the effort of declaring "title" as a field. This TypeScript feature makes
// code easier to write, but arguably sacrifices readability: In the notes for
// "@typescript-eslint/member-ordering" we pointed out that fields are central to
// a class's design, so we wouldn't want to bury them in a constructor signature
// just to save some typing.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Set to 1 (warning) or 2 (error) to enable the rule
'@typescript-eslint/parameter-properties': 0,
// RATIONALE: When left in shipping code, unused variables often indicate a mistake. Dead code
// may impact performance.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-unused-vars': [
1,
{
'vars': 'all',
// Unused function arguments often indicate a mistake in JavaScript code. However in TypeScript code,
// the compiler catches most of those mistakes, and unused arguments are fairly common for type signatures
// that are overriding a base class method or implementing an interface.
'args': 'none'
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-use-before-define': [
2,
{
'functions': false,
'classes': true,
'variables': true,
'enums': true,
'typedefs': true
}
],
// Disallows require statements except in import statements.
// In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6 style imports or import foo = require("foo") imports.
'@typescript-eslint/no-var-requires': 'error',
// RATIONALE: The "module" keyword is deprecated except when describing legacy libraries.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/prefer-namespace-keyword': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Rationale to disable: it's up to developer to decide if he wants to add type annotations
// Set to 1 (warning) or 2 (error) to enable the rule
'@typescript-eslint/no-inferrable-types': 0,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
// Rationale to disable: declaration of empty interfaces may be helpful for generic types scenarios
'@typescript-eslint/no-empty-interface': 0,
// RATIONALE: This rule warns if setters are defined without getters, which is probably a mistake.
'accessor-pairs': 1,
// RATIONALE: In TypeScript, if you write x["y"] instead of x.y, it disables type checking.
'dot-notation': [
1,
{
'allowPattern': '^_'
}
],
// RATIONALE: Catches code that is likely to be incorrect
'eqeqeq': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'for-direction': 1,
// RATIONALE: Catches a common coding mistake.
'guard-for-in': 2,
// RATIONALE: If you have more than 2,000 lines in a single source file, it's probably time
// to split up your code.
'max-lines': ['warn', { max: 2000 }],
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-async-promise-executor': 2,
// RATIONALE: Deprecated language feature.
'no-caller': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-compare-neg-zero': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-cond-assign': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-constant-condition': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-control-regex': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-debugger': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-delete-var': 2,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-duplicate-case': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty-character-class': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty-pattern': 1,
// RATIONALE: Eval is a security concern and a performance concern.
'no-eval': 1,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-ex-assign': 2,
// RATIONALE: System types are global and should not be tampered with in a scalable code base.
// If two different libraries (or two versions of the same library) both try to modify
// a type, only one of them can win. Polyfills are acceptable because they implement
// a standardized interoperable contract, but polyfills are generally coded in plain
// JavaScript.
'no-extend-native': 1,
// Disallow unnecessary labels
'no-extra-label': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-fallthrough': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-func-assign': 1,
// RATIONALE: Catches a common coding mistake.
'no-implied-eval': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-invalid-regexp': 2,
// RATIONALE: Catches a common coding mistake.
'no-label-var': 2,
// RATIONALE: Eliminates redundant code.
'no-lone-blocks': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-misleading-character-class': 2,
// RATIONALE: Catches a common coding mistake.
'no-multi-str': 2,
// RATIONALE: It's generally a bad practice to call "new Thing()" without assigning the result to
// a variable. Either it's part of an awkward expression like "(new Thing()).doSomething()",
// or else implies that the constructor is doing nontrivial computations, which is often
// a poor class design.
'no-new': 1,
// RATIONALE: Obsolete language feature that is deprecated.
'no-new-func': 2,
// RATIONALE: Obsolete language feature that is deprecated.
'no-new-object': 2,
// RATIONALE: Obsolete notation.
'no-new-wrappers': 1,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-octal': 2,
// RATIONALE: Catches code that is likely to be incorrect
'no-octal-escape': 2,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-regex-spaces': 2,
// RATIONALE: Catches a common coding mistake.
'no-return-assign': 2,
// RATIONALE: Security risk.
'no-script-url': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-self-assign': 2,
// RATIONALE: Catches a common coding mistake.
'no-self-compare': 2,
// RATIONALE: This avoids statements such as "while (a = next(), a && a.length);" that use
// commas to create compound expressions. In general code is more readable if each
// step is split onto a separate line. This also makes it easier to set breakpoints
// in the debugger.
'no-sequences': 1,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-shadow-restricted-names': 2,
// RATIONALE: Obsolete language feature that is deprecated.
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-sparse-arrays': 2,
// RATIONALE: Although in theory JavaScript allows any possible data type to be thrown as an exception,
// such flexibility adds pointless complexity, by requiring every catch block to test
// the type of the object that it receives. Whereas if catch blocks can always assume
// that their object implements the "Error" contract, then the code is simpler, and
// we generally get useful additional information like a call stack.
'no-throw-literal': 2,
// RATIONALE: Catches a common coding mistake.
'no-unmodified-loop-condition': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-unsafe-finally': 2,
// RATIONALE: Catches a common coding mistake.
'no-unused-expressions': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-unused-labels': 1,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-useless-catch': 1,
// RATIONALE: Avoids a potential performance problem.
'no-useless-concat': 1,
// RATIONALE: The "var" keyword is deprecated because of its confusing "hoisting" behavior.
// Always use "let" or "const" instead.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'no-var': 2,
// RATIONALE: Generally not needed in modern code.
'no-void': 1,
// RATIONALE: Obsolete language feature that is deprecated.
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-with': 2,
// RATIONALE: Makes logic easier to understand, since constants always have a known value
// @typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js
'prefer-const': 1,
// RATIONALE: Catches a common coding mistake where "resolve" and "reject" are confused.
'promise/param-names': 2,
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'require-atomic-updates': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'require-yield': 1,
// "Use strict" is redundant when using the TypeScript compiler.
'strict': [
2,
'never'
],
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'use-isnan': 2,
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
// Set to 1 (warning) or 2 (error) to enable.
// Rationale to disable: !!{}
'no-extra-boolean-cast': 0,
// ====================================================================
// @microsoft/eslint-plugin-spfx
// ====================================================================
'@microsoft/spfx/import-requires-chunk-name': 1,
'@microsoft/spfx/no-require-ensure': 2,
'@microsoft/spfx/pair-react-dom-render-unmount': 1
}
},
{
// For unit tests, we can be a little bit less strict. The settings below revise the
// defaults specified in the extended configurations, as well as above.
files: [
// Test files
'*.test.ts',
'*.test.tsx',
'*.spec.ts',
'*.spec.tsx',
// Facebook convention
'**/__mocks__/*.ts',
'**/__mocks__/*.tsx',
'**/__tests__/*.ts',
'**/__tests__/*.tsx',
// Microsoft convention
'**/test/*.ts',
'**/test/*.tsx'
],
rules: {}
}
]
};

View File

@ -31,3 +31,6 @@ obj
# Styles Generated Code # Styles Generated Code
*.scss.ts *.scss.ts
# special folders
.heft

View File

@ -1 +0,0 @@
v14.20.0

View File

@ -0,0 +1 @@
v18.19.1

View File

@ -17,12 +17,17 @@
"@microsoft/generator-sharepoint": { "@microsoft/generator-sharepoint": {
"environment": "spo", "environment": "spo",
"framework": "react", "framework": "react",
"sdkVersions": {
"@microsoft/teams-js": "2.24.0",
"@microsoft/microsoft-graph-client": "3.0.2"
},
"isCreatingSolution": true, "isCreatingSolution": true,
"version": "1.14.0", "nodeVersion": "18.19.1",
"version": "1.20.0",
"libraryName": "navigator", "libraryName": "navigator",
"libraryId": "065ee566-e00d-4058-bbfd-356c8d9a8005", "libraryId": "065ee566-e00d-4058-bbfd-356c8d9a8005",
"packageManager": "npm", "packageManager": "npm",
"isDomainIsolated": false, "isDomainIsolated": false,
"componentType": "webpart" "componentType": "webpart"
} }
} }

View File

@ -2,9 +2,9 @@
## Summary ## Summary
This web part fetches all the automatically added Header anchor tags in a SharePoint page and displays them in a Navigation component. This web part fetches all the automatically added header anchor tags in a SharePoint page and displays them in a navigation component.
When added to a Vertical Section it can be used as a Contents table for the page When added to a vertical section it can be used as a contents table for the page:
![Page Navigator](./assets/PageNavigator.gif) ![Page Navigator](./assets/PageNavigator.gif)
@ -15,8 +15,8 @@ When added to a Vertical Section it can be used as a Contents table for the page
| Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.| | Every SPFx version is only compatible with specific version(s) of Node.js. In order to be able to build this sample, please ensure that the version of Node on your workstation matches one of the versions listed in this section. This sample will not work on a different version of Node.|
|Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. | |Refer to <https://aka.ms/spfx-matrix> for more information on SPFx compatibility. |
![SPFx 1.14.0](https://img.shields.io/badge/SPFx-1.14.0-green.svg) ![SPFx 1.20.0](https://img.shields.io/badge/SPFx-1.20.0-green.svg)
![Node.js v14 | v12](https://img.shields.io/badge/Node.js-v14%20%7C%20v12-green.svg) ![Node.js v18](https://img.shields.io/badge/Node.js-v18-green.svg)
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg) ![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower") ![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1") ![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
@ -37,6 +37,7 @@ Version|Date|Comments
1.6|August 8, 2022|Add theme provider and bug fixes 1.6|August 8, 2022|Add theme provider and bug fixes
1.7|December 22, 2022|Fixed issue with duplicated level 2 headings 1.7|December 22, 2022|Fixed issue with duplicated level 2 headings
1.8|May 13, 2023|Fixed issue when heading has a + symbol 1.8|May 13, 2023|Fixed issue when heading has a + symbol
1.9|October 6, 2024|SPFx Upgraded to 1.20.0 and code refactored
## Minimal Path to Awesome ## Minimal Path to Awesome
@ -56,6 +57,7 @@ Version|Date|Comments
* [Aakash Bhardwaj](https://github.com/aakashbhardwaj619) * [Aakash Bhardwaj](https://github.com/aakashbhardwaj619)
* [Jasey Waegebaert](https://github.com/Jwaegebaert) * [Jasey Waegebaert](https://github.com/Jwaegebaert)
* [Mike Zimmerman](https://github.com/mikezimm) * [Mike Zimmerman](https://github.com/mikezimm)
* [Tobias Maestrini](https://github.com/tmaestrini)
## Help ## Help

View File

@ -9,7 +9,7 @@
"This web part fetches all the automatically added Header anchor tags in a SharePoint page and displays them in a Navigation component." "This web part fetches all the automatically added Header anchor tags in a SharePoint page and displays them in a Navigation component."
], ],
"creationDateTime": "2019-09-05", "creationDateTime": "2019-09-05",
"updateDateTime": "2023-05-23", "updateDateTime": "2024-10-06",
"products": [ "products": [
"SharePoint" "SharePoint"
], ],
@ -20,7 +20,7 @@
}, },
{ {
"key": "SPFX-VERSION", "key": "SPFX-VERSION",
"value": "1.14.0" "value": "1.20.0"
} }
], ],
"thumbnails": [ "thumbnails": [

View File

@ -1,5 +1,20 @@
{ {
"preset": "@voitanos/jest-preset-spfx-react16", /**
"rootDir": "../src", * Setup refers to this resource:
* https://titolivio.eu/2024/04/30/testing-sharepoint-framework-spfx-components-with-jest-and-react-testing-library/
*/
// Test root
"roots": ["../src"],
// used within ts-jest for transpiling
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
// find test files matching this pattern
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
// set output to erbose mode
"verbose": true,
// handle coverage report
"collectCoverage": false "collectCoverage": false
} }

View File

@ -10,15 +10,15 @@
}, },
"name": "react-page-navigator", "name": "react-page-navigator",
"id": "065ee566-e00d-4058-bbfd-356c8d9a8005", "id": "065ee566-e00d-4058-bbfd-356c8d9a8005",
"version": "1.7.0.0", "version": "1.9.0.0",
"includeClientSideAssets": true, "includeClientSideAssets": true,
"isDomainIsolated": false, "isDomainIsolated": false,
"metadata": { "metadata": {
"shortDescription": { "shortDescription": {
"default": "navigator description" "default": "This web part fetches all the automatically added header anchor tags in a SharePoint page and displays them in a navigation component."
}, },
"longDescription": { "longDescription": {
"default": "navigator description" "default": "This web part fetches all the automatically added header anchor tags in a SharePoint page and displays them in a navigation component. When added to a vertical section it can be used as a contents table for the page."
}, },
"screenshotPaths": [], "screenshotPaths": [],
"videoUrl": "", "videoUrl": "",
@ -26,10 +26,10 @@
}, },
"features": [ "features": [
{ {
"title": "navigator Feature", "title": "Page navigator",
"description": "The feature that activates elements of the navigator solution.", "description": "The feature that activates elements of the navigator solution.",
"id": "021884c2-d7b3-4937-9d58-5ae47e1adfb7", "id": "021884c2-d7b3-4937-9d58-5ae47e1adfb7",
"version": "1.7.0.0" "version": "1.9.0.0"
} }
] ]
}, },

View File

@ -0,0 +1,3 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/sass.schema.json"
}

View File

@ -1,10 +1,6 @@
{ {
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
"port": 4321, "port": 4321,
"https": true, "https": true,
"initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx", "initialPage": "https://{tenantDomain}/_layouts/workbench.aspx"
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
} }

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="18" failures="0" errors="0" time="2.678">
<testsuite name="The NavLinkBuilder without a preceding collapsable header" errors="0" failures="0" skipped="0" timestamp="2024-10-06T09:59:45" time="2.331" tests="18">
<testcase classname="The NavLinkBuilder without a preceding collapsable header should nest correctly without h1" name="The NavLinkBuilder without a preceding collapsable header should nest correctly without h1" time="0.004">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should nest correctly for wrong order headings" name="The NavLinkBuilder without a preceding collapsable header should nest correctly for wrong order headings" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should nest correctly for headings with a jump" name="The NavLinkBuilder without a preceding collapsable header should nest correctly for headings with a jump" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should add a single item to an empty list" name="The NavLinkBuilder without a preceding collapsable header should add a single item to an empty list" time="0">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should add a two items on the same level" name="The NavLinkBuilder without a preceding collapsable header should add a two items on the same level" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should add a two items on different levels" name="The NavLinkBuilder without a preceding collapsable header should add a two items on different levels" time="0">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should add a two items on the same level and two items on different levels" name="The NavLinkBuilder without a preceding collapsable header should add a two items on the same level and two items on different levels" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should add a four items on different levels" name="The NavLinkBuilder without a preceding collapsable header should add a four items on different levels" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should not nest two h2" name="The NavLinkBuilder without a preceding collapsable header should not nest two h2" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder without a preceding collapsable header should not nest two h3" name="The NavLinkBuilder without a preceding collapsable header should not nest two h3" time="0">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should nest correctly without h1" name="The NavLinkBuilder with a collapsable header should nest correctly without h1" time="0">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should nest correctly for wrong order nestings" name="The NavLinkBuilder with a collapsable header should nest correctly for wrong order nestings" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should nest correctly for headings with a jump" name="The NavLinkBuilder with a collapsable header should nest correctly for headings with a jump" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should add a single item to the heading" name="The NavLinkBuilder with a collapsable header should add a single item to the heading" time="0">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should add a two items on the same level" name="The NavLinkBuilder with a collapsable header should add a two items on the same level" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should add a one item in a collapsable section two inside that one" name="The NavLinkBuilder with a collapsable header should add a one item in a collapsable section two inside that one" time="0.001">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should not nest two h2" name="The NavLinkBuilder with a collapsable header should not nest two h2" time="0">
</testcase>
<testcase classname="The NavLinkBuilder with a collapsable header should not nest two h3" name="The NavLinkBuilder with a collapsable header should not nest two h3" time="0">
</testcase>
</testsuite>
</testsuites>

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,11 @@
{ {
"name": "navigator", "name": "navigator",
"version": "0.0.1", "version": "1.9.0",
"private": true, "private": true,
"main": "lib/index.js", "main": "lib/index.js",
"engines": {
"node": ">=16.13.0 <17.0.0 || >=18.17.1 <19.0.0"
},
"scripts": { "scripts": {
"build": "gulp bundle", "build": "gulp bundle",
"clean": "gulp clean", "clean": "gulp clean",
@ -12,34 +15,43 @@
"test:watch": "./node_modules/.bin/jest --config ./config/jest.config.json --watchAll" "test:watch": "./node_modules/.bin/jest --config ./config/jest.config.json --watchAll"
}, },
"dependencies": { "dependencies": {
"@fluentui/react": "8.106.4",
"@microsoft/rush-stack-compiler-4.2": "^0.1.2", "@microsoft/rush-stack-compiler-4.2": "^0.1.2",
"@microsoft/sp-core-library": "1.14.0", "@microsoft/sp-adaptive-card-extension-base": "1.20.0",
"@microsoft/sp-lodash-subset": "1.14.0", "@microsoft/sp-core-library": "1.20.0",
"@microsoft/sp-office-ui-fabric-core": "1.14.0", "@microsoft/sp-lodash-subset": "1.20.0",
"@microsoft/sp-property-pane": "1.14.0", "@microsoft/sp-office-ui-fabric-core": "1.20.0",
"@microsoft/sp-webpart-base": "1.14.0", "@microsoft/sp-property-pane": "1.20.0",
"@microsoft/sp-webpart-base": "1.20.0",
"@pnp/sp": "^3.2.0", "@pnp/sp": "^3.2.0",
"@pnp/spfx-controls-react": "^3.7.2", "@pnp/spfx-controls-react": "^3.7.2",
"@pnp/spfx-property-controls": "^3.6.0", "@pnp/spfx-property-controls": "^3.6.0",
"office-ui-fabric-react": "^7.185.3", "react": "17.0.1",
"react": "16.13.1", "react-dom": "17.0.1",
"react-dom": "16.13.1" "tslib": "2.3.1"
}, },
"resolutions": { "resolutions": {
"@types/react": "16.8.8" "@types/react": "16.8.8"
}, },
"devDependencies": { "devDependencies": {
"@microsoft/sp-build-web": "1.20.1", "@microsoft/eslint-config-spfx": "1.20.2",
"@microsoft/sp-module-interfaces": "1.14.0", "@microsoft/eslint-plugin-spfx": "1.20.2",
"@microsoft/sp-tslint-rules": "1.14.0", "@microsoft/rush-stack-compiler-4.7": "0.1.0",
"@microsoft/sp-build-web": "1.20.2",
"@microsoft/sp-module-interfaces": "1.20.2",
"@rushstack/eslint-config": "4.0.1",
"@types/es6-promise": "0.0.33", "@types/es6-promise": "0.0.33",
"@types/react": "16.9.51", "@types/jest": "^29.5.13",
"@types/react-dom": "16.9.8", "@types/react": "17.0.45",
"@types/webpack-env": "1.13.1", "@types/react-dom": "17.0.17",
"@voitanos/jest-preset-spfx-react16": "^1.1.0", "@types/webpack-env": "1.15.2",
"ajv": "~5.2.2", "ajv": "6.12.5",
"eslint": "8.57.0",
"eslint-plugin-react-hooks": "4.3.0",
"gulp": "5.0.0", "gulp": "5.0.0",
"gulp-sequence": "1.0.0", "gulp-sequence": "1.0.0",
"jest": "^29.7.0" "jest": "^29.7.0",
"ts-jest": "^29.2.5",
"typescript": "4.7.4"
} }
} }

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { IHierarchyEntry, navLinkBuilder } from "./NavLinkBuilder"; import { IHierarchyEntry, navLinkBuilder } from "./NavLinkBuilder";
interface IMockLink extends IHierarchyEntry<IMockLink> { interface IMockLink extends IHierarchyEntry<IMockLink> {
@ -11,13 +13,13 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
const depth = DEPTH_NO_COLLAPSABLE_HEADER; const depth = DEPTH_NO_COLLAPSABLE_HEADER;
const h1 = depth; const h1 = depth;
const h2 = h1+1; const h2 = h1 + 1;
const h3 = h2+1; const h3 = h2 + 1;
const h4 = h3+1; const h4 = h3 + 1;
it("should nest correctly without h1", () => { it("should nest correctly without h1", () => {
const linkH2: IMockLink = { const linkH2: IMockLink = {
name: "h2", name: "h2",
}; };
const linkH3: IMockLink = { const linkH3: IMockLink = {
name: "h3", name: "h3",
@ -29,7 +31,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "another h3", name: "another h3",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, linkH2, h2); navLinkBuilder.build(actual, linkH2, h2);
navLinkBuilder.build(actual, linkH3, h3); navLinkBuilder.build(actual, linkH3, h3);
navLinkBuilder.build(actual, linkH2a, h2); navLinkBuilder.build(actual, linkH2a, h2);
@ -38,10 +40,10 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
expect(actual).toMatchSnapshot(); expect(actual).toMatchSnapshot();
}); });
it("should nest correctly for wrong order headings", () => { it("should nest correctly for wrong order headings", () => {
const linkH1: IMockLink = { const linkH1: IMockLink = {
name: "h1", name: "h1",
}; };
const linkH2: IMockLink = { const linkH2: IMockLink = {
name: "h2", name: "h2",
@ -53,7 +55,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "h4", name: "h4",
}; };
const actual = [ ]; const actual: any[] = [];
navLinkBuilder.build(actual, linkH4, h4); navLinkBuilder.build(actual, linkH4, h4);
navLinkBuilder.build(actual, linkH3, h3); navLinkBuilder.build(actual, linkH3, h3);
navLinkBuilder.build(actual, linkH2, h2); navLinkBuilder.build(actual, linkH2, h2);
@ -64,7 +66,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
it("should nest correctly for headings with a jump", () => { it("should nest correctly for headings with a jump", () => {
const linkH1: IMockLink = { const linkH1: IMockLink = {
name: "h1", name: "h1",
}; };
const linkH2: IMockLink = { const linkH2: IMockLink = {
name: "h2", name: "h2",
@ -76,7 +78,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "h4", name: "h4",
}; };
const actual = [ ]; const actual: any[] = [];
navLinkBuilder.build(actual, linkH3, h3); navLinkBuilder.build(actual, linkH3, h3);
navLinkBuilder.build(actual, linkH4, h4); navLinkBuilder.build(actual, linkH4, h4);
navLinkBuilder.build(actual, linkH1, h1); navLinkBuilder.build(actual, linkH1, h1);
@ -87,10 +89,10 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
it("should add a single item to an empty list", () => { it("should add a single item to an empty list", () => {
const lnk: IMockLink = { const lnk: IMockLink = {
name: "xyz", name: "xyz",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, lnk, h1); navLinkBuilder.build(actual, lnk, h1);
expect(actual).toMatchSnapshot(); expect(actual).toMatchSnapshot();
@ -104,7 +106,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "abc", name: "abc",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h1); navLinkBuilder.build(actual, lnk2, h1);
@ -119,7 +121,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "abc", name: "abc",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);
@ -140,7 +142,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "abc.1", name: "abc.1",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk11, h2); navLinkBuilder.build(actual, lnk11, h2);
navLinkBuilder.build(actual, lnk2, h1); navLinkBuilder.build(actual, lnk2, h1);
@ -163,7 +165,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "geh", name: "geh",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);
navLinkBuilder.build(actual, lnk3, h3); navLinkBuilder.build(actual, lnk3, h3);
@ -186,7 +188,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "h3", name: "h3",
}; };
const actual = [] const actual: any[] = []
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);
navLinkBuilder.build(actual, lnk3, h2); navLinkBuilder.build(actual, lnk3, h2);
@ -218,7 +220,7 @@ describe("The NavLinkBuilder without a preceding collapsable header", () => {
name: "h4", name: "h4",
}; };
const actual = []; const actual: any[] = [];
navLinkBuilder.build(actual, lnk0, h1); navLinkBuilder.build(actual, lnk0, h1);
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);
@ -235,9 +237,9 @@ describe("The NavLinkBuilder with a collapsable header", () => {
let head: IMockLink; let head: IMockLink;
const depth = DEPTH_COLLAPSABLE_HEADER; const depth = DEPTH_COLLAPSABLE_HEADER;
const h1 = depth; const h1 = depth;
const h2 = h1+1; const h2 = h1 + 1;
const h3 = h2+1; const h3 = h2 + 1;
const h4 = h3+1; const h4 = h3 + 1;
beforeEach(() => { beforeEach(() => {
head = { head = {
@ -247,7 +249,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
it("should nest correctly without h1", () => { it("should nest correctly without h1", () => {
const linkH2: IMockLink = { const linkH2: IMockLink = {
name: "h2", name: "h2",
}; };
const linkH3: IMockLink = { const linkH3: IMockLink = {
name: "h3", name: "h3",
@ -259,7 +261,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "another h3", name: "another h3",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, linkH2, h2); navLinkBuilder.build(actual, linkH2, h2);
navLinkBuilder.build(actual, linkH3, h3); navLinkBuilder.build(actual, linkH3, h3);
navLinkBuilder.build(actual, linkH2a, h2); navLinkBuilder.build(actual, linkH2a, h2);
@ -270,7 +272,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
it("should nest correctly for wrong order nestings", () => { it("should nest correctly for wrong order nestings", () => {
const linkH1: IMockLink = { const linkH1: IMockLink = {
name: "h1", name: "h1",
}; };
const linkH2: IMockLink = { const linkH2: IMockLink = {
name: "h2", name: "h2",
@ -282,7 +284,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "h4", name: "h4",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, linkH4, h4); navLinkBuilder.build(actual, linkH4, h4);
navLinkBuilder.build(actual, linkH3, h3); navLinkBuilder.build(actual, linkH3, h3);
navLinkBuilder.build(actual, linkH2, h2); navLinkBuilder.build(actual, linkH2, h2);
@ -293,7 +295,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
it("should nest correctly for headings with a jump", () => { it("should nest correctly for headings with a jump", () => {
const linkH1: IMockLink = { const linkH1: IMockLink = {
name: "h1", name: "h1",
}; };
const linkH2: IMockLink = { const linkH2: IMockLink = {
name: "h2", name: "h2",
@ -305,7 +307,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "h4", name: "h4",
}; };
const actual = [ ]; const actual: any[] = [];
navLinkBuilder.build(actual, linkH3, h3); navLinkBuilder.build(actual, linkH3, h3);
navLinkBuilder.build(actual, linkH4, h4); navLinkBuilder.build(actual, linkH4, h4);
navLinkBuilder.build(actual, linkH1, h1); navLinkBuilder.build(actual, linkH1, h1);
@ -319,7 +321,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "xyz", name: "xyz",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, lnk, h1); navLinkBuilder.build(actual, lnk, h1);
expect(actual).toMatchSnapshot(); expect(actual).toMatchSnapshot();
@ -333,7 +335,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "abc", name: "abc",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h1); navLinkBuilder.build(actual, lnk2, h1);
@ -351,7 +353,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "def", name: "def",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);
navLinkBuilder.build(actual, lnk3, h2); navLinkBuilder.build(actual, lnk3, h2);
@ -373,7 +375,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "h3", name: "h3",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);
navLinkBuilder.build(actual, lnk3, h2); navLinkBuilder.build(actual, lnk3, h2);
@ -405,7 +407,7 @@ describe("The NavLinkBuilder with a collapsable header", () => {
name: "h4", name: "h4",
}; };
const actual = [ head ]; const actual = [head];
navLinkBuilder.build(actual, lnk0, h1); navLinkBuilder.build(actual, lnk0, h1);
navLinkBuilder.build(actual, lnk1, h1); navLinkBuilder.build(actual, lnk1, h1);
navLinkBuilder.build(actual, lnk2, h2); navLinkBuilder.build(actual, lnk2, h2);

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface IHierarchyEntry<T extends IHierarchyEntry<T>> { export interface IHierarchyEntry<T extends IHierarchyEntry<T>> {
links?: IHierarchyEntry<T>[]; links?: IHierarchyEntry<T>[];
} }
@ -10,7 +12,7 @@ export class navLinkBuilder {
* @param order place order of the new link * @param order place order of the new link
* @returns navLinks * @returns navLinks
*/ */
public static build<T extends IHierarchyEntry<T>>(currentLinks: T[], newLink: T, order: number) { public static build<T extends IHierarchyEntry<T>>(currentLinks: T[], newLink: T, order: number): void {
const lastIndex = currentLinks.length - 1; const lastIndex = currentLinks.length - 1;
const startorder:number = (currentLinks as any).__startorder || 0; const startorder:number = (currentLinks as any).__startorder || 0;

View File

@ -1,6 +1,6 @@
import { INavLink } from 'office-ui-fabric-react/lib/Nav'; import { INavLink } from '@fluentui/react/lib/Nav';
import { WebPartContext } from '@microsoft/sp-webpart-base'; import { WebPartContext } from '@microsoft/sp-webpart-base';
import { SPHttpClient } from '@microsoft/sp-http'; import { SPHttpClient } from '@microsoft/sp-http'; // Ensure correct import
import { navLinkBuilder } from './NavLinkBuilder'; import { navLinkBuilder } from './NavLinkBuilder';
export class SPService { export class SPService {
@ -15,9 +15,9 @@ export class SPService {
private static GetAnchorUrl(headingValue: string): string { private static GetAnchorUrl(headingValue: string): string {
let anchorUrl = `#${headingValue let anchorUrl = `#${headingValue
.toLowerCase() .toLowerCase()
.replace(/[{}|\[\]\<\>#@"'^%`?;:\/=~\\\s\s]/g, " ") .replace(/[{}|[\]<>#@"'^%`?;:/=~\\\s\s]/g, " ")
.replace(/^(-|\s)*|(-|\s)*$/g, "") .replace(/^(-|\s)*|(-|\s)*$/g, "")
.replace(/\'|\?|\\|\/| |\&/g, "-") .replace(/'|\?|\\|\/| |&/g, "-")
.replace(/-+/g, "-") .replace(/-+/g, "-")
.replace(/[+]/g, "%2B") // https://github.com/pnp/sp-dev-fx-webparts/issues/3686 .replace(/[+]/g, "%2B") // https://github.com/pnp/sp-dev-fx-webparts/issues/3686
.substring(0, 128)}`; .substring(0, 128)}`;
@ -25,7 +25,7 @@ export class SPService {
let counter = 1; let counter = 1;
this.allUrls.forEach(url => { this.allUrls.forEach(url => {
if (url === anchorUrl) { if (url === anchorUrl) {
if (counter != 1) { if (counter !== 1) {
anchorUrl = anchorUrl.slice(0, -((counter - 1).toString().length + 1)) + '-' + counter; anchorUrl = anchorUrl.slice(0, -((counter - 1).toString().length + 1)) + '-' + counter;
} else { } else {
@ -44,18 +44,26 @@ export class SPService {
* @param context Web part context * @param context Web part context
* @returns anchorLinks * @returns anchorLinks
*/ */
public static async GetAnchorLinks(context: WebPartContext) { public static async GetAnchorLinks(context: WebPartContext): Promise<INavLink[]> {
let anchorLinks: INavLink[] = []; const anchorLinks: INavLink[] = [];
try { try {
/* Page ID on which the web part is added */ const currentPageRelativeUrl = context.pageContext.site.serverRequestPath;
const pageId = context.pageContext.listItem.id; const currentPageSiteRelativeURl = context.pageContext.site.serverRelativeUrl;
const currentPageUrl = currentPageRelativeUrl.replace(`${currentPageSiteRelativeURl}/`, '')
/* Get the canvasContent1 data for the page which consists of all the HTML */ /* Get the canvasContent1 data for the page which consists of all the HTML */
const data = await context.spHttpClient.get(`${context.pageContext.web.absoluteUrl}/_api/sitepages/pages(${pageId})`, SPHttpClient.configurations.v1); const data = await context.spHttpClient.get(`${context.pageContext.web.absoluteUrl}/_api/sitepages/pages?$select=CanvasContent1&$filter=Url eq '${currentPageUrl}'`, SPHttpClient.configurations.v1);
const jsonData = await data.json(); const jsonData = await data.json();
const canvasContent1 = jsonData.CanvasContent1;
const canvasContent1JSON: any[] = JSON.parse(canvasContent1); // eslint-disable-next-line @typescript-eslint/no-explicit-any
let canvasContent1JSON: any[];
try {
const canvasContent1 = jsonData.value?.[0].CanvasContent1;
canvasContent1JSON = JSON.parse(canvasContent1);
} catch (err) {
throw Error(`Could not retrieve content: ${err.message}`);
}
this.allUrls = []; this.allUrls = [];
@ -63,7 +71,7 @@ export class SPService {
canvasContent1JSON.map((webPart) => { canvasContent1JSON.map((webPart) => {
if (webPart.zoneGroupMetadata && webPart.zoneGroupMetadata.type === 1) { if (webPart.zoneGroupMetadata && webPart.zoneGroupMetadata.type === 1) {
const headingIsEmpty: boolean = !webPart.zoneGroupMetadata.displayName; const headingIsEmpty: boolean = !webPart.zoneGroupMetadata.displayName;
const headingValue: string = headingIsEmpty ? 'Empty Heading' : webPart.zoneGroupMetadata.displayName ; const headingValue: string = headingIsEmpty ? 'Empty Heading' : webPart.zoneGroupMetadata.displayName;
const anchorUrl: string = this.GetAnchorUrl(headingValue); const anchorUrl: string = this.GetAnchorUrl(headingValue);
this.allUrls.push(anchorUrl); this.allUrls.push(anchorUrl);
@ -76,10 +84,10 @@ export class SPService {
if (webPart.innerHTML) { if (webPart.innerHTML) {
const HTMLString: string = webPart.innerHTML; const HTMLString: string = webPart.innerHTML;
const hasCollapsableHeader: boolean = webPart.zoneGroupMetadata && const hasCollapsableHeader: boolean = webPart.zoneGroupMetadata &&
webPart.zoneGroupMetadata.type === 1 && webPart.zoneGroupMetadata.type === 1 &&
( anchorLinks.filter(x => x.name === webPart.zoneGroupMetadata.displayName).length === 1 || (anchorLinks.filter(x => x.name === webPart.zoneGroupMetadata.displayName).length === 1 ||
!webPart.zoneGroupMetadata.displayName ); !webPart.zoneGroupMetadata.displayName);
const htmlObject: HTMLDivElement = document.createElement('div'); const htmlObject: HTMLDivElement = document.createElement('div');
htmlObject.innerHTML = HTMLString; htmlObject.innerHTML = HTMLString;

View File

@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`The NavLinkBuilder with a collapsable header should add a one item in a collapsable section two inside that one 1`] = ` exports[`The NavLinkBuilder with a collapsable header should add a one item in a collapsable section two inside that one 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"links": Array [ "links": [
Object { {
"name": "abc", "name": "abc",
}, },
Object { {
"name": "def", "name": "def",
}, },
], ],
@ -22,10 +22,10 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should add a single item to the heading 1`] = ` exports[`The NavLinkBuilder with a collapsable header should add a single item to the heading 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "xyz", "name": "xyz",
}, },
], ],
@ -35,13 +35,13 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should add a two items on the same level 1`] = ` exports[`The NavLinkBuilder with a collapsable header should add a two items on the same level 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "xyz", "name": "xyz",
}, },
Object { {
"name": "abc", "name": "abc",
}, },
], ],
@ -51,18 +51,18 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should nest correctly for headings with a jump 1`] = ` exports[`The NavLinkBuilder with a collapsable header should nest correctly for headings with a jump 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "h4", "name": "h4",
}, },
], ],
"name": "h3", "name": "h3",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h2", "name": "h2",
}, },
], ],
@ -72,19 +72,19 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should nest correctly for wrong order nestings 1`] = ` exports[`The NavLinkBuilder with a collapsable header should nest correctly for wrong order nestings 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "h4", "name": "h4",
}, },
Object { {
"name": "h3", "name": "h3",
}, },
Object { {
"name": "h2", "name": "h2",
}, },
Object { {
"name": "h1", "name": "h1",
}, },
], ],
@ -94,20 +94,20 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should nest correctly without h1 1`] = ` exports[`The NavLinkBuilder with a collapsable header should nest correctly without h1 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"links": Array [ "links": [
Object { {
"name": "h3", "name": "h3",
}, },
], ],
"name": "h2", "name": "h2",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "another h3", "name": "another h3",
}, },
], ],
@ -120,17 +120,17 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should not nest two h2 1`] = ` exports[`The NavLinkBuilder with a collapsable header should not nest two h2 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"links": Array [ "links": [
Object { {
"name": "h2", "name": "h2",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h3", "name": "h3",
}, },
], ],
@ -146,25 +146,25 @@ Array [
`; `;
exports[`The NavLinkBuilder with a collapsable header should not nest two h3 1`] = ` exports[`The NavLinkBuilder with a collapsable header should not nest two h3 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "h1", "name": "h1",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h2", "name": "h2",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h3", "name": "h3",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h4", "name": "h4",
}, },
], ],
@ -183,14 +183,14 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should add a four items on different levels 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should add a four items on different levels 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"links": Array [ "links": [
Object { {
"links": Array [ "links": [
Object { {
"name": "geh", "name": "geh",
}, },
], ],
@ -206,18 +206,18 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should add a single item to an empty list 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should add a single item to an empty list 1`] = `
Array [ [
Object { {
"name": "xyz", "name": "xyz",
}, },
] ]
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should add a two items on different levels 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should add a two items on different levels 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "abc", "name": "abc",
}, },
], ],
@ -227,29 +227,29 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should add a two items on the same level 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should add a two items on the same level 1`] = `
Array [ [
Object { {
"name": "xyz", "name": "xyz",
}, },
Object { {
"name": "abc", "name": "abc",
}, },
] ]
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should add a two items on the same level and two items on different levels 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should add a two items on the same level and two items on different levels 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "xyz.1", "name": "xyz.1",
}, },
], ],
"name": "xyz", "name": "xyz",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "abc.1", "name": "abc.1",
}, },
], ],
@ -259,18 +259,18 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should nest correctly for headings with a jump 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should nest correctly for headings with a jump 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "h4", "name": "h4",
}, },
], ],
"name": "h3", "name": "h3",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h2", "name": "h2",
}, },
], ],
@ -280,35 +280,35 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should nest correctly for wrong order headings 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should nest correctly for wrong order headings 1`] = `
Array [ [
Object { {
"name": "h4", "name": "h4",
}, },
Object { {
"name": "h3", "name": "h3",
}, },
Object { {
"name": "h2", "name": "h2",
}, },
Object { {
"name": "h1", "name": "h1",
}, },
] ]
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should nest correctly without h1 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should nest correctly without h1 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "h3", "name": "h3",
}, },
], ],
"name": "h2", "name": "h2",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "another h3", "name": "another h3",
}, },
], ],
@ -318,15 +318,15 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should not nest two h2 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should not nest two h2 1`] = `
Array [ [
Object { {
"links": Array [ "links": [
Object { {
"name": "h2", "name": "h2",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h3", "name": "h3",
}, },
], ],
@ -339,23 +339,23 @@ Array [
`; `;
exports[`The NavLinkBuilder without a preceding collapsable header should not nest two h3 1`] = ` exports[`The NavLinkBuilder without a preceding collapsable header should not nest two h3 1`] = `
Array [ [
Object { {
"name": "h1", "name": "h1",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h2", "name": "h2",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h3", "name": "h3",
}, },
Object { {
"links": Array [ "links": [
Object { {
"name": "h4", "name": "h4",
}, },
], ],

View File

@ -18,8 +18,8 @@
"preconfiguredEntries": [{ "preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other "groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" }, "group": { "default": "Other" },
"title": { "default": "PageNavigator" }, "title": { "default": "Page Navigator" },
"description": { "default": "PageNavigator description" }, "description": { "default": "Page Navigator builds a navigation structure on the page, based on the headers in your text." },
"officeFabricIconFontName": "BulletedTreeList", "officeFabricIconFontName": "BulletedTreeList",
"properties": { } "properties": { }
}] }]

View File

@ -4,7 +4,7 @@ import { ServiceKey, Version } from '@microsoft/sp-core-library';
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base"; import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import PageNavigator from './components/PageNavigator'; import PageNavigator from './components/PageNavigator';
import { IPageNavigatorProps } from './components/IPageNavigatorProps'; import { IPageNavigatorProps } from './components/IPageNavigatorProps';
import { INavLink } from 'office-ui-fabric-react/lib/Nav'; import { INavLink } from '@fluentui/react/lib/Nav';
import { SPService } from '../../Service/SPService'; import { SPService } from '../../Service/SPService';
import { IReadonlyTheme, ThemeChangedEventArgs, ThemeProvider } from '@microsoft/sp-component-base'; import { IReadonlyTheme, ThemeChangedEventArgs, ThemeProvider } from '@microsoft/sp-component-base';

View File

@ -1,4 +1,4 @@
import { INavLink } from 'office-ui-fabric-react/lib/Nav'; import { INavLink } from '@fluentui/react/lib/Nav';
import { IReadonlyTheme } from '@microsoft/sp-component-base'; import { IReadonlyTheme } from '@microsoft/sp-component-base';
export interface IPageNavigatorProps { export interface IPageNavigatorProps {

View File

@ -1,4 +1,4 @@
import { INavLink } from 'office-ui-fabric-react/lib/Nav'; import { INavLink } from '@fluentui/react/lib/Nav';
export interface IPageNavigatorState { export interface IPageNavigatorState {
anchorLinks: INavLink[]; anchorLinks: INavLink[];

View File

@ -1,4 +1,4 @@
@import '~office-ui-fabric-react/dist/sass/References.scss'; @import '~@fluentui/react/dist/sass/References.scss';
.pageNavigator { .pageNavigator {
.container { .container {

View File

@ -2,8 +2,8 @@ import * as React from 'react';
import styles from './PageNavigator.module.scss'; import styles from './PageNavigator.module.scss';
import { IPageNavigatorProps } from './IPageNavigatorProps'; import { IPageNavigatorProps } from './IPageNavigatorProps';
import { IPageNavigatorState } from './IPageNavigatorState'; import { IPageNavigatorState } from './IPageNavigatorState';
import { Nav, INavLink } from 'office-ui-fabric-react/lib/Nav'; import { Nav, INavLink } from '@fluentui/react/lib/Nav';
import { ITheme } from 'office-ui-fabric-react'; import { ITheme } from '@fluentui/react';
export default class PageNavigator extends React.Component<IPageNavigatorProps, IPageNavigatorState> { export default class PageNavigator extends React.Component<IPageNavigatorProps, IPageNavigatorState> {
constructor(props: IPageNavigatorProps) { constructor(props: IPageNavigatorProps) {
@ -17,17 +17,17 @@ export default class PageNavigator extends React.Component<IPageNavigatorProps,
this.onLinkClick = this.onLinkClick.bind(this); this.onLinkClick = this.onLinkClick.bind(this);
} }
public componentDidMount() { public componentDidMount(): void {
this.setState({ anchorLinks: this.props.anchorLinks, selectedKey: this.props.anchorLinks[0] ? this.props.anchorLinks[0].key : '' }); this.setState({ anchorLinks: this.props.anchorLinks, selectedKey: this.props.anchorLinks[0] ? this.props.anchorLinks[0].key : '' });
} }
public componentDidUpdate(prevProps: IPageNavigatorProps) { public componentDidUpdate(prevProps: IPageNavigatorProps): void {
if (JSON.stringify(prevProps.anchorLinks) !== JSON.stringify(this.props.anchorLinks)) { if (JSON.stringify(prevProps.anchorLinks) !== JSON.stringify(this.props.anchorLinks)) {
this.setState({ anchorLinks: this.props.anchorLinks, selectedKey: this.props.anchorLinks[0] ? this.props.anchorLinks[0].key : '' }); this.setState({ anchorLinks: this.props.anchorLinks, selectedKey: this.props.anchorLinks[0] ? this.props.anchorLinks[0].key : '' });
} }
} }
private onLinkClick(ev: React.MouseEvent<HTMLElement>, item?: INavLink) { private onLinkClick(ev: React.MouseEvent<HTMLElement>, item?: INavLink): void {
this.setState({ selectedKey: item.key }); this.setState({ selectedKey: item.key });
} }
@ -39,11 +39,7 @@ export default class PageNavigator extends React.Component<IPageNavigatorProps,
<div className={styles.column}> <div className={styles.column}>
<Nav selectedKey={this.state.selectedKey} <Nav selectedKey={this.state.selectedKey}
onLinkClick={this.onLinkClick} onLinkClick={this.onLinkClick}
groups={[ groups={[{ links: this.state.anchorLinks }]}
{
links: this.state.anchorLinks
}
]}
theme={this.props.themeVariant as ITheme} theme={this.props.themeVariant as ITheme}
/> />
</div> </div>

View File

@ -1,5 +1,5 @@
{ {
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.2/includes/tsconfig-web.json", "extends": "./node_modules/@microsoft/rush-stack-compiler-4.7/includes/tsconfig-web.json",
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
@ -12,15 +12,17 @@
"skipLibCheck": true, "skipLibCheck": true,
"outDir": "lib", "outDir": "lib",
"inlineSources": false, "inlineSources": false,
"noImplicitAny": true,
"strictNullChecks": false, "strictNullChecks": false,
"noUnusedLocals": false, "noUnusedLocals": false,
"esModuleInterop": true,
"typeRoots": [ "typeRoots": [
"./node_modules/@types", "./node_modules/@types",
"./node_modules/@microsoft" "./node_modules/@microsoft"
], ],
"types": [ "types": [
"webpack-env", "webpack-env",
"@types/jest" "jest"
], ],
"lib": [ "lib": [
"es5", "es5",

View File

@ -1,30 +0,0 @@
{
"extends": "./node_modules/@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}