first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
export type ISettingsMap<T> = {
[P in keyof T]?: string;
};
/**
* Sends a warning to console, if the api is present.
*
* @public
* @param message - Warning message.
*/
export declare function warn(message: string): void;
/**
* Configures the warning callback. Passing in undefined will reset it to use the default
* console.warn function.
*
* @public
* @param warningCallback - Callback to override the generated warnings.
*/
export declare function setWarningCallback(warningCallback?: (message: string) => void): void;
+28
View File
@@ -0,0 +1,28 @@
/* eslint-disable no-console */
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.warn = warn;
exports.setWarningCallback = setWarningCallback;
var _warningCallback = undefined;
/**
* Sends a warning to console, if the api is present.
*
* @public
* @param message - Warning message.
*/
function warn(message) {
}
/**
* Configures the warning callback. Passing in undefined will reset it to use the default
* console.warn function.
*
* @public
* @param warningCallback - Callback to override the generated warnings.
*/
function setWarningCallback(warningCallback) {
_warningCallback = warningCallback;
}
});
//# sourceMappingURL=warn.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"warn.js","sourceRoot":"../src/","sources":["warn/warn.ts"],"names":[],"mappings":"AAAA,+BAA+B;;;;IAY/B,oBAMC;IASD,gDAEC;IA3BD,IAAI,gBAAgB,GAA4C,SAAS,CAAC;IAI1E;;;;;OAKG;IACH,SAAgB,IAAI,CAAC,OAAe;QAClC,IAAI,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC9D,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;aAAM,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,SAAgB,kBAAkB,CAAC,eAA2C;QAC5E,gBAAgB,GAAG,eAAe,CAAC;IACrC,CAAC","sourcesContent":["/* eslint-disable no-console */\n\nlet _warningCallback: ((message: string) => void) | undefined = undefined;\n\nexport type ISettingsMap<T> = { [P in keyof T]?: string };\n\n/**\n * Sends a warning to console, if the api is present.\n *\n * @public\n * @param message - Warning message.\n */\nexport function warn(message: string): void {\n if (_warningCallback && process.env.NODE_ENV !== 'production') {\n _warningCallback(message);\n } else if (console && console.warn) {\n console.warn(message);\n }\n}\n\n/**\n * Configures the warning callback. Passing in undefined will reset it to use the default\n * console.warn function.\n *\n * @public\n * @param warningCallback - Callback to override the generated warnings.\n */\nexport function setWarningCallback(warningCallback?: (message: string) => void): void {\n _warningCallback = warningCallback;\n}\n"]}
+1
View File
@@ -0,0 +1 @@
export {};
+99
View File
@@ -0,0 +1,99 @@
define(["require", "exports", "./warn", "./warnConditionallyRequiredProps", "./warnMutuallyExclusive", "./warnDeprecations"], function (require, exports, warn_1, warnConditionallyRequiredProps_1, warnMutuallyExclusive_1, warnDeprecations_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var warningCallback = jest.fn();
function sharedBeforeEach() {
(0, warn_1.setWarningCallback)(warningCallback);
}
function sharedAfterEach() {
warningCallback.mockReset();
(0, warn_1.setWarningCallback)(undefined);
}
describe('warnDeprecations', function () {
beforeEach(sharedBeforeEach);
afterEach(sharedAfterEach);
it('does not warn when unnecessary', function () {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(0, warnDeprecations_1.warnDeprecations)('Foo', { bar: 1 }, { foo: null });
expect(warningCallback).not.toHaveBeenCalled();
});
it('can warn on a deprecated prop', function () {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(0, warnDeprecations_1.warnDeprecations)('Foo', { foo: 1 }, { foo: null });
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'foo' was used but has been deprecated.");
});
it('can warn on a deprecated prop with replacement', function () {
(0, warnDeprecations_1.warnDeprecations)('Foo', { foo: 1 }, { foo: 'bar' });
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'foo' was used but has been deprecated. Use 'bar' instead.");
});
});
describe('warnMutuallyExclusive', function () {
beforeEach(sharedBeforeEach);
afterEach(sharedAfterEach);
it('does not warn when unnecessary', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: 1 }, { foo: 'bar' });
expect(warningCallback).not.toHaveBeenCalled();
});
it('does not warn unnecessarily when the key of the exclusive map is explicitly undefined', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: undefined, bar: 1 }, { foo: 'bar' });
expect(warningCallback).not.toHaveBeenCalled();
});
it('does not warn unnecessarily when the matching prop of the exclusive map key is explicitly undefined', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: 1, bar: undefined }, { foo: 'bar' });
expect(warningCallback).not.toHaveBeenCalled();
});
it('does not warn unnecessarily when both of them are explicitly undefined', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: undefined, bar: undefined }, { foo: 'bar' });
expect(warningCallback).not.toHaveBeenCalled();
});
it('does not warn unnecessarily when the key of the exclusive map is implicitly undefined', function () {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { bar: 1 }, { foo: 'bar' });
expect(warningCallback).not.toHaveBeenCalled();
});
it('does not warn unnecessarily when the matching prop of the exclusive map is implicitly undefined', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: 1 }, { foo: 'bar' });
expect(warningCallback).not.toHaveBeenCalled();
});
it('does not warn unnecessarily when both of the props are implicitly undefined ', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', {}, {});
expect(warningCallback).not.toHaveBeenCalled();
});
it('can warn on mutual exclusive props', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: 1, bar: 1 }, { foo: 'bar' });
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'foo' is mutually exclusive with 'bar'. Use one or the other.");
});
it('can warn if the exclusive props with the key in the map is null', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: null, bar: 1 }, { foo: 'bar' });
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'foo' is mutually exclusive with 'bar'. Use one or the other.");
});
it('can warn if the matching key in exclusive map is null', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: 1, bar: null }, { foo: 'bar' });
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'foo' is mutually exclusive with 'bar'. Use one or the other.");
});
it('can warn if both of the props are null', function () {
(0, warnMutuallyExclusive_1.warnMutuallyExclusive)('Foo', { foo: null, bar: null }, { foo: 'bar' });
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'foo' is mutually exclusive with 'bar'. Use one or the other.");
});
});
describe('warnConditionallyRequiredProps', function () {
beforeEach(sharedBeforeEach);
afterEach(sharedAfterEach);
it('does not warn when unnecessary', function () {
(0, warnConditionallyRequiredProps_1.warnConditionallyRequiredProps)('Foo', { foo: 1, bar: 1 }, ['foo', 'bar'], 'foo', true);
expect(warningCallback).not.toHaveBeenCalled();
});
it('can warn on required props', function () {
(0, warnConditionallyRequiredProps_1.warnConditionallyRequiredProps)('Foo', { foo: 1 }, ['foo', 'bar'], 'foo', true);
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Foo property 'bar' is required when 'foo' is used.'");
});
});
});
//# sourceMappingURL=warn.test.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
/**
* Warns when props are required if a condition is met.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param requiredProps - The name of the props that are required when the condition is met.
* @param conditionalPropName - The name of the prop that the condition is based on.
* @param condition - Whether the condition is met.
*/
export declare function warnConditionallyRequiredProps<P extends {}>(componentName: string, props: P, requiredProps: string[], conditionalPropName: string, condition: boolean): void;
@@ -0,0 +1,19 @@
define(["require", "exports", "./warn"], function (require, exports, warn_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.warnConditionallyRequiredProps = warnConditionallyRequiredProps;
/**
* Warns when props are required if a condition is met.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param requiredProps - The name of the props that are required when the condition is met.
* @param conditionalPropName - The name of the prop that the condition is based on.
* @param condition - Whether the condition is met.
*/
function warnConditionallyRequiredProps(componentName, props, requiredProps, conditionalPropName, condition) {
}
});
//# sourceMappingURL=warnConditionallyRequiredProps.js.map
@@ -0,0 +1 @@
{"version":3,"file":"warnConditionallyRequiredProps.js","sourceRoot":"../src/","sources":["warn/warnConditionallyRequiredProps.ts"],"names":[],"mappings":";;;IAWA,wEAcC;IAxBD;;;;;;;;;OASG;IACH,SAAgB,8BAA8B,CAC5C,aAAqB,EACrB,KAAQ,EACR,aAAuB,EACvB,mBAA2B,EAC3B,SAAkB;QAElB,IAAI,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAChE,KAA+B,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa,EAAE,CAAC;gBAA1C,IAAM,gBAAgB,sBAAA;gBACzB,IAAI,CAAC,CAAC,gBAAgB,IAAI,KAAK,CAAC,EAAE,CAAC;oBACjC,IAAA,WAAI,EAAC,UAAG,aAAa,wBAAc,gBAAgB,iCAAuB,mBAAmB,gBAAa,CAAC,CAAC;gBAC9G,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC","sourcesContent":["import { warn } from './warn';\n/**\n * Warns when props are required if a condition is met.\n *\n * @public\n * @param componentName - The name of the component being used.\n * @param props - The props passed into the component.\n * @param requiredProps - The name of the props that are required when the condition is met.\n * @param conditionalPropName - The name of the prop that the condition is based on.\n * @param condition - Whether the condition is met.\n */\nexport function warnConditionallyRequiredProps<P extends {}>(\n componentName: string,\n props: P,\n requiredProps: string[],\n conditionalPropName: string,\n condition: boolean,\n): void {\n if (condition === true && process.env.NODE_ENV !== 'production') {\n for (const requiredPropName of requiredProps) {\n if (!(requiredPropName in props)) {\n warn(`${componentName} property '${requiredPropName}' is required when '${conditionalPropName}' is used.'`);\n }\n }\n }\n}\n"]}
+31
View File
@@ -0,0 +1,31 @@
/** Reset controlled usage warnings for testing purposes. */
export declare function resetControlledWarnings(): void;
export interface IWarnControlledUsageParams<P> {
/** ID of the component instance. Used to prevent showing warnings repeatedly. */
componentId: string;
/** Name of the component class. */
componentName: string;
/** Current props to evaluate. */
props: P;
/** Previous props to evaluate (undefined if called in the constructor). */
oldProps?: P;
/** Name of the prop for the controlled value. */
valueProp: keyof P;
/** Name of the prop for the uncontrolled initial value. */
defaultValueProp: keyof P;
/** Name of the change handler prop. */
onChangeProp: keyof P;
/** Name of the read-only prop. */
readOnlyProp?: keyof P;
}
/**
* Check for and warn on the following error conditions with a form component:
* - A value prop is provided (indicated it's being used as controlled) without a change handler,
* and the component is not read-only
* - Both the value and defaultValue props are provided
* - The component is attempting to switch between controlled and uncontrolled
*
* The messages mimic the warnings React gives for these error conditions on input elements.
* The warning will only be displayed once per component ID.
*/
export declare function warnControlledUsage<P>(params: IWarnControlledUsageParams<P>): void;
+26
View File
@@ -0,0 +1,26 @@
define(["require", "exports", "./warn", "../controlled"], function (require, exports, warn_1, controlled_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetControlledWarnings = resetControlledWarnings;
exports.warnControlledUsage = warnControlledUsage;
var warningsMap;
/** Reset controlled usage warnings for testing purposes. */
function resetControlledWarnings() {
}
/**
* Check for and warn on the following error conditions with a form component:
* - A value prop is provided (indicated it's being used as controlled) without a change handler,
* and the component is not read-only
* - Both the value and defaultValue props are provided
* - The component is attempting to switch between controlled and uncontrolled
*
* The messages mimic the warnings React gives for these error conditions on input elements.
* The warning will only be displayed once per component ID.
*/
function warnControlledUsage(params) {
}
});
//# sourceMappingURL=warnControlledUsage.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
export {};
@@ -0,0 +1,164 @@
define(["require", "exports", "tslib", "./warn", "./warnControlledUsage"], function (require, exports, tslib_1, warn_1, warnControlledUsage_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var warningCallback = jest.fn();
var noOp = function () { return undefined; };
var params = {
componentId: 'TestComponent1',
componentName: 'TestComponent',
valueProp: 'value',
defaultValueProp: 'defaultValue',
onChangeProp: 'onChange',
readOnlyProp: 'readOnly',
};
describe('warnControlledUsage', function () {
beforeEach(function () {
(0, warn_1.setWarningCallback)(warningCallback);
});
afterEach(function () {
warningCallback.mockReset();
(0, warn_1.setWarningCallback)(undefined);
(0, warnControlledUsage_1.resetControlledWarnings)();
});
it('does not warn or throw if old props are undefined', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: {} }));
expect(warningCallback).toHaveBeenCalledTimes(0);
// If oldProps was defined, this would be an error for switching from uncontrolled to controlled
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
});
it('does not warn if uncontrolled regardless of if onChange/readOnly is provided', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { defaultValue: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: {} }));
expect(warningCallback).toHaveBeenCalledTimes(0);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { defaultValue: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { defaultValue: 'test', readOnly: true } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { readOnly: true } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
});
it('does not warn if controlled and onChange is provided', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
});
it('does not warn if controlled and readOnly is true', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test', readOnly: true } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
});
it('warns if controlled and onChange/readOnly is not provided', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: You provided a 'value' prop to a TestComponent without an 'onChange' handler. This will render a " +
"read-only field. If the field should be mutable use 'defaultValue'. Otherwise, set 'onChange' or 'readOnly'.");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('warns if controlled and onChange is not provided (right message for component without readOnly)', function () {
var readOnlyProp = params.readOnlyProp, otherParams = tslib_1.__rest(params, ["readOnlyProp"]);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, otherParams), { props: { value: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: You provided a 'value' prop to a TestComponent without an 'onChange' handler. This will render a " +
"read-only field. If the field should be mutable use 'defaultValue'. Otherwise, set 'onChange'.");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, otherParams), { props: { value: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('re-warns when componentId changes for controlled without onChange', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { componentId: 'TestComponent2', props: { value: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(2);
});
it('warns if controlled and readOnly is false', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test', readOnly: false } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: You provided a 'value' prop to a TestComponent without an 'onChange' handler. This will render a " +
"read-only field. If the field should be mutable use 'defaultValue'. Otherwise, set 'onChange' or 'readOnly'.");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'test', readOnly: false } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('warns if both value and defaultValue are provided', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'hello', defaultValue: 'world', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: You provided both 'value' and 'defaultValue' to a TestComponent. Form fields must be either " +
"controlled or uncontrolled (specify either the 'value' prop, or the 'defaultValue' prop, but not both). " +
"Decide between using a controlled or uncontrolled TestComponent and remove one of these props. " +
"More info: https://fb.me/react-controlled-components");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'hello', defaultValue: 'world', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('re-warns when componentId changes if both value and defaultValue are provided', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: { value: 'hello', defaultValue: 'world', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { componentId: 'TestComponent2', props: { value: 'hello', defaultValue: 'world', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(2);
});
it('does not warn if old and new are uncontrolled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { defaultValue: 'test' }, props: { defaultValue: 'test' } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { props: {}, oldProps: {} }));
expect(warningCallback).toHaveBeenCalledTimes(0);
});
it('does not warn if old and new are controlled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { value: 'world', onChange: noOp }, props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(0);
});
it('warns if old is implicitly uncontrolled and new is controlled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: {}, props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: A component is changing an uncontrolled TestComponent to be controlled. TestComponents should not " +
"switch from controlled to uncontrolled (or vice versa). Decide between using controlled or uncontrolled " +
"for the lifetime of the component. More info: https://fb.me/react-controlled-components");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: {}, props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('warns if old is uncontrolled and new is controlled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: {}, props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: A component is changing an uncontrolled TestComponent to be controlled. TestComponents should not " +
"switch from controlled to uncontrolled (or vice versa). Decide between using controlled or uncontrolled " +
"for the lifetime of the component. More info: https://fb.me/react-controlled-components");
});
it('re-warns when componentId changes if old is uncontrolled and new is controlled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: {}, props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { componentId: 'TestComponent2', oldProps: {}, props: { value: 'test', onChange: noOp } }));
expect(warningCallback).toHaveBeenCalledTimes(2);
});
it('warns if old is controlled and new is implicitly uncontrolled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { value: 'test', onChange: noOp }, props: {} }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: A component is changing a controlled TestComponent to be uncontrolled. TestComponents should not " +
"switch from controlled to uncontrolled (or vice versa). Decide between using controlled or uncontrolled " +
"for the lifetime of the component. More info: https://fb.me/react-controlled-components");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { value: 'test', onChange: noOp }, props: {} }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('warns if old is controlled and new is uncontrolled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { value: 'hello', onChange: noOp }, props: { defaultValue: 'world' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
expect(warningCallback).toHaveBeenLastCalledWith("Warning: A component is changing a controlled TestComponent to be uncontrolled. TestComponents should not " +
"switch from controlled to uncontrolled (or vice versa). Decide between using controlled or uncontrolled " +
"for the lifetime of the component. More info: https://fb.me/react-controlled-components");
// Don't re-warn
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { value: 'hello', onChange: noOp }, props: { defaultValue: 'world' } }));
expect(warningCallback).toHaveBeenCalledTimes(1);
});
it('re-warns when componentId changes if old is controlled and new is implicitly uncontrolled', function () {
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { oldProps: { value: 'test', onChange: noOp }, props: {} }));
expect(warningCallback).toHaveBeenCalledTimes(1);
(0, warnControlledUsage_1.warnControlledUsage)(tslib_1.__assign(tslib_1.__assign({}, params), { componentId: 'TestComponent2', oldProps: { value: 'test', onChange: noOp }, props: {} }));
expect(warningCallback).toHaveBeenCalledTimes(2);
});
});
});
//# sourceMappingURL=warnControlledUsage.test.js.map
File diff suppressed because one or more lines are too long
+11
View File
@@ -0,0 +1,11 @@
import type { ISettingsMap } from './warn';
/**
* Warns when a deprecated props are being used.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param deprecationMap - The map of deprecations, where key is the prop name and the value is
* either null or a replacement prop name.
*/
export declare function warnDeprecations<P extends {}>(componentName: string, props: P, deprecationMap: ISettingsMap<P>): void;
+18
View File
@@ -0,0 +1,18 @@
define(["require", "exports", "./warn"], function (require, exports, warn_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.warnDeprecations = warnDeprecations;
/**
* Warns when a deprecated props are being used.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param deprecationMap - The map of deprecations, where key is the prop name and the value is
* either null or a replacement prop name.
*/
function warnDeprecations(componentName, props, deprecationMap) {
}
});
//# sourceMappingURL=warnDeprecations.js.map
@@ -0,0 +1 @@
{"version":3,"file":"warnDeprecations.js","sourceRoot":"../src/","sources":["warn/warnDeprecations.ts"],"names":[],"mappings":";;;IAYA,4CAaC;IAtBD;;;;;;;;OAQG;IACH,SAAgB,gBAAgB,CAAe,aAAqB,EAAE,KAAQ,EAAE,cAA+B;QAC7G,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC1C,KAAK,IAAM,QAAQ,IAAI,cAAc,EAAE,CAAC;gBACtC,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;oBAC/B,IAAI,kBAAkB,GAAG,UAAG,aAAa,wBAAc,QAAQ,wCAAqC,CAAC;oBACrG,IAAM,mBAAmB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;oBACrD,IAAI,mBAAmB,EAAE,CAAC;wBACxB,kBAAkB,IAAI,gBAAS,mBAAmB,eAAY,CAAC;oBACjE,CAAC;oBACD,IAAA,WAAI,EAAC,kBAAkB,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC","sourcesContent":["import { warn } from './warn';\nimport type { ISettingsMap } from './warn';\n\n/**\n * Warns when a deprecated props are being used.\n *\n * @public\n * @param componentName - The name of the component being used.\n * @param props - The props passed into the component.\n * @param deprecationMap - The map of deprecations, where key is the prop name and the value is\n * either null or a replacement prop name.\n */\nexport function warnDeprecations<P extends {}>(componentName: string, props: P, deprecationMap: ISettingsMap<P>): void {\n if (process.env.NODE_ENV !== 'production') {\n for (const propName in deprecationMap) {\n if (props && propName in props) {\n let deprecationMessage = `${componentName} property '${propName}' was used but has been deprecated.`;\n const replacementPropName = deprecationMap[propName];\n if (replacementPropName) {\n deprecationMessage += ` Use '${replacementPropName}' instead.`;\n }\n warn(deprecationMessage);\n }\n }\n }\n}\n"]}
@@ -0,0 +1,10 @@
import type { ISettingsMap } from './warn';
/**
* Warns when two props which are mutually exclusive are both being used.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param exclusiveMap - A map where the key is a parameter, and the value is the other parameter.
*/
export declare function warnMutuallyExclusive<P>(componentName: string, props: P, exclusiveMap: ISettingsMap<P>): void;
+17
View File
@@ -0,0 +1,17 @@
define(["require", "exports", "./warn"], function (require, exports, warn_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.warnMutuallyExclusive = warnMutuallyExclusive;
/**
* Warns when two props which are mutually exclusive are both being used.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param exclusiveMap - A map where the key is a parameter, and the value is the other parameter.
*/
function warnMutuallyExclusive(componentName, props, exclusiveMap) {
}
});
//# sourceMappingURL=warnMutuallyExclusive.js.map
@@ -0,0 +1 @@
{"version":3,"file":"warnMutuallyExclusive.js","sourceRoot":"../src/","sources":["warn/warnMutuallyExclusive.ts"],"names":[],"mappings":";;;IAWA,sDAcC;IAtBD;;;;;;;OAOG;IACH,SAAgB,qBAAqB,CAAI,aAAqB,EAAE,KAAQ,EAAE,YAA6B;QACrG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC1C,KAAK,IAAM,QAAQ,IAAI,YAAY,EAAE,CAAC;gBACpC,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;oBAC3C,IAAI,uBAAuB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;oBACrD,IAAI,uBAAuB,IAAI,KAAK,CAAC,uBAAkC,CAAC,KAAK,SAAS,EAAE,CAAC;wBACvF,IAAA,WAAI,EACF,UAAG,aAAa,wBAAc,QAAQ,2CAAiC,YAAY,CAAC,QAAQ,CAAC,QAAK;4BAChG,uBAAuB,CAC1B,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC","sourcesContent":["import { warn } from './warn';\nimport type { ISettingsMap } from './warn';\n\n/**\n * Warns when two props which are mutually exclusive are both being used.\n *\n * @public\n * @param componentName - The name of the component being used.\n * @param props - The props passed into the component.\n * @param exclusiveMap - A map where the key is a parameter, and the value is the other parameter.\n */\nexport function warnMutuallyExclusive<P>(componentName: string, props: P, exclusiveMap: ISettingsMap<P>): void {\n if (process.env.NODE_ENV !== 'production') {\n for (const propName in exclusiveMap) {\n if (props && props[propName] !== undefined) {\n let propInExclusiveMapValue = exclusiveMap[propName];\n if (propInExclusiveMapValue && props[propInExclusiveMapValue as keyof P] !== undefined) {\n warn(\n `${componentName} property '${propName}' is mutually exclusive with '${exclusiveMap[propName]}'. ` +\n `Use one or the other.`,\n );\n }\n }\n }\n }\n}\n"]}