@cratis/scene.primereact 4.5.0 → 4.6.0
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/README.md +25 -3
- package/chart/ChartGallery.stories.tsx +63 -0
- package/chart/ChartType.ts +14 -0
- package/chart/ChartTypeResolution.ts +14 -0
- package/chart/PrimeChart.tsx +62 -0
- package/chart/chartHasData.ts +22 -0
- package/chart/chartTypeChoices.ts +32 -0
- package/chart/index.ts +7 -0
- package/chart/resolveChartType.ts +61 -0
- package/chart/useChart.ts +61 -0
- package/dist/cjs/chart/ChartType.js +18 -0
- package/dist/cjs/chart/ChartType.js.map +1 -0
- package/dist/cjs/chart/PrimeChart.js +92 -0
- package/dist/cjs/chart/PrimeChart.js.map +1 -0
- package/dist/cjs/chart/chartHasData.js +24 -0
- package/dist/cjs/chart/chartHasData.js.map +1 -0
- package/dist/cjs/chart/chartTypeChoices.js +43 -0
- package/dist/cjs/chart/chartTypeChoices.js.map +1 -0
- package/dist/cjs/chart/resolveChartType.js +69 -0
- package/dist/cjs/chart/resolveChartType.js.map +1 -0
- package/dist/cjs/chart/useChart.js +62 -0
- package/dist/cjs/chart/useChart.js.map +1 -0
- package/dist/cjs/form/MultiStateGlyph.js +59 -0
- package/dist/cjs/form/MultiStateGlyph.js.map +1 -0
- package/dist/cjs/form/PrimeMultiStateCheckbox.js +123 -0
- package/dist/cjs/form/PrimeMultiStateCheckbox.js.map +1 -0
- package/dist/cjs/form/multiStateOptions.js +77 -0
- package/dist/cjs/form/multiStateOptions.js.map +1 -0
- package/dist/cjs/form/multiStateStates.js +32 -0
- package/dist/cjs/form/multiStateStates.js.map +1 -0
- package/dist/cjs/form/useMultiStateSelection.js +51 -0
- package/dist/cjs/form/useMultiStateSelection.js.map +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/primeReactComponents.js +5 -0
- package/dist/cjs/primeReactComponents.js.map +1 -1
- package/dist/cjs/primeReactDescriptors.js +157 -0
- package/dist/cjs/primeReactDescriptors.js.map +1 -0
- package/dist/cjs/primeReactPackage.js +4 -0
- package/dist/cjs/primeReactPackage.js.map +1 -1
- package/dist/cjs/properties.js +11 -0
- package/dist/cjs/properties.js.map +1 -1
- package/dist/cjs/structurallyEqual.js +27 -0
- package/dist/cjs/structurallyEqual.js.map +1 -0
- package/dist/cjs/useStructuralValue.js +20 -0
- package/dist/cjs/useStructuralValue.js.map +1 -0
- package/dist/esm/chart/ChartGallery.stories.d.ts +14 -0
- package/dist/esm/chart/ChartGallery.stories.d.ts.map +1 -0
- package/dist/esm/chart/ChartGallery.stories.js +47 -0
- package/dist/esm/chart/ChartGallery.stories.js.map +1 -0
- package/dist/esm/chart/ChartType.d.ts +11 -0
- package/dist/esm/chart/ChartType.d.ts.map +1 -0
- package/dist/esm/chart/ChartType.js +16 -0
- package/dist/esm/chart/ChartType.js.map +1 -0
- package/dist/esm/chart/ChartTypeResolution.d.ts +10 -0
- package/dist/esm/chart/ChartTypeResolution.d.ts.map +1 -0
- package/dist/esm/chart/ChartTypeResolution.js +2 -0
- package/dist/esm/chart/ChartTypeResolution.js.map +1 -0
- package/dist/esm/chart/PrimeChart.d.ts +3 -0
- package/dist/esm/chart/PrimeChart.d.ts.map +1 -0
- package/dist/esm/chart/PrimeChart.js +90 -0
- package/dist/esm/chart/PrimeChart.js.map +1 -0
- package/dist/esm/chart/chartHasData.d.ts +2 -0
- package/dist/esm/chart/chartHasData.d.ts.map +1 -0
- package/dist/esm/chart/chartHasData.js +22 -0
- package/dist/esm/chart/chartHasData.js.map +1 -0
- package/dist/esm/chart/chartTypeChoices.d.ts +3 -0
- package/dist/esm/chart/chartTypeChoices.d.ts.map +1 -0
- package/dist/esm/chart/chartTypeChoices.js +41 -0
- package/dist/esm/chart/chartTypeChoices.js.map +1 -0
- package/dist/esm/chart/index.d.ts +5 -0
- package/dist/esm/chart/index.d.ts.map +1 -0
- package/dist/esm/chart/index.js +5 -0
- package/dist/esm/chart/index.js.map +1 -0
- package/dist/esm/chart/resolveChartType.d.ts +6 -0
- package/dist/esm/chart/resolveChartType.d.ts.map +1 -0
- package/dist/esm/chart/resolveChartType.js +66 -0
- package/dist/esm/chart/resolveChartType.js.map +1 -0
- package/dist/esm/chart/useChart.d.ts +4 -0
- package/dist/esm/chart/useChart.d.ts.map +1 -0
- package/dist/esm/chart/useChart.js +60 -0
- package/dist/esm/chart/useChart.js.map +1 -0
- package/dist/esm/form/FormGallery.stories.d.ts.map +1 -1
- package/dist/esm/form/FormGallery.stories.js +8 -0
- package/dist/esm/form/FormGallery.stories.js.map +1 -1
- package/dist/esm/form/MultiStateGlyph.d.ts +8 -0
- package/dist/esm/form/MultiStateGlyph.d.ts.map +1 -0
- package/dist/esm/form/MultiStateGlyph.js +57 -0
- package/dist/esm/form/MultiStateGlyph.js.map +1 -0
- package/dist/esm/form/MultiStateOption.d.ts +7 -0
- package/dist/esm/form/MultiStateOption.d.ts.map +1 -0
- package/dist/esm/form/MultiStateOption.js +2 -0
- package/dist/esm/form/MultiStateOption.js.map +1 -0
- package/dist/esm/form/PrimeMultiStateCheckbox.d.ts +3 -0
- package/dist/esm/form/PrimeMultiStateCheckbox.d.ts.map +1 -0
- package/dist/esm/form/PrimeMultiStateCheckbox.js +121 -0
- package/dist/esm/form/PrimeMultiStateCheckbox.js.map +1 -0
- package/dist/esm/form/index.d.ts +1 -0
- package/dist/esm/form/index.d.ts.map +1 -1
- package/dist/esm/form/index.js +1 -0
- package/dist/esm/form/index.js.map +1 -1
- package/dist/esm/form/multiStateOptions.d.ts +4 -0
- package/dist/esm/form/multiStateOptions.d.ts.map +1 -0
- package/dist/esm/form/multiStateOptions.js +75 -0
- package/dist/esm/form/multiStateOptions.js.map +1 -0
- package/dist/esm/form/multiStateStates.d.ts +4 -0
- package/dist/esm/form/multiStateStates.d.ts.map +1 -0
- package/dist/esm/form/multiStateStates.js +30 -0
- package/dist/esm/form/multiStateStates.js.map +1 -0
- package/dist/esm/form/useMultiStateSelection.d.ts +6 -0
- package/dist/esm/form/useMultiStateSelection.d.ts.map +1 -0
- package/dist/esm/form/useMultiStateSelection.js +49 -0
- package/dist/esm/form/useMultiStateSelection.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/primeReactComponents.d.ts.map +1 -1
- package/dist/esm/primeReactComponents.js +5 -0
- package/dist/esm/primeReactComponents.js.map +1 -1
- package/dist/esm/primeReactDescriptors.d.ts +3 -0
- package/dist/esm/primeReactDescriptors.d.ts.map +1 -0
- package/dist/esm/primeReactDescriptors.js +155 -0
- package/dist/esm/primeReactDescriptors.js.map +1 -0
- package/dist/esm/primeReactPackage.d.ts.map +1 -1
- package/dist/esm/primeReactPackage.js +4 -0
- package/dist/esm/primeReactPackage.js.map +1 -1
- package/dist/esm/properties.d.ts +1 -0
- package/dist/esm/properties.d.ts.map +1 -1
- package/dist/esm/properties.js +11 -1
- package/dist/esm/properties.js.map +1 -1
- package/dist/esm/structurallyEqual.d.ts +2 -0
- package/dist/esm/structurallyEqual.d.ts.map +1 -0
- package/dist/esm/structurallyEqual.js +25 -0
- package/dist/esm/structurallyEqual.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/useStructuralValue.d.ts +2 -0
- package/dist/esm/useStructuralValue.d.ts.map +1 -0
- package/dist/esm/useStructuralValue.js +18 -0
- package/dist/esm/useStructuralValue.js.map +1 -0
- package/form/FormGallery.stories.tsx +8 -0
- package/form/MultiStateGlyph.tsx +55 -0
- package/form/MultiStateOption.ts +17 -0
- package/form/PrimeMultiStateCheckbox.tsx +101 -0
- package/form/index.ts +1 -0
- package/form/multiStateOptions.ts +78 -0
- package/form/multiStateStates.ts +23 -0
- package/form/useMultiStateSelection.ts +48 -0
- package/index.ts +2 -0
- package/package.json +17 -7
- package/primeReactComponents.ts +4 -0
- package/primeReactDescriptors.ts +48 -0
- package/primeReactPackage.ts +4 -2
- package/properties.ts +14 -0
- package/structurallyEqual.ts +29 -0
- package/useStructuralValue.ts +17 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { SceneIcon } from '@cratis/scene.react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The box a multi-state checkbox draws, themed with the PrimeReact checkbox tokens (`--p-checkbox-*`), so
|
|
6
|
+
* it follows the active Scene theme and looks like its sibling `checkbox`. It holds the state's icon - a
|
|
7
|
+
* PrimeIcons class or a qualified icon reference - or a check mark when the state has no icon of its own.
|
|
8
|
+
* An empty state draws only its own icon, if it has one. It is decorative: the state is announced through the control's text, not through this glyph.
|
|
9
|
+
*/ function MultiStateGlyph({ state, isEmpty, isInactive }) {
|
|
10
|
+
const icon = state?.icon;
|
|
11
|
+
return /*#__PURE__*/ jsx("span", {
|
|
12
|
+
"aria-hidden": "true",
|
|
13
|
+
"data-scene-part": "glyph",
|
|
14
|
+
style: {
|
|
15
|
+
display: 'inline-flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
flexShrink: 0,
|
|
19
|
+
boxSizing: 'border-box',
|
|
20
|
+
width: 'var(--p-checkbox-width, 1.125rem)',
|
|
21
|
+
height: 'var(--p-checkbox-height, 1.125rem)',
|
|
22
|
+
borderRadius: 'var(--p-checkbox-border-radius, 4px)',
|
|
23
|
+
border: `1px solid ${isEmpty ? 'var(--p-checkbox-border-color, currentColor)' : 'var(--p-checkbox-checked-border-color, currentColor)'}`,
|
|
24
|
+
backgroundColor: isEmpty ? 'var(--p-checkbox-background, transparent)' : 'var(--p-checkbox-checked-background, currentColor)',
|
|
25
|
+
color: glyphColor(isEmpty, isInactive),
|
|
26
|
+
fontSize: 'var(--p-checkbox-icon-size, 0.75rem)'
|
|
27
|
+
},
|
|
28
|
+
children: icon === undefined ? !isEmpty && /*#__PURE__*/ jsx(CheckMark, {}) : typeof icon === 'string' ? /*#__PURE__*/ jsx("i", {
|
|
29
|
+
className: icon
|
|
30
|
+
}) : /*#__PURE__*/ jsx(SceneIcon, {
|
|
31
|
+
reference: icon,
|
|
32
|
+
size: "var(--p-checkbox-icon-size, 0.75rem)"
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function glyphColor(isEmpty, isInactive) {
|
|
37
|
+
if (isInactive) return 'var(--p-checkbox-icon-disabled-color, currentColor)';
|
|
38
|
+
return isEmpty ? 'var(--p-checkbox-icon-color, currentColor)' : 'var(--p-checkbox-icon-checked-color, Canvas)';
|
|
39
|
+
}
|
|
40
|
+
function CheckMark() {
|
|
41
|
+
return /*#__PURE__*/ jsx("svg", {
|
|
42
|
+
viewBox: "0 0 12 12",
|
|
43
|
+
width: "1em",
|
|
44
|
+
height: "1em",
|
|
45
|
+
fill: "none",
|
|
46
|
+
stroke: "currentColor",
|
|
47
|
+
strokeWidth: "2",
|
|
48
|
+
strokeLinecap: "round",
|
|
49
|
+
strokeLinejoin: "round",
|
|
50
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
51
|
+
d: "M2 6.5 5 9.5 10 3"
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { MultiStateGlyph };
|
|
57
|
+
//# sourceMappingURL=MultiStateGlyph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiStateGlyph.js","sources":["../../../form/MultiStateGlyph.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneIcon } from '@cratis/scene.react';\nimport { MultiStateOption } from './MultiStateOption';\n\nexport interface MultiStateGlyphProps {\n /** The state being shown. */\n state: MultiStateOption | undefined;\n\n /** Whether the state is the empty (`null`) state, drawn as an empty box. */\n isEmpty: boolean;\n\n /** Whether the control is disabled or read only. */\n isInactive: boolean;\n}\n\n/**\n * The box a multi-state checkbox draws, themed with the PrimeReact checkbox tokens (`--p-checkbox-*`), so\n * it follows the active Scene theme and looks like its sibling `checkbox`. It holds the state's icon - a\n * PrimeIcons class or a qualified icon reference - or a check mark when the state has no icon of its own.\n * An empty state draws only its own icon, if it has one. It is decorative: the state is announced through the control's text, not through this glyph.\n */\nexport function MultiStateGlyph({ state, isEmpty, isInactive }: MultiStateGlyphProps) {\n const icon = state?.icon;\n return (\n <span\n aria-hidden='true'\n data-scene-part='glyph'\n style={{\n display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, boxSizing: 'border-box',\n width: 'var(--p-checkbox-width, 1.125rem)', height: 'var(--p-checkbox-height, 1.125rem)',\n borderRadius: 'var(--p-checkbox-border-radius, 4px)',\n border: `1px solid ${isEmpty ? 'var(--p-checkbox-border-color, currentColor)' : 'var(--p-checkbox-checked-border-color, currentColor)'}`,\n backgroundColor: isEmpty ? 'var(--p-checkbox-background, transparent)' : 'var(--p-checkbox-checked-background, currentColor)',\n color: glyphColor(isEmpty, isInactive),\n fontSize: 'var(--p-checkbox-icon-size, 0.75rem)',\n }}>\n {icon === undefined ? !isEmpty && <CheckMark /> : typeof icon === 'string' ? <i className={icon} /> : <SceneIcon reference={icon} size='var(--p-checkbox-icon-size, 0.75rem)' />}\n </span>\n );\n}\n\nfunction glyphColor(isEmpty: boolean, isInactive: boolean): string {\n if (isInactive) return 'var(--p-checkbox-icon-disabled-color, currentColor)';\n return isEmpty ? 'var(--p-checkbox-icon-color, currentColor)' : 'var(--p-checkbox-icon-checked-color, Canvas)';\n}\n\nfunction CheckMark() {\n return (\n <svg viewBox='0 0 12 12' width='1em' height='1em' fill='none' stroke='currentColor' strokeWidth='2' strokeLinecap='round' strokeLinejoin='round'>\n <path d='M2 6.5 5 9.5 10 3' />\n </svg>\n );\n}\n"],"names":["MultiStateGlyph","state","isEmpty","isInactive","icon","_jsx","span","aria-hidden","data-scene-part","style","display","alignItems","justifyContent","flexShrink","boxSizing","width","height","borderRadius","border","backgroundColor","color","glyphColor","fontSize","undefined","CheckMark","i","className","SceneIcon","reference","size","svg","viewBox","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","path","d"],"mappings":";;;AAiBA;;;;;IAMO,SAASA,eAAAA,CAAgB,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAwB,EAAA;AAChF,IAAA,MAAMC,OAAOH,KAAAA,EAAOG,IAAAA;AACpB,IAAA,qBACIC,GAAA,CAACC,MAAAA,EAAAA;QACGC,aAAAA,EAAY,MAAA;QACZC,iBAAAA,EAAgB,OAAA;QAChBC,KAAAA,EAAO;YACHC,OAAAA,EAAS,aAAA;YAAeC,UAAAA,EAAY,QAAA;YAAUC,cAAAA,EAAgB,QAAA;YAAUC,UAAAA,EAAY,CAAA;YAAGC,SAAAA,EAAW,YAAA;YAClGC,KAAAA,EAAO,mCAAA;YAAqCC,MAAAA,EAAQ,oCAAA;YACpDC,YAAAA,EAAc,sCAAA;AACdC,YAAAA,MAAAA,EAAQ,CAAC,UAAU,EAAEhB,OAAAA,GAAU,iDAAiD,sDAAA,CAAA,CAAwD;AACxIiB,YAAAA,eAAAA,EAAiBjB,UAAU,2CAAA,GAA8C,oDAAA;AACzEkB,YAAAA,KAAAA,EAAOC,WAAWnB,OAAAA,EAASC,UAAAA,CAAAA;YAC3BmB,QAAAA,EAAU;AACd,SAAA;kBACClB,IAAAA,KAASmB,SAAAA,GAAY,CAACrB,OAAAA,kBAAWG,GAAA,CAACmB,iBAAe,OAAOpB,IAAAA,KAAS,yBAAWC,GAAA,CAACoB,GAAAA,EAAAA;YAAEC,SAAAA,EAAWtB;2BAAWC,GAAA,CAACsB,SAAAA,EAAAA;YAAUC,SAAAA,EAAWxB,IAAAA;YAAMyB,IAAAA,EAAK;;;AAGnJ;AAEA,SAASR,UAAAA,CAAWnB,OAAgB,EAAEC,UAAmB,EAAA;AACrD,IAAA,IAAIA,YAAY,OAAO,qDAAA;AACvB,IAAA,OAAOD,UAAU,4CAAA,GAA+C,8CAAA;AACpE;AAEA,SAASsB,SAAAA,GAAAA;AACL,IAAA,qBACInB,GAAA,CAACyB,KAAAA,EAAAA;QAAIC,OAAAA,EAAQ,WAAA;QAAYhB,KAAAA,EAAM,KAAA;QAAMC,MAAAA,EAAO,KAAA;QAAMgB,IAAAA,EAAK,MAAA;QAAOC,MAAAA,EAAO,cAAA;QAAeC,WAAAA,EAAY,GAAA;QAAIC,aAAAA,EAAc,OAAA;QAAQC,cAAAA,EAAe,OAAA;AACrI,QAAA,QAAA,gBAAA/B,GAAA,CAACgC,MAAAA,EAAAA;YAAKC,CAAAA,EAAE;;;AAGpB;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiStateOption.d.ts","sourceRoot":"","sources":["../../../form/MultiStateOption.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpD,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiStateOption.js","sourceRoot":"","sources":["../../../form/MultiStateOption.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrimeMultiStateCheckbox.d.ts","sourceRoot":"","sources":["../../../form/PrimeMultiStateCheckbox.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AA6B/D,wBAAgB,uBAAuB,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,wBAAwB,+BAqD1F"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useId, useState } from 'react';
|
|
3
|
+
import { isIconReference } from '@cratis/scene.model';
|
|
4
|
+
import { booleanProperty, stringProperty } from '../properties.js';
|
|
5
|
+
import { MultiStateGlyph } from './MultiStateGlyph.js';
|
|
6
|
+
import { multiStateOptions } from './multiStateOptions.js';
|
|
7
|
+
import { multiStateStates } from './multiStateStates.js';
|
|
8
|
+
import { useMultiStateSelection } from './useMultiStateSelection.js';
|
|
9
|
+
|
|
10
|
+
const visuallyHidden = {
|
|
11
|
+
position: 'absolute',
|
|
12
|
+
width: 1,
|
|
13
|
+
height: 1,
|
|
14
|
+
margin: -1,
|
|
15
|
+
padding: 0,
|
|
16
|
+
overflow: 'hidden',
|
|
17
|
+
clip: 'rect(0 0 0 0)',
|
|
18
|
+
whiteSpace: 'nowrap',
|
|
19
|
+
border: 0
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The `PrimeReact:multiStateCheckbox` component.
|
|
23
|
+
*
|
|
24
|
+
* PrimeReact 11 removed MultiStateCheckbox, so Scene renders its original behavior with a native button.
|
|
25
|
+
* It cycles through the authored states in order, including the optional empty (`null`) state, and keeps
|
|
26
|
+
* option values and icons exactly as the element carries them. Each click moves one step; the position is
|
|
27
|
+
* an index, so duplicated or `null` option values do not make later states unreachable.
|
|
28
|
+
*
|
|
29
|
+
* Accessibility: a state cycle is not a true/false choice, so the control does not claim `checkbox`
|
|
30
|
+
* semantics (every non-empty state would announce as "checked"). It is a button whose name is the authored
|
|
31
|
+
* `ariaLabel`, whose description is the current state, and whose state changes are announced through a
|
|
32
|
+
* polite live region. `readOnly` keeps the control focusable and unchanged; `disabled` removes it from the
|
|
33
|
+
* tab order.
|
|
34
|
+
*
|
|
35
|
+
* The control follows the document: a changed `value` or `options` restarts the cycle from the new value,
|
|
36
|
+
* so an inspector edit is reflected immediately. It does not report its own selection to behaviors -
|
|
37
|
+
* Scene's interaction handlers carry no value.
|
|
38
|
+
*/ function PrimeMultiStateCheckbox({ element, interactions }) {
|
|
39
|
+
const stateId = useId();
|
|
40
|
+
const allowEmpty = booleanProperty(element, 'empty', true);
|
|
41
|
+
const emptyLabel = stringProperty(element, 'emptyLabel', 'No selection');
|
|
42
|
+
const emptyIcon = element.properties.emptyIcon;
|
|
43
|
+
const states = multiStateStates(multiStateOptions(element, emptyLabel), allowEmpty, emptyLabel, typeof emptyIcon === 'string' || isIconReference(emptyIcon) ? emptyIcon : undefined);
|
|
44
|
+
const authored = element.properties.value;
|
|
45
|
+
const { index, advance } = useMultiStateSelection(states, authored === undefined && allowEmpty ? null : authored);
|
|
46
|
+
const [focused, setFocused] = useState(false);
|
|
47
|
+
const selected = states[index];
|
|
48
|
+
const readOnly = booleanProperty(element, 'readOnly', false);
|
|
49
|
+
const disabled = !element.isEnabled || booleanProperty(element, 'disabled', false) || states.length === 0;
|
|
50
|
+
const ariaLabel = stringProperty(element, 'ariaLabel', element.name || 'Multi-state checkbox');
|
|
51
|
+
const stateText = selected?.label ?? stringProperty(element, 'placeholder', unmatchedText(states.length, authored, emptyLabel));
|
|
52
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ jsxs("button", {
|
|
55
|
+
type: "button",
|
|
56
|
+
"data-scene-id": element.id,
|
|
57
|
+
"data-scene-component": "multiStateCheckbox",
|
|
58
|
+
"data-scene-state-index": index,
|
|
59
|
+
"aria-label": ariaLabel,
|
|
60
|
+
"aria-describedby": stateId,
|
|
61
|
+
"aria-disabled": readOnly ? true : undefined,
|
|
62
|
+
disabled: disabled,
|
|
63
|
+
style: {
|
|
64
|
+
display: 'inline-flex',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
gap: '0.5rem',
|
|
67
|
+
padding: 0,
|
|
68
|
+
border: 0,
|
|
69
|
+
background: 'none',
|
|
70
|
+
font: 'inherit',
|
|
71
|
+
color: 'inherit',
|
|
72
|
+
cursor: disabled ? 'not-allowed' : readOnly ? 'default' : 'pointer',
|
|
73
|
+
opacity: disabled ? 0.6 : 1,
|
|
74
|
+
outline: focused ? 'var(--p-focus-ring-width, 2px) var(--p-focus-ring-style, solid) var(--p-focus-ring-color, currentColor)' : 'none',
|
|
75
|
+
outlineOffset: 'var(--p-focus-ring-offset, 2px)'
|
|
76
|
+
},
|
|
77
|
+
onFocus: (event)=>setFocused(isFocusVisible(event.currentTarget)),
|
|
78
|
+
onBlur: ()=>setFocused(false),
|
|
79
|
+
onClick: (event)=>{
|
|
80
|
+
if (!readOnly) advance();
|
|
81
|
+
interactions?.onClick?.(event);
|
|
82
|
+
if (readOnly) return;
|
|
83
|
+
interactions?.onChange?.();
|
|
84
|
+
interactions?.onSelect?.();
|
|
85
|
+
},
|
|
86
|
+
onDoubleClick: interactions?.onDoubleClick,
|
|
87
|
+
children: [
|
|
88
|
+
/*#__PURE__*/ jsx(MultiStateGlyph, {
|
|
89
|
+
state: selected,
|
|
90
|
+
isEmpty: selected === undefined || selected.value === null,
|
|
91
|
+
isInactive: disabled || readOnly
|
|
92
|
+
}),
|
|
93
|
+
/*#__PURE__*/ jsx("span", {
|
|
94
|
+
"aria-hidden": "true",
|
|
95
|
+
children: stateText
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ jsx("span", {
|
|
100
|
+
id: stateId,
|
|
101
|
+
role: "status",
|
|
102
|
+
style: visuallyHidden,
|
|
103
|
+
children: stateText
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function unmatchedText(stateCount, authored, emptyLabel) {
|
|
109
|
+
if (stateCount === 0) return 'No states';
|
|
110
|
+
return authored === undefined ? emptyLabel : 'No matching state';
|
|
111
|
+
}
|
|
112
|
+
function isFocusVisible(target) {
|
|
113
|
+
try {
|
|
114
|
+
return target.matches(':focus-visible');
|
|
115
|
+
} catch {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { PrimeMultiStateCheckbox };
|
|
121
|
+
//# sourceMappingURL=PrimeMultiStateCheckbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrimeMultiStateCheckbox.js","sources":["../../../form/PrimeMultiStateCheckbox.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { CSSProperties, useId, useState } from 'react';\nimport { isIconReference } from '@cratis/scene.model';\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { booleanProperty, stringProperty } from '../properties';\nimport { MultiStateGlyph } from './MultiStateGlyph';\nimport { multiStateOptions } from './multiStateOptions';\nimport { multiStateStates } from './multiStateStates';\nimport { useMultiStateSelection } from './useMultiStateSelection';\n\nconst visuallyHidden: CSSProperties = {\n position: 'absolute', width: 1, height: 1, margin: -1, padding: 0, overflow: 'hidden', clip: 'rect(0 0 0 0)', whiteSpace: 'nowrap', border: 0,\n};\n\n/**\n * The `PrimeReact:multiStateCheckbox` component.\n *\n * PrimeReact 11 removed MultiStateCheckbox, so Scene renders its original behavior with a native button.\n * It cycles through the authored states in order, including the optional empty (`null`) state, and keeps\n * option values and icons exactly as the element carries them. Each click moves one step; the position is\n * an index, so duplicated or `null` option values do not make later states unreachable.\n *\n * Accessibility: a state cycle is not a true/false choice, so the control does not claim `checkbox`\n * semantics (every non-empty state would announce as \"checked\"). It is a button whose name is the authored\n * `ariaLabel`, whose description is the current state, and whose state changes are announced through a\n * polite live region. `readOnly` keeps the control focusable and unchanged; `disabled` removes it from the\n * tab order.\n *\n * The control follows the document: a changed `value` or `options` restarts the cycle from the new value,\n * so an inspector edit is reflected immediately. It does not report its own selection to behaviors -\n * Scene's interaction handlers carry no value.\n */\nexport function PrimeMultiStateCheckbox({ element, interactions }: RegisteredComponentProps) {\n const stateId = useId();\n const allowEmpty = booleanProperty(element, 'empty', true);\n const emptyLabel = stringProperty(element, 'emptyLabel', 'No selection');\n const emptyIcon = element.properties.emptyIcon;\n const states = multiStateStates(\n multiStateOptions(element, emptyLabel),\n allowEmpty,\n emptyLabel,\n typeof emptyIcon === 'string' || isIconReference(emptyIcon) ? emptyIcon : undefined);\n const authored = element.properties.value;\n const { index, advance } = useMultiStateSelection(states, authored === undefined && allowEmpty ? null : authored);\n const [focused, setFocused] = useState(false);\n\n const selected = states[index];\n const readOnly = booleanProperty(element, 'readOnly', false);\n const disabled = !element.isEnabled || booleanProperty(element, 'disabled', false) || states.length === 0;\n const ariaLabel = stringProperty(element, 'ariaLabel', element.name || 'Multi-state checkbox');\n const stateText = selected?.label ?? stringProperty(element, 'placeholder', unmatchedText(states.length, authored, emptyLabel));\n\n return (\n <>\n <button\n type='button'\n data-scene-id={element.id}\n data-scene-component='multiStateCheckbox'\n data-scene-state-index={index}\n aria-label={ariaLabel}\n aria-describedby={stateId}\n aria-disabled={readOnly ? true : undefined}\n disabled={disabled}\n style={{\n display: 'inline-flex', alignItems: 'center', gap: '0.5rem', padding: 0, border: 0, background: 'none', font: 'inherit',\n color: 'inherit', cursor: disabled ? 'not-allowed' : readOnly ? 'default' : 'pointer', opacity: disabled ? 0.6 : 1,\n outline: focused ? 'var(--p-focus-ring-width, 2px) var(--p-focus-ring-style, solid) var(--p-focus-ring-color, currentColor)' : 'none',\n outlineOffset: 'var(--p-focus-ring-offset, 2px)',\n }}\n onFocus={(event) => setFocused(isFocusVisible(event.currentTarget))}\n onBlur={() => setFocused(false)}\n onClick={(event) => {\n if (!readOnly) advance();\n interactions?.onClick?.(event);\n if (readOnly) return;\n interactions?.onChange?.();\n interactions?.onSelect?.();\n }}\n onDoubleClick={interactions?.onDoubleClick}>\n <MultiStateGlyph state={selected} isEmpty={selected === undefined || selected.value === null} isInactive={disabled || readOnly} />\n <span aria-hidden='true'>{stateText}</span>\n </button>\n <span id={stateId} role='status' style={visuallyHidden}>{stateText}</span>\n </>\n );\n}\n\nfunction unmatchedText(stateCount: number, authored: unknown, emptyLabel: string): string {\n if (stateCount === 0) return 'No states';\n return authored === undefined ? emptyLabel : 'No matching state';\n}\n\nfunction isFocusVisible(target: HTMLElement): boolean {\n try {\n return target.matches(':focus-visible');\n } catch {\n return true;\n }\n}\n"],"names":["visuallyHidden","position","width","height","margin","padding","overflow","clip","whiteSpace","border","PrimeMultiStateCheckbox","element","interactions","stateId","useId","allowEmpty","booleanProperty","emptyLabel","stringProperty","emptyIcon","properties","states","multiStateStates","multiStateOptions","isIconReference","undefined","authored","value","index","advance","useMultiStateSelection","focused","setFocused","useState","selected","readOnly","disabled","isEnabled","length","ariaLabel","name","stateText","label","unmatchedText","_jsxs","_Fragment","button","type","data-scene-id","id","data-scene-component","data-scene-state-index","aria-label","aria-describedby","aria-disabled","style","display","alignItems","gap","background","font","color","cursor","opacity","outline","outlineOffset","onFocus","event","isFocusVisible","currentTarget","onBlur","onClick","onChange","onSelect","onDoubleClick","_jsx","MultiStateGlyph","state","isEmpty","isInactive","span","aria-hidden","role","stateCount","target","matches"],"mappings":";;;;;;;;;AAYA,MAAMA,cAAAA,GAAgC;IAClCC,QAAAA,EAAU,UAAA;IAAYC,KAAAA,EAAO,CAAA;IAAGC,MAAAA,EAAQ,CAAA;AAAGC,IAAAA,MAAAA,EAAQ,EAAC;IAAGC,OAAAA,EAAS,CAAA;IAAGC,QAAAA,EAAU,QAAA;IAAUC,IAAAA,EAAM,eAAA;IAAiBC,UAAAA,EAAY,QAAA;IAAUC,MAAAA,EAAQ;AAChJ,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBC,IACM,SAASC,uBAAAA,CAAwB,EAAEC,OAAO,EAAEC,YAAY,EAA4B,EAAA;AACvF,IAAA,MAAMC,OAAAA,GAAUC,KAAAA,EAAAA;IAChB,MAAMC,UAAAA,GAAaC,eAAAA,CAAgBL,OAAAA,EAAS,OAAA,EAAS,IAAA,CAAA;IACrD,MAAMM,UAAAA,GAAaC,cAAAA,CAAeP,OAAAA,EAAS,YAAA,EAAc,cAAA,CAAA;AACzD,IAAA,MAAMQ,SAAAA,GAAYR,OAAAA,CAAQS,UAAU,CAACD,S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8D,aAAAA;;kCAC7BC,GAAA,CAACC,eAAAA,EAAAA;wBAAgBC,KAAAA,EAAO3C,QAAAA;AAAU4C,wBAAAA,OAAAA,EAAS5C,QAAAA,KAAaT,SAAAA,IAAaS,QAAAA,CAASP,KAAK,KAAK,IAAA;AAAMoD,wBAAAA,UAAAA,EAAY3C,QAAAA,IAAYD;;kCACtHwC,GAAA,CAACK,MAAAA,EAAAA;wBAAKC,aAAAA,EAAY,MAAA;AAAQxC,wBAAAA,QAAAA,EAAAA;;;;0BAE9BkC,GAAA,CAACK,MAAAA,EAAAA;gBAAK/B,EAAAA,EAAIpC,OAAAA;gBAASqE,IAAAA,EAAK,QAAA;gBAAS3B,KAAAA,EAAOvD,cAAAA;AAAiByC,gBAAAA,QAAAA,EAAAA;;;;AAGrE;AAEA,SAASE,aAAAA,CAAcwC,UAAkB,EAAEzD,QAAiB,EAAET,UAAkB,EAAA;IAC5E,IAAIkE,UAAAA,KAAe,GAAG,OAAO,WAAA;IAC7B,OAAOzD,QAAAA,KAAaD,YAAYR,UAAAA,GAAa,mBAAA;AACjD;AAEA,SAASmD,eAAegB,MAAmB,EAAA;IACvC,IAAI;QACA,OAAOA,MAAAA,CAAOC,OAAO,CAAC,gBAAA,CAAA;AAC1B,IAAA,CAAA,CAAE,OAAM;QACJ,OAAO,IAAA;AACX,IAAA;AACJ;;"}
|
package/dist/esm/form/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './PrimeMultiSelect';
|
|
|
9
9
|
export * from './PrimeListBox';
|
|
10
10
|
export * from './PrimeSelectButton';
|
|
11
11
|
export * from './PrimeCheckbox';
|
|
12
|
+
export * from './PrimeMultiStateCheckbox';
|
|
12
13
|
export * from './PrimeRadioButton';
|
|
13
14
|
export * from './PrimeToggleSwitch';
|
|
14
15
|
export * from './PrimeSlider';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../form/index.ts"],"names":[],"mappings":"AAGA,c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cAAc,mBAAmB,CAAC"}
|
package/dist/esm/form/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './PrimeMultiSelect';
|
|
|
9
9
|
export * from './PrimeListBox';
|
|
10
10
|
export * from './PrimeSelectButton';
|
|
11
11
|
export * from './PrimeCheckbox';
|
|
12
|
+
export * from './PrimeMultiStateCheckbox';
|
|
12
13
|
export * from './PrimeRadioButton';
|
|
13
14
|
export * from './PrimeToggleSwitch';
|
|
14
15
|
export * from './PrimeSlider';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../form/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../form/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiStateOptions.d.ts","sourceRoot":"","sources":["../../../form/multiStateOptions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAmB,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAgBtD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAY/F"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { isIconReference } from '@cratis/scene.model';
|
|
2
|
+
import { stringProperty, arrayProperty } from '../properties.js';
|
|
3
|
+
|
|
4
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
5
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
6
|
+
/**
|
|
7
|
+
* Reads multi-state options without reshaping their values, dropping any of them, or changing their order.
|
|
8
|
+
*
|
|
9
|
+
* This follows the original PrimeReact control. An option that is a record gives its value through
|
|
10
|
+
* `optionValue` (default, and when that field is absent: its `value` field, and the whole option when it has none) and its label through
|
|
11
|
+
* `optionLabel` (default: its `label` field). Any other option - a string, number, boolean, `null` or an
|
|
12
|
+
* array - is its own value. A label that is not text is shown as its JSON, so a numeric or boolean label,
|
|
13
|
+
* or an option with no label at all, still produces a state the user can reach. A `null` value with no
|
|
14
|
+
* label of its own is labeled with `emptyLabel`.
|
|
15
|
+
*
|
|
16
|
+
* A state's icon is, in order: the option's own `icon`, then the entry of the element's `icons` that is
|
|
17
|
+
* aligned with the option (an array) or keyed by its value (an object). Either may be a PrimeIcons class
|
|
18
|
+
* name, kept for legacy documents, or a qualified {@link IconReference}.
|
|
19
|
+
*/ function multiStateOptions(element, emptyLabel) {
|
|
20
|
+
const labelPath = stringProperty(element, 'optionLabel');
|
|
21
|
+
const valuePath = stringProperty(element, 'optionValue');
|
|
22
|
+
const icons = element.properties.icons;
|
|
23
|
+
return arrayProperty(element, 'options').map((option, index)=>{
|
|
24
|
+
const record = isRecord(option) ? option : undefined;
|
|
25
|
+
const value = record === undefined ? option : valueOf(record, valuePath);
|
|
26
|
+
const label = record === undefined ? undefined : resolvePath(record, labelPath ?? 'label');
|
|
27
|
+
const icon = toIcon(record?.icon) ?? iconAt(icons, value, index);
|
|
28
|
+
return {
|
|
29
|
+
label: labelText(label, value, emptyLabel),
|
|
30
|
+
value,
|
|
31
|
+
...icon === undefined ? {} : {
|
|
32
|
+
icon
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function valueOf(record, valuePath) {
|
|
38
|
+
const authored = valuePath === undefined ? undefined : resolvePath(record, valuePath);
|
|
39
|
+
if (authored !== undefined) return authored;
|
|
40
|
+
return record.value !== undefined ? record.value : record;
|
|
41
|
+
}
|
|
42
|
+
function resolvePath(record, path) {
|
|
43
|
+
if (Object.hasOwn(record, path)) return record[path];
|
|
44
|
+
let current = record;
|
|
45
|
+
for (const segment of path.split('.')){
|
|
46
|
+
if (!isRecord(current) || !Object.hasOwn(current, segment)) return undefined;
|
|
47
|
+
current = current[segment];
|
|
48
|
+
}
|
|
49
|
+
return current;
|
|
50
|
+
}
|
|
51
|
+
function labelText(label, value, emptyLabel) {
|
|
52
|
+
if (typeof label === 'string' && label.length > 0) return label;
|
|
53
|
+
if (label !== undefined && label !== null && label !== '') return display(label);
|
|
54
|
+
return value === null ? emptyLabel : display(value);
|
|
55
|
+
}
|
|
56
|
+
function display(value) {
|
|
57
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value) ?? String(value);
|
|
58
|
+
return text === '' ? '""' : text;
|
|
59
|
+
}
|
|
60
|
+
function toIcon(candidate) {
|
|
61
|
+
if (typeof candidate === 'string' && candidate.length > 0) return candidate;
|
|
62
|
+
return isIconReference(candidate) ? candidate : undefined;
|
|
63
|
+
}
|
|
64
|
+
function iconAt(icons, value, index) {
|
|
65
|
+
if (Array.isArray(icons)) return toIcon(icons[index]);
|
|
66
|
+
if (!isRecord(icons)) return undefined;
|
|
67
|
+
const isKey = value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
|
|
68
|
+
return isKey ? toIcon(icons[String(value)]) : undefined;
|
|
69
|
+
}
|
|
70
|
+
function isRecord(value) {
|
|
71
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { multiStateOptions };
|
|
75
|
+
//# sourceMappingURL=multiStateOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiStateOptions.js","sources":["../../../form/multiStateOptions.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneElement, isIconReference } from '@cratis/scene.model';\nimport { arrayProperty, stringProperty } from '../properties';\nimport { MultiStateOption } from './MultiStateOption';\n\n/**\n * Reads multi-state options without reshaping their values, dropping any of them, or changing their order.\n *\n * This follows the original PrimeReact control. An option that is a record gives its value through\n * `optionValue` (default, and when that field is absent: its `value` field, and the whole option when it has none) and its label through\n * `optionLabel` (default: its `label` field). Any other option - a string, number, boolean, `null` or an\n * array - is its own value. A label that is not text is shown as its JSON, so a numeric or boolean label,\n * or an option with no label at all, still produces a state the user can reach. A `null` value with no\n * label of its own is labeled with `emptyLabel`.\n *\n * A state's icon is, in order: the option's own `icon`, then the entry of the element's `icons` that is\n * aligned with the option (an array) or keyed by its value (an object). Either may be a PrimeIcons class\n * name, kept for legacy documents, or a qualified {@link IconReference}.\n */\nexport function multiStateOptions(element: SceneElement, emptyLabel: string): MultiStateOption[] {\n const labelPath = stringProperty(element, 'optionLabel');\n const valuePath = stringProperty(element, 'optionValue');\n const icons = element.properties.icons;\n\n return arrayProperty(element, 'options').map((option, index) => {\n const record = isRecord(option) ? option : undefined;\n const value = record === undefined ? option : valueOf(record, valuePath);\n const label = record === undefined ? undefined : resolvePath(record, labelPath ?? 'label');\n const icon = toIcon(record?.icon) ?? iconAt(icons, value, index);\n return { label: labelText(label, value, emptyLabel), value, ...(icon === undefined ? {} : { icon }) };\n });\n}\n\nfunction valueOf(record: Record<string, unknown>, valuePath: string | undefined): unknown {\n const authored = valuePath === undefined ? undefined : resolvePath(record, valuePath);\n if (authored !== undefined) return authored;\n return record.value !== undefined ? record.value : record;\n}\n\nfunction resolvePath(record: Record<string, unknown>, path: string): unknown {\n if (Object.hasOwn(record, path)) return record[path];\n let current: unknown = record;\n for (const segment of path.split('.')) {\n if (!isRecord(current) || !Object.hasOwn(current, segment)) return undefined;\n current = current[segment];\n }\n return current;\n}\n\nfunction labelText(label: unknown, value: unknown, emptyLabel: string): string {\n if (typeof label === 'string' && label.length > 0) return label;\n if (label !== undefined && label !== null && label !== '') return display(label);\n return value === null ? emptyLabel : display(value);\n}\n\nfunction display(value: unknown): string {\n const text = typeof value === 'string' ? value : JSON.stringify(value) ?? String(value);\n return text === '' ? '\"\"' : text;\n}\n\nfunction toIcon(candidate: unknown): MultiStateOption['icon'] {\n if (typeof candidate === 'string' && candidate.length > 0) return candidate;\n return isIconReference(candidate) ? candidate : undefined;\n}\n\nfunction iconAt(icons: unknown, value: unknown, index: number): MultiStateOption['icon'] {\n if (Array.isArray(icons)) return toIcon(icons[index]);\n if (!isRecord(icons)) return undefined;\n\n const isKey = value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';\n return isKey ? toIcon(icons[String(value)]) : undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n"],"names":["multiStateOptions","element","emptyLabel","labelPath","stringProperty","valuePath","icons","properties","arrayProperty","map","option","index","record","isRecord","undefined","value","valueOf","label","resolvePath","icon","toIcon","iconAt","labelText","authored","path","Object","hasOwn","current","segment","split","length","display","text","JSON","stringify","String","candidate","isIconReference","Array","isArray","isKey"],"mappings":";;;AAAA;AACA;AAMA;;;;;;;;;;;;;AAaC,IACM,SAASA,iBAAAA,CAAkBC,OAAqB,EAAEC,UAAkB,EAAA;IACvE,MAAMC,SAAAA,GAAYC,eAAeH,OAAAA,EAAS,aAAA,CAAA;IAC1C,MAAMI,SAAAA,GAAYD,eAAeH,OAAAA,EAAS,aAAA,CAAA;AAC1C,IAAA,MAAMK,KAAAA,GAAQL,OAAAA,CAAQM,UAAU,CAACD,KAAK;AAEtC,IAAA,OAAOE,cAAcP,OAAAA,EAAS,SAAA,CAAA,CAAWQ,GAAG,CAAC,CAACC,MAAAA,EAAQC,KAAAA,GAAAA;QAClD,MAAMC,MAAAA,GAASC,QAAAA,CAASH,MAAAA,CAAAA,GAAUA,MAAAA,GAASI,SAAAA;AAC3C,QAAA,MAAMC,KAAAA,GAAQH,MAAAA,KAAWE,SAAAA,GAAYJ,MAAAA,GAASM,QAAQJ,MAAAA,EAAQP,SAAAA,CAAAA;AAC9D,QAAA,MAAMY,QAAQL,MAAAA,KAAWE,SAAAA,GAAYA,SAAAA,GAAYI,WAAAA,CAAYN,QAAQT,SAAAA,IAAa,OAAA,CAAA;AAClF,QAAA,MAAMgB,OAAOC,MAAAA,CAAOR,MAAAA,EAAQO,IAAAA,CAAAA,IAASE,MAAAA,CAAOf,OAAOS,KAAAA,EAAOJ,KAAAA,CAAAA;QAC1D,OAAO;YA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
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IconReference } from '@cratis/scene.model';
|
|
2
|
+
import { MultiStateOption } from './MultiStateOption';
|
|
3
|
+
export declare function multiStateStates(options: MultiStateOption[], allowEmpty: boolean, emptyLabel: string, emptyIcon: string | IconReference | undefined): MultiStateOption[];
|
|
4
|
+
//# sourceMappingURL=multiStateStates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiStateStates.d.ts","sourceRoot":"","sources":["../../../form/multiStateStates.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAetD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,GAAG,gBAAgB,EAAE,CAGxK"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/**
|
|
4
|
+
* Builds the ordered states a multi-state checkbox cycles through.
|
|
5
|
+
*
|
|
6
|
+
* With the empty state allowed, a state whose value is `null` comes first - unless an authored option
|
|
7
|
+
* already has the value `null`, in which case that option *is* the empty state and keeps its authored
|
|
8
|
+
* position, label and icon. Adding a second `null` state would leave two states with one value, and a
|
|
9
|
+
* control that finds its place by value could then never move past the first of them.
|
|
10
|
+
*
|
|
11
|
+
* @param options The authored options, in order.
|
|
12
|
+
* @param allowEmpty Whether a `null` state is available.
|
|
13
|
+
* @param emptyLabel The label of the synthesized empty state.
|
|
14
|
+
* @param emptyIcon The icon of the synthesized empty state.
|
|
15
|
+
*/ function multiStateStates(options, allowEmpty, emptyLabel, emptyIcon) {
|
|
16
|
+
if (!allowEmpty || options.some((option)=>option.value === null)) return options;
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
label: emptyLabel,
|
|
20
|
+
value: null,
|
|
21
|
+
...emptyIcon === undefined ? {} : {
|
|
22
|
+
icon: emptyIcon
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
...options
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { multiStateStates };
|
|
30
|
+
//# sourceMappingURL=multiStateStates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiStateStates.js","sources":["../../../form/multiStateStates.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IconReference } from '@cratis/scene.model';\nimport { MultiStateOption } from './MultiStateOption';\n\n/**\n * Builds the ordered states a multi-state checkbox cycles through.\n *\n * With the empty state allowed, a state whose value is `null` comes first - unless an authored option\n * already has the value `null`, in which case that option *is* the empty state and keeps its authored\n * position, label and icon. Adding a second `null` state would leave two states with one value, and a\n * control that finds its place by value could then never move past the first of them.\n *\n * @param options The authored options, in order.\n * @param allowEmpty Whether a `null` state is available.\n * @param emptyLabel The label of the synthesized empty state.\n * @param emptyIcon The icon of the synthesized empty state.\n */\nexport function multiStateStates(options: MultiStateOption[], allowEmpty: boolean, emptyLabel: string, emptyIcon: string | IconReference | undefined): MultiStateOption[] {\n if (!allowEmpty || options.some(option => option.value === null)) return options;\n return [{ label: emptyLabel, value: null, ...(emptyIcon === undefined ? {} : { icon: emptyIcon }) }, ...options];\n}\n"],"names":["multiStateStates","options","allowEmpty","emptyLabel","emptyIcon","some","option","value","label","undefined","icon"],"mappings":"AAAA;AACA;AAKA;;;;;;;;;;;;IAaO,SAASA,gBAAAA,CAAiBC,OAA2B,EAAEC,UAAmB,EAAEC,UAAkB,EAAEC,SAA6C,EAAA;IAChJ,IAAI,CAACF,UAAAA,IAAcD,OAAAA,CAAQI,IAAI,CAACC,CAAAA,MAAAA,GAAUA,MAAAA,CAAOC,KAAK,KAAK,IAAA,CAAA,EAAO,OAAON,OAAAA;IACzE,OAAO;AAAC,QAAA;YAAEO,KAAAA,EAAOL,UAAAA;YAAYI,KAAAA,EAAO,IAAA;YAAM,GAAIH,SAAAA,KAAcK,SAAAA,GAAY,EAAC,GAAI;gBAAEC,IAAAA,EAAMN;;AAAa,SAAA;AAAMH,QAAAA,GAAAA;AAAQ,KAAA;AACpH;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMultiStateSelection.d.ts","sourceRoot":"","sources":["../../../form/useMultiStateSelection.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAwBtD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,IAAI,MAAM,CAAA;CAAE,CAkBvH"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { structurallyEqual } from '../structurallyEqual.js';
|
|
3
|
+
|
|
4
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
5
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
6
|
+
/**
|
|
7
|
+
* The state a multi-state checkbox is in, as an index into its states.
|
|
8
|
+
*
|
|
9
|
+
* The position is tracked by index, not recovered by looking the current value up: several states can
|
|
10
|
+
* share a value (a duplicated option), and a lookup by value always finds the first of them, which would
|
|
11
|
+
* make every later state unreachable. The index follows the cycle; the value is only used to find the
|
|
12
|
+
* starting position.
|
|
13
|
+
*
|
|
14
|
+
* The control is driven by the document as well as by the user. When the authored `value` or the states
|
|
15
|
+
* change in content - an edit in the inspector, a hydrated document - the selection starts again from the
|
|
16
|
+
* new value. A document clone with equal content changes nothing, so the user's position survives it.
|
|
17
|
+
*
|
|
18
|
+
* @param states The states, in cycle order.
|
|
19
|
+
* @param value The authored current value.
|
|
20
|
+
* @returns The selected index (`-1` when the value matches no state) and a function that moves to the next.
|
|
21
|
+
*/ function useMultiStateSelection(states, value) {
|
|
22
|
+
const values = states.map((state)=>state.value);
|
|
23
|
+
const start = ()=>({
|
|
24
|
+
source: value,
|
|
25
|
+
values,
|
|
26
|
+
index: values.findIndex((candidate)=>structurallyEqual(candidate, value))
|
|
27
|
+
});
|
|
28
|
+
const [selection, setSelection] = useState(start);
|
|
29
|
+
let current = selection;
|
|
30
|
+
if (!structurallyEqual(selection.source, value) || !structurallyEqual(selection.values, values)) {
|
|
31
|
+
current = start();
|
|
32
|
+
setSelection(current);
|
|
33
|
+
}
|
|
34
|
+
const advance = ()=>{
|
|
35
|
+
const index = states.length === 0 ? -1 : (current.index + 1) % states.length;
|
|
36
|
+
setSelection({
|
|
37
|
+
...current,
|
|
38
|
+
index
|
|
39
|
+
});
|
|
40
|
+
return index;
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
index: current.index,
|
|
44
|
+
advance
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { useMultiStateSelection };
|
|
49
|
+
//# sourceMappingURL=useMultiStateSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMultiStateSelection.js","sources":["../../../form/useMultiStateSelection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useState } from 'react';\nimport { structurallyEqual } from '../structurallyEqual';\nimport { MultiStateOption } from './MultiStateOption';\n\ninterface Selection {\n source: unknown;\n values: unknown[];\n index: number;\n}\n\n/**\n * The state a multi-state checkbox is in, as an index into its states.\n *\n * The position is tracked by index, not recovered by looking the current value up: several states can\n * share a value (a duplicated option), and a lookup by value always finds the first of them, which would\n * make every later state unreachable. The index follows the cycle; the value is only used to find the\n * starting position.\n *\n * The control is driven by the document as well as by the user. When the authored `value` or the states\n * change in content - an edit in the inspector, a hydrated document - the selection starts again from the\n * new value. A document clone with equal content changes nothing, so the user's position survives it.\n *\n * @param states The states, in cycle order.\n * @param value The authored current value.\n * @returns The selected index (`-1` when the value matches no state) and a function that moves to the next.\n */\nexport function useMultiStateSelection(states: MultiStateOption[], value: unknown): { index: number; advance(): number } {\n const values = states.map(state => state.value);\n const start = (): Selection => ({ source: value, values, index: values.findIndex(candidate => structurallyEqual(candidate, value)) });\n const [selection, setSelection] = useState<Selection>(start);\n\n let current = selection;\n if (!structurallyEqual(selection.source, value) || !structurallyEqual(selection.values, values)) {\n current = start();\n setSelection(current);\n }\n\n const advance = () => {\n const index = states.length === 0 ? -1 : (current.index + 1) % states.length;\n setSelection({ ...current, index });\n return index;\n };\n\n return { index: current.index, advance };\n}\n"],"names":["useMultiStateSelection","states","value","values","map","state","start","source","index","findIndex","candidate","structurallyEqual","selection","setSelection","useState","current","advance","length"],"mappings":";;;AAAA;AACA;AAYA;;;;;;;;;;;;;;;AAeC,IACM,SAASA,sBAAAA,CAAuBC,MAA0B,EAAEC,KAAc,EAAA;AAC7E,IAAA,MAAMC,SAASF,MAAAA,CAAOG,GAAG,CAACC,CAAAA,KAAAA,GAASA,MAAMH,KAAK,CAAA;IAC9C,MAAMI,KAAAA,GAAQ,KAAkB;YAAEC,MAAAA,EAAQL,KAAAA;AAAOC,YAAAA,MAAAA;AAAQK,YAAAA,KAAAA,EAAOL,OAAOM,SAAS,CAACC,CAAAA,SAAAA,GAAaC,kBAAkBD,SAAAA,EAAWR,KAAAA,CAAAA;SAAQ,CAAA;AACnI,IAAA,MAAM,CAACU,SAAAA,EAAWC,YAAAA,CAAa,GAAGC,QAAAA,CAAoBR,KAAAA,CAAAA;AAEtD,IAAA,IAAIS,OAAAA,GAAUH,SAAAA;IACd,IAAI,CAACD,iBAAAA,CAAkBC,SAAAA,CAAUL,MAAM,EAAEL,KAAAA,CAAAA,IAAU,CAACS,iBAAAA,CAAkBC,SAAAA,CAAUT,MAAM,EAAEA,MAAAA,CAAAA,EAAS;QAC7FY,OAAAA,GAAUT,KAAAA,EAAAA;QACVO,YAAAA,CAAaE,OAAAA,CAAAA;AACjB,IAAA;AAEA,IAAA,MAAMC,OAAAA,GAAU,IAAA;AACZ,QAAA,MAAMR,KAAAA,GAAQP,MAAAA,CAAOgB,MAAM,KAAK,IAAI,EAAC,GAAI,CAACF,QAAQP,KAAK,GAAG,CAAA,IAAKP,OAAOgB,MAAM;QAC5EJ,YAAAA,CAAa;AAAE,YAAA,GAAGE,OAAO;AAAEP,YAAAA;AAAM,SAAA,CAAA;QACjC,OAAOA,KAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AAAEA,QAAAA,KAAAA,EAAOO,QAAQP,KAAK;AAAEQ,QAAAA;AAAQ,KAAA;AAC3C;;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './menuItems';
|
|
|
7
7
|
export * from './treeNodes';
|
|
8
8
|
export * from './button';
|
|
9
9
|
export * from './form';
|
|
10
|
+
export * from './chart';
|
|
10
11
|
export * from './data';
|
|
11
12
|
export * from './panel';
|
|
12
13
|
export * from './overlay';
|
|
@@ -17,5 +18,6 @@ export * from './misc';
|
|
|
17
18
|
export * from './screen';
|
|
18
19
|
export * from './theme';
|
|
19
20
|
export * from './primeReactComponents';
|
|
21
|
+
export * from './primeReactDescriptors';
|
|
20
22
|
export * from './primeReactPackage';
|
|
21
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { arrayProperty, booleanProperty, numberProperty, optionsProperty, recordArrayProperty, severityProperty, stringArrayProperty, stringProperty } from './properties.js';
|
|
1
|
+
export { arrayProperty, booleanProperty, numberProperty, optionsProperty, recordArrayProperty, recordProperty, severityProperty, stringArrayProperty, stringProperty } from './properties.js';
|
|
2
2
|
export { menuItemsProperty, toMenuItems } from './menuItems.js';
|
|
3
3
|
export { toTreeNodes, treeNodesProperty } from './treeNodes.js';
|
|
4
4
|
export { PrimeButton } from './button/PrimeButton.js';
|
|
@@ -17,6 +17,7 @@ export { PrimeMultiSelect } from './form/PrimeMultiSelect.js';
|
|
|
17
17
|
export { PrimeListBox } from './form/PrimeListBox.js';
|
|
18
18
|
export { PrimeSelectButton } from './form/PrimeSelectButton.js';
|
|
19
19
|
export { PrimeCheckbox } from './form/PrimeCheckbox.js';
|
|
20
|
+
export { PrimeMultiStateCheckbox } from './form/PrimeMultiStateCheckbox.js';
|
|
20
21
|
export { PrimeRadioButton } from './form/PrimeRadioButton.js';
|
|
21
22
|
export { PrimeToggleSwitch } from './form/PrimeToggleSwitch.js';
|
|
22
23
|
export { PrimeSlider } from './form/PrimeSlider.js';
|
|
@@ -28,6 +29,9 @@ export { PrimeChips } from './form/PrimeChips.js';
|
|
|
28
29
|
export { PrimeAutoComplete } from './form/PrimeAutoComplete.js';
|
|
29
30
|
export { TreeSelect } from './form/TreeSelect.js';
|
|
30
31
|
export { PrimeTreeSelect } from './form/PrimeTreeSelect.js';
|
|
32
|
+
export { ChartType } from './chart/ChartType.js';
|
|
33
|
+
export { PrimeChart } from './chart/PrimeChart.js';
|
|
34
|
+
export { legacyChartTypes, resolveChartType } from './chart/resolveChartType.js';
|
|
31
35
|
export { Column } from './data/Column.js';
|
|
32
36
|
export { columnDefinitions } from './data/columnDefinitions.js';
|
|
33
37
|
export { PrimeColumn } from './data/PrimeColumn.js';
|
|
@@ -107,5 +111,6 @@ export { primeReactTheme, primeReactThemeCompatibility, primeReactThemeLicense,
|
|
|
107
111
|
export { primeReactThemePreset } from './theme/primeReactThemePreset.js';
|
|
108
112
|
export { primeReactDarkModeClass, usePrimeReactTheme } from './theme/usePrimeReactTheme.js';
|
|
109
113
|
export { primeReactComponents } from './primeReactComponents.js';
|
|
114
|
+
export { primeReactDescriptors } from './primeReactDescriptors.js';
|
|
110
115
|
export { primeReactPackage, primeReactPackageManifest } from './primeReactPackage.js';
|
|
111
116
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primeReactComponents.d.ts","sourceRoot":"","sources":["../../primeReactComponents.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAwB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"primeReactComponents.d.ts","sourceRoot":"","sources":["../../primeReactComponents.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAwB,MAAM,qBAAqB,CAAC;AAiG9E,eAAO,MAAM,oBAAoB,EAAE,iBA+FlC,CAAC"}
|
|
@@ -6,6 +6,8 @@ import { PrimeButtonGroup } from './button/PrimeButtonGroup.js';
|
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
import 'primereact/button';
|
|
8
8
|
import 'primereact/popover';
|
|
9
|
+
import { PrimeChart } from './chart/PrimeChart.js';
|
|
10
|
+
import './chart/resolveChartType.js';
|
|
9
11
|
import './data/Column.js';
|
|
10
12
|
import { PrimeColumn } from './data/PrimeColumn.js';
|
|
11
13
|
import { PrimeDataTable } from './data/PrimeDataTable.js';
|
|
@@ -27,6 +29,7 @@ import { PrimeMultiSelect } from './form/PrimeMultiSelect.js';
|
|
|
27
29
|
import { PrimeListBox } from './form/PrimeListBox.js';
|
|
28
30
|
import { PrimeSelectButton } from './form/PrimeSelectButton.js';
|
|
29
31
|
import { PrimeCheckbox } from './form/PrimeCheckbox.js';
|
|
32
|
+
import { PrimeMultiStateCheckbox } from './form/PrimeMultiStateCheckbox.js';
|
|
30
33
|
import { PrimeRadioButton } from './form/PrimeRadioButton.js';
|
|
31
34
|
import { PrimeToggleSwitch } from './form/PrimeToggleSwitch.js';
|
|
32
35
|
import { PrimeSlider } from './form/PrimeSlider.js';
|
|
@@ -124,6 +127,7 @@ import { PrimeAction } from './screen/PrimeAction.js';
|
|
|
124
127
|
[componentRegistryKey('PrimeReact', 'listBox')]: PrimeListBox,
|
|
125
128
|
[componentRegistryKey('PrimeReact', 'selectButton')]: PrimeSelectButton,
|
|
126
129
|
[componentRegistryKey('PrimeReact', 'checkbox')]: PrimeCheckbox,
|
|
130
|
+
[componentRegistryKey('PrimeReact', 'multiStateCheckbox')]: PrimeMultiStateCheckbox,
|
|
127
131
|
[componentRegistryKey('PrimeReact', 'radioButton')]: PrimeRadioButton,
|
|
128
132
|
[componentRegistryKey('PrimeReact', 'toggleSwitch')]: PrimeToggleSwitch,
|
|
129
133
|
[componentRegistryKey('PrimeReact', 'slider')]: PrimeSlider,
|
|
@@ -148,6 +152,7 @@ import { PrimeAction } from './screen/PrimeAction.js';
|
|
|
148
152
|
[componentRegistryKey('PrimeReact', 'orderList')]: PrimeOrderList,
|
|
149
153
|
[componentRegistryKey('PrimeReact', 'pickList')]: PrimePickList,
|
|
150
154
|
[componentRegistryKey('PrimeReact', 'organizationChart')]: PrimeOrganizationChart,
|
|
155
|
+
[componentRegistryKey('PrimeReact', 'chart')]: PrimeChart,
|
|
151
156
|
[componentRegistryKey('PrimeReact', 'card')]: PrimeCard,
|
|
152
157
|
[componentRegistryKey('PrimeReact', 'panel')]: PrimePanel,
|
|
153
158
|
[componentRegistryKey('PrimeReact', 'accordion')]: PrimeAccordion,
|