@contember/react-select 1.3.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/components/MultiSelect.cjs +33 -0
- package/dist/development/components/MultiSelect.cjs.map +1 -0
- package/dist/development/components/MultiSelect.js +33 -0
- package/dist/development/components/MultiSelect.js.map +1 -0
- package/dist/development/components/Select.cjs +31 -0
- package/dist/development/components/Select.cjs.map +1 -0
- package/dist/development/components/Select.js +31 -0
- package/dist/development/components/Select.js.map +1 -0
- package/dist/development/components/SelectDataView.cjs +12 -0
- package/dist/development/components/SelectDataView.cjs.map +1 -0
- package/dist/development/components/SelectDataView.js +12 -0
- package/dist/development/components/SelectDataView.js.map +1 -0
- package/dist/development/components/SelectEachItem.cjs +11 -0
- package/dist/development/components/SelectEachItem.cjs.map +1 -0
- package/dist/development/components/SelectEachItem.js +11 -0
- package/dist/development/components/SelectEachItem.js.map +1 -0
- package/dist/development/components/SelectItemTrigger.cjs +17 -0
- package/dist/development/components/SelectItemTrigger.cjs.map +1 -0
- package/dist/development/components/SelectItemTrigger.js +17 -0
- package/dist/development/components/SelectItemTrigger.js.map +1 -0
- package/dist/development/components/SelectNewItem.cjs +40 -0
- package/dist/development/components/SelectNewItem.cjs.map +1 -0
- package/dist/development/components/SelectNewItem.js +40 -0
- package/dist/development/components/SelectNewItem.js.map +1 -0
- package/dist/development/components/SelectOption.cjs +22 -0
- package/dist/development/components/SelectOption.cjs.map +1 -0
- package/dist/development/components/SelectOption.js +22 -0
- package/dist/development/components/SelectOption.js.map +1 -0
- package/dist/development/components/SelectPlaceholder.cjs +10 -0
- package/dist/development/components/SelectPlaceholder.cjs.map +1 -0
- package/dist/development/components/SelectPlaceholder.js +10 -0
- package/dist/development/components/SelectPlaceholder.js.map +1 -0
- package/dist/development/components/SortableMultiSelect.cjs +36 -0
- package/dist/development/components/SortableMultiSelect.cjs.map +1 -0
- package/dist/development/components/SortableMultiSelect.js +36 -0
- package/dist/development/components/SortableMultiSelect.js.map +1 -0
- package/dist/development/contexts.cjs +24 -0
- package/dist/development/contexts.cjs.map +1 -0
- package/dist/development/contexts.js +24 -0
- package/dist/development/contexts.js.map +1 -0
- package/dist/development/index.cjs +30 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +30 -0
- package/dist/development/index.js.map +1 -0
- package/dist/production/components/MultiSelect.cjs +33 -0
- package/dist/production/components/MultiSelect.cjs.map +1 -0
- package/dist/production/components/MultiSelect.js +33 -0
- package/dist/production/components/MultiSelect.js.map +1 -0
- package/dist/production/components/Select.cjs +31 -0
- package/dist/production/components/Select.cjs.map +1 -0
- package/dist/production/components/Select.js +31 -0
- package/dist/production/components/Select.js.map +1 -0
- package/dist/production/components/SelectDataView.cjs +12 -0
- package/dist/production/components/SelectDataView.cjs.map +1 -0
- package/dist/production/components/SelectDataView.js +12 -0
- package/dist/production/components/SelectDataView.js.map +1 -0
- package/dist/production/components/SelectEachItem.cjs +11 -0
- package/dist/production/components/SelectEachItem.cjs.map +1 -0
- package/dist/production/components/SelectEachItem.js +11 -0
- package/dist/production/components/SelectEachItem.js.map +1 -0
- package/dist/production/components/SelectItemTrigger.cjs +17 -0
- package/dist/production/components/SelectItemTrigger.cjs.map +1 -0
- package/dist/production/components/SelectItemTrigger.js +17 -0
- package/dist/production/components/SelectItemTrigger.js.map +1 -0
- package/dist/production/components/SelectNewItem.cjs +40 -0
- package/dist/production/components/SelectNewItem.cjs.map +1 -0
- package/dist/production/components/SelectNewItem.js +40 -0
- package/dist/production/components/SelectNewItem.js.map +1 -0
- package/dist/production/components/SelectOption.cjs +22 -0
- package/dist/production/components/SelectOption.cjs.map +1 -0
- package/dist/production/components/SelectOption.js +22 -0
- package/dist/production/components/SelectOption.js.map +1 -0
- package/dist/production/components/SelectPlaceholder.cjs +10 -0
- package/dist/production/components/SelectPlaceholder.cjs.map +1 -0
- package/dist/production/components/SelectPlaceholder.js +10 -0
- package/dist/production/components/SelectPlaceholder.js.map +1 -0
- package/dist/production/components/SortableMultiSelect.cjs +36 -0
- package/dist/production/components/SortableMultiSelect.cjs.map +1 -0
- package/dist/production/components/SortableMultiSelect.js +36 -0
- package/dist/production/components/SortableMultiSelect.js.map +1 -0
- package/dist/production/contexts.cjs +24 -0
- package/dist/production/contexts.cjs.map +1 -0
- package/dist/production/contexts.js +24 -0
- package/dist/production/contexts.js.map +1 -0
- package/dist/production/index.cjs +30 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +30 -0
- package/dist/production/index.js.map +1 -0
- package/dist/types/components/MultiSelect.d.ts +14 -0
- package/dist/types/components/MultiSelect.d.ts.map +1 -0
- package/dist/types/components/Select.d.ts +14 -0
- package/dist/types/components/Select.d.ts.map +1 -0
- package/dist/types/components/SelectDataView.d.ts +7 -0
- package/dist/types/components/SelectDataView.d.ts.map +1 -0
- package/dist/types/components/SelectEachItem.d.ts +5 -0
- package/dist/types/components/SelectEachItem.d.ts.map +1 -0
- package/dist/types/components/SelectItemTrigger.d.ts +7 -0
- package/dist/types/components/SelectItemTrigger.d.ts.map +1 -0
- package/dist/types/components/SelectNewItem.d.ts +5 -0
- package/dist/types/components/SelectNewItem.d.ts.map +1 -0
- package/dist/types/components/SelectOption.d.ts +7 -0
- package/dist/types/components/SelectOption.d.ts.map +1 -0
- package/dist/types/components/SelectPlaceholder.d.ts +5 -0
- package/dist/types/components/SelectPlaceholder.d.ts.map +1 -0
- package/dist/types/components/SortableMultiSelect.d.ts +18 -0
- package/dist/types/components/SortableMultiSelect.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/contexts.d.ts +15 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types/events.d.ts +6 -0
- package/dist/types/types/events.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/components/MultiSelect.tsx +55 -0
- package/src/components/Select.tsx +53 -0
- package/src/components/SelectDataView.tsx +17 -0
- package/src/components/SelectEachItem.tsx +13 -0
- package/src/components/SelectItemTrigger.tsx +19 -0
- package/src/components/SelectNewItem.tsx +54 -0
- package/src/components/SelectOption.tsx +22 -0
- package/src/components/SelectPlaceholder.tsx +7 -0
- package/src/components/SortableMultiSelect.tsx +65 -0
- package/src/components/index.ts +9 -0
- package/src/contexts.ts +25 -0
- package/src/index.ts +3 -0
- package/src/tsconfig.json +13 -0
- package/src/types/events.ts +6 -0
- package/src/types/index.ts +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactBinding = require("@contember/react-binding");
|
|
7
|
+
const reactUtils = require("@contember/react-utils");
|
|
8
|
+
const MultiSelect = reactBinding.Component(({ field, children, options, onSelect, onUnselect }) => {
|
|
9
|
+
const entities = reactBinding.useEntityList({ field });
|
|
10
|
+
const entitiesArr = react.useMemo(() => Array.from(entities), [entities]);
|
|
11
|
+
const selectedEntities = react.useMemo(() => Array.from(entities).map((it) => it.id), [entities]);
|
|
12
|
+
const handler = reactUtils.useReferentiallyStableCallback((entity, action = "toggle") => {
|
|
13
|
+
const isSelected2 = selectedEntities.includes(entity.id);
|
|
14
|
+
if (action === "toggle") {
|
|
15
|
+
action = isSelected2 ? "unselect" : "select";
|
|
16
|
+
}
|
|
17
|
+
if (action === "unselect" && isSelected2) {
|
|
18
|
+
entities.disconnectEntity(entity);
|
|
19
|
+
onUnselect?.(entity);
|
|
20
|
+
} else if (action === "select" && !isSelected2) {
|
|
21
|
+
entities.connectEntity(entity);
|
|
22
|
+
onSelect?.(entity);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const isSelected = react.useCallback((entity) => {
|
|
26
|
+
return selectedEntities.includes(entity.id);
|
|
27
|
+
}, [selectedEntities]);
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectCurrentEntitiesContext.Provider, { value: entitiesArr, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectIsSelectedContext.Provider, { value: isSelected, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectHandleSelectContext.Provider, { value: handler, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectOptionsContext.Provider, { value: options, children }) }) }) });
|
|
29
|
+
}, ({ field, children }) => {
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.HasMany, { field, children });
|
|
31
|
+
});
|
|
32
|
+
exports.MultiSelect = MultiSelect;
|
|
33
|
+
//# sourceMappingURL=MultiSelect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiSelect.cjs","sources":["../../../src/components/MultiSelect.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo } from 'react'\nimport { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext, SelectIsSelectedContext, SelectOptionsContext } from '../contexts'\nimport { Component, EntityAccessor, HasMany, SugaredQualifiedEntityList, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\nimport { SelectEvents } from '../types'\n\nexport type MultiSelectProps =\n\t& {\n\t\tchildren: ReactNode\n\t\tfield: SugaredRelativeEntityList['field']\n\t\toptions: SugaredQualifiedEntityList['entities']\n\t}\n\t& SelectEvents\n\nexport const MultiSelect = Component(({ field, children, options, onSelect, onUnselect }: MultiSelectProps) => {\n\tconst entities = useEntityList({ field })\n\tconst entitiesArr = useMemo(() => Array.from(entities), [entities])\n\tconst selectedEntities = useMemo(() => Array.from(entities).map(it => it.id), [entities])\n\n\tconst handler = useReferentiallyStableCallback<SelectHandler>((entity, action = 'toggle') => {\n\t\tconst isSelected = selectedEntities.includes(entity.id)\n\t\tif (action === 'toggle') {\n\t\t\taction = isSelected ? 'unselect' : 'select'\n\t\t}\n\t\tif (action === 'unselect' && isSelected) {\n\t\t\tentities.disconnectEntity(entity)\n\t\t\tonUnselect?.(entity)\n\t\t} else if (action === 'select' && !isSelected) {\n\t\t\tentities.connectEntity(entity)\n\t\t\tonSelect?.(entity)\n\t\t}\n\t})\n\tconst isSelected = useCallback((entity: EntityAccessor) => {\n\t\treturn selectedEntities.includes(entity.id)\n\t}, [selectedEntities])\n\n\treturn (\n\t\t<SelectCurrentEntitiesContext.Provider value={entitiesArr}>\n\t\t\t<SelectIsSelectedContext.Provider value={isSelected}>\n\t\t\t\t<SelectHandleSelectContext.Provider value={handler}>\n\t\t\t\t\t<SelectOptionsContext.Provider value={options}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</SelectOptionsContext.Provider>\n\t\t\t\t</SelectHandleSelectContext.Provider>\n\t\t\t</SelectIsSelectedContext.Provider>\n\t\t</SelectCurrentEntitiesContext.Provider>\n\t)\n}, ({ field, children }) => {\n\treturn (\n\t\t<HasMany field={field}>\n\t\t\t{children}\n\t\t</HasMany>\n\t)\n})\n\n"],"names":["Component","useEntityList","useMemo","useReferentiallyStableCallback","isSelected","useCallback","jsx","SelectCurrentEntitiesContext","SelectIsSelectedContext","SelectHandleSelectContext","SelectOptionsContext","HasMany"],"mappings":";;;;;;;AAca,MAAA,cAAcA,aAAAA,UAAU,CAAC,EAAE,OAAO,UAAU,SAAS,UAAU,iBAAmC;AAC9G,QAAM,WAAWC,aAAAA,cAAc,EAAE,MAAO,CAAA;AAClC,QAAA,cAAcC,cAAQ,MAAM,MAAM,KAAK,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAClE,QAAM,mBAAmBA,MAAA,QAAQ,MAAM,MAAM,KAAK,QAAQ,EAAE,IAAI,CAAA,OAAM,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC;AAExF,QAAM,UAAUC,WAAA,+BAA8C,CAAC,QAAQ,SAAS,aAAa;AAC5F,UAAMC,cAAa,iBAAiB,SAAS,OAAO,EAAE;AACtD,QAAI,WAAW,UAAU;AACxB,eAASA,cAAa,aAAa;AAAA,IACpC;AACI,QAAA,WAAW,cAAcA,aAAY;AACxC,eAAS,iBAAiB,MAAM;AAChC,mBAAa,MAAM;AAAA,IACT,WAAA,WAAW,YAAY,CAACA,aAAY;AAC9C,eAAS,cAAc,MAAM;AAC7B,iBAAW,MAAM;AAAA,IAClB;AAAA,EAAA,CACA;AACK,QAAA,aAAaC,kBAAY,CAAC,WAA2B;AACnD,WAAA,iBAAiB,SAAS,OAAO,EAAE;AAAA,EAAA,GACxC,CAAC,gBAAgB,CAAC;AAGpB,SAAAC,2BAAAA,IAACC,SAAAA,6BAA6B,UAA7B,EAAsC,OAAO,aAC7C,UAAAD,2BAAA,IAACE,SAAwB,wBAAA,UAAxB,EAAiC,OAAO,YACxC,UAAAF,2BAAAA,IAACG,SAAAA,0BAA0B,UAA1B,EAAmC,OAAO,SAC1C,UAAAH,2BAAA,IAACI,SAAqB,qBAAA,UAArB,EAA8B,OAAO,SACpC,SACF,CAAA,EACD,CAAA,EACD,CAAA,EACD,CAAA;AAEF,GAAG,CAAC,EAAE,OAAO,eAAe;AAE1B,SAAAJ,2BAAA,IAACK,aAAQ,SAAA,EAAA,OACP,SACF,CAAA;AAEF,CAAC;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useCallback } from "react";
|
|
3
|
+
import { SelectCurrentEntitiesContext, SelectIsSelectedContext, SelectHandleSelectContext, SelectOptionsContext } from "../contexts.js";
|
|
4
|
+
import { Component, useEntityList, HasMany } from "@contember/react-binding";
|
|
5
|
+
import { useReferentiallyStableCallback } from "@contember/react-utils";
|
|
6
|
+
const MultiSelect = Component(({ field, children, options, onSelect, onUnselect }) => {
|
|
7
|
+
const entities = useEntityList({ field });
|
|
8
|
+
const entitiesArr = useMemo(() => Array.from(entities), [entities]);
|
|
9
|
+
const selectedEntities = useMemo(() => Array.from(entities).map((it) => it.id), [entities]);
|
|
10
|
+
const handler = useReferentiallyStableCallback((entity, action = "toggle") => {
|
|
11
|
+
const isSelected2 = selectedEntities.includes(entity.id);
|
|
12
|
+
if (action === "toggle") {
|
|
13
|
+
action = isSelected2 ? "unselect" : "select";
|
|
14
|
+
}
|
|
15
|
+
if (action === "unselect" && isSelected2) {
|
|
16
|
+
entities.disconnectEntity(entity);
|
|
17
|
+
onUnselect?.(entity);
|
|
18
|
+
} else if (action === "select" && !isSelected2) {
|
|
19
|
+
entities.connectEntity(entity);
|
|
20
|
+
onSelect?.(entity);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const isSelected = useCallback((entity) => {
|
|
24
|
+
return selectedEntities.includes(entity.id);
|
|
25
|
+
}, [selectedEntities]);
|
|
26
|
+
return /* @__PURE__ */ jsx(SelectCurrentEntitiesContext.Provider, { value: entitiesArr, children: /* @__PURE__ */ jsx(SelectIsSelectedContext.Provider, { value: isSelected, children: /* @__PURE__ */ jsx(SelectHandleSelectContext.Provider, { value: handler, children: /* @__PURE__ */ jsx(SelectOptionsContext.Provider, { value: options, children }) }) }) });
|
|
27
|
+
}, ({ field, children }) => {
|
|
28
|
+
return /* @__PURE__ */ jsx(HasMany, { field, children });
|
|
29
|
+
});
|
|
30
|
+
export {
|
|
31
|
+
MultiSelect
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=MultiSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiSelect.js","sources":["../../../src/components/MultiSelect.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo } from 'react'\nimport { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext, SelectIsSelectedContext, SelectOptionsContext } from '../contexts'\nimport { Component, EntityAccessor, HasMany, SugaredQualifiedEntityList, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\nimport { SelectEvents } from '../types'\n\nexport type MultiSelectProps =\n\t& {\n\t\tchildren: ReactNode\n\t\tfield: SugaredRelativeEntityList['field']\n\t\toptions: SugaredQualifiedEntityList['entities']\n\t}\n\t& SelectEvents\n\nexport const MultiSelect = Component(({ field, children, options, onSelect, onUnselect }: MultiSelectProps) => {\n\tconst entities = useEntityList({ field })\n\tconst entitiesArr = useMemo(() => Array.from(entities), [entities])\n\tconst selectedEntities = useMemo(() => Array.from(entities).map(it => it.id), [entities])\n\n\tconst handler = useReferentiallyStableCallback<SelectHandler>((entity, action = 'toggle') => {\n\t\tconst isSelected = selectedEntities.includes(entity.id)\n\t\tif (action === 'toggle') {\n\t\t\taction = isSelected ? 'unselect' : 'select'\n\t\t}\n\t\tif (action === 'unselect' && isSelected) {\n\t\t\tentities.disconnectEntity(entity)\n\t\t\tonUnselect?.(entity)\n\t\t} else if (action === 'select' && !isSelected) {\n\t\t\tentities.connectEntity(entity)\n\t\t\tonSelect?.(entity)\n\t\t}\n\t})\n\tconst isSelected = useCallback((entity: EntityAccessor) => {\n\t\treturn selectedEntities.includes(entity.id)\n\t}, [selectedEntities])\n\n\treturn (\n\t\t<SelectCurrentEntitiesContext.Provider value={entitiesArr}>\n\t\t\t<SelectIsSelectedContext.Provider value={isSelected}>\n\t\t\t\t<SelectHandleSelectContext.Provider value={handler}>\n\t\t\t\t\t<SelectOptionsContext.Provider value={options}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</SelectOptionsContext.Provider>\n\t\t\t\t</SelectHandleSelectContext.Provider>\n\t\t\t</SelectIsSelectedContext.Provider>\n\t\t</SelectCurrentEntitiesContext.Provider>\n\t)\n}, ({ field, children }) => {\n\treturn (\n\t\t<HasMany field={field}>\n\t\t\t{children}\n\t\t</HasMany>\n\t)\n})\n\n"],"names":["isSelected"],"mappings":";;;;;AAca,MAAA,cAAc,UAAU,CAAC,EAAE,OAAO,UAAU,SAAS,UAAU,iBAAmC;AAC9G,QAAM,WAAW,cAAc,EAAE,MAAO,CAAA;AAClC,QAAA,cAAc,QAAQ,MAAM,MAAM,KAAK,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAClE,QAAM,mBAAmB,QAAQ,MAAM,MAAM,KAAK,QAAQ,EAAE,IAAI,CAAA,OAAM,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC;AAExF,QAAM,UAAU,+BAA8C,CAAC,QAAQ,SAAS,aAAa;AAC5F,UAAMA,cAAa,iBAAiB,SAAS,OAAO,EAAE;AACtD,QAAI,WAAW,UAAU;AACxB,eAASA,cAAa,aAAa;AAAA,IACpC;AACI,QAAA,WAAW,cAAcA,aAAY;AACxC,eAAS,iBAAiB,MAAM;AAChC,mBAAa,MAAM;AAAA,IACT,WAAA,WAAW,YAAY,CAACA,aAAY;AAC9C,eAAS,cAAc,MAAM;AAC7B,iBAAW,MAAM;AAAA,IAClB;AAAA,EAAA,CACA;AACK,QAAA,aAAa,YAAY,CAAC,WAA2B;AACnD,WAAA,iBAAiB,SAAS,OAAO,EAAE;AAAA,EAAA,GACxC,CAAC,gBAAgB,CAAC;AAGpB,SAAA,oBAAC,6BAA6B,UAA7B,EAAsC,OAAO,aAC7C,UAAA,oBAAC,wBAAwB,UAAxB,EAAiC,OAAO,YACxC,UAAA,oBAAC,0BAA0B,UAA1B,EAAmC,OAAO,SAC1C,UAAA,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,SACpC,SACF,CAAA,EACD,CAAA,EACD,CAAA,EACD,CAAA;AAEF,GAAG,CAAC,EAAE,OAAO,eAAe;AAE1B,SAAA,oBAAC,SAAQ,EAAA,OACP,SACF,CAAA;AAEF,CAAC;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactBinding = require("@contember/react-binding");
|
|
7
|
+
const reactUtils = require("@contember/react-utils");
|
|
8
|
+
const Select = reactBinding.Component(({ field, children, onUnselect, onSelect, options }) => {
|
|
9
|
+
const entity = reactBinding.useEntity();
|
|
10
|
+
const selectedEntity = entity.getEntity({ field });
|
|
11
|
+
const entityExists = selectedEntity.existsOnServer || selectedEntity.hasUnpersistedChanges;
|
|
12
|
+
const entitiesArr = react.useMemo(() => entityExists ? [selectedEntity] : [], [entityExists, selectedEntity]);
|
|
13
|
+
const handleSelect = reactUtils.useReferentiallyStableCallback((selected, action = "toggle") => {
|
|
14
|
+
if (action === "toggle") {
|
|
15
|
+
action = selected.id === selectedEntity.id ? "unselect" : "select";
|
|
16
|
+
}
|
|
17
|
+
if (action === "unselect") {
|
|
18
|
+
entity.disconnectEntityAtField({ field });
|
|
19
|
+
onUnselect?.(selected);
|
|
20
|
+
} else if (action === "select") {
|
|
21
|
+
entity.connectEntityAtField({ field }, selected);
|
|
22
|
+
onSelect?.(selected);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const isSelected = react.useCallback((entity2) => entity2.id === selectedEntity.id, [selectedEntity.id]);
|
|
26
|
+
return /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectCurrentEntitiesContext.Provider, { value: entitiesArr, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectIsSelectedContext.Provider, { value: isSelected, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectHandleSelectContext.Provider, { value: handleSelect, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectOptionsContext.Provider, { value: options, children }) }) }) });
|
|
27
|
+
}, ({ field, children }) => {
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactBinding.HasOne, { field, children });
|
|
29
|
+
});
|
|
30
|
+
exports.Select = Select;
|
|
31
|
+
//# sourceMappingURL=Select.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.cjs","sources":["../../../src/components/Select.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo } from 'react'\nimport { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext, SelectIsSelectedContext, SelectOptionsContext } from '../contexts'\nimport { Component, EntityAccessor, HasOne, SugaredQualifiedEntityList, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\nimport { SelectEvents } from '../types'\n\nexport type SelectProps =\n\t& {\n\t\tchildren: ReactNode\n\t\tfield: SugaredRelativeSingleEntity['field']\n\t\toptions: SugaredQualifiedEntityList['entities']\n\t}\n\t& SelectEvents\n\nexport const Select = Component(({ field, children, onUnselect, onSelect, options }: SelectProps) => {\n\tconst entity = useEntity()\n\tconst selectedEntity = entity.getEntity({ field })\n\tconst entityExists = selectedEntity.existsOnServer || selectedEntity.hasUnpersistedChanges\n\tconst entitiesArr = useMemo(() => entityExists ? [selectedEntity] : [], [entityExists, selectedEntity])\n\n\tconst handleSelect = useReferentiallyStableCallback<SelectHandler>((selected, action = 'toggle') => {\n\t\tif (action === 'toggle') {\n\t\t\taction = selected.id === selectedEntity.id ? 'unselect' : 'select'\n\t\t}\n\t\tif (action === 'unselect') {\n\t\t\tentity.disconnectEntityAtField({ field })\n\t\t\tonUnselect?.(selected)\n\t\t} else if (action === 'select') {\n\t\t\tentity.connectEntityAtField({ field }, selected)\n\t\t\tonSelect?.(selected)\n\t\t}\n\t})\n\tconst isSelected = useCallback((entity: EntityAccessor) => entity.id === selectedEntity.id, [selectedEntity.id])\n\n\treturn (\n\t\t<SelectCurrentEntitiesContext.Provider value={entitiesArr}>\n\t\t\t<SelectIsSelectedContext.Provider value={isSelected}>\n\t\t\t\t<SelectHandleSelectContext.Provider value={handleSelect}>\n\t\t\t\t\t<SelectOptionsContext.Provider value={options}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</SelectOptionsContext.Provider>\n\t\t\t\t</SelectHandleSelectContext.Provider>\n\t\t\t</SelectIsSelectedContext.Provider>\n\t\t</SelectCurrentEntitiesContext.Provider>\n\t)\n}, ({ field, children }) => {\n\treturn (\n\t\t<HasOne field={field}>\n\t\t\t{children}\n\t\t</HasOne>\n\t)\n})\n\n"],"names":["Component","useEntity","useMemo","useReferentiallyStableCallback","useCallback","entity","jsx","SelectCurrentEntitiesContext","SelectIsSelectedContext","SelectHandleSelectContext","SelectOptionsContext","HasOne"],"mappings":";;;;;;;AAca,MAAA,SAASA,aAAAA,UAAU,CAAC,EAAE,OAAO,UAAU,YAAY,UAAU,cAA2B;AACpG,QAAM,SAASC,aAAAA;AACf,QAAM,iBAAiB,OAAO,UAAU,EAAE,MAAO,CAAA;AAC3C,QAAA,eAAe,eAAe,kBAAkB,eAAe;AACrE,QAAM,cAAcC,MAAAA,QAAQ,MAAM,eAAe,CAAC,cAAc,IAAI,CAAA,GAAI,CAAC,cAAc,cAAc,CAAC;AAEtG,QAAM,eAAeC,WAAA,+BAA8C,CAAC,UAAU,SAAS,aAAa;AACnG,QAAI,WAAW,UAAU;AACxB,eAAS,SAAS,OAAO,eAAe,KAAK,aAAa;AAAA,IAC3D;AACA,QAAI,WAAW,YAAY;AACnB,aAAA,wBAAwB,EAAE,MAAA,CAAO;AACxC,mBAAa,QAAQ;AAAA,IAAA,WACX,WAAW,UAAU;AAC/B,aAAO,qBAAqB,EAAE,MAAM,GAAG,QAAQ;AAC/C,iBAAW,QAAQ;AAAA,IACpB;AAAA,EAAA,CACA;AACK,QAAA,aAAaC,MAAAA,YAAY,CAACC,YAA2BA,QAAO,OAAO,eAAe,IAAI,CAAC,eAAe,EAAE,CAAC;AAG9G,SAAAC,2BAAAA,IAACC,SAAAA,6BAA6B,UAA7B,EAAsC,OAAO,aAC7C,UAAAD,2BAAA,IAACE,SAAwB,wBAAA,UAAxB,EAAiC,OAAO,YACxC,UAAAF,2BAAAA,IAACG,SAAAA,0BAA0B,UAA1B,EAAmC,OAAO,cAC1C,UAAAH,2BAAA,IAACI,SAAqB,qBAAA,UAArB,EAA8B,OAAO,SACpC,SACF,CAAA,EACD,CAAA,EACD,CAAA,EACD,CAAA;AAEF,GAAG,CAAC,EAAE,OAAO,eAAe;AAE1B,SAAAJ,2BAAA,IAACK,aAAO,QAAA,EAAA,OACN,SACF,CAAA;AAEF,CAAC;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useCallback } from "react";
|
|
3
|
+
import { SelectCurrentEntitiesContext, SelectIsSelectedContext, SelectHandleSelectContext, SelectOptionsContext } from "../contexts.js";
|
|
4
|
+
import { Component, useEntity, HasOne } from "@contember/react-binding";
|
|
5
|
+
import { useReferentiallyStableCallback } from "@contember/react-utils";
|
|
6
|
+
const Select = Component(({ field, children, onUnselect, onSelect, options }) => {
|
|
7
|
+
const entity = useEntity();
|
|
8
|
+
const selectedEntity = entity.getEntity({ field });
|
|
9
|
+
const entityExists = selectedEntity.existsOnServer || selectedEntity.hasUnpersistedChanges;
|
|
10
|
+
const entitiesArr = useMemo(() => entityExists ? [selectedEntity] : [], [entityExists, selectedEntity]);
|
|
11
|
+
const handleSelect = useReferentiallyStableCallback((selected, action = "toggle") => {
|
|
12
|
+
if (action === "toggle") {
|
|
13
|
+
action = selected.id === selectedEntity.id ? "unselect" : "select";
|
|
14
|
+
}
|
|
15
|
+
if (action === "unselect") {
|
|
16
|
+
entity.disconnectEntityAtField({ field });
|
|
17
|
+
onUnselect?.(selected);
|
|
18
|
+
} else if (action === "select") {
|
|
19
|
+
entity.connectEntityAtField({ field }, selected);
|
|
20
|
+
onSelect?.(selected);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const isSelected = useCallback((entity2) => entity2.id === selectedEntity.id, [selectedEntity.id]);
|
|
24
|
+
return /* @__PURE__ */ jsx(SelectCurrentEntitiesContext.Provider, { value: entitiesArr, children: /* @__PURE__ */ jsx(SelectIsSelectedContext.Provider, { value: isSelected, children: /* @__PURE__ */ jsx(SelectHandleSelectContext.Provider, { value: handleSelect, children: /* @__PURE__ */ jsx(SelectOptionsContext.Provider, { value: options, children }) }) }) });
|
|
25
|
+
}, ({ field, children }) => {
|
|
26
|
+
return /* @__PURE__ */ jsx(HasOne, { field, children });
|
|
27
|
+
});
|
|
28
|
+
export {
|
|
29
|
+
Select
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=Select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.js","sources":["../../../src/components/Select.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo } from 'react'\nimport { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext, SelectIsSelectedContext, SelectOptionsContext } from '../contexts'\nimport { Component, EntityAccessor, HasOne, SugaredQualifiedEntityList, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\nimport { SelectEvents } from '../types'\n\nexport type SelectProps =\n\t& {\n\t\tchildren: ReactNode\n\t\tfield: SugaredRelativeSingleEntity['field']\n\t\toptions: SugaredQualifiedEntityList['entities']\n\t}\n\t& SelectEvents\n\nexport const Select = Component(({ field, children, onUnselect, onSelect, options }: SelectProps) => {\n\tconst entity = useEntity()\n\tconst selectedEntity = entity.getEntity({ field })\n\tconst entityExists = selectedEntity.existsOnServer || selectedEntity.hasUnpersistedChanges\n\tconst entitiesArr = useMemo(() => entityExists ? [selectedEntity] : [], [entityExists, selectedEntity])\n\n\tconst handleSelect = useReferentiallyStableCallback<SelectHandler>((selected, action = 'toggle') => {\n\t\tif (action === 'toggle') {\n\t\t\taction = selected.id === selectedEntity.id ? 'unselect' : 'select'\n\t\t}\n\t\tif (action === 'unselect') {\n\t\t\tentity.disconnectEntityAtField({ field })\n\t\t\tonUnselect?.(selected)\n\t\t} else if (action === 'select') {\n\t\t\tentity.connectEntityAtField({ field }, selected)\n\t\t\tonSelect?.(selected)\n\t\t}\n\t})\n\tconst isSelected = useCallback((entity: EntityAccessor) => entity.id === selectedEntity.id, [selectedEntity.id])\n\n\treturn (\n\t\t<SelectCurrentEntitiesContext.Provider value={entitiesArr}>\n\t\t\t<SelectIsSelectedContext.Provider value={isSelected}>\n\t\t\t\t<SelectHandleSelectContext.Provider value={handleSelect}>\n\t\t\t\t\t<SelectOptionsContext.Provider value={options}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</SelectOptionsContext.Provider>\n\t\t\t\t</SelectHandleSelectContext.Provider>\n\t\t\t</SelectIsSelectedContext.Provider>\n\t\t</SelectCurrentEntitiesContext.Provider>\n\t)\n}, ({ field, children }) => {\n\treturn (\n\t\t<HasOne field={field}>\n\t\t\t{children}\n\t\t</HasOne>\n\t)\n})\n\n"],"names":["entity"],"mappings":";;;;;AAca,MAAA,SAAS,UAAU,CAAC,EAAE,OAAO,UAAU,YAAY,UAAU,cAA2B;AACpG,QAAM,SAAS;AACf,QAAM,iBAAiB,OAAO,UAAU,EAAE,MAAO,CAAA;AAC3C,QAAA,eAAe,eAAe,kBAAkB,eAAe;AACrE,QAAM,cAAc,QAAQ,MAAM,eAAe,CAAC,cAAc,IAAI,CAAA,GAAI,CAAC,cAAc,cAAc,CAAC;AAEtG,QAAM,eAAe,+BAA8C,CAAC,UAAU,SAAS,aAAa;AACnG,QAAI,WAAW,UAAU;AACxB,eAAS,SAAS,OAAO,eAAe,KAAK,aAAa;AAAA,IAC3D;AACA,QAAI,WAAW,YAAY;AACnB,aAAA,wBAAwB,EAAE,MAAA,CAAO;AACxC,mBAAa,QAAQ;AAAA,IAAA,WACX,WAAW,UAAU;AAC/B,aAAO,qBAAqB,EAAE,MAAM,GAAG,QAAQ;AAC/C,iBAAW,QAAQ;AAAA,IACpB;AAAA,EAAA,CACA;AACK,QAAA,aAAa,YAAY,CAACA,YAA2BA,QAAO,OAAO,eAAe,IAAI,CAAC,eAAe,EAAE,CAAC;AAG9G,SAAA,oBAAC,6BAA6B,UAA7B,EAAsC,OAAO,aAC7C,UAAA,oBAAC,wBAAwB,UAAxB,EAAiC,OAAO,YACxC,UAAA,oBAAC,0BAA0B,UAA1B,EAAmC,OAAO,cAC1C,UAAA,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,SACpC,SACF,CAAA,EACD,CAAA,EACD,CAAA,EACD,CAAA;AAEF,GAAG,CAAC,EAAE,OAAO,eAAe;AAE1B,SAAA,oBAAC,QAAO,EAAA,OACN,SACF,CAAA;AAEF,CAAC;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../contexts.cjs");
|
|
5
|
+
const reactDataview = require("@contember/react-dataview");
|
|
6
|
+
const SelectDataView = (props) => {
|
|
7
|
+
const handleSelect = contexts.useSelectHandleSelect();
|
|
8
|
+
const entities = contexts.useSelectOptions();
|
|
9
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactDataview.DataView, { ...props, onSelectHighlighted: handleSelect, entities });
|
|
10
|
+
};
|
|
11
|
+
exports.SelectDataView = SelectDataView;
|
|
12
|
+
//# sourceMappingURL=SelectDataView.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectDataView.cjs","sources":["../../../src/components/SelectDataView.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useSelectHandleSelect, useSelectOptions } from '../contexts'\nimport { DataViewProps, DataView } from '@contember/react-dataview'\n\nexport type SelectDataViewProps =\n\t& Omit<DataViewProps, 'entities'>\n\t& {\n\t\tchildren: ReactNode\n\t}\n\nexport const SelectDataView = (props: SelectDataViewProps) => {\n\tconst handleSelect = useSelectHandleSelect()\n\tconst entities = useSelectOptions()\n\treturn (\n\t\t<DataView {...props} onSelectHighlighted={handleSelect} entities={entities} />\n\t)\n}\n"],"names":["useSelectHandleSelect","useSelectOptions","DataView"],"mappings":";;;;;AAUa,MAAA,iBAAiB,CAAC,UAA+B;AAC7D,QAAM,eAAeA,SAAAA;AACrB,QAAM,WAAWC,SAAAA;AACjB,wCACEC,cAAU,UAAA,EAAA,GAAG,OAAO,qBAAqB,cAAc,SAAoB,CAAA;AAE9E;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSelectHandleSelect, useSelectOptions } from "../contexts.js";
|
|
3
|
+
import { DataView } from "@contember/react-dataview";
|
|
4
|
+
const SelectDataView = (props) => {
|
|
5
|
+
const handleSelect = useSelectHandleSelect();
|
|
6
|
+
const entities = useSelectOptions();
|
|
7
|
+
return /* @__PURE__ */ jsx(DataView, { ...props, onSelectHighlighted: handleSelect, entities });
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
SelectDataView
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=SelectDataView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectDataView.js","sources":["../../../src/components/SelectDataView.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useSelectHandleSelect, useSelectOptions } from '../contexts'\nimport { DataViewProps, DataView } from '@contember/react-dataview'\n\nexport type SelectDataViewProps =\n\t& Omit<DataViewProps, 'entities'>\n\t& {\n\t\tchildren: ReactNode\n\t}\n\nexport const SelectDataView = (props: SelectDataViewProps) => {\n\tconst handleSelect = useSelectHandleSelect()\n\tconst entities = useSelectOptions()\n\treturn (\n\t\t<DataView {...props} onSelectHighlighted={handleSelect} entities={entities} />\n\t)\n}\n"],"names":[],"mappings":";;;AAUa,MAAA,iBAAiB,CAAC,UAA+B;AAC7D,QAAM,eAAe;AACrB,QAAM,WAAW;AACjB,6BACE,UAAU,EAAA,GAAG,OAAO,qBAAqB,cAAc,SAAoB,CAAA;AAE9E;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../contexts.cjs");
|
|
5
|
+
const reactBinding = require("@contember/react-binding");
|
|
6
|
+
const SelectEachValue = ({ children }) => {
|
|
7
|
+
const entities = contexts.useSelectCurrentEntities();
|
|
8
|
+
return entities.map((entity) => /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Entity, { accessor: entity, children }, entity.key));
|
|
9
|
+
};
|
|
10
|
+
exports.SelectEachValue = SelectEachValue;
|
|
11
|
+
//# sourceMappingURL=SelectEachItem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectEachItem.cjs","sources":["../../../src/components/SelectEachItem.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useSelectCurrentEntities } from '../contexts'\nimport { Entity } from '@contember/react-binding'\n\n\nexport const SelectEachValue = ({ children }: { children: ReactNode }) => {\n\tconst entities = useSelectCurrentEntities()\n\treturn entities.map(entity => (\n\t\t<Entity key={entity.key} accessor={entity}>\n\t\t\t{children}\n\t\t</Entity>\n\t))\n}\n"],"names":["useSelectCurrentEntities","jsx","Entity"],"mappings":";;;;;AAKO,MAAM,kBAAkB,CAAC,EAAE,eAAwC;AACzE,QAAM,WAAWA,SAAAA;AACV,SAAA,SAAS,IAAI,CAAA,WAClBC,2BAAA,IAAAC,aAAA,QAAA,EAAwB,UAAU,QACjC,SAAA,GADW,OAAO,GAEpB,CACA;AACF;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSelectCurrentEntities } from "../contexts.js";
|
|
3
|
+
import { Entity } from "@contember/react-binding";
|
|
4
|
+
const SelectEachValue = ({ children }) => {
|
|
5
|
+
const entities = useSelectCurrentEntities();
|
|
6
|
+
return entities.map((entity) => /* @__PURE__ */ jsx(Entity, { accessor: entity, children }, entity.key));
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
SelectEachValue
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=SelectEachItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectEachItem.js","sources":["../../../src/components/SelectEachItem.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useSelectCurrentEntities } from '../contexts'\nimport { Entity } from '@contember/react-binding'\n\n\nexport const SelectEachValue = ({ children }: { children: ReactNode }) => {\n\tconst entities = useSelectCurrentEntities()\n\treturn entities.map(entity => (\n\t\t<Entity key={entity.key} accessor={entity}>\n\t\t\t{children}\n\t\t</Entity>\n\t))\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,kBAAkB,CAAC,EAAE,eAAwC;AACzE,QAAM,WAAW;AACV,SAAA,SAAS,IAAI,CAAA,WAClB,oBAAA,QAAA,EAAwB,UAAU,QACjC,SAAA,GADW,OAAO,GAEpB,CACA;AACF;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
7
|
+
const reactBinding = require("@contember/react-binding");
|
|
8
|
+
const SelectItemTrigger = react.forwardRef(({ action, ...props }, ref) => {
|
|
9
|
+
const handleSelect = contexts.useSelectHandleSelect();
|
|
10
|
+
const entity = reactBinding.useEntity();
|
|
11
|
+
const onClick = react.useCallback(() => {
|
|
12
|
+
handleSelect?.(entity, action);
|
|
13
|
+
}, [action, entity, handleSelect]);
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactSlot.Slot, { onClick, ...props, ref });
|
|
15
|
+
});
|
|
16
|
+
exports.SelectItemTrigger = SelectItemTrigger;
|
|
17
|
+
//# sourceMappingURL=SelectItemTrigger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectItemTrigger.cjs","sources":["../../../src/components/SelectItemTrigger.tsx"],"sourcesContent":["import React, { forwardRef, ReactElement, useCallback } from 'react'\nimport { useSelectHandleSelect } from '../contexts'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useEntity } from '@contember/react-binding'\n\nexport type SelectItemTriggerProps = {\n\tchildren: ReactElement\n\taction?: 'select' | 'unselect' | 'toggle'\n}\n\nexport const SelectItemTrigger = forwardRef<HTMLElement, SelectItemTriggerProps>(({ action, ...props }: SelectItemTriggerProps, ref) => {\n\tconst handleSelect = useSelectHandleSelect()\n\tconst entity = useEntity()\n\tconst onClick = useCallback(() => {\n\t\thandleSelect?.(entity, action)\n\t}, [action, entity, handleSelect])\n\n\treturn <Slot onClick={onClick} {...props} ref={ref} />\n})\n"],"names":["forwardRef","useSelectHandleSelect","useEntity","useCallback","jsx","Slot"],"mappings":";;;;;;;AAUa,MAAA,oBAAoBA,iBAAgD,CAAC,EAAE,QAAQ,GAAG,SAAiC,QAAQ;AACvI,QAAM,eAAeC,SAAAA;AACrB,QAAM,SAASC,aAAAA;AACT,QAAA,UAAUC,MAAAA,YAAY,MAAM;AACjC,mBAAe,QAAQ,MAAM;AAAA,EAC3B,GAAA,CAAC,QAAQ,QAAQ,YAAY,CAAC;AAEjC,SAAQC,2BAAAA,IAAAC,UAAAA,MAAA,EAAK,SAAmB,GAAG,OAAO,IAAU,CAAA;AACrD,CAAC;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback } from "react";
|
|
3
|
+
import { useSelectHandleSelect } from "../contexts.js";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { useEntity } from "@contember/react-binding";
|
|
6
|
+
const SelectItemTrigger = forwardRef(({ action, ...props }, ref) => {
|
|
7
|
+
const handleSelect = useSelectHandleSelect();
|
|
8
|
+
const entity = useEntity();
|
|
9
|
+
const onClick = useCallback(() => {
|
|
10
|
+
handleSelect?.(entity, action);
|
|
11
|
+
}, [action, entity, handleSelect]);
|
|
12
|
+
return /* @__PURE__ */ jsx(Slot, { onClick, ...props, ref });
|
|
13
|
+
});
|
|
14
|
+
export {
|
|
15
|
+
SelectItemTrigger
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=SelectItemTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectItemTrigger.js","sources":["../../../src/components/SelectItemTrigger.tsx"],"sourcesContent":["import React, { forwardRef, ReactElement, useCallback } from 'react'\nimport { useSelectHandleSelect } from '../contexts'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useEntity } from '@contember/react-binding'\n\nexport type SelectItemTriggerProps = {\n\tchildren: ReactElement\n\taction?: 'select' | 'unselect' | 'toggle'\n}\n\nexport const SelectItemTrigger = forwardRef<HTMLElement, SelectItemTriggerProps>(({ action, ...props }: SelectItemTriggerProps, ref) => {\n\tconst handleSelect = useSelectHandleSelect()\n\tconst entity = useEntity()\n\tconst onClick = useCallback(() => {\n\t\thandleSelect?.(entity, action)\n\t}, [action, entity, handleSelect])\n\n\treturn <Slot onClick={onClick} {...props} ref={ref} />\n})\n"],"names":[],"mappings":";;;;;AAUa,MAAA,oBAAoB,WAAgD,CAAC,EAAE,QAAQ,GAAG,SAAiC,QAAQ;AACvI,QAAM,eAAe;AACrB,QAAM,SAAS;AACT,QAAA,UAAU,YAAY,MAAM;AACjC,mBAAe,QAAQ,MAAM;AAAA,EAC3B,GAAA,CAAC,QAAQ,QAAQ,YAAY,CAAC;AAEjC,SAAQ,oBAAA,MAAA,EAAK,SAAmB,GAAG,OAAO,IAAU,CAAA;AACrD,CAAC;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const reactBinding = require("@contember/react-binding");
|
|
5
|
+
const react = require("react");
|
|
6
|
+
const contexts = require("../contexts.cjs");
|
|
7
|
+
const SelectNewItem = ({ children }) => {
|
|
8
|
+
const options = contexts.useSelectOptions();
|
|
9
|
+
const env = reactBinding.useEnvironment();
|
|
10
|
+
const { entityName } = react.useMemo(() => reactBinding.QueryLanguage.desugarQualifiedEntityList({ entities: options }, env), [env, options]);
|
|
11
|
+
const [state, setState] = react.useState(null);
|
|
12
|
+
const extendTree = reactBinding.useExtendTree();
|
|
13
|
+
const getSubTree = reactBinding.useGetEntitySubTree();
|
|
14
|
+
react.useEffect(() => {
|
|
15
|
+
(async () => {
|
|
16
|
+
const treeRootId = await extendTree(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.EntitySubTree, { entity: {
|
|
17
|
+
entityName
|
|
18
|
+
}, expectedMutation: "none", isUnpersisted: true, isCreating: true, children }) }));
|
|
19
|
+
if (!treeRootId) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const entity = getSubTree({
|
|
23
|
+
entity: {
|
|
24
|
+
entityName
|
|
25
|
+
},
|
|
26
|
+
isCreating: true
|
|
27
|
+
}, treeRootId);
|
|
28
|
+
setState({
|
|
29
|
+
entity,
|
|
30
|
+
treeRootId
|
|
31
|
+
});
|
|
32
|
+
})();
|
|
33
|
+
}, [children, entityName, extendTree, getSubTree]);
|
|
34
|
+
if (!state) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.TreeRootIdProvider, { treeRootId: state.treeRootId, children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Entity, { accessor: state.entity, children }) }) });
|
|
38
|
+
};
|
|
39
|
+
exports.SelectNewItem = SelectNewItem;
|
|
40
|
+
//# sourceMappingURL=SelectNewItem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectNewItem.cjs","sources":["../../../src/components/SelectNewItem.tsx"],"sourcesContent":["import { Entity, EntityAccessor, EntitySubTree, QueryLanguage, TreeRootId, TreeRootIdProvider, useEnvironment, useExtendTree, useGetEntitySubTree } from '@contember/react-binding'\nimport * as React from 'react'\nimport { ReactNode, useEffect, useMemo, useState } from 'react'\nimport { useSelectOptions } from '../contexts'\n\nexport const SelectNewItem = ({ children }: { children: ReactNode }) => {\n\tconst options = useSelectOptions()\n\tconst env = useEnvironment()\n\tconst { entityName } = useMemo((() => QueryLanguage.desugarQualifiedEntityList({ entities: options }, env)), [env, options])\n\n\tconst [state, setState] = useState<{ entity: EntityAccessor, treeRootId: TreeRootId } | null>(null)\n\tconst extendTree = useExtendTree()\n\tconst getSubTree = useGetEntitySubTree()\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tconst treeRootId = await extendTree(<>\n\t\t\t\t<EntitySubTree entity={{\n\t\t\t\t\tentityName,\n\t\t\t\t}} expectedMutation={'none'} isUnpersisted isCreating>\n\t\t\t\t\t{children}\n\t\t\t\t</EntitySubTree>\n\t\t\t</>)\n\t\t\tif (!treeRootId) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst entity = getSubTree({\n\t\t\t\tentity: {\n\t\t\t\t\tentityName: entityName,\n\t\t\t\t},\n\t\t\t\tisCreating: true,\n\t\t\t}, treeRootId)\n\t\t\tsetState({\n\t\t\t\tentity,\n\t\t\t\ttreeRootId,\n\t\t\t})\n\t\t})()\n\t}, [children, entityName, extendTree, getSubTree])\n\n\tif (!state) {\n\t\treturn null\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<TreeRootIdProvider treeRootId={state.treeRootId}>\n\t\t\t\t<Entity accessor={state.entity}>\n\t\t\t\t\t{children}\n\t\t\t\t</Entity>\n\t\t\t</TreeRootIdProvider>\n\t\t</>\n\t)\n}\n"],"names":["useSelectOptions","useEnvironment","useMemo","QueryLanguage","useState","useExtendTree","useGetEntitySubTree","useEffect","jsx","Fragment","EntitySubTree","TreeRootIdProvider","Entity"],"mappings":";;;;;;AAKO,MAAM,gBAAgB,CAAC,EAAE,eAAwC;AACvE,QAAM,UAAUA,SAAAA;AAChB,QAAM,MAAMC,aAAAA;AACZ,QAAM,EAAE,WAAW,IAAIC,MAAS,QAAA,MAAMC,aAAAA,cAAc,2BAA2B,EAAE,UAAU,QAAA,GAAW,GAAG,GAAI,CAAC,KAAK,OAAO,CAAC;AAE3H,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAoE,IAAI;AAClG,QAAM,aAAaC,aAAAA;AACnB,QAAM,aAAaC,aAAAA;AAEnBC,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,YAAM,aAAa,MAAM,WACxBC,+BAAAC,WAAAA,UAAA,EAAA,UAAAD,2BAAA,IAACE,8BAAc,QAAQ;AAAA,QACtB;AAAA,MAAA,GACE,kBAAkB,QAAQ,eAAa,MAAC,YAAU,MACnD,SACF,CAAA,EACD,CAAA,CAAG;AACH,UAAI,CAAC,YAAY;AAChB;AAAA,MACD;AAEA,YAAM,SAAS,WAAW;AAAA,QACzB,QAAQ;AAAA,UACP;AAAA,QACD;AAAA,QACA,YAAY;AAAA,SACV,UAAU;AACJ,eAAA;AAAA,QACR;AAAA,QACA;AAAA,MAAA,CACA;AAAA,IAAA;KAEA,CAAC,UAAU,YAAY,YAAY,UAAU,CAAC;AAEjD,MAAI,CAAC,OAAO;AACJ,WAAA;AAAA,EACR;AAEA,SAEEF,2BAAA,IAAAC,WAAA,UAAA,EAAA,UAAAD,2BAAA,IAACG,iCAAmB,EAAA,YAAY,MAAM,YACrC,UAACH,+BAAAI,aAAAA,QAAA,EAAO,UAAU,MAAM,QACtB,SACF,CAAA,GACD,EACD,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEnvironment, QueryLanguage, useExtendTree, useGetEntitySubTree, EntitySubTree, TreeRootIdProvider, Entity } from "@contember/react-binding";
|
|
3
|
+
import { useMemo, useState, useEffect } from "react";
|
|
4
|
+
import { useSelectOptions } from "../contexts.js";
|
|
5
|
+
const SelectNewItem = ({ children }) => {
|
|
6
|
+
const options = useSelectOptions();
|
|
7
|
+
const env = useEnvironment();
|
|
8
|
+
const { entityName } = useMemo(() => QueryLanguage.desugarQualifiedEntityList({ entities: options }, env), [env, options]);
|
|
9
|
+
const [state, setState] = useState(null);
|
|
10
|
+
const extendTree = useExtendTree();
|
|
11
|
+
const getSubTree = useGetEntitySubTree();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
(async () => {
|
|
14
|
+
const treeRootId = await extendTree(/* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(EntitySubTree, { entity: {
|
|
15
|
+
entityName
|
|
16
|
+
}, expectedMutation: "none", isUnpersisted: true, isCreating: true, children }) }));
|
|
17
|
+
if (!treeRootId) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const entity = getSubTree({
|
|
21
|
+
entity: {
|
|
22
|
+
entityName
|
|
23
|
+
},
|
|
24
|
+
isCreating: true
|
|
25
|
+
}, treeRootId);
|
|
26
|
+
setState({
|
|
27
|
+
entity,
|
|
28
|
+
treeRootId
|
|
29
|
+
});
|
|
30
|
+
})();
|
|
31
|
+
}, [children, entityName, extendTree, getSubTree]);
|
|
32
|
+
if (!state) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(TreeRootIdProvider, { treeRootId: state.treeRootId, children: /* @__PURE__ */ jsx(Entity, { accessor: state.entity, children }) }) });
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
SelectNewItem
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=SelectNewItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectNewItem.js","sources":["../../../src/components/SelectNewItem.tsx"],"sourcesContent":["import { Entity, EntityAccessor, EntitySubTree, QueryLanguage, TreeRootId, TreeRootIdProvider, useEnvironment, useExtendTree, useGetEntitySubTree } from '@contember/react-binding'\nimport * as React from 'react'\nimport { ReactNode, useEffect, useMemo, useState } from 'react'\nimport { useSelectOptions } from '../contexts'\n\nexport const SelectNewItem = ({ children }: { children: ReactNode }) => {\n\tconst options = useSelectOptions()\n\tconst env = useEnvironment()\n\tconst { entityName } = useMemo((() => QueryLanguage.desugarQualifiedEntityList({ entities: options }, env)), [env, options])\n\n\tconst [state, setState] = useState<{ entity: EntityAccessor, treeRootId: TreeRootId } | null>(null)\n\tconst extendTree = useExtendTree()\n\tconst getSubTree = useGetEntitySubTree()\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tconst treeRootId = await extendTree(<>\n\t\t\t\t<EntitySubTree entity={{\n\t\t\t\t\tentityName,\n\t\t\t\t}} expectedMutation={'none'} isUnpersisted isCreating>\n\t\t\t\t\t{children}\n\t\t\t\t</EntitySubTree>\n\t\t\t</>)\n\t\t\tif (!treeRootId) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst entity = getSubTree({\n\t\t\t\tentity: {\n\t\t\t\t\tentityName: entityName,\n\t\t\t\t},\n\t\t\t\tisCreating: true,\n\t\t\t}, treeRootId)\n\t\t\tsetState({\n\t\t\t\tentity,\n\t\t\t\ttreeRootId,\n\t\t\t})\n\t\t})()\n\t}, [children, entityName, extendTree, getSubTree])\n\n\tif (!state) {\n\t\treturn null\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<TreeRootIdProvider treeRootId={state.treeRootId}>\n\t\t\t\t<Entity accessor={state.entity}>\n\t\t\t\t\t{children}\n\t\t\t\t</Entity>\n\t\t\t</TreeRootIdProvider>\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":";;;;AAKO,MAAM,gBAAgB,CAAC,EAAE,eAAwC;AACvE,QAAM,UAAU;AAChB,QAAM,MAAM;AACZ,QAAM,EAAE,WAAW,IAAI,QAAS,MAAM,cAAc,2BAA2B,EAAE,UAAU,QAAA,GAAW,GAAG,GAAI,CAAC,KAAK,OAAO,CAAC;AAE3H,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoE,IAAI;AAClG,QAAM,aAAa;AACnB,QAAM,aAAa;AAEnB,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,YAAM,aAAa,MAAM,WACxB,oBAAA,UAAA,EAAA,UAAA,oBAAC,iBAAc,QAAQ;AAAA,QACtB;AAAA,MAAA,GACE,kBAAkB,QAAQ,eAAa,MAAC,YAAU,MACnD,SACF,CAAA,EACD,CAAA,CAAG;AACH,UAAI,CAAC,YAAY;AAChB;AAAA,MACD;AAEA,YAAM,SAAS,WAAW;AAAA,QACzB,QAAQ;AAAA,UACP;AAAA,QACD;AAAA,QACA,YAAY;AAAA,SACV,UAAU;AACJ,eAAA;AAAA,QACR;AAAA,QACA;AAAA,MAAA,CACA;AAAA,IAAA;KAEA,CAAC,UAAU,YAAY,YAAY,UAAU,CAAC;AAEjD,MAAI,CAAC,OAAO;AACJ,WAAA;AAAA,EACR;AAEA,SAEE,oBAAA,UAAA,EAAA,UAAA,oBAAC,oBAAmB,EAAA,YAAY,MAAM,YACrC,UAAC,oBAAA,QAAA,EAAO,UAAU,MAAM,QACtB,SACF,CAAA,GACD,EACD,CAAA;AAEF;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
7
|
+
const reactBinding = require("@contember/react-binding");
|
|
8
|
+
const utilities = require("@contember/utilities");
|
|
9
|
+
const SelectOption = react.forwardRef(({ action, ...props }, ref) => {
|
|
10
|
+
const isSelected = contexts.useSelectIsSelected();
|
|
11
|
+
const entity = reactBinding.useEntity();
|
|
12
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
13
|
+
reactSlot.Slot,
|
|
14
|
+
{
|
|
15
|
+
ref,
|
|
16
|
+
"data-selected": utilities.dataAttribute(isSelected?.(entity)),
|
|
17
|
+
...props
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
exports.SelectOption = SelectOption;
|
|
22
|
+
//# sourceMappingURL=SelectOption.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectOption.cjs","sources":["../../../src/components/SelectOption.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode } from 'react'\nimport { useSelectIsSelected } from '../contexts'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useEntity } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\n\nexport type SelectOptionProps = {\n\tchildren: ReactNode\n\taction?: 'select' | 'unselect' | 'toggle'\n}\n\nexport const SelectOption = forwardRef<HTMLElement, SelectOptionProps>(({ action, ...props }, ref) => {\n\tconst isSelected = useSelectIsSelected()\n\tconst entity = useEntity()\n\treturn (\n\t\t<Slot\n\t\t\tref={ref}\n\t\t\tdata-selected={dataAttribute(isSelected?.(entity))}\n\t\t\t{...props}\n\t\t/>\n\t)\n})\n"],"names":["forwardRef","useSelectIsSelected","useEntity","jsx","Slot","dataAttribute"],"mappings":";;;;;;;;AAWa,MAAA,eAAeA,iBAA2C,CAAC,EAAE,QAAQ,GAAG,SAAS,QAAQ;AACrG,QAAM,aAAaC,SAAAA;AACnB,QAAM,SAASC,aAAAA;AAEd,SAAAC,2BAAA;AAAA,IAACC,UAAA;AAAA,IAAA;AAAA,MACA;AAAA,MACA,iBAAeC,UAAA,cAAc,aAAa,MAAM,CAAC;AAAA,MAChD,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { useSelectIsSelected } from "../contexts.js";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { useEntity } from "@contember/react-binding";
|
|
6
|
+
import { dataAttribute } from "@contember/utilities";
|
|
7
|
+
const SelectOption = forwardRef(({ action, ...props }, ref) => {
|
|
8
|
+
const isSelected = useSelectIsSelected();
|
|
9
|
+
const entity = useEntity();
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
Slot,
|
|
12
|
+
{
|
|
13
|
+
ref,
|
|
14
|
+
"data-selected": dataAttribute(isSelected?.(entity)),
|
|
15
|
+
...props
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
export {
|
|
20
|
+
SelectOption
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=SelectOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectOption.js","sources":["../../../src/components/SelectOption.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode } from 'react'\nimport { useSelectIsSelected } from '../contexts'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useEntity } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\n\nexport type SelectOptionProps = {\n\tchildren: ReactNode\n\taction?: 'select' | 'unselect' | 'toggle'\n}\n\nexport const SelectOption = forwardRef<HTMLElement, SelectOptionProps>(({ action, ...props }, ref) => {\n\tconst isSelected = useSelectIsSelected()\n\tconst entity = useEntity()\n\treturn (\n\t\t<Slot\n\t\t\tref={ref}\n\t\t\tdata-selected={dataAttribute(isSelected?.(entity))}\n\t\t\t{...props}\n\t\t/>\n\t)\n})\n"],"names":[],"mappings":";;;;;;AAWa,MAAA,eAAe,WAA2C,CAAC,EAAE,QAAQ,GAAG,SAAS,QAAQ;AACrG,QAAM,aAAa;AACnB,QAAM,SAAS;AAEd,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,iBAAe,cAAc,aAAa,MAAM,CAAC;AAAA,MAChD,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../contexts.cjs");
|
|
5
|
+
const SelectPlaceholder = ({ children }) => {
|
|
6
|
+
const hasEntities = contexts.useSelectCurrentEntities().length > 0;
|
|
7
|
+
return hasEntities ? null : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
8
|
+
};
|
|
9
|
+
exports.SelectPlaceholder = SelectPlaceholder;
|
|
10
|
+
//# sourceMappingURL=SelectPlaceholder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectPlaceholder.cjs","sources":["../../../src/components/SelectPlaceholder.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useSelectCurrentEntities } from '../contexts'\n\nexport const SelectPlaceholder = ({ children }: { children: ReactNode }) => {\n\tconst hasEntities = useSelectCurrentEntities().length > 0\n\treturn hasEntities ? null : <>{children}</>\n}\n"],"names":["useSelectCurrentEntities","jsx","Fragment"],"mappings":";;;;AAGO,MAAM,oBAAoB,CAAC,EAAE,eAAwC;AACrE,QAAA,cAAcA,SAAAA,2BAA2B,SAAS;AACjD,SAAA,cAAc,OAAOC,2BAAAA,IAAAC,WAAAA,UAAA,EAAG,SAAS,CAAA;AACzC;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useSelectCurrentEntities } from "../contexts.js";
|
|
3
|
+
const SelectPlaceholder = ({ children }) => {
|
|
4
|
+
const hasEntities = useSelectCurrentEntities().length > 0;
|
|
5
|
+
return hasEntities ? null : /* @__PURE__ */ jsx(Fragment, { children });
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
SelectPlaceholder
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=SelectPlaceholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectPlaceholder.js","sources":["../../../src/components/SelectPlaceholder.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useSelectCurrentEntities } from '../contexts'\n\nexport const SelectPlaceholder = ({ children }: { children: ReactNode }) => {\n\tconst hasEntities = useSelectCurrentEntities().length > 0\n\treturn hasEntities ? null : <>{children}</>\n}\n"],"names":[],"mappings":";;AAGO,MAAM,oBAAoB,CAAC,EAAE,eAAwC;AACrE,QAAA,cAAc,2BAA2B,SAAS;AACjD,SAAA,cAAc,OAAO,oBAAA,UAAA,EAAG,SAAS,CAAA;AACzC;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const contexts = require("../contexts.cjs");
|
|
6
|
+
const reactBinding = require("@contember/react-binding");
|
|
7
|
+
const reactUtils = require("@contember/react-utils");
|
|
8
|
+
const reactRepeater = require("@contember/react-repeater");
|
|
9
|
+
const SortableMultiSelect = reactBinding.Component(({ field, children, sortableBy, connectAt, options, onSelect, onUnselect }) => {
|
|
10
|
+
const list = reactBinding.useEntityList({ field });
|
|
11
|
+
const entitiesArr = react.useMemo(() => Array.from(list), [list]);
|
|
12
|
+
const selectedEntities = react.useMemo(() => Array.from(list).map((it) => it.getEntity({ field: connectAt }).id), [connectAt, list]);
|
|
13
|
+
const handler = reactUtils.useReferentiallyStableCallback((entity, action = "toggle") => {
|
|
14
|
+
const isSelected2 = selectedEntities.includes(entity.id);
|
|
15
|
+
if (action === "toggle") {
|
|
16
|
+
action = isSelected2 ? "unselect" : "select";
|
|
17
|
+
}
|
|
18
|
+
if (action === "unselect" && isSelected2) {
|
|
19
|
+
Array.from(list).find((it) => it.getEntity({ field: connectAt }).id === entity.id)?.deleteEntity();
|
|
20
|
+
onUnselect?.(entity);
|
|
21
|
+
} else if (action === "select" && !isSelected2) {
|
|
22
|
+
list.createNewEntity((getEntity) => {
|
|
23
|
+
getEntity().connectEntityAtField({ field: connectAt }, entity);
|
|
24
|
+
onSelect?.(entity);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const isSelected = react.useCallback((entity) => {
|
|
29
|
+
return selectedEntities.includes(entity.id);
|
|
30
|
+
}, [selectedEntities]);
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRepeater.Repeater, { field, sortableBy, initialEntityCount: 0, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectCurrentEntitiesContext.Provider, { value: entitiesArr, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectIsSelectedContext.Provider, { value: isSelected, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectHandleSelectContext.Provider, { value: handler, children: /* @__PURE__ */ jsxRuntime.jsx(contexts.SelectOptionsContext.Provider, { value: options, children }) }) }) }) });
|
|
32
|
+
}, ({ children, field, sortableBy, connectAt }) => {
|
|
33
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRepeater.Repeater, { field, sortableBy, initialEntityCount: 0, children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.HasOne, { field: connectAt, children }) });
|
|
34
|
+
});
|
|
35
|
+
exports.SortableMultiSelect = SortableMultiSelect;
|
|
36
|
+
//# sourceMappingURL=SortableMultiSelect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortableMultiSelect.cjs","sources":["../../../src/components/SortableMultiSelect.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo } from 'react'\nimport { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext, SelectIsSelectedContext, SelectOptionsContext } from '../contexts'\nimport { Component, EntityAccessor, HasOne, SugaredQualifiedEntityList, SugaredRelativeEntityList, SugaredRelativeSingleEntity, SugaredRelativeSingleField, useEntityList } from '@contember/react-binding'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\nimport { Repeater } from '@contember/react-repeater'\nimport { SelectEvents } from '../types'\n\nexport type SortableMultiSelectProps =\n\t& {\n\t\tchildren: ReactNode\n\t\tfield: SugaredRelativeEntityList['field']\n\t\toptions: SugaredQualifiedEntityList['entities']\n\t\tsortableBy: SugaredRelativeSingleField['field']\n\t\tconnectAt: SugaredRelativeSingleEntity['field']\n\t}\n\t& SelectEvents\n\nexport const SortableMultiSelect = Component(({ field, children, sortableBy, connectAt, options, onSelect, onUnselect }: SortableMultiSelectProps) => {\n\tconst list = useEntityList({ field })\n\tconst entitiesArr = useMemo(() => Array.from(list), [list])\n\n\tconst selectedEntities = useMemo(() => Array.from(list).map(it => it.getEntity({ field: connectAt }).id), [connectAt, list])\n\n\tconst handler = useReferentiallyStableCallback<SelectHandler>((entity, action = 'toggle') => {\n\t\tconst isSelected = selectedEntities.includes(entity.id)\n\t\tif (action === 'toggle') {\n\t\t\taction = isSelected ? 'unselect' : 'select'\n\t\t}\n\t\tif (action === 'unselect' && isSelected) {\n\t\t\tArray.from(list).find(it => it.getEntity({ field: connectAt }).id === entity.id)?.deleteEntity()\n\t\t\tonUnselect?.(entity)\n\t\t} else if (action === 'select' && !isSelected) {\n\t\t\tlist.createNewEntity(getEntity => {\n\t\t\t\tgetEntity().connectEntityAtField({ field: connectAt }, entity)\n\t\t\t\tonSelect?.(entity)\n\t\t\t})\n\t\t}\n\t})\n\tconst isSelected = useCallback((entity: EntityAccessor) => {\n\t\treturn selectedEntities.includes(entity.id)\n\t}, [selectedEntities])\n\n\treturn (\n\t\t<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0}>\n\t\t\t<SelectCurrentEntitiesContext.Provider value={entitiesArr}>\n\t\t\t\t<SelectIsSelectedContext.Provider value={isSelected}>\n\t\t\t\t\t<SelectHandleSelectContext.Provider value={handler}>\n\t\t\t\t\t\t<SelectOptionsContext.Provider value={options}>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t</SelectOptionsContext.Provider>\n\t\t\t\t\t</SelectHandleSelectContext.Provider>\n\t\t\t\t</SelectIsSelectedContext.Provider>\n\t\t\t</SelectCurrentEntitiesContext.Provider>\n\t\t</Repeater>\n\t)\n}, ({ children, field, sortableBy, connectAt }) => {\n\treturn (\n\t\t<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0}>\n\t\t\t<HasOne field={connectAt}>\n\t\t\t\t{children}\n\t\t\t</HasOne>\n\t\t</Repeater>\n\t)\n})\n\n"],"names":["Component","useEntityList","useMemo","useReferentiallyStableCallback","isSelected","useCallback","jsx","Repeater","SelectCurrentEntitiesContext","SelectIsSelectedContext","SelectHandleSelectContext","SelectOptionsContext","HasOne"],"mappings":";;;;;;;;AAiBa,MAAA,sBAAsBA,aAAU,UAAA,CAAC,EAAE,OAAO,UAAU,YAAY,WAAW,SAAS,UAAU,iBAA2C;AACrJ,QAAM,OAAOC,aAAAA,cAAc,EAAE,MAAO,CAAA;AAC9B,QAAA,cAAcC,cAAQ,MAAM,MAAM,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC;AAEpD,QAAA,mBAAmBA,cAAQ,MAAM,MAAM,KAAK,IAAI,EAAE,IAAI,CAAM,OAAA,GAAG,UAAU,EAAE,OAAO,WAAW,EAAE,EAAE,GAAG,CAAC,WAAW,IAAI,CAAC;AAE3H,QAAM,UAAUC,WAAA,+BAA8C,CAAC,QAAQ,SAAS,aAAa;AAC5F,UAAMC,cAAa,iBAAiB,SAAS,OAAO,EAAE;AACtD,QAAI,WAAW,UAAU;AACxB,eAASA,cAAa,aAAa;AAAA,IACpC;AACI,QAAA,WAAW,cAAcA,aAAY;AACxC,YAAM,KAAK,IAAI,EAAE,KAAK,CAAA,OAAM,GAAG,UAAU,EAAE,OAAO,UAAW,CAAA,EAAE,OAAO,OAAO,EAAE,GAAG;AAClF,mBAAa,MAAM;AAAA,IACT,WAAA,WAAW,YAAY,CAACA,aAAY;AAC9C,WAAK,gBAAgB,CAAa,cAAA;AACjC,kBAAA,EAAY,qBAAqB,EAAE,OAAO,UAAA,GAAa,MAAM;AAC7D,mBAAW,MAAM;AAAA,MAAA,CACjB;AAAA,IACF;AAAA,EAAA,CACA;AACK,QAAA,aAAaC,kBAAY,CAAC,WAA2B;AACnD,WAAA,iBAAiB,SAAS,OAAO,EAAE;AAAA,EAAA,GACxC,CAAC,gBAAgB,CAAC;AAErB,SACEC,2BAAA,IAAAC,cAAA,UAAA,EAAS,OAAc,YAAwB,oBAAoB,GACnE,UAAAD,2BAAA,IAACE,SAA6B,6BAAA,UAA7B,EAAsC,OAAO,aAC7C,UAACF,2BAAAA,IAAAG,SAAA,wBAAwB,UAAxB,EAAiC,OAAO,YACxC,UAAAH,2BAAAA,IAACI,SAAAA,0BAA0B,UAA1B,EAAmC,OAAO,SAC1C,UAACJ,+BAAAK,SAAAA,qBAAqB,UAArB,EAA8B,OAAO,SACpC,SAAA,CACF,EACD,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF,GAAG,CAAC,EAAE,UAAU,OAAO,YAAY,gBAAgB;AAEjD,SAAAL,2BAAAA,IAACC,cAAAA,UAAS,EAAA,OAAc,YAAwB,oBAAoB,GACnE,UAAAD,2BAAAA,IAACM,aAAAA,QAAO,EAAA,OAAO,WACb,SAAA,CACF,EACD,CAAA;AAEF,CAAC;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useCallback } from "react";
|
|
3
|
+
import { SelectCurrentEntitiesContext, SelectIsSelectedContext, SelectHandleSelectContext, SelectOptionsContext } from "../contexts.js";
|
|
4
|
+
import { Component, useEntityList, HasOne } from "@contember/react-binding";
|
|
5
|
+
import { useReferentiallyStableCallback } from "@contember/react-utils";
|
|
6
|
+
import { Repeater } from "@contember/react-repeater";
|
|
7
|
+
const SortableMultiSelect = Component(({ field, children, sortableBy, connectAt, options, onSelect, onUnselect }) => {
|
|
8
|
+
const list = useEntityList({ field });
|
|
9
|
+
const entitiesArr = useMemo(() => Array.from(list), [list]);
|
|
10
|
+
const selectedEntities = useMemo(() => Array.from(list).map((it) => it.getEntity({ field: connectAt }).id), [connectAt, list]);
|
|
11
|
+
const handler = useReferentiallyStableCallback((entity, action = "toggle") => {
|
|
12
|
+
const isSelected2 = selectedEntities.includes(entity.id);
|
|
13
|
+
if (action === "toggle") {
|
|
14
|
+
action = isSelected2 ? "unselect" : "select";
|
|
15
|
+
}
|
|
16
|
+
if (action === "unselect" && isSelected2) {
|
|
17
|
+
Array.from(list).find((it) => it.getEntity({ field: connectAt }).id === entity.id)?.deleteEntity();
|
|
18
|
+
onUnselect?.(entity);
|
|
19
|
+
} else if (action === "select" && !isSelected2) {
|
|
20
|
+
list.createNewEntity((getEntity) => {
|
|
21
|
+
getEntity().connectEntityAtField({ field: connectAt }, entity);
|
|
22
|
+
onSelect?.(entity);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const isSelected = useCallback((entity) => {
|
|
27
|
+
return selectedEntities.includes(entity.id);
|
|
28
|
+
}, [selectedEntities]);
|
|
29
|
+
return /* @__PURE__ */ jsx(Repeater, { field, sortableBy, initialEntityCount: 0, children: /* @__PURE__ */ jsx(SelectCurrentEntitiesContext.Provider, { value: entitiesArr, children: /* @__PURE__ */ jsx(SelectIsSelectedContext.Provider, { value: isSelected, children: /* @__PURE__ */ jsx(SelectHandleSelectContext.Provider, { value: handler, children: /* @__PURE__ */ jsx(SelectOptionsContext.Provider, { value: options, children }) }) }) }) });
|
|
30
|
+
}, ({ children, field, sortableBy, connectAt }) => {
|
|
31
|
+
return /* @__PURE__ */ jsx(Repeater, { field, sortableBy, initialEntityCount: 0, children: /* @__PURE__ */ jsx(HasOne, { field: connectAt, children }) });
|
|
32
|
+
});
|
|
33
|
+
export {
|
|
34
|
+
SortableMultiSelect
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=SortableMultiSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortableMultiSelect.js","sources":["../../../src/components/SortableMultiSelect.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo } from 'react'\nimport { SelectCurrentEntitiesContext, SelectHandler, SelectHandleSelectContext, SelectIsSelectedContext, SelectOptionsContext } from '../contexts'\nimport { Component, EntityAccessor, HasOne, SugaredQualifiedEntityList, SugaredRelativeEntityList, SugaredRelativeSingleEntity, SugaredRelativeSingleField, useEntityList } from '@contember/react-binding'\nimport { useReferentiallyStableCallback } from '@contember/react-utils'\nimport { Repeater } from '@contember/react-repeater'\nimport { SelectEvents } from '../types'\n\nexport type SortableMultiSelectProps =\n\t& {\n\t\tchildren: ReactNode\n\t\tfield: SugaredRelativeEntityList['field']\n\t\toptions: SugaredQualifiedEntityList['entities']\n\t\tsortableBy: SugaredRelativeSingleField['field']\n\t\tconnectAt: SugaredRelativeSingleEntity['field']\n\t}\n\t& SelectEvents\n\nexport const SortableMultiSelect = Component(({ field, children, sortableBy, connectAt, options, onSelect, onUnselect }: SortableMultiSelectProps) => {\n\tconst list = useEntityList({ field })\n\tconst entitiesArr = useMemo(() => Array.from(list), [list])\n\n\tconst selectedEntities = useMemo(() => Array.from(list).map(it => it.getEntity({ field: connectAt }).id), [connectAt, list])\n\n\tconst handler = useReferentiallyStableCallback<SelectHandler>((entity, action = 'toggle') => {\n\t\tconst isSelected = selectedEntities.includes(entity.id)\n\t\tif (action === 'toggle') {\n\t\t\taction = isSelected ? 'unselect' : 'select'\n\t\t}\n\t\tif (action === 'unselect' && isSelected) {\n\t\t\tArray.from(list).find(it => it.getEntity({ field: connectAt }).id === entity.id)?.deleteEntity()\n\t\t\tonUnselect?.(entity)\n\t\t} else if (action === 'select' && !isSelected) {\n\t\t\tlist.createNewEntity(getEntity => {\n\t\t\t\tgetEntity().connectEntityAtField({ field: connectAt }, entity)\n\t\t\t\tonSelect?.(entity)\n\t\t\t})\n\t\t}\n\t})\n\tconst isSelected = useCallback((entity: EntityAccessor) => {\n\t\treturn selectedEntities.includes(entity.id)\n\t}, [selectedEntities])\n\n\treturn (\n\t\t<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0}>\n\t\t\t<SelectCurrentEntitiesContext.Provider value={entitiesArr}>\n\t\t\t\t<SelectIsSelectedContext.Provider value={isSelected}>\n\t\t\t\t\t<SelectHandleSelectContext.Provider value={handler}>\n\t\t\t\t\t\t<SelectOptionsContext.Provider value={options}>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t</SelectOptionsContext.Provider>\n\t\t\t\t\t</SelectHandleSelectContext.Provider>\n\t\t\t\t</SelectIsSelectedContext.Provider>\n\t\t\t</SelectCurrentEntitiesContext.Provider>\n\t\t</Repeater>\n\t)\n}, ({ children, field, sortableBy, connectAt }) => {\n\treturn (\n\t\t<Repeater field={field} sortableBy={sortableBy} initialEntityCount={0}>\n\t\t\t<HasOne field={connectAt}>\n\t\t\t\t{children}\n\t\t\t</HasOne>\n\t\t</Repeater>\n\t)\n})\n\n"],"names":["isSelected"],"mappings":";;;;;;AAiBa,MAAA,sBAAsB,UAAU,CAAC,EAAE,OAAO,UAAU,YAAY,WAAW,SAAS,UAAU,iBAA2C;AACrJ,QAAM,OAAO,cAAc,EAAE,MAAO,CAAA;AAC9B,QAAA,cAAc,QAAQ,MAAM,MAAM,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC;AAEpD,QAAA,mBAAmB,QAAQ,MAAM,MAAM,KAAK,IAAI,EAAE,IAAI,CAAM,OAAA,GAAG,UAAU,EAAE,OAAO,WAAW,EAAE,EAAE,GAAG,CAAC,WAAW,IAAI,CAAC;AAE3H,QAAM,UAAU,+BAA8C,CAAC,QAAQ,SAAS,aAAa;AAC5F,UAAMA,cAAa,iBAAiB,SAAS,OAAO,EAAE;AACtD,QAAI,WAAW,UAAU;AACxB,eAASA,cAAa,aAAa;AAAA,IACpC;AACI,QAAA,WAAW,cAAcA,aAAY;AACxC,YAAM,KAAK,IAAI,EAAE,KAAK,CAAA,OAAM,GAAG,UAAU,EAAE,OAAO,UAAW,CAAA,EAAE,OAAO,OAAO,EAAE,GAAG;AAClF,mBAAa,MAAM;AAAA,IACT,WAAA,WAAW,YAAY,CAACA,aAAY;AAC9C,WAAK,gBAAgB,CAAa,cAAA;AACjC,kBAAA,EAAY,qBAAqB,EAAE,OAAO,UAAA,GAAa,MAAM;AAC7D,mBAAW,MAAM;AAAA,MAAA,CACjB;AAAA,IACF;AAAA,EAAA,CACA;AACK,QAAA,aAAa,YAAY,CAAC,WAA2B;AACnD,WAAA,iBAAiB,SAAS,OAAO,EAAE;AAAA,EAAA,GACxC,CAAC,gBAAgB,CAAC;AAErB,SACE,oBAAA,UAAA,EAAS,OAAc,YAAwB,oBAAoB,GACnE,UAAA,oBAAC,6BAA6B,UAA7B,EAAsC,OAAO,aAC7C,UAAC,oBAAA,wBAAwB,UAAxB,EAAiC,OAAO,YACxC,UAAA,oBAAC,0BAA0B,UAA1B,EAAmC,OAAO,SAC1C,UAAC,oBAAA,qBAAqB,UAArB,EAA8B,OAAO,SACpC,SAAA,CACF,EACD,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF,GAAG,CAAC,EAAE,UAAU,OAAO,YAAY,gBAAgB;AAEjD,SAAA,oBAAC,UAAS,EAAA,OAAc,YAAwB,oBAAoB,GACnE,UAAA,oBAAC,QAAO,EAAA,OAAO,WACb,SAAA,CACF,EACD,CAAA;AAEF,CAAC;"}
|