diff --git a/CHANGELOG.md b/CHANGELOG.md index 02816ca8ce..7ff341b08a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,16 @@ should change the heading of the (upcoming) version to include a major version b - Added support for `UiSchema` `"ui:rows"` option for `textarea` elements, fixing [#4070](https://github.com/rjsf-team/react-jsonschema-form/issues/4070). +# @rjsf/utils + +- [#4080](https://github.com/rjsf-team/react-jsonschema-form/issues/4080) - BREAKING CHANGE: Removed the `base64` object from the `@rjsf/utils` package. Note that this is a breaking change if you relied on the `base64` object exported by `@rjsf/utils`. Since this change caused [#4080](https://github.com/rjsf-team/react-jsonschema-form/issues/4080), and was only internally used by playground code, we are shipping this change in a patch release. + +## Dev / docs / playground + +- [#4080](https://github.com/rjsf-team/react-jsonschema-form/issues/4080) - Moved the `base64` encoder/decoder object to the Playground package. +- Added test configuration and script to the Playground. + + # 5.17.0 ## @rjsf/core diff --git a/package-lock.json b/package-lock.json index cb795cf535..6fe7a25489 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34844,7 +34844,9 @@ "@material-ui/icons": "^4.11.3", "@monaco-editor/react": "^4.6.0", "@mui/icons-material": "5.15.2", + "@types/jest": "^29.5.12", "@types/lodash": "^4.14.202", + "@types/node": "^18.19.14", "@types/react-frame-component": "^4.1.6", "@vitejs/plugin-react": "^4.2.1", "cross-env": "^7.0.3", @@ -34853,6 +34855,8 @@ "gh-pages": "^3.2.3", "html": "^1.0.0", "html-webpack-plugin": "^5.6.0", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", "loader-utils": "^3.2.1", "mini-css-extract-plugin": "^2.8.0", "prettier": "^2.8.8", diff --git a/packages/docs/docs/api-reference/utility-functions.md b/packages/docs/docs/api-reference/utility-functions.md index 70a857fee5..fdee1aa0f6 100644 --- a/packages/docs/docs/api-reference/utility-functions.md +++ b/packages/docs/docs/api-reference/utility-functions.md @@ -1181,34 +1181,3 @@ For more information about how to specify the path see the [eslint lodash plugin #### Returns - ErrorSchemaBuilder<T> - The instance of the `ErrorSchemaBuilder` class - -## utility object - -### base64 - -An object providing base64 encoding and decoding functions using the UTF-8 charset. -By default, the `btoa()` and `atob()` built-in functions are only support the Latin-1 character range that means that non Latin-1 characters are not supported(for example, Chinese characters). - -#### encode() - -Encodes the given `input` string into a base64 encoded string - -##### Parameters - -- input: string - The string to encode - -##### Returns - -- string: The base64 encoded string - -#### decode() - -Decodes the given `input` string from a base64 encoded string - -##### Parameters - -- input: string - The string to decode - -##### Returns - -- string: The decoded string diff --git a/packages/playground/.babelrc b/packages/playground/.babelrc deleted file mode 100644 index f444a1e0c7..0000000000 --- a/packages/playground/.babelrc +++ /dev/null @@ -1,30 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "modules": false, // don't convert modules into CommonJS - "useBuiltIns": "usage", // use polyfill when needed - "corejs": 3 - } - ], - "@babel/preset-react" - ], - "plugins": [ - "@babel/plugin-syntax-dynamic-import", - "@babel/plugin-proposal-object-rest-spread", - "@babel/plugin-proposal-class-properties", - [ - "@babel/plugin-transform-runtime", - { - "corejs": 3, - "useESModules": true - } - ] - ], - "env": { - "development": { - "plugins": ["@babel/plugin-transform-react-jsx"] - } - } -} diff --git a/packages/playground/babel.config.js b/packages/playground/babel.config.js new file mode 100644 index 0000000000..5f772a56c4 --- /dev/null +++ b/packages/playground/babel.config.js @@ -0,0 +1,3 @@ +const defaultConfig = require('../../babel.config'); + +module.exports = defaultConfig; diff --git a/packages/playground/jest.config.js b/packages/playground/jest.config.js new file mode 100644 index 0000000000..b16fb29a11 --- /dev/null +++ b/packages/playground/jest.config.js @@ -0,0 +1,6 @@ +module.exports = { + verbose: true, + testEnvironment: 'jsdom', + testMatch: ['**/test/**/*.test.[jt]s?(x)'], + transformIgnorePatterns: [`/node_modules/(?!nanoid)`], +}; diff --git a/packages/playground/package.json b/packages/playground/package.json index c6c81b8e5f..bada529e24 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -3,7 +3,7 @@ "version": "5.17.0", "description": "rjsf playground", "private": true, - "type": "module", + "type": "commonjs", "scripts": { "cs-check": "prettier -l \"src/**/*.ts?(x)\"", "cs-format": "prettier \"src/**/*.ts?(x)\" --write", @@ -13,7 +13,8 @@ "publish-to-gh-pages": "npm run build && gh-pages --dist build/", "publish-to-npm": "npm run build && npm publish", "start": "vite --force", - "preview": "vite preview" + "preview": "vite preview", + "test": "jest" }, "lint-staged": { "src/**/*.ts?(x)": [ @@ -92,6 +93,8 @@ "@monaco-editor/react": "^4.6.0", "@mui/icons-material": "5.15.2", "@types/lodash": "^4.14.202", + "@types/jest": "^29.5.12", + "@types/node": "^18.19.14", "@types/react-frame-component": "^4.1.6", "@vitejs/plugin-react": "^4.2.1", "cross-env": "^7.0.3", @@ -100,6 +103,8 @@ "gh-pages": "^3.2.3", "html": "^1.0.0", "html-webpack-plugin": "^5.6.0", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", "loader-utils": "^3.2.1", "mini-css-extract-plugin": "^2.8.0", "prettier": "^2.8.8", diff --git a/packages/playground/src/components/Header.tsx b/packages/playground/src/components/Header.tsx index 47c3ae7c3f..200e474e16 100644 --- a/packages/playground/src/components/Header.tsx +++ b/packages/playground/src/components/Header.tsx @@ -1,7 +1,8 @@ import { useCallback } from 'react'; import Form, { IChangeEvent } from '@rjsf/core'; -import { base64, RJSFSchema, UiSchema, ValidatorType } from '@rjsf/utils'; +import { RJSFSchema, UiSchema, ValidatorType } from '@rjsf/utils'; import localValidator from '@rjsf/validator-ajv8'; +import base64 from '../utils/base64'; import CopyLink from './CopyLink'; import ThemeSelector, { ThemesType } from './ThemeSelector'; diff --git a/packages/playground/src/components/Playground.tsx b/packages/playground/src/components/Playground.tsx index 426b796df7..fe3d43fcb2 100644 --- a/packages/playground/src/components/Playground.tsx +++ b/packages/playground/src/components/Playground.tsx @@ -1,6 +1,7 @@ import { ComponentType, FormEvent, useCallback, useEffect, useRef, useState } from 'react'; import { FormProps, IChangeEvent, withTheme } from '@rjsf/core'; -import { base64, ErrorSchema, RJSFSchema, RJSFValidationError, UiSchema, ValidatorType } from '@rjsf/utils'; +import { ErrorSchema, RJSFSchema, RJSFValidationError, UiSchema, ValidatorType } from '@rjsf/utils'; +import base64 from '../utils/base64'; import { samples } from '../samples'; import Header, { LiveSettings } from './Header'; diff --git a/packages/utils/src/base64.ts b/packages/playground/src/utils/base64.ts similarity index 100% rename from packages/utils/src/base64.ts rename to packages/playground/src/utils/base64.ts diff --git a/packages/utils/test/base64.test.ts b/packages/playground/test/utils/base64.test.ts similarity index 97% rename from packages/utils/test/base64.test.ts rename to packages/playground/test/utils/base64.test.ts index 2131c730c5..99cc9722d7 100644 --- a/packages/utils/test/base64.test.ts +++ b/packages/playground/test/utils/base64.test.ts @@ -1,4 +1,4 @@ -import { base64 } from '../src'; +import base64 from '../../src/utils/base64'; describe('base64', () => { it('should successfully encode a ascii character', () => { diff --git a/packages/playground/tsconfig.json b/packages/playground/tsconfig.json index 1b8e30ff70..3eee8acf04 100644 --- a/packages/playground/tsconfig.json +++ b/packages/playground/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../../tsconfig.base.json", + "include": ["./"], "compilerOptions": { - "rootDir": "./src", + "rootDir": "./", "baseUrl": "./", "target": "ESNext", "useDefineForClassFields": true, @@ -18,9 +19,9 @@ "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - "types": ["vite/client"] + "types": ["vite/client", "jest", "node"] }, - "include": ["src"], + "include": ["src", "test"], "references": [ { "path": "../antd" }, { "path": "../bootstrap-4" }, diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 7527d496f0..5f40d22f94 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -51,7 +51,6 @@ import utcToLocal from './utcToLocal'; import validationDataMerge from './validationDataMerge'; import withIdRefPrefix from './withIdRefPrefix'; import getOptionMatchingSimpleDiscriminator from './getOptionMatchingSimpleDiscriminator'; -import base64 from './base64'; export * from './types'; export * from './enums'; @@ -121,5 +120,4 @@ export { utcToLocal, validationDataMerge, withIdRefPrefix, - base64, };