@progress/kendo-react-inputs 13.4.0-develop.5 → 14.0.0-develop.2

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.
@@ -7,11 +7,11 @@
7
7
  */
8
8
  import * as e from "react";
9
9
  import a from "prop-types";
10
- import { createPropsContext as Ve, usePropsContext as Pe, useId as Ee, dispatchEvent as P, useKendoPaste as Be, Keys as _, useDir as Ne, classNames as E, getTabIndex as Ie, kendoThemeMaps as $ } from "@progress/kendo-react-common";
10
+ import { usePropsContext as Ve, useId as Pe, dispatchEvent as P, useKendoPaste as Ee, Keys as _, useDir as Be, classNames as E, getTabIndex as Ne, kendoThemeMaps as $, createPropsContext as Ie } from "@progress/kendo-react-common";
11
11
  import { useLocalization as Fe } from "@progress/kendo-react-intl";
12
12
  import { messages as ze, checkboxValidation as Ke, checkboxOptionalText as Me } from "../messages/index.mjs";
13
- const Se = Ve(), W = e.forwardRef((j, G) => {
14
- const B = Pe(Se, j), {
13
+ const Se = Ie(), W = e.forwardRef((j, G) => {
14
+ const B = Ve(Se, j), {
15
15
  ariaDescribedBy: J,
16
16
  ariaLabelledBy: Q,
17
17
  checked: N,
@@ -56,7 +56,7 @@ const Se = Ve(), W = e.forwardRef((j, G) => {
56
56
  [D]
57
57
  );
58
58
  e.useImperativeHandle(G, c);
59
- const [se, ce] = e.useState(ee), [re, ie] = e.useState(ae), T = typeof s == "boolean" || s === null, v = N !== void 0, i = T, C = i ? s : re, g = v ? N : i ? void 0 : se, w = z || b, L = g === void 0 && C, O = L ? C : g, u = L || i ? s === null ? s : void 0 : s || C, de = O === null || u === null, q = Ee(), ue = Fe(), R = (t) => ue.toLanguageString(t, ze[t]), H = R(Ke), be = R(Me), y = K !== void 0 ? K : d ? !!g : !0;
59
+ const [se, ce] = e.useState(ee), [re, ie] = e.useState(ae), T = typeof s == "boolean" || s === null, v = N !== void 0, i = T, C = i ? s : re, g = v ? N : i ? void 0 : se, w = z || b, L = g === void 0 && C, O = L ? C : g, u = L || i ? s === null ? s : void 0 : s || C, de = O === null || u === null, q = Pe(), ue = Fe(), R = (t) => ue.toLanguageString(t, ze[t]), H = R(Ke), be = R(Me), y = K !== void 0 ? K : d ? !!g : !0;
60
60
  e.useEffect(() => {
61
61
  n.current && n.current.setCustomValidity && n.current.setCustomValidity(y ? "" : M || H);
62
62
  }, [y, M, H]);
@@ -83,7 +83,7 @@ const Se = Ve(), W = e.forwardRef((j, G) => {
83
83
  },
84
84
  [r]
85
85
  );
86
- Be(n, {
86
+ Ee(n, {
87
87
  fieldName: w,
88
88
  onValueChange: me,
89
89
  enabled: !!w
@@ -120,7 +120,7 @@ const Se = Ve(), W = e.forwardRef((j, G) => {
120
120
  h && !o && P(h, t, c(), void 0);
121
121
  },
122
122
  [h, o, c]
123
- ), Ce = Ne(n, B.dir), ge = E("k-checkbox-wrap", X), U = {
123
+ ), Ce = Be(n, B.dir), ge = E("k-checkbox-wrap", X), U = {
124
124
  type: "checkbox",
125
125
  className: E("k-checkbox", {
126
126
  [`k-checkbox-${$.sizeMap[m] || m}`]: m,
@@ -134,7 +134,7 @@ const Se = Ve(), W = e.forwardRef((j, G) => {
134
134
  id: b || q,
135
135
  disabled: o,
136
136
  required: d !== void 0 ? d : !1,
137
- tabIndex: Ie(oe, o),
137
+ tabIndex: Ne(oe, o),
138
138
  role: "checkbox",
139
139
  checked: !!O,
140
140
  "aria-describedby": J,
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import * as r from "react";
9
9
  import o from "prop-types";
10
- import { withIdHOC as F, createPropsContext as G, withPropsContext as M, validatePackage as A, getLicenseMessage as _, canUseDOM as N, Navigation as f, getActiveElement as b, disableNavigatableContainer as C, focusFirstFocusableChild as I, enableNavigatableContainer as T, keepFocusInContainer as O, TABBABLE_ELEMENTS as z, getTabIndex as k, classNames as B, kendoThemeMaps as P, Draggable as V, WatermarkOverlay as K } from "@progress/kendo-react-common";
10
+ import { withIdHOC as F, withPropsContext as G, createPropsContext as M, validatePackage as A, getLicenseMessage as _, canUseDOM as N, Navigation as f, getActiveElement as b, disableNavigatableContainer as C, focusFirstFocusableChild as I, enableNavigatableContainer as T, keepFocusInContainer as O, TABBABLE_ELEMENTS as z, getTabIndex as k, classNames as B, kendoThemeMaps as P, Draggable as V, WatermarkOverlay as K } from "@progress/kendo-react-common";
11
11
  import { packageMetadata as R } from "../package-metadata.mjs";
12
12
  import { Slider as S } from "../slider/Slider.mjs";
13
13
  import { isPresent as y, fitIntoBounds as E } from "./utils/misc.mjs";
@@ -358,8 +358,8 @@ h.displayName = "ColorGradient", h.propTypes = {
358
358
  size: void 0
359
359
  };
360
360
  let m = h;
361
- const ie = G(), re = F(
362
- M(
361
+ const ie = M(), re = F(
362
+ G(
363
363
  ie,
364
364
  m
365
365
  )
@@ -5,8 +5,8 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import { default as PropTypes } from 'prop-types';
9
8
  import { ColorPaletteProps } from './interfaces/ColorPaletteProps.js';
9
+ import { ColorPaletteHandle } from './interfaces/ColorPaletteHandle.js';
10
10
  import * as React from 'react';
11
11
  /**
12
12
  * @hidden
@@ -21,85 +21,25 @@ export declare const DEFAULT_COLUMNS_COUNT = 10;
21
21
  */
22
22
  export declare const DEFAULT_PRESET = "office";
23
23
  /**
24
+ * The default props of the ColorPalette component.
25
+ *
24
26
  * @hidden
25
27
  */
28
+ export declare const defaultColorPaletteProps: {
29
+ palette: string;
30
+ columns: number;
31
+ tileSize: number;
32
+ };
33
+ /**
34
+ * @hidden
35
+ *
36
+ * @deprecated This interface is no longer used in the functional implementation but maintained for backward compatibility
37
+ */
26
38
  export interface ColorPaletteState {
27
39
  selectedColor?: string;
28
40
  focusedColor?: string;
29
41
  isFirstRender: boolean;
30
42
  }
31
- /** @hidden */
32
- export declare class ColorPaletteWithoutContext extends React.Component<ColorPaletteProps, ColorPaletteState> {
33
- static displayName: string;
34
- /**
35
- * @hidden
36
- */
37
- static propTypes: {
38
- palette: PropTypes.Requireable<NonNullable<string | string[] | null | undefined>>;
39
- columns: PropTypes.Requireable<number>;
40
- tileSize: PropTypes.Requireable<any>;
41
- defaultValue: PropTypes.Requireable<string>;
42
- value: PropTypes.Requireable<string>;
43
- disabled: PropTypes.Requireable<boolean>;
44
- tabIndex: PropTypes.Requireable<number>;
45
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
46
- onFocus: PropTypes.Requireable<(...args: any[]) => any>;
47
- id: PropTypes.Requireable<string>;
48
- ariaLabelledBy: PropTypes.Requireable<string>;
49
- ariaDescribedBy: PropTypes.Requireable<string>;
50
- className: PropTypes.Requireable<string>;
51
- size: PropTypes.Requireable<string | null>;
52
- };
53
- /**
54
- * @hidden
55
- */
56
- static defaultProps: {
57
- palette: string;
58
- tileSize: number;
59
- size: undefined;
60
- };
61
- /**
62
- * @hidden
63
- */
64
- wrapperRef: React.RefObject<HTMLDivElement | null>;
65
- private paletteService;
66
- private get guid();
67
- constructor(props: ColorPaletteProps);
68
- /**
69
- * @hidden
70
- */
71
- focus: () => void;
72
- /**
73
- * @hidden
74
- */
75
- render(): "" | React.JSX.Element;
76
- /**
77
- * @hidden
78
- */
79
- static getDerivedStateFromProps(props: ColorPaletteProps, state: ColorPaletteState): {
80
- selectedColor: undefined;
81
- isFirstRender?: undefined;
82
- } | {
83
- selectedColor: string;
84
- isFirstRender?: undefined;
85
- } | {
86
- isFirstRender: boolean;
87
- selectedColor?: undefined;
88
- } | null;
89
- private onKeyDown;
90
- private onColorClick;
91
- private onFocus;
92
- private onBlur;
93
- private handleCellNavigation;
94
- private handleEnter;
95
- private dispatchChangeEvent;
96
- private get focusedColorCooridanates();
97
- private get isUncontrolled();
98
- private getPaletteInfo;
99
- private renderRows;
100
- private renderColumns;
101
- private createCellId;
102
- }
103
43
  /**
104
44
  * Represents the PropsContext of the `ColorPalette` component.
105
45
  * Used for global configuration of all `ColorPalette` instances.
@@ -108,14 +48,7 @@ export declare class ColorPaletteWithoutContext extends React.Component<ColorPal
108
48
  */
109
49
  export declare const ColorPalettePropsContext: React.Context<(p: ColorPaletteProps) => ColorPaletteProps>;
110
50
  /**
111
- * Represent the `ref` of the ColorPalette component.
112
- */
113
- export interface ColorPaletteHandle extends Pick<ColorPaletteWithoutContext, keyof ColorPaletteWithoutContext> {
114
- }
115
- /** @hidden */
116
- export type ColorPalette = ColorPaletteHandle;
117
- /**
118
- * Represents the [KendoReact ColorPalette component](https://www.telerik.com/kendo-react-ui/components/inputs/colorpalette).
51
+ * Represents the [KendoReact ColorPalette component](https://www.telerik.com/kendo-react-ui/components/inputs/colorpalette) (Functional Implementation).
119
52
  *
120
53
  * Accepts properties of type [ColorPaletteProps](https://www.telerik.com/kendo-react-ui/components/inputs/api/colorpaletteprops).
121
54
  * Obtaining the `ref` returns an object of type [ColorPaletteHandle](https://www.telerik.com/kendo-react-ui/components/inputs/api/colorpalettehandle).
@@ -127,3 +60,9 @@ export type ColorPalette = ColorPaletteHandle;
127
60
  * ```
128
61
  */
129
62
  export declare const ColorPalette: React.ForwardRefExoticComponent<ColorPaletteProps & React.RefAttributes<any>>;
63
+ /**
64
+ * ColorPalette component without context (for backward compatibility).
65
+ *
66
+ * @hidden
67
+ */
68
+ export declare const ColorPaletteWithoutContext: React.ForwardRefExoticComponent<ColorPaletteProps & React.RefAttributes<ColorPaletteHandle>>;
@@ -5,4 +5,4 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react"),s=require("prop-types"),k=require("./utils/color-palette.service.js"),r=require("@progress/kendo-react-common"),T=require("./models/palette-presets.js"),F=require("./utils/misc.js"),N=require("./utils/color-parser.js");function D(a){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const e in a)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(a,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>a[e]})}}return t.default=a,Object.freeze(t)}const l=D(R),g=24,u=10,v="office",n=class n extends l.Component{constructor(t){super(t),this.wrapperRef=l.createRef(),this.paletteService=null,this.focus=()=>{this.wrapperRef&&this.wrapperRef.current&&this.wrapperRef.current.focus()},this.onKeyDown=e=>{switch(e.key){case r.KEYS.down:this.handleCellNavigation(0,1);break;case r.KEYS.up:this.handleCellNavigation(0,-1);break;case r.KEYS.right:this.handleCellNavigation(1,0);break;case r.KEYS.left:this.handleCellNavigation(-1,0);break;case r.KEYS.enter:this.handleEnter(e);break;default:return}e.preventDefault()},this.onColorClick=(e,o)=>{this.isUncontrolled?this.setState({selectedColor:e,focusedColor:e}):this.setState({focusedColor:e}),this.dispatchChangeEvent(e,o)},this.onFocus=e=>{this.paletteService&&(this.setState({focusedColor:this.state.selectedColor||this.paletteService.colorRows[0][0]}),this.props.onFocus&&this.props.onFocus.call(void 0,e))},this.onBlur=()=>{this.setState({focusedColor:void 0})},this.state={selectedColor:this.props.value!==void 0?this.props.value:this.props.defaultValue?this.props.defaultValue:void 0,isFirstRender:!0}}get guid(){return this.props.id}render(){const t=this.getPaletteInfo(),e=this.paletteService=new k.ColorPaletteService;e.setColorMatrix(t.colors,t.columns);const o=e.getCellCoordsFor(this.state.selectedColor),i=e.getCellCoordsFor(this.state.focusedColor);return t.colors.length?l.createElement("div",{id:this.props.id,role:"grid",className:r.classNames("k-colorpalette",{[`k-colorpalette-${r.kendoThemeMaps.sizeMap[this.props.size]||this.props.size}`]:this.props.size,"k-disabled":this.props.disabled},this.props.className),onFocus:this.onFocus,onBlur:this.onBlur,onKeyDown:this.onKeyDown,"aria-disabled":this.props.ariaDisabled||(this.props.disabled?"true":void 0),"aria-labelledby":this.props.ariaLabelledBy,"aria-describedby":this.props.ariaDescribedBy,tabIndex:r.getTabIndex(this.props.tabIndex,this.props.disabled),ref:this.wrapperRef},l.createElement("table",{className:"k-colorpalette-table",role:"presentation"},l.createElement("tbody",{role:"rowgroup"},this.renderRows(e.colorRows,o,i)))):""}static getDerivedStateFromProps(t,e){if(!e.isFirstRender&&t.value!==void 0){if(t.value===""&&e.selectedColor!==void 0)return{selectedColor:void 0};if(t.value!==""&&t.value!==e.selectedColor)return{selectedColor:t.value}}else if(e.isFirstRender)return{isFirstRender:!1};return null}handleCellNavigation(t,e){if(this.paletteService)if(this.focusedColorCooridanates){const o=this.paletteService.getNextCell(this.focusedColorCooridanates,t,e);this.setState({focusedColor:this.paletteService.getColorAt(o)})}else this.setState({focusedColor:this.paletteService.colorRows[0][0]})}handleEnter(t){this.isUncontrolled&&this.setState({selectedColor:this.state.focusedColor}),this.dispatchChangeEvent(this.state.focusedColor,t)}dispatchChangeEvent(t,e){r.dispatchEvent(this.props.onChange,e,this,{value:t,rgbaValue:N.parseColor(t,"rgba")})}get focusedColorCooridanates(){return this.state.focusedColor&&this.paletteService?this.paletteService.getCellCoordsFor(this.state.focusedColor):void 0}get isUncontrolled(){return this.props.value===void 0}getPaletteInfo(){if(typeof this.props.palette=="string"){const t=T.PALETTEPRESETS[this.props.palette];return F.isPresent(t)?{colors:t.colors,columns:this.props.columns||t.columns||u}:{colors:[],columns:0}}return{colors:this.props.palette||[],columns:this.props.columns||u}}renderRows(t,e,o){return t.map((i,c)=>l.createElement("tr",{role:"row",key:c},this.renderColumns(i,c,e,o)))}renderColumns(t,e,o,i){const c=o!==void 0&&o.row===e,m=o&&o.col,E=i!==void 0&&i.row===e,w=i&&i.col;return t.map((h,d)=>{const f=c&&m===d,y=r.classNames("k-colorpalette-tile",{"k-selected":f,"k-focus":E&&w===d});let C={width:this.props.tileSize,height:this.props.tileSize};return typeof this.props.tileSize=="object"&&(C={width:this.props.tileSize.width,height:this.props.tileSize.height}),l.createElement("td",{role:"gridcell",className:y,"aria-label":h,"aria-selected":f?!0:this.props.disabled?void 0:!1,style:{backgroundColor:h,...C},onClick:P=>this.onColorClick(h,P),id:this.createCellId({row:e,col:d}),key:d})})}createCellId(t){return`${this.guid}_${t.row}_${t.col}`}};n.displayName="ColorPalette",n.propTypes={palette:s.oneOfType([s.arrayOf(s.string.isRequired),s.string]),columns:s.number,tileSize:s.any,defaultValue:s.string,value:s.string,disabled:s.bool,tabIndex:s.number,onChange:s.func,onFocus:s.func,id:s.string,ariaLabelledBy:s.string,ariaDescribedBy:s.string,className:s.string,size:s.oneOf(["small","medium","large",null])},n.defaultProps={palette:v,tileSize:g,size:void 0};let p=n;const S=r.createPropsContext(),b=r.withIdHOC(r.withPropsContext(S,p));b.displayName="KendoReactColorPalette";exports.ColorPalette=b;exports.ColorPalettePropsContext=S;exports.ColorPaletteWithoutContext=p;exports.DEFAULT_COLUMNS_COUNT=u;exports.DEFAULT_PRESET=v;exports.DEFAULT_TILE_SIZE=g;
8
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),l=require("prop-types"),re=require("./utils/color-palette.service.js"),w=require("@progress/kendo-react-common"),se=require("./models/palette-presets.js"),q=require("./utils/color-parser.js");function le(c){const p=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const h in c)if(h!=="default"){const E=Object.getOwnPropertyDescriptor(c,h);Object.defineProperty(p,h,E.get?E:{enumerable:!0,get:()=>c[h]})}}return p.default=c,Object.freeze(p)}const k=le(n),z=24,B=10,j="office",D={palette:j,columns:B,tileSize:z},V=w.createPropsContext(),ne=c=>{if(Array.isArray(c))return c;if(typeof c=="string"){const p=se.PALETTEPRESETS[c];if(p)return p.colors}return[]},F=k.forwardRef((c,p)=>{const h=w.usePropsContext(V,c),{palette:E=D.palette,columns:L=D.columns,tileSize:u=D.tileSize,value:x,defaultValue:$,disabled:d=!1,tabIndex:K,onChange:P,onFocus:I,className:W,size:N,id:Z,ariaLabelledBy:G,ariaDescribedBy:J}=h,S=n.useRef(null),Q=n.useRef({focus:()=>{var o;(o=S.current)==null||o.focus()},wrapperRef:S}),_=L!=null?L:D.columns,b=n.useMemo(()=>ne(E),[E]),t=n.useMemo(()=>{const o=new re.ColorPaletteService;return o.setColorMatrix(b,_),o},[b,_]),[g,O]=n.useState(()=>x!==void 0?x:$||""),[T,R]=n.useState(""),y=x!==void 0;n.useEffect(()=>{y&&O(x)},[x,y]);const X=n.useCallback(o=>{if(d||b.length===0)return;const f=g||b[0];R(f),I&&I(o)},[d,b,g,I]),Y=n.useCallback(()=>{R("")},[]),ee=n.useCallback(o=>{if(d)return;const{key:f}=o,r=()=>T||g||b[0],m=(s,e)=>s<0?e:s>e?0:s;switch(f){case"ArrowRight":o.preventDefault();{const s=r(),e=t.getCellCoordsFor(s);if(e&&t.colorRows[e.row]){const C=t.colorRows[e.row].length-1,a=m(e.col+1,C),i=t.colorRows[e.row][a];i&&R(i)}}break;case"ArrowLeft":o.preventDefault();{const s=r(),e=t.getCellCoordsFor(s);if(e&&t.colorRows[e.row]){const C=t.colorRows[e.row].length-1,a=m(e.col-1,C),i=t.colorRows[e.row][a];i&&R(i)}}break;case"ArrowDown":o.preventDefault();{const s=r(),e=t.getCellCoordsFor(s);if(e){const C=t.colorRows.length-1,a=m(e.row+1,C),i=Math.min(e.col,t.colorRows[a].length-1),v=t.colorRows[a][i];v&&R(v)}}break;case"ArrowUp":o.preventDefault();{const s=r(),e=t.getCellCoordsFor(s);if(e){const C=t.colorRows.length-1,a=m(e.row-1,C),i=Math.min(e.col,t.colorRows[a].length-1),v=t.colorRows[a][i];v&&R(v)}}break;case"Enter":o.preventDefault();{const s=r();if(s&&(y||O(s),P)){const e=q.parseColor(s,"rgba");w.dispatchEvent(P,o,null,{value:s,rgbaValue:e||""})}}break}},[d,T,g,b,t,y,P]),A=n.useCallback((o,f)=>{if(d)return;const r=o;if(y||O(r),P){const m=q.parseColor(r,"rgba");w.dispatchEvent(P,f,null,{value:r,rgbaValue:m||""})}},[d,P,y]),U=n.useCallback((o,f)=>o.map((r,m)=>{const s=g&&r.toLowerCase()===g.toLowerCase(),e=T&&r.toLowerCase()===T.toLowerCase(),C=w.classNames("k-colorpalette-tile",{"k-selected":s,"k-focus":e}),a={backgroundColor:r};return typeof u=="number"?(a.width=`${u}px`,a.height=`${u}px`):u&&typeof u=="object"&&("width"in u&&(a.width=`${u.width}px`),"height"in u&&(a.height=`${u.height}px`)),k.createElement("td",{key:r,role:"gridcell",className:C,style:a,"aria-label":r,"aria-selected":s?"true":"false",onClick:i=>A(r,i)})}),[g,T,u,A]),oe=n.useCallback(()=>t.colorRows.map((f,r)=>k.createElement("tr",{key:f[0]||r,role:"row"},U(f,r))),[t,U]),M=n.useCallback(()=>({focus:()=>{var o;(o=S.current)==null||o.focus()},wrapperRef:S}),[]);n.useImperativeHandle(Q,M),n.useImperativeHandle(p,M);const te=w.classNames("k-colorpalette",W,{"k-disabled":d,"k-colorpalette-sm":N==="small","k-colorpalette-md":N==="medium","k-colorpalette-lg":N==="large"});return k.createElement("div",{ref:S,role:"grid",className:te,tabIndex:w.getTabIndex(K,d),id:Z,"aria-labelledby":G,"aria-describedby":J,"aria-disabled":d?"true":void 0,onFocus:X,onBlur:Y,onKeyDown:ee},k.createElement("table",{className:"k-colorpalette-table",role:"presentation"},k.createElement("tbody",null,oe())))});F.displayName="ColorPalette";F.propTypes={palette:l.oneOfType([l.arrayOf(l.string.isRequired),l.string]),columns:l.number,tileSize:l.any,defaultValue:l.string,value:l.string,disabled:l.bool,tabIndex:l.number,onChange:l.func,onFocus:l.func,id:l.string,ariaLabelledBy:l.string,ariaDescribedBy:l.string,className:l.string,size:l.oneOf(["small","medium","large"])};const H=w.withIdHOC(F);H.displayName="KendoReactColorPalette";const ae=F;exports.ColorPalette=H;exports.ColorPalettePropsContext=V;exports.ColorPaletteWithoutContext=ae;exports.DEFAULT_COLUMNS_COUNT=B;exports.DEFAULT_PRESET=j;exports.DEFAULT_TILE_SIZE=z;exports.defaultColorPaletteProps=D;
@@ -5,200 +5,226 @@
5
5
  * Licensed under commercial license. See LICENSE.md in the package root for more information
6
6
  *-------------------------------------------------------------------------------------------
7
7
  */
8
- import * as i from "react";
9
- import s from "prop-types";
10
- import { ColorPaletteService as w } from "./utils/color-palette.service.mjs";
11
- import { withIdHOC as y, createPropsContext as E, withPropsContext as k, KEYS as l, getTabIndex as R, classNames as f, kendoThemeMaps as F, dispatchEvent as N } from "@progress/kendo-react-common";
12
- import { PALETTEPRESETS as z } from "./models/palette-presets.mjs";
13
- import { isPresent as T } from "./utils/misc.mjs";
14
- import { parseColor as P } from "./utils/color-parser.mjs";
15
- const I = 24, C = 10, D = "office", a = class a extends i.Component {
16
- constructor(t) {
17
- super(t), this.wrapperRef = i.createRef(), this.paletteService = null, this.focus = () => {
18
- this.wrapperRef && this.wrapperRef.current && this.wrapperRef.current.focus();
19
- }, this.onKeyDown = (e) => {
20
- switch (e.key) {
21
- case l.down:
22
- this.handleCellNavigation(0, 1);
8
+ import * as R from "react";
9
+ import { useRef as z, useMemo as O, useState as U, useEffect as re, useCallback as p, useImperativeHandle as V } from "react";
10
+ import l from "prop-types";
11
+ import { ColorPaletteService as se } from "./utils/color-palette.service.mjs";
12
+ import { withIdHOC as le, createPropsContext as ne, usePropsContext as ae, dispatchEvent as M, classNames as H, getTabIndex as ce } from "@progress/kendo-react-common";
13
+ import { PALETTEPRESETS as ie } from "./models/palette-presets.mjs";
14
+ import { parseColor as $ } from "./utils/color-parser.mjs";
15
+ const ue = 24, de = 10, fe = "office", F = {
16
+ palette: fe,
17
+ columns: de,
18
+ tileSize: ue
19
+ }, Ce = ne(), we = (m) => {
20
+ if (Array.isArray(m))
21
+ return m;
22
+ if (typeof m == "string") {
23
+ const P = ie[m];
24
+ if (P)
25
+ return P.colors;
26
+ }
27
+ return [];
28
+ }, v = R.forwardRef((m, P) => {
29
+ const K = ae(Ce, m), {
30
+ palette: I = F.palette,
31
+ columns: S = F.columns,
32
+ tileSize: c = F.tileSize,
33
+ value: y,
34
+ defaultValue: j,
35
+ disabled: i = !1,
36
+ tabIndex: q,
37
+ onChange: g,
38
+ onFocus: D,
39
+ className: W,
40
+ size: L,
41
+ id: Z,
42
+ ariaLabelledBy: G,
43
+ ariaDescribedBy: J
44
+ } = K, k = z(null), Q = z({
45
+ focus: () => {
46
+ var o;
47
+ (o = k.current) == null || o.focus();
48
+ },
49
+ wrapperRef: k
50
+ }), A = S != null ? S : F.columns, f = O(() => we(I), [I]), t = O(() => {
51
+ const o = new se();
52
+ return o.setColorMatrix(f, A), o;
53
+ }, [f, A]), [C, T] = U(() => y !== void 0 ? y : j || ""), [x, b] = U(""), h = y !== void 0;
54
+ re(() => {
55
+ h && T(y);
56
+ }, [y, h]);
57
+ const X = p(
58
+ (o) => {
59
+ if (i || f.length === 0)
60
+ return;
61
+ const u = C || f[0];
62
+ b(u), D && D(o);
63
+ },
64
+ [i, f, C, D]
65
+ ), Y = p(() => {
66
+ b("");
67
+ }, []), ee = p(
68
+ (o) => {
69
+ if (i)
70
+ return;
71
+ const { key: u } = o, r = () => x || C || f[0], w = (s, e) => s < 0 ? e : s > e ? 0 : s;
72
+ switch (u) {
73
+ case "ArrowRight":
74
+ o.preventDefault();
75
+ {
76
+ const s = r(), e = t.getCellCoordsFor(s);
77
+ if (e && t.colorRows[e.row]) {
78
+ const d = t.colorRows[e.row].length - 1, n = w(e.col + 1, d), a = t.colorRows[e.row][n];
79
+ a && b(a);
80
+ }
81
+ }
23
82
  break;
24
- case l.up:
25
- this.handleCellNavigation(0, -1);
83
+ case "ArrowLeft":
84
+ o.preventDefault();
85
+ {
86
+ const s = r(), e = t.getCellCoordsFor(s);
87
+ if (e && t.colorRows[e.row]) {
88
+ const d = t.colorRows[e.row].length - 1, n = w(e.col - 1, d), a = t.colorRows[e.row][n];
89
+ a && b(a);
90
+ }
91
+ }
26
92
  break;
27
- case l.right:
28
- this.handleCellNavigation(1, 0);
93
+ case "ArrowDown":
94
+ o.preventDefault();
95
+ {
96
+ const s = r(), e = t.getCellCoordsFor(s);
97
+ if (e) {
98
+ const d = t.colorRows.length - 1, n = w(e.row + 1, d), a = Math.min(e.col, t.colorRows[n].length - 1), E = t.colorRows[n][a];
99
+ E && b(E);
100
+ }
101
+ }
29
102
  break;
30
- case l.left:
31
- this.handleCellNavigation(-1, 0);
103
+ case "ArrowUp":
104
+ o.preventDefault();
105
+ {
106
+ const s = r(), e = t.getCellCoordsFor(s);
107
+ if (e) {
108
+ const d = t.colorRows.length - 1, n = w(e.row - 1, d), a = Math.min(e.col, t.colorRows[n].length - 1), E = t.colorRows[n][a];
109
+ E && b(E);
110
+ }
111
+ }
32
112
  break;
33
- case l.enter:
34
- this.handleEnter(e);
113
+ case "Enter":
114
+ o.preventDefault();
115
+ {
116
+ const s = r();
117
+ if (s && (h || T(s), g)) {
118
+ const e = $(s, "rgba");
119
+ M(g, o, null, {
120
+ value: s,
121
+ rgbaValue: e || ""
122
+ });
123
+ }
124
+ }
35
125
  break;
36
- default:
37
- return;
38
126
  }
39
- e.preventDefault();
40
- }, this.onColorClick = (e, o) => {
41
- this.isUncontrolled ? this.setState({ selectedColor: e, focusedColor: e }) : this.setState({ focusedColor: e }), this.dispatchChangeEvent(e, o);
42
- }, this.onFocus = (e) => {
43
- this.paletteService && (this.setState({ focusedColor: this.state.selectedColor || this.paletteService.colorRows[0][0] }), this.props.onFocus && this.props.onFocus.call(void 0, e));
44
- }, this.onBlur = () => {
45
- this.setState({ focusedColor: void 0 });
46
- }, this.state = {
47
- selectedColor: this.props.value !== void 0 ? this.props.value : this.props.defaultValue ? this.props.defaultValue : void 0,
48
- isFirstRender: !0
49
- };
50
- }
51
- get guid() {
52
- return this.props.id;
53
- }
54
- /**
55
- * @hidden
56
- */
57
- render() {
58
- const t = this.getPaletteInfo(), e = this.paletteService = new w();
59
- e.setColorMatrix(t.colors, t.columns);
60
- const o = e.getCellCoordsFor(this.state.selectedColor), r = e.getCellCoordsFor(this.state.focusedColor);
61
- return t.colors.length ? /* @__PURE__ */ i.createElement(
62
- "div",
63
- {
64
- id: this.props.id,
65
- role: "grid",
66
- className: f(
67
- "k-colorpalette",
68
- {
69
- [`k-colorpalette-${F.sizeMap[this.props.size] || this.props.size}`]: this.props.size,
70
- "k-disabled": this.props.disabled
71
- },
72
- this.props.className
73
- ),
74
- onFocus: this.onFocus,
75
- onBlur: this.onBlur,
76
- onKeyDown: this.onKeyDown,
77
- "aria-disabled": this.props.ariaDisabled || (this.props.disabled ? "true" : void 0),
78
- "aria-labelledby": this.props.ariaLabelledBy,
79
- "aria-describedby": this.props.ariaDescribedBy,
80
- tabIndex: R(this.props.tabIndex, this.props.disabled),
81
- ref: this.wrapperRef
82
- },
83
- /* @__PURE__ */ i.createElement("table", { className: "k-colorpalette-table", role: "presentation" }, /* @__PURE__ */ i.createElement("tbody", { role: "rowgroup" }, this.renderRows(e.colorRows, o, r)))
84
- ) : "";
85
- }
86
- /**
87
- * @hidden
88
- */
89
- static getDerivedStateFromProps(t, e) {
90
- if (!e.isFirstRender && t.value !== void 0) {
91
- if (t.value === "" && e.selectedColor !== void 0)
92
- return { selectedColor: void 0 };
93
- if (t.value !== "" && t.value !== e.selectedColor)
94
- return { selectedColor: t.value };
95
- } else if (e.isFirstRender)
96
- return { isFirstRender: !1 };
97
- return null;
98
- }
99
- handleCellNavigation(t, e) {
100
- if (this.paletteService)
101
- if (this.focusedColorCooridanates) {
102
- const o = this.paletteService.getNextCell(
103
- this.focusedColorCooridanates,
104
- t,
105
- e
106
- );
107
- this.setState({ focusedColor: this.paletteService.getColorAt(o) });
108
- } else
109
- this.setState({ focusedColor: this.paletteService.colorRows[0][0] });
110
- }
111
- handleEnter(t) {
112
- this.isUncontrolled && this.setState({ selectedColor: this.state.focusedColor }), this.dispatchChangeEvent(this.state.focusedColor, t);
113
- }
114
- dispatchChangeEvent(t, e) {
115
- N(this.props.onChange, e, this, { value: t, rgbaValue: P(t, "rgba") });
116
- }
117
- get focusedColorCooridanates() {
118
- return this.state.focusedColor && this.paletteService ? this.paletteService.getCellCoordsFor(this.state.focusedColor) : void 0;
119
- }
120
- get isUncontrolled() {
121
- return this.props.value === void 0;
122
- }
123
- getPaletteInfo() {
124
- if (typeof this.props.palette == "string") {
125
- const t = z[this.props.palette];
126
- return T(t) ? {
127
- colors: t.colors,
128
- columns: this.props.columns || t.columns || C
129
- } : { colors: [], columns: 0 };
130
- }
131
- return { colors: this.props.palette || [], columns: this.props.columns || C };
132
- }
133
- renderRows(t, e, o) {
134
- return t.map((r, n) => /* @__PURE__ */ i.createElement("tr", { role: "row", key: n }, this.renderColumns(r, n, e, o)));
135
- }
136
- renderColumns(t, e, o, r) {
137
- const n = o !== void 0 && o.row === e, m = o && o.col, g = r !== void 0 && r.row === e, v = r && r.col;
138
- return t.map((p, c) => {
139
- const h = n && m === c, b = f("k-colorpalette-tile", {
140
- "k-selected": h,
141
- "k-focus": g && v === c
142
- });
143
- let u = {
144
- width: this.props.tileSize,
145
- height: this.props.tileSize
127
+ },
128
+ [i, x, C, f, t, h, g]
129
+ ), N = p(
130
+ (o, u) => {
131
+ if (i)
132
+ return;
133
+ const r = o;
134
+ if (h || T(r), g) {
135
+ const w = $(r, "rgba");
136
+ M(g, u, null, {
137
+ value: r,
138
+ rgbaValue: w || ""
139
+ });
140
+ }
141
+ },
142
+ [i, g, h]
143
+ ), B = p(
144
+ (o, u) => o.map((r, w) => {
145
+ const s = C && r.toLowerCase() === C.toLowerCase(), e = x && r.toLowerCase() === x.toLowerCase(), d = H("k-colorpalette-tile", {
146
+ "k-selected": s,
147
+ "k-focus": e
148
+ }), n = {
149
+ backgroundColor: r
146
150
  };
147
- return typeof this.props.tileSize == "object" && (u = {
148
- width: this.props.tileSize.width,
149
- height: this.props.tileSize.height
150
- }), /* @__PURE__ */ i.createElement(
151
+ return typeof c == "number" ? (n.width = `${c}px`, n.height = `${c}px`) : c && typeof c == "object" && ("width" in c && (n.width = `${c.width}px`), "height" in c && (n.height = `${c.height}px`)), /* @__PURE__ */ R.createElement(
151
152
  "td",
152
153
  {
154
+ key: r,
153
155
  role: "gridcell",
154
- className: b,
155
- "aria-label": p,
156
- "aria-selected": h ? !0 : this.props.disabled ? void 0 : !1,
157
- style: { backgroundColor: p, ...u },
158
- onClick: (S) => this.onColorClick(p, S),
159
- id: this.createCellId({ row: e, col: c }),
160
- key: c
156
+ className: d,
157
+ style: n,
158
+ "aria-label": r,
159
+ "aria-selected": s ? "true" : "false",
160
+ onClick: (a) => N(r, a)
161
161
  }
162
162
  );
163
- });
164
- }
165
- createCellId(t) {
166
- return `${this.guid}_${t.row}_${t.col}`;
167
- }
168
- };
169
- a.displayName = "ColorPalette", a.propTypes = {
170
- palette: s.oneOfType([s.arrayOf(s.string.isRequired), s.string]),
171
- columns: s.number,
172
- tileSize: s.any,
173
- defaultValue: s.string,
174
- value: s.string,
175
- disabled: s.bool,
176
- tabIndex: s.number,
177
- onChange: s.func,
178
- onFocus: s.func,
179
- id: s.string,
180
- ariaLabelledBy: s.string,
181
- ariaDescribedBy: s.string,
182
- className: s.string,
183
- size: s.oneOf(["small", "medium", "large", null])
184
- }, a.defaultProps = {
185
- palette: D,
186
- tileSize: I,
187
- size: void 0
163
+ }),
164
+ [C, x, c, N]
165
+ ), oe = p(() => t.colorRows.map((u, r) => /* @__PURE__ */ R.createElement("tr", { key: u[0] || r, role: "row" }, B(u, r))), [t, B]), _ = p(
166
+ () => ({
167
+ focus: () => {
168
+ var o;
169
+ (o = k.current) == null || o.focus();
170
+ },
171
+ wrapperRef: k
172
+ }),
173
+ []
174
+ );
175
+ V(Q, _), V(P, _);
176
+ const te = H("k-colorpalette", W, {
177
+ "k-disabled": i,
178
+ "k-colorpalette-sm": L === "small",
179
+ "k-colorpalette-md": L === "medium",
180
+ "k-colorpalette-lg": L === "large"
181
+ });
182
+ return /* @__PURE__ */ R.createElement(
183
+ "div",
184
+ {
185
+ ref: k,
186
+ role: "grid",
187
+ className: te,
188
+ tabIndex: ce(q, i),
189
+ id: Z,
190
+ "aria-labelledby": G,
191
+ "aria-describedby": J,
192
+ "aria-disabled": i ? "true" : void 0,
193
+ onFocus: X,
194
+ onBlur: Y,
195
+ onKeyDown: ee
196
+ },
197
+ /* @__PURE__ */ R.createElement("table", { className: "k-colorpalette-table", role: "presentation" }, /* @__PURE__ */ R.createElement("tbody", null, oe()))
198
+ );
199
+ });
200
+ v.displayName = "ColorPalette";
201
+ v.propTypes = {
202
+ palette: l.oneOfType([l.arrayOf(l.string.isRequired), l.string]),
203
+ columns: l.number,
204
+ tileSize: l.any,
205
+ defaultValue: l.string,
206
+ value: l.string,
207
+ disabled: l.bool,
208
+ tabIndex: l.number,
209
+ onChange: l.func,
210
+ onFocus: l.func,
211
+ id: l.string,
212
+ ariaLabelledBy: l.string,
213
+ ariaDescribedBy: l.string,
214
+ className: l.string,
215
+ size: l.oneOf(["small", "medium", "large"])
188
216
  };
189
- let d = a;
190
- const L = E(), U = y(
191
- k(
192
- L,
193
- d
194
- )
217
+ const pe = le(
218
+ v
195
219
  );
196
- U.displayName = "KendoReactColorPalette";
220
+ pe.displayName = "KendoReactColorPalette";
221
+ const ke = v;
197
222
  export {
198
- U as ColorPalette,
199
- L as ColorPalettePropsContext,
200
- d as ColorPaletteWithoutContext,
201
- C as DEFAULT_COLUMNS_COUNT,
202
- D as DEFAULT_PRESET,
203
- I as DEFAULT_TILE_SIZE
223
+ pe as ColorPalette,
224
+ Ce as ColorPalettePropsContext,
225
+ ke as ColorPaletteWithoutContext,
226
+ de as DEFAULT_COLUMNS_COUNT,
227
+ fe as DEFAULT_PRESET,
228
+ ue as DEFAULT_TILE_SIZE,
229
+ F as defaultColorPaletteProps
204
230
  };