@elliemae/ds-props-helpers 3.80.0-next.8 → 3.80.0-next.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -39,6 +39,11 @@ __export(index_exports, {
39
39
  getPropsPerSlotPropTypes: () => import_propsPerSlot.getPropsPerSlotPropTypes,
40
40
  getXstyledProps: () => import_xstyledProps.getXstyledProps,
41
41
  globalAttributesPropTypes: () => import_globalProps.globalAttributesPropTypes,
42
+ isActivationKey: () => import_lockedInteractions.isActivationKey,
43
+ isLocked: () => import_lockedInteractions.isLocked,
44
+ omitLockAttributes: () => import_lockedInteractions.omitLockAttributes,
45
+ omitLockedHandlers: () => import_lockedInteractions.omitLockedHandlers,
46
+ resolveAriaDisabled: () => import_lockedInteractions.resolveAriaDisabled,
42
47
  throwRequiredError: () => import_validation.throwRequiredError,
43
48
  throwTypeError: () => import_validation.throwTypeError,
44
49
  useDeprecateComponent: () => import_useDeprecateComponent.useDeprecateComponent,
@@ -63,4 +68,5 @@ var import_contractProps = require("./contractProps/index.js");
63
68
  var import_propsPerDataTestId = require("./propsPerDataTestId/index.js");
64
69
  var import_propsPerSlot = require("./propsPerSlot/index.js");
65
70
  var import_useOwnerProps = require("./useOwnerProps/index.js");
71
+ var import_lockedInteractions = require("./lockedInteractions/index.js");
66
72
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getContractProps } from './contractProps/index.js';\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAA6C;AAC7C,sBAA2C;AAC3C,yBAKO;AACP,uBAA4D;AAE5D,wBAKO;AACP,0BAAyF;AACzF,mCAAsC;AAEtC,2BAAiC;AACjC,gCAAsE;AACtE,0BAAyC;AACzC,2BAA8B;",
4
+ "sourcesContent": ["export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getContractProps } from './contractProps/index.js';\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\nexport {\n isLocked,\n isActivationKey,\n omitLockAttributes,\n omitLockedHandlers,\n resolveAriaDisabled,\n type LockProps,\n type LockedControlKind,\n} from './lockedInteractions/index.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAA6C;AAC7C,sBAA2C;AAC3C,yBAKO;AACP,uBAA4D;AAE5D,wBAKO;AACP,0BAAyF;AACzF,mCAAsC;AAEtC,2BAAiC;AACjC,gCAAsE;AACtE,0BAAyC;AACzC,2BAA8B;AAC9B,gCAQO;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var lockedInteractions_exports = {};
30
+ __export(lockedInteractions_exports, {
31
+ isActivationKey: () => import_lockedInteractions.isActivationKey,
32
+ isLocked: () => import_lockedInteractions.isLocked,
33
+ omitLockAttributes: () => import_lockedInteractions.omitLockAttributes,
34
+ omitLockedHandlers: () => import_lockedInteractions.omitLockedHandlers,
35
+ resolveAriaDisabled: () => import_lockedInteractions.resolveAriaDisabled
36
+ });
37
+ module.exports = __toCommonJS(lockedInteractions_exports);
38
+ var React = __toESM(require("react"));
39
+ var import_lockedInteractions = require("./lockedInteractions.js");
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lockedInteractions/index.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["export {\n isLocked,\n isActivationKey,\n omitLockAttributes,\n omitLockedHandlers,\n resolveAriaDisabled,\n type LockProps,\n type LockedControlKind,\n} from './lockedInteractions.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,gCAQO;",
6
+ "names": []
7
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var lockedInteractions_exports = {};
30
+ __export(lockedInteractions_exports, {
31
+ isActivationKey: () => isActivationKey,
32
+ isLocked: () => isLocked,
33
+ omitLockAttributes: () => omitLockAttributes,
34
+ omitLockedHandlers: () => omitLockedHandlers,
35
+ resolveAriaDisabled: () => resolveAriaDisabled
36
+ });
37
+ module.exports = __toCommonJS(lockedInteractions_exports);
38
+ var React = __toESM(require("react"));
39
+ const isLocked = ({ disabled, applyAriaDisabled, readOnly }) => Boolean(disabled || applyAriaDisabled || readOnly);
40
+ const resolveAriaDisabled = ({
41
+ disabled,
42
+ softLocked,
43
+ consumerValue
44
+ }) => {
45
+ if (disabled) return void 0;
46
+ return softLocked ? true : consumerValue;
47
+ };
48
+ const omitLockAttributes = (attributes) => {
49
+ const rest = { ...attributes };
50
+ delete rest.disabled;
51
+ delete rest.readOnly;
52
+ return rest;
53
+ };
54
+ const ACTIVATION_KEYS = ["Enter", " ", "Space"];
55
+ const isActivationKey = (event) => ACTIVATION_KEYS.includes(event.key ?? "") || ["Enter", "Space"].includes(event.code ?? "");
56
+ const CHANGE_HANDLERS = ["onChange", "onInput", "onBeforeInput", "onPaste", "onCut", "onDrop"];
57
+ const ACTIVATION_HANDLERS = [
58
+ "onClick",
59
+ "onDoubleClick",
60
+ "onMouseDown",
61
+ "onMouseUp",
62
+ "onPointerDown",
63
+ "onPointerUp",
64
+ "onTouchStart",
65
+ "onTouchEnd",
66
+ "onDragStart",
67
+ "onSubmit",
68
+ ...CHANGE_HANDLERS
69
+ ];
70
+ const LOCKED_KEY_HANDLERS = ["onKeyDown", "onKeyPress", "onKeyUp"];
71
+ const withoutCaptureSuffix = (key) => key.replace(/Capture$/, "");
72
+ const skipActivationKeys = (handler) => (event) => {
73
+ if (!isActivationKey(event)) handler(event);
74
+ };
75
+ const omitLockedHandlers = (attributes, locked, kind = "activation") => {
76
+ if (!locked) return attributes;
77
+ const isChangeKind = kind === "change";
78
+ const removed = isChangeKind ? CHANGE_HANDLERS : ACTIVATION_HANDLERS;
79
+ const lockedAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {
80
+ const name = withoutCaptureSuffix(key);
81
+ if (removed.includes(name)) return acc;
82
+ if (isChangeKind) {
83
+ acc[key] = value;
84
+ return acc;
85
+ }
86
+ acc[key] = LOCKED_KEY_HANDLERS.includes(name) && typeof value === "function" ? skipActivationKeys(value) : value;
87
+ return acc;
88
+ }, {});
89
+ return lockedAttributes;
90
+ };
91
+ //# sourceMappingURL=lockedInteractions.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lockedInteractions/lockedInteractions.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["import type { AriaAttributes, KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n// Shared helpers of the lock states `disabled`, `applyAriaDisabled` and `readOnly` (PUI-16695).\n// A locked control keeps its focus and hover behaviour, but it does not call the consumer's activation / change\n// handlers (which ones depends on the kind of control, see `LockedControlKind`: an activation control withholds its\n// actions, a change control withholds its changes). `readOnly` and `applyAriaDisabled` are synonyms and behave identically.\n\nexport type LockProps = { disabled?: boolean; applyAriaDisabled?: boolean; readOnly?: boolean };\n\nexport const isLocked = ({ disabled, applyAriaDisabled, readOnly }: LockProps): boolean =>\n Boolean(disabled || applyAriaDisabled || readOnly);\n\n/**\n * The `aria-disabled` a locked control prints. Use it AFTER the global attributes spread, so that the lock wins over a\n * consumer value and an unlocked control keeps the consumer's own value (inversion of control):\n * - `disabled` on a control that is natively disabled: nothing. The native attribute is the whole announcement.\n * - a soft lock (`softLocked`): `true`, whatever the consumer passes. A consumer `aria-disabled=\"false\"` cannot lift it.\n * - otherwise: the consumer's own value, as they wrote it (`undefined` when they passed none).\n * On a non-native element (div, span, summary, li) `disabled` cannot be written, so do not pass `disabled` and pass the\n * whole lock (`isLocked(...)`) as `softLocked`: `aria-disabled=\"true\"` is then the announcement for every lock.\n */\nexport const resolveAriaDisabled = ({\n disabled,\n softLocked,\n consumerValue,\n}: {\n disabled?: boolean;\n softLocked?: boolean;\n consumerValue?: AriaAttributes['aria-disabled'];\n}): AriaAttributes['aria-disabled'] => {\n if (disabled) return undefined;\n return softLocked ? true : consumerValue;\n};\n\n// `disabled` and `readOnly` are in the global attributes whitelist, so they ride along in any global attributes spread.\n// On a non-native element (div, span, li, label...) they would print a meaningless `disabled=\"\"` / `readonly=\"\"`.\n// Use it on the spread that lands on a non-native element. Real controls (button, input, select, textarea) keep them.\nexport const omitLockAttributes = <T extends object>(attributes: T): Omit<T, 'disabled' | 'readOnly'> => {\n const rest = { ...attributes } as Record<string, unknown>;\n delete rest.disabled;\n delete rest.readOnly;\n return rest as Omit<T, 'disabled' | 'readOnly'>;\n};\n\nconst ACTIVATION_KEYS = ['Enter', ' ', 'Space'];\n\nexport const isActivationKey = (event: { key?: string; code?: string }): boolean =>\n ACTIVATION_KEYS.includes(event.key ?? '') || ['Enter', 'Space'].includes(event.code ?? '');\n\n// What a lock withholds depends on the kind of control (see `LockedControlKind`). Focus, blur, hover, pointer\n// enter/leave and dismissal handlers are never listed: they keep working.\n// - the handlers that CHANGE a value: a control with a change event is gated on these\nconst CHANGE_HANDLERS = ['onChange', 'onInput', 'onBeforeInput', 'onPaste', 'onCut', 'onDrop'];\n// - the handlers that run an ACTION: a control with no native change element is gated on these (plus Enter / Space)\nconst ACTIVATION_HANDLERS = [\n 'onClick',\n 'onDoubleClick',\n 'onMouseDown',\n 'onMouseUp',\n 'onPointerDown',\n 'onPointerUp',\n 'onTouchStart',\n 'onTouchEnd',\n 'onDragStart',\n 'onSubmit',\n ...CHANGE_HANDLERS,\n];\n\n/**\n * The two kinds of locked control:\n * - `activation` (default): a control with no native change element (button, chip, tab, menu item, card, accordion\n * header, any element with a role). Nothing in the browser turns a key or a click into a change, so click, Enter and\n * Space ARE the way to activate it: the consumer's action handlers are withheld, and so are Enter and Space on key\n * handlers.\n * - `change`: a control with a change event (text input, textarea, checkbox, radio, combobox input). The gate is the\n * change: the consumer's change handlers are withheld (and a controlled value is put back by React). Clicks and keys\n * are only observed, so those handlers are left alone.\n */\nexport type LockedControlKind = 'activation' | 'change';\n\n// keyboard handlers: only the activating keys are blocked, every other key keeps reaching the consumer\nconst LOCKED_KEY_HANDLERS = ['onKeyDown', 'onKeyPress', 'onKeyUp'];\n\n// the capture variants (`onClickCapture`, `onKeyDownCapture`...) are in the global attributes too, same rules apply\nconst withoutCaptureSuffix = (key: string) => key.replace(/Capture$/, '');\n\nconst skipActivationKeys =\n (handler: (event: ReactKeyboardEvent) => unknown) =>\n (event: ReactKeyboardEvent): void => {\n if (!isActivationKey(event)) handler(event);\n };\n\n/**\n * Use it on the `{...globalAttributes}` spread of a locked control so that a consumer handler spread after (or instead\n * of) the internal gate cannot override it. What is withheld depends on the `kind` of the control (see\n * `LockedControlKind`): an `activation` control loses its action handlers and Enter / Space on its key handlers; a\n * `change` control loses its change handlers only.\n */\nexport const omitLockedHandlers = <T extends object>(\n attributes: T,\n locked: boolean,\n kind: LockedControlKind = 'activation',\n): T => {\n if (!locked) return attributes;\n const isChangeKind = kind === 'change';\n const removed = isChangeKind ? CHANGE_HANDLERS : ACTIVATION_HANDLERS;\n const lockedAttributes = Object.entries(attributes).reduce<Record<string, unknown>>((acc, [key, value]) => {\n const name = withoutCaptureSuffix(key);\n if (removed.includes(name)) return acc;\n if (isChangeKind) {\n acc[key] = value;\n return acc;\n }\n acc[key] =\n LOCKED_KEY_HANDLERS.includes(name) && typeof value === 'function'\n ? skipActivationKeys(value as (event: ReactKeyboardEvent) => unknown)\n : value;\n return acc;\n }, {});\n return lockedAttributes as T;\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADShB,MAAM,WAAW,CAAC,EAAE,UAAU,mBAAmB,SAAS,MAC/D,QAAQ,YAAY,qBAAqB,QAAQ;AAW5C,MAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF,MAIuC;AACrC,MAAI,SAAU,QAAO;AACrB,SAAO,aAAa,OAAO;AAC7B;AAKO,MAAM,qBAAqB,CAAmB,eAAoD;AACvG,QAAM,OAAO,EAAE,GAAG,WAAW;AAC7B,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO;AACT;AAEA,MAAM,kBAAkB,CAAC,SAAS,KAAK,OAAO;AAEvC,MAAM,kBAAkB,CAAC,UAC9B,gBAAgB,SAAS,MAAM,OAAO,EAAE,KAAK,CAAC,SAAS,OAAO,EAAE,SAAS,MAAM,QAAQ,EAAE;AAK3F,MAAM,kBAAkB,CAAC,YAAY,WAAW,iBAAiB,WAAW,SAAS,QAAQ;AAE7F,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL;AAeA,MAAM,sBAAsB,CAAC,aAAa,cAAc,SAAS;AAGjE,MAAM,uBAAuB,CAAC,QAAgB,IAAI,QAAQ,YAAY,EAAE;AAExE,MAAM,qBACJ,CAAC,YACD,CAAC,UAAoC;AACnC,MAAI,CAAC,gBAAgB,KAAK,EAAG,SAAQ,KAAK;AAC5C;AAQK,MAAM,qBAAqB,CAChC,YACA,QACA,OAA0B,iBACpB;AACN,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,eAAe,SAAS;AAC9B,QAAM,UAAU,eAAe,kBAAkB;AACjD,QAAM,mBAAmB,OAAO,QAAQ,UAAU,EAAE,OAAgC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACzG,UAAM,OAAO,qBAAqB,GAAG;AACrC,QAAI,QAAQ,SAAS,IAAI,EAAG,QAAO;AACnC,QAAI,cAAc;AAChB,UAAI,GAAG,IAAI;AACX,aAAO;AAAA,IACT;AACA,QAAI,GAAG,IACL,oBAAoB,SAAS,IAAI,KAAK,OAAO,UAAU,aACnD,mBAAmB,KAA+C,IAClE;AACN,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACL,SAAO;AACT;",
6
+ "names": []
7
+ }
package/dist/esm/index.js CHANGED
@@ -19,6 +19,13 @@ import { getContractProps } from "./contractProps/index.js";
19
19
  import { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from "./propsPerDataTestId/index.js";
20
20
  import { getPropsPerSlotPropTypes } from "./propsPerSlot/index.js";
21
21
  import { useOwnerProps } from "./useOwnerProps/index.js";
22
+ import {
23
+ isLocked,
24
+ isActivationKey,
25
+ omitLockAttributes,
26
+ omitLockedHandlers,
27
+ resolveAriaDisabled
28
+ } from "./lockedInteractions/index.js";
22
29
  export {
23
30
  PropTypes,
24
31
  describe,
@@ -31,6 +38,11 @@ export {
31
38
  getPropsPerSlotPropTypes,
32
39
  getXstyledProps,
33
40
  globalAttributesPropTypes,
41
+ isActivationKey,
42
+ isLocked,
43
+ omitLockAttributes,
44
+ omitLockedHandlers,
45
+ resolveAriaDisabled,
34
46
  throwRequiredError,
35
47
  throwTypeError,
36
48
  useDeprecateComponent,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getContractProps } from './contractProps/index.js';\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,oCAAoC;AAC7C,SAAS,cAAc,oBAAoB;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,iBAAyC;AAE5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAA4B,oBAAoB,kBAAkB,uBAAuB;AACzF,SAAS,6BAA6B;AAEtC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB,sCAAsC;AACtE,SAAS,gCAAgC;AACzC,SAAS,qBAAqB;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getContractProps } from './contractProps/index.js';\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\nexport {\n isLocked,\n isActivationKey,\n omitLockAttributes,\n omitLockedHandlers,\n resolveAriaDisabled,\n type LockProps,\n type LockedControlKind,\n} from './lockedInteractions/index.js';\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,oCAAoC;AAC7C,SAAS,cAAc,oBAAoB;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,iBAAyC;AAE5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAA4B,oBAAoB,kBAAkB,uBAAuB;AACzF,SAAS,6BAA6B;AAEtC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB,sCAAsC;AACtE,SAAS,gCAAgC;AACzC,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import {
3
+ isLocked,
4
+ isActivationKey,
5
+ omitLockAttributes,
6
+ omitLockedHandlers,
7
+ resolveAriaDisabled
8
+ } from "./lockedInteractions.js";
9
+ export {
10
+ isActivationKey,
11
+ isLocked,
12
+ omitLockAttributes,
13
+ omitLockedHandlers,
14
+ resolveAriaDisabled
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/lockedInteractions/index.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export {\n isLocked,\n isActivationKey,\n omitLockAttributes,\n omitLockedHandlers,\n resolveAriaDisabled,\n type LockProps,\n type LockedControlKind,\n} from './lockedInteractions.js';\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;",
6
+ "names": []
7
+ }
@@ -0,0 +1,61 @@
1
+ import * as React from "react";
2
+ const isLocked = ({ disabled, applyAriaDisabled, readOnly }) => Boolean(disabled || applyAriaDisabled || readOnly);
3
+ const resolveAriaDisabled = ({
4
+ disabled,
5
+ softLocked,
6
+ consumerValue
7
+ }) => {
8
+ if (disabled) return void 0;
9
+ return softLocked ? true : consumerValue;
10
+ };
11
+ const omitLockAttributes = (attributes) => {
12
+ const rest = { ...attributes };
13
+ delete rest.disabled;
14
+ delete rest.readOnly;
15
+ return rest;
16
+ };
17
+ const ACTIVATION_KEYS = ["Enter", " ", "Space"];
18
+ const isActivationKey = (event) => ACTIVATION_KEYS.includes(event.key ?? "") || ["Enter", "Space"].includes(event.code ?? "");
19
+ const CHANGE_HANDLERS = ["onChange", "onInput", "onBeforeInput", "onPaste", "onCut", "onDrop"];
20
+ const ACTIVATION_HANDLERS = [
21
+ "onClick",
22
+ "onDoubleClick",
23
+ "onMouseDown",
24
+ "onMouseUp",
25
+ "onPointerDown",
26
+ "onPointerUp",
27
+ "onTouchStart",
28
+ "onTouchEnd",
29
+ "onDragStart",
30
+ "onSubmit",
31
+ ...CHANGE_HANDLERS
32
+ ];
33
+ const LOCKED_KEY_HANDLERS = ["onKeyDown", "onKeyPress", "onKeyUp"];
34
+ const withoutCaptureSuffix = (key) => key.replace(/Capture$/, "");
35
+ const skipActivationKeys = (handler) => (event) => {
36
+ if (!isActivationKey(event)) handler(event);
37
+ };
38
+ const omitLockedHandlers = (attributes, locked, kind = "activation") => {
39
+ if (!locked) return attributes;
40
+ const isChangeKind = kind === "change";
41
+ const removed = isChangeKind ? CHANGE_HANDLERS : ACTIVATION_HANDLERS;
42
+ const lockedAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {
43
+ const name = withoutCaptureSuffix(key);
44
+ if (removed.includes(name)) return acc;
45
+ if (isChangeKind) {
46
+ acc[key] = value;
47
+ return acc;
48
+ }
49
+ acc[key] = LOCKED_KEY_HANDLERS.includes(name) && typeof value === "function" ? skipActivationKeys(value) : value;
50
+ return acc;
51
+ }, {});
52
+ return lockedAttributes;
53
+ };
54
+ export {
55
+ isActivationKey,
56
+ isLocked,
57
+ omitLockAttributes,
58
+ omitLockedHandlers,
59
+ resolveAriaDisabled
60
+ };
61
+ //# sourceMappingURL=lockedInteractions.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/lockedInteractions/lockedInteractions.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { AriaAttributes, KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n// Shared helpers of the lock states `disabled`, `applyAriaDisabled` and `readOnly` (PUI-16695).\n// A locked control keeps its focus and hover behaviour, but it does not call the consumer's activation / change\n// handlers (which ones depends on the kind of control, see `LockedControlKind`: an activation control withholds its\n// actions, a change control withholds its changes). `readOnly` and `applyAriaDisabled` are synonyms and behave identically.\n\nexport type LockProps = { disabled?: boolean; applyAriaDisabled?: boolean; readOnly?: boolean };\n\nexport const isLocked = ({ disabled, applyAriaDisabled, readOnly }: LockProps): boolean =>\n Boolean(disabled || applyAriaDisabled || readOnly);\n\n/**\n * The `aria-disabled` a locked control prints. Use it AFTER the global attributes spread, so that the lock wins over a\n * consumer value and an unlocked control keeps the consumer's own value (inversion of control):\n * - `disabled` on a control that is natively disabled: nothing. The native attribute is the whole announcement.\n * - a soft lock (`softLocked`): `true`, whatever the consumer passes. A consumer `aria-disabled=\"false\"` cannot lift it.\n * - otherwise: the consumer's own value, as they wrote it (`undefined` when they passed none).\n * On a non-native element (div, span, summary, li) `disabled` cannot be written, so do not pass `disabled` and pass the\n * whole lock (`isLocked(...)`) as `softLocked`: `aria-disabled=\"true\"` is then the announcement for every lock.\n */\nexport const resolveAriaDisabled = ({\n disabled,\n softLocked,\n consumerValue,\n}: {\n disabled?: boolean;\n softLocked?: boolean;\n consumerValue?: AriaAttributes['aria-disabled'];\n}): AriaAttributes['aria-disabled'] => {\n if (disabled) return undefined;\n return softLocked ? true : consumerValue;\n};\n\n// `disabled` and `readOnly` are in the global attributes whitelist, so they ride along in any global attributes spread.\n// On a non-native element (div, span, li, label...) they would print a meaningless `disabled=\"\"` / `readonly=\"\"`.\n// Use it on the spread that lands on a non-native element. Real controls (button, input, select, textarea) keep them.\nexport const omitLockAttributes = <T extends object>(attributes: T): Omit<T, 'disabled' | 'readOnly'> => {\n const rest = { ...attributes } as Record<string, unknown>;\n delete rest.disabled;\n delete rest.readOnly;\n return rest as Omit<T, 'disabled' | 'readOnly'>;\n};\n\nconst ACTIVATION_KEYS = ['Enter', ' ', 'Space'];\n\nexport const isActivationKey = (event: { key?: string; code?: string }): boolean =>\n ACTIVATION_KEYS.includes(event.key ?? '') || ['Enter', 'Space'].includes(event.code ?? '');\n\n// What a lock withholds depends on the kind of control (see `LockedControlKind`). Focus, blur, hover, pointer\n// enter/leave and dismissal handlers are never listed: they keep working.\n// - the handlers that CHANGE a value: a control with a change event is gated on these\nconst CHANGE_HANDLERS = ['onChange', 'onInput', 'onBeforeInput', 'onPaste', 'onCut', 'onDrop'];\n// - the handlers that run an ACTION: a control with no native change element is gated on these (plus Enter / Space)\nconst ACTIVATION_HANDLERS = [\n 'onClick',\n 'onDoubleClick',\n 'onMouseDown',\n 'onMouseUp',\n 'onPointerDown',\n 'onPointerUp',\n 'onTouchStart',\n 'onTouchEnd',\n 'onDragStart',\n 'onSubmit',\n ...CHANGE_HANDLERS,\n];\n\n/**\n * The two kinds of locked control:\n * - `activation` (default): a control with no native change element (button, chip, tab, menu item, card, accordion\n * header, any element with a role). Nothing in the browser turns a key or a click into a change, so click, Enter and\n * Space ARE the way to activate it: the consumer's action handlers are withheld, and so are Enter and Space on key\n * handlers.\n * - `change`: a control with a change event (text input, textarea, checkbox, radio, combobox input). The gate is the\n * change: the consumer's change handlers are withheld (and a controlled value is put back by React). Clicks and keys\n * are only observed, so those handlers are left alone.\n */\nexport type LockedControlKind = 'activation' | 'change';\n\n// keyboard handlers: only the activating keys are blocked, every other key keeps reaching the consumer\nconst LOCKED_KEY_HANDLERS = ['onKeyDown', 'onKeyPress', 'onKeyUp'];\n\n// the capture variants (`onClickCapture`, `onKeyDownCapture`...) are in the global attributes too, same rules apply\nconst withoutCaptureSuffix = (key: string) => key.replace(/Capture$/, '');\n\nconst skipActivationKeys =\n (handler: (event: ReactKeyboardEvent) => unknown) =>\n (event: ReactKeyboardEvent): void => {\n if (!isActivationKey(event)) handler(event);\n };\n\n/**\n * Use it on the `{...globalAttributes}` spread of a locked control so that a consumer handler spread after (or instead\n * of) the internal gate cannot override it. What is withheld depends on the `kind` of the control (see\n * `LockedControlKind`): an `activation` control loses its action handlers and Enter / Space on its key handlers; a\n * `change` control loses its change handlers only.\n */\nexport const omitLockedHandlers = <T extends object>(\n attributes: T,\n locked: boolean,\n kind: LockedControlKind = 'activation',\n): T => {\n if (!locked) return attributes;\n const isChangeKind = kind === 'change';\n const removed = isChangeKind ? CHANGE_HANDLERS : ACTIVATION_HANDLERS;\n const lockedAttributes = Object.entries(attributes).reduce<Record<string, unknown>>((acc, [key, value]) => {\n const name = withoutCaptureSuffix(key);\n if (removed.includes(name)) return acc;\n if (isChangeKind) {\n acc[key] = value;\n return acc;\n }\n acc[key] =\n LOCKED_KEY_HANDLERS.includes(name) && typeof value === 'function'\n ? skipActivationKeys(value as (event: ReactKeyboardEvent) => unknown)\n : value;\n return acc;\n }, {});\n return lockedAttributes as T;\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACShB,MAAM,WAAW,CAAC,EAAE,UAAU,mBAAmB,SAAS,MAC/D,QAAQ,YAAY,qBAAqB,QAAQ;AAW5C,MAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF,MAIuC;AACrC,MAAI,SAAU,QAAO;AACrB,SAAO,aAAa,OAAO;AAC7B;AAKO,MAAM,qBAAqB,CAAmB,eAAoD;AACvG,QAAM,OAAO,EAAE,GAAG,WAAW;AAC7B,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO;AACT;AAEA,MAAM,kBAAkB,CAAC,SAAS,KAAK,OAAO;AAEvC,MAAM,kBAAkB,CAAC,UAC9B,gBAAgB,SAAS,MAAM,OAAO,EAAE,KAAK,CAAC,SAAS,OAAO,EAAE,SAAS,MAAM,QAAQ,EAAE;AAK3F,MAAM,kBAAkB,CAAC,YAAY,WAAW,iBAAiB,WAAW,SAAS,QAAQ;AAE7F,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL;AAeA,MAAM,sBAAsB,CAAC,aAAa,cAAc,SAAS;AAGjE,MAAM,uBAAuB,CAAC,QAAgB,IAAI,QAAQ,YAAY,EAAE;AAExE,MAAM,qBACJ,CAAC,YACD,CAAC,UAAoC;AACnC,MAAI,CAAC,gBAAgB,KAAK,EAAG,SAAQ,KAAK;AAC5C;AAQK,MAAM,qBAAqB,CAChC,YACA,QACA,OAA0B,iBACpB;AACN,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,eAAe,SAAS;AAC9B,QAAM,UAAU,eAAe,kBAAkB;AACjD,QAAM,mBAAmB,OAAO,QAAQ,UAAU,EAAE,OAAgC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACzG,UAAM,OAAO,qBAAqB,GAAG;AACrC,QAAI,QAAQ,SAAS,IAAI,EAAG,QAAO;AACnC,QAAI,cAAc;AAChB,UAAI,GAAG,IAAI;AACX,aAAO;AAAA,IACT;AACA,QAAI,GAAG,IACL,oBAAoB,SAAS,IAAI,KAAK,OAAO,UAAU,aACnD,mBAAmB,KAA+C,IAClE;AACN,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACL,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -10,3 +10,4 @@ export { getContractProps } from './contractProps/index.js';
10
10
  export { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';
11
11
  export { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';
12
12
  export { useOwnerProps } from './useOwnerProps/index.js';
13
+ export { isLocked, isActivationKey, omitLockAttributes, omitLockedHandlers, resolveAriaDisabled, type LockProps, type LockedControlKind, } from './lockedInteractions/index.js';
@@ -0,0 +1 @@
1
+ export { isLocked, isActivationKey, omitLockAttributes, omitLockedHandlers, resolveAriaDisabled, type LockProps, type LockedControlKind, } from './lockedInteractions.js';
@@ -0,0 +1,44 @@
1
+ import type { AriaAttributes } from 'react';
2
+ export type LockProps = {
3
+ disabled?: boolean;
4
+ applyAriaDisabled?: boolean;
5
+ readOnly?: boolean;
6
+ };
7
+ export declare const isLocked: ({ disabled, applyAriaDisabled, readOnly }: LockProps) => boolean;
8
+ /**
9
+ * The `aria-disabled` a locked control prints. Use it AFTER the global attributes spread, so that the lock wins over a
10
+ * consumer value and an unlocked control keeps the consumer's own value (inversion of control):
11
+ * - `disabled` on a control that is natively disabled: nothing. The native attribute is the whole announcement.
12
+ * - a soft lock (`softLocked`): `true`, whatever the consumer passes. A consumer `aria-disabled="false"` cannot lift it.
13
+ * - otherwise: the consumer's own value, as they wrote it (`undefined` when they passed none).
14
+ * On a non-native element (div, span, summary, li) `disabled` cannot be written, so do not pass `disabled` and pass the
15
+ * whole lock (`isLocked(...)`) as `softLocked`: `aria-disabled="true"` is then the announcement for every lock.
16
+ */
17
+ export declare const resolveAriaDisabled: ({ disabled, softLocked, consumerValue, }: {
18
+ disabled?: boolean;
19
+ softLocked?: boolean;
20
+ consumerValue?: AriaAttributes["aria-disabled"];
21
+ }) => AriaAttributes["aria-disabled"];
22
+ export declare const omitLockAttributes: <T extends object>(attributes: T) => Omit<T, "disabled" | "readOnly">;
23
+ export declare const isActivationKey: (event: {
24
+ key?: string;
25
+ code?: string;
26
+ }) => boolean;
27
+ /**
28
+ * The two kinds of locked control:
29
+ * - `activation` (default): a control with no native change element (button, chip, tab, menu item, card, accordion
30
+ * header, any element with a role). Nothing in the browser turns a key or a click into a change, so click, Enter and
31
+ * Space ARE the way to activate it: the consumer's action handlers are withheld, and so are Enter and Space on key
32
+ * handlers.
33
+ * - `change`: a control with a change event (text input, textarea, checkbox, radio, combobox input). The gate is the
34
+ * change: the consumer's change handlers are withheld (and a controlled value is put back by React). Clicks and keys
35
+ * are only observed, so those handlers are left alone.
36
+ */
37
+ export type LockedControlKind = 'activation' | 'change';
38
+ /**
39
+ * Use it on the `{...globalAttributes}` spread of a locked control so that a consumer handler spread after (or instead
40
+ * of) the internal gate cannot override it. What is withheld depends on the `kind` of the control (see
41
+ * `LockedControlKind`): an `activation` control loses its action handlers and Enter / Space on its key handlers; a
42
+ * `change` control loses its change handlers only.
43
+ */
44
+ export declare const omitLockedHandlers: <T extends object>(attributes: T, locked: boolean, kind?: LockedControlKind) => T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-props-helpers",
3
- "version": "3.80.0-next.8",
3
+ "version": "3.80.0-next.80",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Props Helpers",
6
6
  "files": [
@@ -33,14 +33,14 @@
33
33
  "indent": 4
34
34
  },
35
35
  "dependencies": {
36
+ "@elliemae/ds-system": "3.80.0-next.80",
37
+ "@elliemae/ds-typescript-helpers": "3.80.0-next.80",
36
38
  "fast-deep-equal": "~3.1.3",
37
- "prop-types": "~15.8.1",
38
- "@elliemae/ds-system": "3.80.0-next.8",
39
- "@elliemae/ds-typescript-helpers": "3.80.0-next.8"
39
+ "prop-types": "~15.8.1"
40
40
  },
41
41
  "devDependencies": {
42
- "jest": "^30.0.0",
43
- "@elliemae/ds-monorepo-devops": "3.80.0-next.8"
42
+ "@elliemae/ds-monorepo-devops": "3.80.0-next.80",
43
+ "jest": "^30.0.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "lodash-es": "^4.18.1",