@rebasepro/cms 0.24.1-canary.gcb918fc → 0.25.0-canary.ge06257e
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/collection_editor/ui/collection_editor/properties/StringPropertyField.js +3 -3
- package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +10 -0
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +95 -34
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +6 -3
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +4 -2
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.js +12 -2
- package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -1
- package/dist/editor/editor.js +19 -13
- package/dist/editor/editor.js.map +1 -1
- package/dist/preview/components/storageRenditions.js +6 -4
- package/dist/preview/components/storageRenditions.js.map +1 -1
- package/package.json +9 -9
|
@@ -68,8 +68,8 @@ function StringPropertyField({ widgetId, disabled, showErrors }) {
|
|
|
68
68
|
case "text": return "text (unlimited)";
|
|
69
69
|
case "char": return "char (fixed length)";
|
|
70
70
|
case "varchar": return "varchar (variable length)";
|
|
71
|
-
case "_default_": return "Default (
|
|
72
|
-
default: return "Default (
|
|
71
|
+
case "_default_": return "Default (text)";
|
|
72
|
+
default: return "Default (text)";
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
error: Boolean(columnTypeError),
|
|
@@ -81,7 +81,7 @@ function StringPropertyField({ widgetId, disabled, showErrors }) {
|
|
|
81
81
|
}),
|
|
82
82
|
/* @__PURE__ */ jsx(SelectItem, {
|
|
83
83
|
value: "_default_",
|
|
84
|
-
children: " Default (
|
|
84
|
+
children: " Default (text) "
|
|
85
85
|
}),
|
|
86
86
|
/* @__PURE__ */ jsx(SelectItem, {
|
|
87
87
|
value: "varchar",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringPropertyField.js","names":[],"sources":["../../../../../src/collection_editor/ui/collection_editor/properties/StringPropertyField.tsx"],"sourcesContent":["import { FieldCaption } from \"../../../_cms_internals\";\nimport React from \"react\";\nimport { StringPropertyValidation } from \"./validation/StringPropertyValidation\";\nimport { ValidationPanel } from \"./validation/ValidationPanel\";\nimport { getIn, useFormex } from \"@rebasepro/forms\";\nimport { useTranslation } from \"@rebasepro/app\";\n;\nimport { Select, SelectItem, TextField } from \"@rebasepro/ui\";\n\nexport function StringPropertyField({\n widgetId,\n disabled,\n showErrors\n}: {\n widgetId: \"text_field\" | \"multiline\" | \"email\" | \"user_select\";\n disabled: boolean;\n showErrors: boolean;\n}) {\n\n const { values, setFieldValue, touched, errors } = useFormex();\n const { t } = useTranslation();\n\n const columnTypePath = \"columnType\";\n const columnTypeValue: string | undefined = getIn(values, columnTypePath) as string | undefined;\n const columnTypeError: string | undefined = (getIn(touched, columnTypePath) && getIn(errors, columnTypePath)) as string | undefined;\n\n const isIdPath = \"isId\";\n const isIdValue: string | boolean | undefined = getIn(values, isIdPath) as string | boolean | undefined;\n const isIdError: string | undefined = (getIn(touched, isIdPath) && getIn(errors, isIdPath)) as string | undefined;\n\n return (\n <>\n <div className={\"col-span-12\"}>\n\n <ValidationPanel>\n\n {widgetId === \"text_field\" &&\n <StringPropertyValidation disabled={disabled}\n length={true}\n lowercase={true}\n matches={true}\n max={true}\n min={true}\n trim={true}\n uppercase={true}\n showErrors={showErrors}/>}\n {widgetId === \"user_select\" &&\n <StringPropertyValidation disabled={disabled}\n showErrors={showErrors}/>}\n\n {widgetId === \"multiline\" &&\n <StringPropertyValidation disabled={disabled}\n length={true}\n lowercase={true}\n max={true}\n min={true}\n trim={true}\n uppercase={true}\n showErrors={showErrors}/>}\n\n {widgetId === \"email\" &&\n <StringPropertyValidation disabled={disabled}\n max={true}\n min={true}\n trim={true}\n showErrors={showErrors}/>}\n\n </ValidationPanel>\n\n </div>\n\n <div className={\"col-span-12\"}>\n <Select name={columnTypePath}\n disabled={disabled || Boolean(isIdValue)}\n fullWidth={true}\n value={isIdValue === \"uuid\" ? \"uuid\" : (columnTypeValue ?? \"_default_\")}\n onValueChange={(v) => setFieldValue(columnTypePath, v === \"_default_\" ? undefined : v)}\n renderValue={(v) => {\n if (isIdValue === \"uuid\") return \"uuid (forced by Primary Key)\";\n switch (v) {\n case \"text\": return \"text (unlimited)\";\n case \"char\": return \"char (fixed length)\";\n case \"varchar\": return \"varchar (variable length)\";\n case \"_default_\": return \"Default (varchar)\";\n default: return \"Default (varchar)\";\n }\n }}\n error={Boolean(columnTypeError)}\n label={t(\"db_column_type\")}>\n {isIdValue === \"uuid\" && <SelectItem value={\"uuid\"}> uuid (forced by Primary Key) </SelectItem>}\n <SelectItem value={\"_default_\"}> Default (varchar) </SelectItem>\n <SelectItem value={\"varchar\"}> varchar (variable length) </SelectItem>\n <SelectItem value={\"text\"}> text (unlimited) </SelectItem>\n <SelectItem value={\"char\"}> char (fixed length) </SelectItem>\n </Select>\n <FieldCaption error={Boolean(columnTypeError)}>\n {columnTypeError ?? \"Optional database override for this string field.\"}\n </FieldCaption>\n </div>\n\n <div className={\"col-span-12\"}>\n <Select name={isIdPath}\n disabled={disabled}\n fullWidth={true}\n value={isIdValue === true ? \"true\" : (isIdValue === false ? \"false\" : (isIdValue ?? \"_default_\"))}\n onValueChange={(v) => {\n if (v === \"_default_\" || v === \"false\") setFieldValue(isIdPath, undefined);\n else if (v === \"true\") setFieldValue(isIdPath, true);\n else setFieldValue(isIdPath, v);\n }}\n renderValue={(v) => {\n switch (v) {\n case \"true\": return \"Yes (Auto-generated UUID/String)\";\n case \"manual\": return \"Yes (Manual input)\";\n case \"uuid\": return \"Yes (UUID)\";\n case \"cuid\": return \"Yes (CUID)\";\n case \"false\":\n case \"_default_\": return \"No\";\n default: return `Yes (${v})`;\n }\n }}\n error={Boolean(isIdError)}\n label={t(\"primary_key_unique_id\")}>\n <SelectItem value={\"_default_\"}> No </SelectItem>\n <SelectItem value={\"manual\"}> Yes (Manual input) </SelectItem>\n <SelectItem value={\"true\"}> Yes (Auto-generated UUID/String) </SelectItem>\n <SelectItem value={\"uuid\"}> Yes (UUID) </SelectItem>\n <SelectItem value={\"cuid\"}> Yes (CUID) </SelectItem>\n </Select>\n <FieldCaption error={Boolean(isIdError)}>\n {isIdError ?? \"Set as Primary Key and configure ID generation strategy.\"}\n </FieldCaption>\n </div>\n\n <div className={\"col-span-12\"}>\n\n <TextField name={\"defaultValue\"}\n disabled={disabled}\n onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setFieldValue(\"defaultValue\", e.target.value === \"\" ? undefined : e.target.value);\n }}\n label={t(\"default_value\")}\n value={(getIn(values, \"defaultValue\") as string | undefined) ?? \"\"}/>\n\n </div>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,oBAAoB,EAChC,UACA,UACA,cAKD;CAEC,MAAM,EAAE,QAAQ,eAAe,SAAS,WAAW,UAAU;CAC7D,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,iBAAiB;CACvB,MAAM,kBAAsC,MAAM,QAAQ,cAAc;CACxE,MAAM,kBAAuC,MAAM,SAAS,cAAc,KAAK,MAAM,QAAQ,cAAc;CAE3G,MAAM,WAAW;CACjB,MAAM,YAA0C,MAAM,QAAQ,QAAQ;CACtE,MAAM,YAAiC,MAAM,SAAS,QAAQ,KAAK,MAAM,QAAQ,QAAQ;CAEzF,OACI,qBAAA,UAAA,EAAA,UAAA;EACI,oBAAC,OAAD;GAAK,WAAW;aAEZ,qBAAC,iBAAD,EAAA,UAAA;IAEK,aAAa,gBACV,oBAAC,0BAAD;KAAoC;KAChC,QAAQ;KACR,WAAW;KACX,SAAS;KACT,KAAK;KACL,KAAK;KACL,MA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AAM;IACA;IACV,WAAW;IACX,OAAO,cAAc,OAAO,SAAU,cAAc,QAAQ,UAAW,aAAa;IACpF,gBAAgB,MAAM;KAClB,IAAI,MAAM,eAAe,MAAM,SAAS,cAAc,UAAU,KAAA,CAAS;UACpE,IAAI,MAAM,QAAQ,cAAc,UAAU,IAAI;UAC9C,cAAc,UAAU,CAAC;IAClC;IACA,cAAc,MAAM;KAChB,QAAQ,GAAR;MACI,KAAK,QAAQ,OAAO;MACpB,KAAK,UAAU,OAAO;MACtB,KAAK,QAAQ,OAAO;MACpB,KAAK,QAAQ,OAAO;MACpB,KAAK;MACL,KAAK,aAAa,OAAO;MACzB,SAAS,OAAO,QAAQ,EAAE;KAC9B;IACJ;IACA,OAAO,QAAQ,SAAS;IACxB,OAAO,EAAE,uBAAuB;cArBpC;KAsBI,oBAAC,YAAD;MAAY,OAAO;gBAAa;KAAgB,CAAA;KAChD,oBAAC,YAAD;MAAY,OAAO;gBAAU;KAAgC,CAAA;KAC7D,oBAAC,YAAD;MAAY,OAAO;gBAAQ;KAA8C,CAAA;KACzE,oBAAC,YAAD;MAAY,OAAO;gBAAQ;KAAwB,CAAA;KACnD,oBAAC,YAAD;MAAY,OAAO;gBAAQ;KAAwB,CAAA;IAC/C;OACR,oBAAC,cAAD;IAAc,OAAO,QAAQ,SAAS;cACjC,aAAa;GACJ,CAAA,CACb;;EAEL,oBAAC,OAAD;GAAK,WAAW;aAEZ,oBAAC,WAAD;IAAW,MAAM;IACH;IACV,WAAW,MAAiE;KACxE,cAAc,gBAAgB,EAAE,OAAO,UAAU,KAAK,KAAA,IAAY,EAAE,OAAO,KAAK;IACpF;IACA,OAAO,EAAE,eAAe;IACxB,OAAQ,MAAM,QAAQ,cAAc,KAA4B;GAAI,CAAA;EAEvE,CAAA;CACP,EAAA,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"StringPropertyField.js","names":[],"sources":["../../../../../src/collection_editor/ui/collection_editor/properties/StringPropertyField.tsx"],"sourcesContent":["import { FieldCaption } from \"../../../_cms_internals\";\nimport React from \"react\";\nimport { StringPropertyValidation } from \"./validation/StringPropertyValidation\";\nimport { ValidationPanel } from \"./validation/ValidationPanel\";\nimport { getIn, useFormex } from \"@rebasepro/forms\";\nimport { useTranslation } from \"@rebasepro/app\";\n;\nimport { Select, SelectItem, TextField } from \"@rebasepro/ui\";\n\nexport function StringPropertyField({\n widgetId,\n disabled,\n showErrors\n}: {\n widgetId: \"text_field\" | \"multiline\" | \"email\" | \"user_select\";\n disabled: boolean;\n showErrors: boolean;\n}) {\n\n const { values, setFieldValue, touched, errors } = useFormex();\n const { t } = useTranslation();\n\n const columnTypePath = \"columnType\";\n const columnTypeValue: string | undefined = getIn(values, columnTypePath) as string | undefined;\n const columnTypeError: string | undefined = (getIn(touched, columnTypePath) && getIn(errors, columnTypePath)) as string | undefined;\n\n const isIdPath = \"isId\";\n const isIdValue: string | boolean | undefined = getIn(values, isIdPath) as string | boolean | undefined;\n const isIdError: string | undefined = (getIn(touched, isIdPath) && getIn(errors, isIdPath)) as string | undefined;\n\n return (\n <>\n <div className={\"col-span-12\"}>\n\n <ValidationPanel>\n\n {widgetId === \"text_field\" &&\n <StringPropertyValidation disabled={disabled}\n length={true}\n lowercase={true}\n matches={true}\n max={true}\n min={true}\n trim={true}\n uppercase={true}\n showErrors={showErrors}/>}\n {widgetId === \"user_select\" &&\n <StringPropertyValidation disabled={disabled}\n showErrors={showErrors}/>}\n\n {widgetId === \"multiline\" &&\n <StringPropertyValidation disabled={disabled}\n length={true}\n lowercase={true}\n max={true}\n min={true}\n trim={true}\n uppercase={true}\n showErrors={showErrors}/>}\n\n {widgetId === \"email\" &&\n <StringPropertyValidation disabled={disabled}\n max={true}\n min={true}\n trim={true}\n showErrors={showErrors}/>}\n\n </ValidationPanel>\n\n </div>\n\n <div className={\"col-span-12\"}>\n <Select name={columnTypePath}\n disabled={disabled || Boolean(isIdValue)}\n fullWidth={true}\n value={isIdValue === \"uuid\" ? \"uuid\" : (columnTypeValue ?? \"_default_\")}\n onValueChange={(v) => setFieldValue(columnTypePath, v === \"_default_\" ? undefined : v)}\n renderValue={(v) => {\n if (isIdValue === \"uuid\") return \"uuid (forced by Primary Key)\";\n switch (v) {\n case \"text\": return \"text (unlimited)\";\n case \"char\": return \"char (fixed length)\";\n case \"varchar\": return \"varchar (variable length)\";\n // No `columnType` is a TEXT column: what the schema\n // planner creates for a string that names none.\n case \"_default_\": return \"Default (text)\";\n default: return \"Default (text)\";\n }\n }}\n error={Boolean(columnTypeError)}\n label={t(\"db_column_type\")}>\n {isIdValue === \"uuid\" && <SelectItem value={\"uuid\"}> uuid (forced by Primary Key) </SelectItem>}\n <SelectItem value={\"_default_\"}> Default (text) </SelectItem>\n <SelectItem value={\"varchar\"}> varchar (variable length) </SelectItem>\n <SelectItem value={\"text\"}> text (unlimited) </SelectItem>\n <SelectItem value={\"char\"}> char (fixed length) </SelectItem>\n </Select>\n <FieldCaption error={Boolean(columnTypeError)}>\n {columnTypeError ?? \"Optional database override for this string field.\"}\n </FieldCaption>\n </div>\n\n <div className={\"col-span-12\"}>\n <Select name={isIdPath}\n disabled={disabled}\n fullWidth={true}\n value={isIdValue === true ? \"true\" : (isIdValue === false ? \"false\" : (isIdValue ?? \"_default_\"))}\n onValueChange={(v) => {\n if (v === \"_default_\" || v === \"false\") setFieldValue(isIdPath, undefined);\n else if (v === \"true\") setFieldValue(isIdPath, true);\n else setFieldValue(isIdPath, v);\n }}\n renderValue={(v) => {\n switch (v) {\n case \"true\": return \"Yes (Auto-generated UUID/String)\";\n case \"manual\": return \"Yes (Manual input)\";\n case \"uuid\": return \"Yes (UUID)\";\n case \"cuid\": return \"Yes (CUID)\";\n case \"false\":\n case \"_default_\": return \"No\";\n default: return `Yes (${v})`;\n }\n }}\n error={Boolean(isIdError)}\n label={t(\"primary_key_unique_id\")}>\n <SelectItem value={\"_default_\"}> No </SelectItem>\n <SelectItem value={\"manual\"}> Yes (Manual input) </SelectItem>\n <SelectItem value={\"true\"}> Yes (Auto-generated UUID/String) </SelectItem>\n <SelectItem value={\"uuid\"}> Yes (UUID) </SelectItem>\n <SelectItem value={\"cuid\"}> Yes (CUID) </SelectItem>\n </Select>\n <FieldCaption error={Boolean(isIdError)}>\n {isIdError ?? \"Set as Primary Key and configure ID generation strategy.\"}\n </FieldCaption>\n </div>\n\n <div className={\"col-span-12\"}>\n\n <TextField name={\"defaultValue\"}\n disabled={disabled}\n onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setFieldValue(\"defaultValue\", e.target.value === \"\" ? undefined : e.target.value);\n }}\n label={t(\"default_value\")}\n value={(getIn(values, \"defaultValue\") as string | undefined) ?? \"\"}/>\n\n </div>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,oBAAoB,EAChC,UACA,UACA,cAKD;CAEC,MAAM,EAAE,QAAQ,eAAe,SAAS,WAAW,UAAU;CAC7D,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,iBAAiB;CACvB,MAAM,kBAAsC,MAAM,QAAQ,cAAc;CACxE,MAAM,kBAAuC,MAAM,SAAS,cAAc,KAAK,MAAM,QAAQ,cAAc;CAE3G,MAAM,WAAW;CACjB,MAAM,YAA0C,MAAM,QAAQ,QAAQ;CACtE,MAAM,YAAiC,MAAM,SAAS,QAAQ,KAAK,MAAM,QAAQ,QAAQ;CAEzF,OACI,qBAAA,UAAA,EAAA,UAAA;EACI,oBAAC,OAAD;GAAK,WAAW;aAEZ,qBAAC,iBAAD,EAAA,UAAA;IAEK,aAAa,gBACV,oBAAC,0BAAD;KAAoC;KAChC,QAAQ;KACR,WAAW;KACX,SAAS;KACT,KAAK;KACL,KAAK;KACL,MAAM;KACN,WAAW;KACC;IAAY,CAAA;IAC/B,aAAa,iBACV,oBAAC,0BAAD;KAAoC;KACpB;IAAY,CAAA;IAE/B,aAAa,eACV,oBAAC,0BAAD;KAAoC;KAChC,QAAQ;KACR,WAAW;KACX,KAAK;KACL,KAAK;KACL,MAAM;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,UAAU,IAAI;UAC9C,cAAc,UAAU,CAAC;IAClC;IACA,cAAc,MAAM;KAChB,QAAQ,GAAR;MACI,KAAK,QAAQ,OAAO;MACpB,KAAK,UAAU,OAAO;MACtB,KAAK,QAAQ,OAAO;MACpB,KAAK,QAAQ,OAAO;MACpB,KAAK;MACL,KAAK,aAAa,OAAO;MACzB,SAAS,OAAO,QAAQ,EAAE;KAC9B;IACJ;IACA,OAAO,QAAQ,SAAS;IACxB,OAAO,EAAE,uBAAuB;cArBpC;KAsBI,oBAAC,YAAD;MAAY,OAAO;gBAAa;KAAgB,CAAA;KAChD,oBAAC,YAAD;MAAY,OAAO;gBAAU;KAAgC,CAAA;KAC7D,oBAAC,YAAD;MAAY,OAAO;gBAAQ;KAA8C,CAAA;KACzE,oBAAC,YAAD;MAAY,OAAO;gBAAQ;KAAwB,CAAA;KACnD,oBAAC,YAAD;MAAY,OAAO;gBAAQ;KAAwB,CAAA;IAC/C;OACR,oBAAC,cAAD;IAAc,OAAO,QAAQ,SAAS;cACjC,aAAa;GACJ,CAAA,CACb;;EAEL,oBAAC,OAAD;GAAK,WAAW;aAEZ,oBAAC,WAAD;IAAW,MAAM;IACH;IACV,WAAW,MAAiE;KACxE,cAAc,gBAAgB,EAAE,OAAO,UAAU,KAAK,KAAA,IAAY,EAAE,OAAO,KAAK;IACpF;IACA,OAAO,EAAE,eAAe;IACxB,OAAQ,MAAM,QAAQ,cAAc,KAA4B;GAAI,CAAA;EAEvE,CAAA;CACP,EAAA,CAAA;AAEV"}
|
|
@@ -21,5 +21,15 @@ interface CollectionTableToolbarProps {
|
|
|
21
21
|
*/
|
|
22
22
|
compact?: boolean;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether the toolbar this control sits in has room for its controls' labels
|
|
26
|
+
* ("Filters", "Add existing", "Add Tag"), or wants their icon-only forms.
|
|
27
|
+
*
|
|
28
|
+
* Decided by the toolbar's own width, not the window's: a relation tab beside
|
|
29
|
+
* the split list is a narrow toolbar in a wide window, and its labelled
|
|
30
|
+
* controls overflowed the left group and were drawn over the search bar.
|
|
31
|
+
* `true` outside a toolbar.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useToolbarLabels(): boolean;
|
|
24
34
|
export declare function CollectionTableToolbar({ actions, actionsStart, loading, onTextSearch, title, viewModeToggle, initialSearchText, compact }: CollectionTableToolbarProps): React.JSX.Element;
|
|
25
35
|
export {};
|
|
@@ -1,50 +1,111 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useContext, useLayoutEffect, useRef, useState } from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { CircularProgress, SearchBar, cls } from "@rebasepro/ui";
|
|
4
4
|
import { useLargeLayout, useTranslation } from "@rebasepro/app";
|
|
5
5
|
//#region src/components/CollectionTableBinding/internal/CollectionTableToolbar.tsx
|
|
6
|
+
var ToolbarLabelsContext = React.createContext(true);
|
|
7
|
+
/**
|
|
8
|
+
* Whether the toolbar this control sits in has room for its controls' labels
|
|
9
|
+
* ("Filters", "Add existing", "Add Tag"), or wants their icon-only forms.
|
|
10
|
+
*
|
|
11
|
+
* Decided by the toolbar's own width, not the window's: a relation tab beside
|
|
12
|
+
* the split list is a narrow toolbar in a wide window, and its labelled
|
|
13
|
+
* controls overflowed the left group and were drawn over the search bar.
|
|
14
|
+
* `true` outside a toolbar.
|
|
15
|
+
*/
|
|
16
|
+
function useToolbarLabels() {
|
|
17
|
+
return useContext(ToolbarLabelsContext);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether `row` — the toolbar's controls at their natural width — fits in
|
|
21
|
+
* `container`. Once it has not, the width the labelled controls needed is kept,
|
|
22
|
+
* and the labels come back only when the container has that much room again:
|
|
23
|
+
* measured on the icon-only row, they would always seem to fit.
|
|
24
|
+
*/
|
|
25
|
+
function useLabelsFit(container, row) {
|
|
26
|
+
const [labelled, setLabelled] = useState(true);
|
|
27
|
+
const labelledRef = useRef(true);
|
|
28
|
+
const labelledWidth = useRef(void 0);
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
const containerElement = container.current;
|
|
31
|
+
const rowElement = row.current;
|
|
32
|
+
if (!containerElement || !rowElement || typeof ResizeObserver === "undefined") return void 0;
|
|
33
|
+
const measure = () => {
|
|
34
|
+
const available = containerElement.clientWidth;
|
|
35
|
+
let next = labelledRef.current;
|
|
36
|
+
if (labelledRef.current) {
|
|
37
|
+
const needed = rowElement.scrollWidth;
|
|
38
|
+
if (needed > available + 1) {
|
|
39
|
+
labelledWidth.current = needed;
|
|
40
|
+
next = false;
|
|
41
|
+
}
|
|
42
|
+
} else if (labelledWidth.current !== void 0 && available >= labelledWidth.current) next = true;
|
|
43
|
+
if (next !== labelledRef.current) {
|
|
44
|
+
labelledRef.current = next;
|
|
45
|
+
setLabelled(next);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const observer = new ResizeObserver(measure);
|
|
49
|
+
observer.observe(containerElement);
|
|
50
|
+
observer.observe(rowElement);
|
|
51
|
+
measure();
|
|
52
|
+
return () => observer.disconnect();
|
|
53
|
+
}, [container, row]);
|
|
54
|
+
return labelled;
|
|
55
|
+
}
|
|
6
56
|
function CollectionTableToolbar({ actions, actionsStart, loading, onTextSearch, title, viewModeToggle, initialSearchText, compact = false }) {
|
|
7
57
|
const largeLayout = useLargeLayout();
|
|
8
58
|
const { t } = useTranslation();
|
|
59
|
+
const containerRef = useRef(null);
|
|
60
|
+
const rowRef = useRef(null);
|
|
61
|
+
const labelled = useLabelsFit(containerRef, rowRef);
|
|
9
62
|
const actionChildren = React.Children.toArray(actions);
|
|
10
63
|
const addButton = actionChildren.length > 0 ? actionChildren[actionChildren.length - 1] : null;
|
|
11
64
|
const secondaryActions = actionChildren.slice(0, -1);
|
|
12
|
-
return /* @__PURE__ */
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}),
|
|
31
|
-
!compact && onTextSearch && /* @__PURE__ */ jsx(SearchBar, {
|
|
32
|
-
size: "small",
|
|
33
|
-
placeholder: t("search"),
|
|
34
|
-
onTextSearch,
|
|
35
|
-
expandable: true,
|
|
36
|
-
initialValue: initialSearchText
|
|
37
|
-
}, "search-bar"),
|
|
38
|
-
/* @__PURE__ */ jsx("div", {
|
|
65
|
+
return /* @__PURE__ */ jsx("div", {
|
|
66
|
+
ref: containerRef,
|
|
67
|
+
className: cls("no-scrollbar min-h-[52px] overflow-x-auto bg-surface-sheet flex w-full"),
|
|
68
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
69
|
+
ref: rowRef,
|
|
70
|
+
className: "px-2 md:px-4 flex flex-row justify-between items-center min-w-full w-max",
|
|
71
|
+
children: /* @__PURE__ */ jsxs(ToolbarLabelsContext.Provider, {
|
|
72
|
+
value: labelled,
|
|
73
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
74
|
+
className: "flex items-center gap-1 md:mr-4 mr-2",
|
|
75
|
+
children: [
|
|
76
|
+
!compact && viewModeToggle,
|
|
77
|
+
title && /* @__PURE__ */ jsx("div", {
|
|
78
|
+
className: "flex items-center",
|
|
79
|
+
children: title
|
|
80
|
+
}),
|
|
81
|
+
actionsStart
|
|
82
|
+
]
|
|
83
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
39
84
|
className: "flex items-center gap-1",
|
|
40
|
-
children:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
85
|
+
children: [
|
|
86
|
+
largeLayout && !compact && loading && /* @__PURE__ */ jsx("div", {
|
|
87
|
+
className: "mr-4",
|
|
88
|
+
children: /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" })
|
|
89
|
+
}),
|
|
90
|
+
!compact && onTextSearch && /* @__PURE__ */ jsx(SearchBar, {
|
|
91
|
+
size: "small",
|
|
92
|
+
placeholder: t("search"),
|
|
93
|
+
onTextSearch,
|
|
94
|
+
expandable: true,
|
|
95
|
+
initialValue: initialSearchText
|
|
96
|
+
}, "search-bar"),
|
|
97
|
+
/* @__PURE__ */ jsx("div", {
|
|
98
|
+
className: "flex items-center gap-1",
|
|
99
|
+
children: secondaryActions
|
|
100
|
+
}),
|
|
101
|
+
addButton
|
|
102
|
+
]
|
|
103
|
+
})]
|
|
104
|
+
})
|
|
105
|
+
})
|
|
45
106
|
});
|
|
46
107
|
}
|
|
47
108
|
//#endregion
|
|
48
|
-
export { CollectionTableToolbar };
|
|
109
|
+
export { CollectionTableToolbar, useToolbarLabels };
|
|
49
110
|
|
|
50
111
|
//# sourceMappingURL=CollectionTableToolbar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollectionTableToolbar.js","names":[],"sources":["../../../../src/components/CollectionTableBinding/internal/CollectionTableToolbar.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { CircularProgress, cls, SearchBar } from \"@rebasepro/ui\";\nimport { useLargeLayout, useTranslation } from \"@rebasepro/app\";\n\ninterface CollectionTableToolbarProps {\n loading: boolean;\n actionsStart?: React.ReactNode;\n actions?: React.ReactNode;\n /**\n * View mode toggle button, positioned left of the search bar.\n */\n viewModeToggle?: React.ReactNode;\n title?: React.ReactNode,\n onTextSearch?: (searchString?: string) => void;\n /**\n * Initial search string to pre-populate the search bar (e.g. from URL params).\n */\n initialSearchText?: string;\n /**\n * When true the toolbar is in \"compact\" mode for the split-view left panel.\n * - Search bar, loading spinner, and view-mode toggle are hidden.\n * - Secondary actions remain inline (displayed horizontally).\n * - Only `actionsStart` (filters) and the add button (last child of `actions`) remain visible.\n */\n compact?: boolean;\n}\n\nexport function CollectionTableToolbar({\n actions,\n actionsStart,\n loading,\n onTextSearch,\n title,\n viewModeToggle,\n initialSearchText,\n compact = false\n}: CollectionTableToolbarProps) {\n\n const largeLayout = useLargeLayout();\n const { t } = useTranslation();\n\n // Split actions into \"primary\" (add button = last child) and \"secondary\" (everything else)\n const actionChildren = React.Children.toArray(actions);\n const addButton = actionChildren.length > 0 ? actionChildren[actionChildren.length - 1] : null;\n const secondaryActions = actionChildren.slice(0, -1);\n\n return (\n <div\n className={cls(\"no-scrollbar min-h-[52px] overflow-x-auto px-2 md:px-4
|
|
1
|
+
{"version":3,"file":"CollectionTableToolbar.js","names":[],"sources":["../../../../src/components/CollectionTableBinding/internal/CollectionTableToolbar.tsx"],"sourcesContent":["import React, { useContext, useLayoutEffect, useRef, useState } from \"react\";\n\nimport { CircularProgress, cls, SearchBar } from \"@rebasepro/ui\";\nimport { useLargeLayout, useTranslation } from \"@rebasepro/app\";\n\ninterface CollectionTableToolbarProps {\n loading: boolean;\n actionsStart?: React.ReactNode;\n actions?: React.ReactNode;\n /**\n * View mode toggle button, positioned left of the search bar.\n */\n viewModeToggle?: React.ReactNode;\n title?: React.ReactNode,\n onTextSearch?: (searchString?: string) => void;\n /**\n * Initial search string to pre-populate the search bar (e.g. from URL params).\n */\n initialSearchText?: string;\n /**\n * When true the toolbar is in \"compact\" mode for the split-view left panel.\n * - Search bar, loading spinner, and view-mode toggle are hidden.\n * - Secondary actions remain inline (displayed horizontally).\n * - Only `actionsStart` (filters) and the add button (last child of `actions`) remain visible.\n */\n compact?: boolean;\n}\n\nconst ToolbarLabelsContext = React.createContext(true);\n\n/**\n * Whether the toolbar this control sits in has room for its controls' labels\n * (\"Filters\", \"Add existing\", \"Add Tag\"), or wants their icon-only forms.\n *\n * Decided by the toolbar's own width, not the window's: a relation tab beside\n * the split list is a narrow toolbar in a wide window, and its labelled\n * controls overflowed the left group and were drawn over the search bar.\n * `true` outside a toolbar.\n */\nexport function useToolbarLabels(): boolean {\n return useContext(ToolbarLabelsContext);\n}\n\n/**\n * Whether `row` — the toolbar's controls at their natural width — fits in\n * `container`. Once it has not, the width the labelled controls needed is kept,\n * and the labels come back only when the container has that much room again:\n * measured on the icon-only row, they would always seem to fit.\n */\nfunction useLabelsFit(\n container: React.RefObject<HTMLDivElement | null>,\n row: React.RefObject<HTMLDivElement | null>\n): boolean {\n const [labelled, setLabelled] = useState(true);\n const labelledRef = useRef(true);\n const labelledWidth = useRef<number | undefined>(undefined);\n\n useLayoutEffect(() => {\n const containerElement = container.current;\n const rowElement = row.current;\n if (!containerElement || !rowElement || typeof ResizeObserver === \"undefined\") return undefined;\n\n const measure = () => {\n const available = containerElement.clientWidth;\n let next = labelledRef.current;\n if (labelledRef.current) {\n const needed = rowElement.scrollWidth;\n if (needed > available + 1) {\n labelledWidth.current = needed;\n next = false;\n }\n } else if (labelledWidth.current !== undefined && available >= labelledWidth.current) {\n next = true;\n }\n if (next !== labelledRef.current) {\n labelledRef.current = next;\n setLabelled(next);\n }\n };\n\n // The container for the room there is, the row for what the controls\n // take — a selection count appearing widens the row, not the toolbar.\n const observer = new ResizeObserver(measure);\n observer.observe(containerElement);\n observer.observe(rowElement);\n measure();\n return () => observer.disconnect();\n }, [container, row]);\n\n return labelled;\n}\n\nexport function CollectionTableToolbar({\n actions,\n actionsStart,\n loading,\n onTextSearch,\n title,\n viewModeToggle,\n initialSearchText,\n compact = false\n}: CollectionTableToolbarProps) {\n\n const largeLayout = useLargeLayout();\n const { t } = useTranslation();\n\n const containerRef = useRef<HTMLDivElement>(null);\n const rowRef = useRef<HTMLDivElement>(null);\n const labelled = useLabelsFit(containerRef, rowRef);\n\n // Split actions into \"primary\" (add button = last child) and \"secondary\" (everything else)\n const actionChildren = React.Children.toArray(actions);\n const addButton = actionChildren.length > 0 ? actionChildren[actionChildren.length - 1] : null;\n const secondaryActions = actionChildren.slice(0, -1);\n\n return (\n <div\n ref={containerRef}\n className={cls(\"no-scrollbar min-h-[52px] overflow-x-auto bg-surface-sheet flex w-full\")}>\n\n {/* At least as wide as the toolbar, and never narrower than its\n controls: the two groups cannot be squeezed into each other.\n When even the icon-only controls do not fit, the toolbar\n scrolls. */}\n <div\n ref={rowRef}\n className={\"px-2 md:px-4 flex flex-row justify-between items-center min-w-full w-max\"}>\n\n <ToolbarLabelsContext.Provider value={labelled}>\n\n <div className=\"flex items-center gap-1 md:mr-4 mr-2\">\n\n {/* View toggle — hidden in compact */}\n {!compact && viewModeToggle}\n\n {title && <div className={\"flex items-center\"}>\n {title}\n </div>}\n\n {actionsStart}\n\n </div>\n\n <div className=\"flex items-center gap-1\">\n\n {/* Loading spinner — hidden in compact */}\n {largeLayout && !compact && loading && (\n <div className=\"mr-4\">\n <CircularProgress size={\"smallest\"}/>\n </div>\n )}\n\n {/* Search bar — hidden in compact */}\n {!compact && onTextSearch &&\n <SearchBar\n key={\"search-bar\"}\n size={\"small\"}\n placeholder={t(\"search\")}\n onTextSearch={onTextSearch}\n expandable={true}\n initialValue={initialSearchText}/>}\n\n {/* Secondary actions — always inline */}\n <div className=\"flex items-center gap-1\">\n {secondaryActions}\n </div>\n\n {/* Add button — always visible */}\n {addButton}\n\n </div>\n\n </ToolbarLabelsContext.Provider>\n\n </div>\n\n </div>\n );\n}\n"],"mappings":";;;;;AA4BA,IAAM,uBAAuB,MAAM,cAAc,IAAI;;;;;;;;;;AAWrD,SAAgB,mBAA4B;CACxC,OAAO,WAAW,oBAAoB;AAC1C;;;;;;;AAQA,SAAS,aACL,WACA,KACO;CACP,MAAM,CAAC,UAAU,eAAe,SAAS,IAAI;CAC7C,MAAM,cAAc,OAAO,IAAI;CAC/B,MAAM,gBAAgB,OAA2B,KAAA,CAAS;CAE1D,sBAAsB;EAClB,MAAM,mBAAmB,UAAU;EACnC,MAAM,aAAa,IAAI;EACvB,IAAI,CAAC,oBAAoB,CAAC,cAAc,OAAO,mBAAmB,aAAa,OAAO,KAAA;EAEtF,MAAM,gBAAgB;GAClB,MAAM,YAAY,iBAAiB;GACnC,IAAI,OAAO,YAAY;GACvB,IAAI,YAAY,SAAS;IACrB,MAAM,SAAS,WAAW;IAC1B,IAAI,SAAS,YAAY,GAAG;KACxB,cAAc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AAQ;OACT;OACd,YAAY;OACZ,cAAc;MAAmB,GAL5B,YAK4B;MAGzC,oBAAC,OAAD;OAAK,WAAU;iBACV;MACA,CAAA;MAGJ;KAEA;MAEsB;;EAE9B,CAAA;CAEJ,CAAA;AAEb"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useAdminContext } from "../../hooks/useAdminContext.js";
|
|
2
|
+
import { useToolbarLabels } from "../CollectionTableBinding/internal/CollectionTableToolbar.js";
|
|
2
3
|
import { useCollectionEditorController } from "../../collection_editor/useCollectionEditorController.js";
|
|
3
4
|
import { EditorCollectionAction } from "../../collection_editor/ui/EditorCollectionAction.js";
|
|
4
5
|
import React, { Suspense } from "react";
|
|
@@ -13,11 +14,13 @@ function CollectionViewActions({ collection, relativePath, parentCollectionSlugs
|
|
|
13
14
|
const context = useAdminContext();
|
|
14
15
|
const { canCreate, canDelete } = usePermissions();
|
|
15
16
|
const largeLayout = useLargeLayout();
|
|
17
|
+
const toolbarLabels = useToolbarLabels();
|
|
18
|
+
const labelled = largeLayout && !compact && toolbarLabels;
|
|
16
19
|
const { t } = useTranslation();
|
|
17
20
|
const collectionEditorController = useCollectionEditorController();
|
|
18
21
|
const hasCollectionEditor = Boolean(collectionEditorController?.editCollection);
|
|
19
22
|
const { selectedCount, hasSelection } = selectionController;
|
|
20
|
-
const addButton = canCreate(collection, path) && onNewClick && (
|
|
23
|
+
const addButton = canCreate(collection, path) && onNewClick && (labelled ? /* @__PURE__ */ jsx(Button, {
|
|
21
24
|
id: `add_entity_${path}`,
|
|
22
25
|
onClick: onNewClick,
|
|
23
26
|
startIcon: /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }),
|
|
@@ -34,7 +37,7 @@ function CollectionViewActions({ collection, relativePath, parentCollectionSlugs
|
|
|
34
37
|
"aria-label": t("add_specific", { name: collection.singularName ?? collection.name }),
|
|
35
38
|
children: /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small })
|
|
36
39
|
}));
|
|
37
|
-
const linkButton = onAddExistingClick && (
|
|
40
|
+
const linkButton = onAddExistingClick && (labelled ? /* @__PURE__ */ jsx(Button, {
|
|
38
41
|
id: `link_entity_${path}`,
|
|
39
42
|
onClick: onAddExistingClick,
|
|
40
43
|
startIcon: /* @__PURE__ */ jsx(Link2Icon, { size: iconSize.small }),
|
|
@@ -58,7 +61,7 @@ function CollectionViewActions({ collection, relativePath, parentCollectionSlugs
|
|
|
58
61
|
let multipleDeleteButton;
|
|
59
62
|
if (hasSelection) {
|
|
60
63
|
const RemoveIcon = removeUnlinks ? Unlink2Icon : Trash2Icon;
|
|
61
|
-
const button =
|
|
64
|
+
const button = labelled ? /* @__PURE__ */ jsxs(Button, {
|
|
62
65
|
variant: "text",
|
|
63
66
|
disabled: !multipleDeleteEnabled,
|
|
64
67
|
startIcon: /* @__PURE__ */ jsx(RemoveIcon, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollectionViewActions.js","names":[],"sources":["../../../src/components/CollectionViewBinding/CollectionViewActions.tsx"],"sourcesContent":["\n\nimport React, { Suspense } from \"react\";\n\nimport { useLargeLayout, useTranslation, useSlot, resolveComponentRef } from \"@rebasepro/app\";\nimport { CollectionActionsProps, EntityTableController, SelectionController, AdminCollection } from \"@rebasepro/cms-types\";\nimport { Button, IconButton, Tooltip, Popover, iconSize, lazyChunk } from \"@rebasepro/ui\";\nimport { ErrorBoundary, Link2Icon, MoreVerticalIcon, PlusIcon, Trash2Icon, Unlink2Icon } from \"@rebasepro/ui\";\nimport { usePermissions } from \"@rebasepro/app\";\nimport { toArray } from \"@rebasepro/utils\";\n// Lazy-load import/export — pulls in exceljs only on demand\nconst ImportCollectionAction = lazyChunk(() => import(\"../../data_import/import\").then(m => ({ default: m.ImportCollectionAction })));\nconst ExportCollectionAction = lazyChunk(() => import(\"../../data_export/export\").then(m => ({ default: m.ExportCollectionAction })));\nimport { EditorCollectionAction } from \"../../collection_editor/ui/EditorCollectionAction\";\nimport { useCollectionEditorController } from \"../../collection_editor/useCollectionEditorController\";\nimport { useAdminContext } from \"../../hooks/useAdminContext\";\n\nexport type CollectionViewActionsProps<M extends Record<string, unknown>> = {\n collection: AdminCollection<M>;\n path: string;\n relativePath: string;\n parentCollectionSlugs: string[], parentEntityIds: string[];\n selectionEnabled: boolean;\n onNewClick: () => void;\n /**\n * Attach a row that already exists to this parent. Only supplied for a\n * junction-backed tab, where the parent owns the link rather than the row.\n */\n onAddExistingClick?: () => void;\n onMultipleDeleteClick: () => void;\n /**\n * The rows are shared with other records through a junction, so removing\n * them unlinks them from this record and deletes nothing. The bin says so.\n */\n removeUnlinks?: boolean;\n selectionController: SelectionController<M>;\n tableController: EntityTableController<M>;\n collectionEntitiesCount?: number;\n compact?: boolean;\n children?: React.ReactNode;\n openNewDocument: (defaultValues?: Record<string, unknown>) => void;\n}\n\nexport function CollectionViewActions<M extends Record<string, unknown>>({\n collection,\n relativePath,\n parentCollectionSlugs, parentEntityIds,\n onNewClick,\n onAddExistingClick,\n onMultipleDeleteClick,\n removeUnlinks,\n selectionEnabled,\n path,\n selectionController,\n tableController,\n collectionEntitiesCount,\n compact,\n children,\n openNewDocument\n}: CollectionViewActionsProps<M>) {\n const context = useAdminContext();\n\n const { canCreate, canDelete } = usePermissions();\n\n const largeLayout = useLargeLayout();\n const { t } = useTranslation();\n\n // Check if the collection editor context is available (ConfigControllerProvider present)\n const collectionEditorController = useCollectionEditorController();\n const hasCollectionEditor = Boolean(collectionEditorController?.editCollection);\n\n const { selectedCount, hasSelection } = selectionController;\n\n const addButton = canCreate(collection, path) &&\n onNewClick && (largeLayout && !compact\n ? <Button\n id={`add_entity_${path}`}\n onClick={onNewClick}\n startIcon={<PlusIcon size={iconSize.small}/>}\n size=\"small\"\n variant=\"filled\"\n color=\"primary\">\n {t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n </Button>\n // In the compact split-list toolbar the add action is the one filled\n // control: a rounded square, so it reads as a button and not a badge.\n : <IconButton\n id={`add_entity_${path}`}\n onClick={onNewClick}\n variant=\"filled\"\n shape=\"square\"\n size=\"small\"\n aria-label={t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n >\n <PlusIcon size={iconSize.small}/>\n </IconButton>);\n\n // On a junction-backed tab, creating a row is only half of what \"add\" means:\n // the far more common act is attaching one that already exists. There was no\n // way to do that at all — the junction row was only ever written alongside an\n // insert — so a shared vocabulary could only ever grow.\n const linkButton = onAddExistingClick && (largeLayout && !compact\n ? <Button\n id={`link_entity_${path}`}\n onClick={onAddExistingClick}\n startIcon={<Link2Icon size={iconSize.small}/>}\n size=\"small\"\n variant=\"outlined\"\n color=\"neutral\">\n {t(\"add_existing\")}\n </Button>\n : <Tooltip title={t(\"add_existing\")}>\n <Button\n id={`link_entity_${path}`}\n onClick={onAddExistingClick}\n variant=\"outlined\"\n color=\"neutral\"\n size=\"small\">\n <Link2Icon size={iconSize.small}/>\n </Button>\n </Tooltip>);\n\n const multipleDeleteEnabled = canDelete(collection, path, null);\n\n // Only once something is selected. A permanently-disabled bin sat in every\n // collection toolbar — and in the split view, where the toolbar is a narrow\n // strip above the list, it was a third of the visible controls doing\n // nothing. It appears the moment you tick a row, which is when you want it.\n\n // `undefined` is \"every matching row, and nobody knows how many\" — a full\n // selection against an accessor with no `count`. Rendering it as 0 would\n // say the opposite of what is true.\n const countLabel = selectedCount === undefined ? \"…\" : selectedCount.toLocaleString();\n\n let multipleDeleteButton: React.ReactNode | undefined;\n if (hasSelection) {\n const RemoveIcon = removeUnlinks ? Unlink2Icon : Trash2Icon;\n const button = largeLayout && !compact\n // `min-w`, not `w`. A fixed 80px was enough for the one- and\n // two-digit counts you could reach by ticking rows; \"select all\n // matching\" put six digits in here, and a flex child over its width\n // compresses — so the bin itself was what gave way, shrinking to a\n // sliver beside the number. The width is a floor now, so the\n // control still holds its place in the toolbar when the count is\n // short, and `shrink-0` means the icon can never be the thing that\n // gives.\n ? <Button\n variant={\"text\"}\n disabled={!multipleDeleteEnabled}\n startIcon={<RemoveIcon size={iconSize.small} className={\"shrink-0\"}/>}\n onClick={onMultipleDeleteClick}\n color={\"neutral\"}\n className=\"lg:min-w-20\"\n >\n ({countLabel})\n </Button>\n : <IconButton aria-label={t(\"delete_selected\")}\n size={\"small\"}\n disabled={!multipleDeleteEnabled}\n onClick={onMultipleDeleteClick}>\n <RemoveIcon size={iconSize.small}/>\n </IconButton>;\n multipleDeleteButton =\n <Tooltip\n title={multipleDeleteEnabled\n ? (removeUnlinks ? t(\"remove_from_record\") : t(\"delete\"))\n : t(\"delete_not_allowed\")}>\n {button}\n </Tooltip>\n }\n\n const actionProps: CollectionActionsProps<M> = {\n path,\n relativePath,\n parentCollectionSlugs,\nparentEntityIds,\n collection,\n selectionController,\n context,\n tableController,\n collectionEntitiesCount,\n openNewDocument\n };\n\n const actions = toArray(collection.Actions)\n .map((actionRef, i) => {\n const Action = resolveComponentRef(actionRef);\n if (!Action) return null;\n return (\n <ErrorBoundary key={`actions_${i}`}>\n <Suspense fallback={null}>\n <Action {...actionProps}/>\n </Suspense>\n </ErrorBoundary>\n );\n });\n\n const pluginActions = useSlot(\"collection.actions\", actionProps as CollectionActionsProps);\n\n const secondaryActions = (\n <>\n {children}\n <ErrorBoundary>\n {actions}\n {pluginActions}\n </ErrorBoundary>\n <ErrorBoundary>\n <Suspense fallback={null}>\n <ImportCollectionAction {...(actionProps as CollectionActionsProps)}/>\n </Suspense>\n </ErrorBoundary>\n <ErrorBoundary>\n <Suspense fallback={null}>\n <ExportCollectionAction {...(actionProps as CollectionActionsProps)}/>\n </Suspense>\n </ErrorBoundary>\n {hasCollectionEditor && (\n <ErrorBoundary>\n <EditorCollectionAction {...(actionProps as CollectionActionsProps)}/>\n </ErrorBoundary>\n )}\n </>\n );\n\n const [overflowOpen, setOverflowOpen] = React.useState(false);\n\n return (\n <div className=\"flex items-center gap-1\">\n {!compact ? (\n secondaryActions\n ) : (\n <Popover\n open={overflowOpen}\n onOpenChange={setOverflowOpen}\n trigger={\n <IconButton aria-label={t(\"more_actions\")} size=\"small\">\n <MoreVerticalIcon size={iconSize.smallest}/>\n </IconButton>\n }>\n <div className=\"flex flex-row items-center gap-1 p-2\">\n {secondaryActions}\n </div>\n </Popover>\n )}\n {multipleDeleteButton}\n {linkButton}\n {addButton}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,yBAAyB,gBAAgB,OAAO,oCAA2B,CAAC,MAAK,OAAM,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;AACpI,IAAM,yBAAyB,gBAAgB,OAAO,oCAA2B,CAAC,MAAK,OAAM,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;AA+BpI,SAAgB,sBAAyD,EACrE,YACA,cACA,uBAAuB,iBACvB,YACA,oBACA,uBACA,eACA,kBACA,MACA,qBACA,iBACA,yBACA,SACA,UACA,mBAC8B;CAC9B,MAAM,UAAU,gBAAgB;CAEhC,MAAM,EAAE,WAAW,cAAc,eAAe;CAEhD,MAAM,cAAc,eAAe;CACnC,MAAM,EAAE,MAAM,eAAe;CAG7B,MAAM,6BAA6B,8BAA8B;CACjE,MAAM,sBAAsB,QAAQ,4BAA4B,cAAc;CAE9E,MAAM,EAAE,eAAe,iBAAiB;CAExC,MAAM,YAAY,UAAU,YAAY,IAAI,KACxC,eAAe,eAAe,CAAC,UACzB,oBAAC,QAAD;EACE,IAAI,cAAc;EAClB,SAAS;EACT,WAAW,oBAAC,UAAD,EAAU,MAAM,SAAS,MAAO,CAAA;EAC3C,MAAK;EACL,SAAQ;EACR,OAAM;YACL,EAAE,gBAAgB,EAAE,MAAM,WAAW,gBAAgB,WAAW,KAAK,CAAC;CACnE,CAAA,IAGN,oBAAC,YAAD;EACE,IAAI,cAAc;EAClB,SAAS;EACT,SAAQ;EACR,OAAM;EACN,MAAK;EACL,cAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,gBAAgB,WAAW,KAAK,CAAC;YAElF,oBAAC,UAAD,EAAU,MAAM,SAAS,MAAO,CAAA;CACxB,CAAA;CAMpB,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tC,KAAK,WAAW,MAAM;GACnB,MAAM,SAAS,oBAAoB,SAAS;GAC5C,IAAI,CAAC,QAAQ,OAAO;GACpB,OACI,oBAAC,eAAD,EAAA,UACI,oBAAC,UAAD;IAAU,UAAU;cAChB,oBAAC,QAAD,EAAQ,GAAI,YAAa,CAAA;GACnB,CAAA,EACC,GAJK,WAAW,GAIhB;EAEvB,CAQS,GANS,QAAQ,sBAAsB,WAOvC,CACU,EAAA,CAAA;EACf,oBAAC,eAAD,EAAA,UACI,oBAAC,UAAD;GAAU,UAAU;aAChB,oBAAC,wBAAD,EAAwB,GAAK,YAAwC,CAAA;EAC/D,CAAA,EACC,CAAA;EACf,oBAAC,eAAD,EAAA,UACI,oBAAC,UAAD;GAAU,UAAU;aAChB,oBAAC,wBAAD,EAAwB,GAAK,YAAwC,CAAA;EAC/D,CAAA,EACC,CAAA;EACd,uBACG,oBAAC,eAAD,EAAA,UACI,oBAAC,wBAAD,EAAwB,GAAK,YAAwC,CAAA,EAC1D,CAAA;CAErB,EAAA,CAAA;CAGN,MAAM,CAAC,cAAc,mBAAmB,MAAM,SAAS,KAAK;CAE5D,OACI,qBAAC,OAAD;EAAK,WAAU;YAAf;GACK,CAAC,UACE,mBAEA,oBAAC,SAAD;IACI,MAAM;IACN,cAAc;IACd,SACI,oBAAC,YAAD;KAAY,cAAY,EAAE,cAAc;KAAG,MAAK;eAC5C,oBAAC,kBAAD,EAAkB,MAAM,SAAS,SAAU,CAAA;IACnC,CAAA;cAEhB,oBAAC,OAAD;KAAK,WAAU;eACV;IACA,CAAA;GACA,CAAA;GAEZ;GACA;GACA;EACA;;AAEb"}
|
|
1
|
+
{"version":3,"file":"CollectionViewActions.js","names":[],"sources":["../../../src/components/CollectionViewBinding/CollectionViewActions.tsx"],"sourcesContent":["\n\nimport React, { Suspense } from \"react\";\n\nimport { useLargeLayout, useTranslation, useSlot, resolveComponentRef } from \"@rebasepro/app\";\nimport { CollectionActionsProps, EntityTableController, SelectionController, AdminCollection } from \"@rebasepro/cms-types\";\nimport { Button, IconButton, Tooltip, Popover, iconSize, lazyChunk } from \"@rebasepro/ui\";\nimport { ErrorBoundary, Link2Icon, MoreVerticalIcon, PlusIcon, Trash2Icon, Unlink2Icon } from \"@rebasepro/ui\";\nimport { usePermissions } from \"@rebasepro/app\";\nimport { toArray } from \"@rebasepro/utils\";\n// Lazy-load import/export — pulls in exceljs only on demand\nconst ImportCollectionAction = lazyChunk(() => import(\"../../data_import/import\").then(m => ({ default: m.ImportCollectionAction })));\nconst ExportCollectionAction = lazyChunk(() => import(\"../../data_export/export\").then(m => ({ default: m.ExportCollectionAction })));\nimport { EditorCollectionAction } from \"../../collection_editor/ui/EditorCollectionAction\";\nimport { useCollectionEditorController } from \"../../collection_editor/useCollectionEditorController\";\nimport { useAdminContext } from \"../../hooks/useAdminContext\";\nimport { useToolbarLabels } from \"../CollectionTableBinding/internal/CollectionTableToolbar\";\n\nexport type CollectionViewActionsProps<M extends Record<string, unknown>> = {\n collection: AdminCollection<M>;\n path: string;\n relativePath: string;\n parentCollectionSlugs: string[], parentEntityIds: string[];\n selectionEnabled: boolean;\n onNewClick: () => void;\n /**\n * Attach a row that already exists to this parent. Only supplied for a\n * junction-backed tab, where the parent owns the link rather than the row.\n */\n onAddExistingClick?: () => void;\n onMultipleDeleteClick: () => void;\n /**\n * The rows are shared with other records through a junction, so removing\n * them unlinks them from this record and deletes nothing. The bin says so.\n */\n removeUnlinks?: boolean;\n selectionController: SelectionController<M>;\n tableController: EntityTableController<M>;\n collectionEntitiesCount?: number;\n compact?: boolean;\n children?: React.ReactNode;\n openNewDocument: (defaultValues?: Record<string, unknown>) => void;\n}\n\nexport function CollectionViewActions<M extends Record<string, unknown>>({\n collection,\n relativePath,\n parentCollectionSlugs, parentEntityIds,\n onNewClick,\n onAddExistingClick,\n onMultipleDeleteClick,\n removeUnlinks,\n selectionEnabled,\n path,\n selectionController,\n tableController,\n collectionEntitiesCount,\n compact,\n children,\n openNewDocument\n}: CollectionViewActionsProps<M>) {\n const context = useAdminContext();\n\n const { canCreate, canDelete } = usePermissions();\n\n const largeLayout = useLargeLayout();\n const toolbarLabels = useToolbarLabels();\n // Labelled controls on a wide layout whose toolbar has room for them;\n // their icon-only forms otherwise.\n const labelled = largeLayout && !compact && toolbarLabels;\n const { t } = useTranslation();\n\n // Check if the collection editor context is available (ConfigControllerProvider present)\n const collectionEditorController = useCollectionEditorController();\n const hasCollectionEditor = Boolean(collectionEditorController?.editCollection);\n\n const { selectedCount, hasSelection } = selectionController;\n\n const addButton = canCreate(collection, path) &&\n onNewClick && (labelled\n ? <Button\n id={`add_entity_${path}`}\n onClick={onNewClick}\n startIcon={<PlusIcon size={iconSize.small}/>}\n size=\"small\"\n variant=\"filled\"\n color=\"primary\">\n {t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n </Button>\n // In the compact split-list toolbar the add action is the one filled\n // control: a rounded square, so it reads as a button and not a badge.\n : <IconButton\n id={`add_entity_${path}`}\n onClick={onNewClick}\n variant=\"filled\"\n shape=\"square\"\n size=\"small\"\n aria-label={t(\"add_specific\", { name: collection.singularName ?? collection.name })}\n >\n <PlusIcon size={iconSize.small}/>\n </IconButton>);\n\n // On a junction-backed tab, creating a row is only half of what \"add\" means:\n // the far more common act is attaching one that already exists. There was no\n // way to do that at all — the junction row was only ever written alongside an\n // insert — so a shared vocabulary could only ever grow.\n const linkButton = onAddExistingClick && (labelled\n ? <Button\n id={`link_entity_${path}`}\n onClick={onAddExistingClick}\n startIcon={<Link2Icon size={iconSize.small}/>}\n size=\"small\"\n variant=\"outlined\"\n color=\"neutral\">\n {t(\"add_existing\")}\n </Button>\n : <Tooltip title={t(\"add_existing\")}>\n <Button\n id={`link_entity_${path}`}\n onClick={onAddExistingClick}\n variant=\"outlined\"\n color=\"neutral\"\n size=\"small\">\n <Link2Icon size={iconSize.small}/>\n </Button>\n </Tooltip>);\n\n const multipleDeleteEnabled = canDelete(collection, path, null);\n\n // Only once something is selected. A permanently-disabled bin sat in every\n // collection toolbar — and in the split view, where the toolbar is a narrow\n // strip above the list, it was a third of the visible controls doing\n // nothing. It appears the moment you tick a row, which is when you want it.\n\n // `undefined` is \"every matching row, and nobody knows how many\" — a full\n // selection against an accessor with no `count`. Rendering it as 0 would\n // say the opposite of what is true.\n const countLabel = selectedCount === undefined ? \"…\" : selectedCount.toLocaleString();\n\n let multipleDeleteButton: React.ReactNode | undefined;\n if (hasSelection) {\n const RemoveIcon = removeUnlinks ? Unlink2Icon : Trash2Icon;\n const button = labelled\n // `min-w`, not `w`. A fixed 80px was enough for the one- and\n // two-digit counts you could reach by ticking rows; \"select all\n // matching\" put six digits in here, and a flex child over its width\n // compresses — so the bin itself was what gave way, shrinking to a\n // sliver beside the number. The width is a floor now, so the\n // control still holds its place in the toolbar when the count is\n // short, and `shrink-0` means the icon can never be the thing that\n // gives.\n ? <Button\n variant={\"text\"}\n disabled={!multipleDeleteEnabled}\n startIcon={<RemoveIcon size={iconSize.small} className={\"shrink-0\"}/>}\n onClick={onMultipleDeleteClick}\n color={\"neutral\"}\n className=\"lg:min-w-20\"\n >\n ({countLabel})\n </Button>\n : <IconButton aria-label={t(\"delete_selected\")}\n size={\"small\"}\n disabled={!multipleDeleteEnabled}\n onClick={onMultipleDeleteClick}>\n <RemoveIcon size={iconSize.small}/>\n </IconButton>;\n multipleDeleteButton =\n <Tooltip\n title={multipleDeleteEnabled\n ? (removeUnlinks ? t(\"remove_from_record\") : t(\"delete\"))\n : t(\"delete_not_allowed\")}>\n {button}\n </Tooltip>\n }\n\n const actionProps: CollectionActionsProps<M> = {\n path,\n relativePath,\n parentCollectionSlugs,\nparentEntityIds,\n collection,\n selectionController,\n context,\n tableController,\n collectionEntitiesCount,\n openNewDocument\n };\n\n const actions = toArray(collection.Actions)\n .map((actionRef, i) => {\n const Action = resolveComponentRef(actionRef);\n if (!Action) return null;\n return (\n <ErrorBoundary key={`actions_${i}`}>\n <Suspense fallback={null}>\n <Action {...actionProps}/>\n </Suspense>\n </ErrorBoundary>\n );\n });\n\n const pluginActions = useSlot(\"collection.actions\", actionProps as CollectionActionsProps);\n\n const secondaryActions = (\n <>\n {children}\n <ErrorBoundary>\n {actions}\n {pluginActions}\n </ErrorBoundary>\n <ErrorBoundary>\n <Suspense fallback={null}>\n <ImportCollectionAction {...(actionProps as CollectionActionsProps)}/>\n </Suspense>\n </ErrorBoundary>\n <ErrorBoundary>\n <Suspense fallback={null}>\n <ExportCollectionAction {...(actionProps as CollectionActionsProps)}/>\n </Suspense>\n </ErrorBoundary>\n {hasCollectionEditor && (\n <ErrorBoundary>\n <EditorCollectionAction {...(actionProps as CollectionActionsProps)}/>\n </ErrorBoundary>\n )}\n </>\n );\n\n const [overflowOpen, setOverflowOpen] = React.useState(false);\n\n return (\n <div className=\"flex items-center gap-1\">\n {!compact ? (\n secondaryActions\n ) : (\n <Popover\n open={overflowOpen}\n onOpenChange={setOverflowOpen}\n trigger={\n <IconButton aria-label={t(\"more_actions\")} size=\"small\">\n <MoreVerticalIcon size={iconSize.smallest}/>\n </IconButton>\n }>\n <div className=\"flex flex-row items-center gap-1 p-2\">\n {secondaryActions}\n </div>\n </Popover>\n )}\n {multipleDeleteButton}\n {linkButton}\n {addButton}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAM,yBAAyB,gBAAgB,OAAO,oCAA2B,CAAC,MAAK,OAAM,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;AACpI,IAAM,yBAAyB,gBAAgB,OAAO,oCAA2B,CAAC,MAAK,OAAM,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;AAgCpI,SAAgB,sBAAyD,EACrE,YACA,cACA,uBAAuB,iBACvB,YACA,oBACA,uBACA,eACA,kBACA,MACA,qBACA,iBACA,yBACA,SACA,UACA,mBAC8B;CAC9B,MAAM,UAAU,gBAAgB;CAEhC,MAAM,EAAE,WAAW,cAAc,eAAe;CAEhD,MAAM,cAAc,eAAe;CACnC,MAAM,gBAAgB,iBAAiB;CAGvC,MAAM,W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D,CAAA;CAErB,EAAA,CAAA;CAGN,MAAM,CAAC,cAAc,mBAAmB,MAAM,SAAS,KAAK;CAE5D,OACI,qBAAC,OAAD;EAAK,WAAU;YAAf;GACK,CAAC,UACE,mBAEA,oBAAC,SAAD;IACI,MAAM;IACN,cAAc;IACd,SACI,oBAAC,YAAD;KAAY,cAAY,EAAE,cAAc;KAAG,MAAK;eAC5C,oBAAC,kBAAD,EAAkB,MAAM,SAAS,SAAU,CAAA;IACnC,CAAA;cAEhB,oBAAC,OAAD;KAAK,WAAU;eACV;IACA,CAAA;GACA,CAAA;GAEZ;GACA;GACA;EACA;;AAEb"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useUrlController } from "../../hooks/navigation/contexts/UrlContext.js";
|
|
2
2
|
import { useAdminContext } from "../../hooks/useAdminContext.js";
|
|
3
|
+
import { useToolbarLabels } from "../CollectionTableBinding/internal/CollectionTableToolbar.js";
|
|
3
4
|
import { withListState } from "../../util/view_mode.js";
|
|
4
5
|
import { SelectionMenu } from "../../selection/SelectionMenu.js";
|
|
5
6
|
import { useSplitView } from "./SplitViewContext.js";
|
|
@@ -16,6 +17,7 @@ import { useNavigate } from "react-router";
|
|
|
16
17
|
function CollectionViewStartActions({ collection, relativePath, parentCollectionSlugs, parentEntityIds, path, selectionController, tableController, collectionEntitiesCount, entitiesCount, resolvedProperties, viewMode, selectionEnabled, selectionQuery, compact, openNewDocument }) {
|
|
17
18
|
const context = useAdminContext();
|
|
18
19
|
const largeLayout = useLargeLayout();
|
|
20
|
+
const toolbarLabels = useToolbarLabels();
|
|
19
21
|
const { t } = useTranslation();
|
|
20
22
|
const navigate = useNavigate();
|
|
21
23
|
const urlController = useUrlController();
|
|
@@ -53,13 +55,13 @@ function CollectionViewStartActions({ collection, relativePath, parentCollection
|
|
|
53
55
|
children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.smallest })
|
|
54
56
|
})
|
|
55
57
|
}, "close_tooltip");
|
|
56
|
-
const iconOnlyToolbar = !largeLayout || Boolean(compact);
|
|
58
|
+
const iconOnlyToolbar = !largeLayout || Boolean(compact) || !toolbarLabels;
|
|
57
59
|
const filtersButton = resolvedProperties && tableController.setFilterValues && /* @__PURE__ */ jsx(Tooltip, {
|
|
58
60
|
title: t("filters"),
|
|
59
61
|
children: /* @__PURE__ */ jsx(Badge, {
|
|
60
62
|
color: "primary",
|
|
61
63
|
invisible: activeFilterCount === 0,
|
|
62
|
-
children:
|
|
64
|
+
children: !iconOnlyToolbar ? /* @__PURE__ */ jsx(Button, {
|
|
63
65
|
variant: "text",
|
|
64
66
|
size: "small",
|
|
65
67
|
onClick: () => setFiltersDialogOpen(true),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollectionViewStartActions.js","names":[],"sources":["../../../src/components/CollectionViewBinding/CollectionViewStartActions.tsx"],"sourcesContent":["import type { Properties } from \"@rebasepro/types\";\n\nimport React, { useState, useCallback } from \"react\";\nimport { useAuthController, useLargeLayout, useTranslation, useSlot } from \"@rebasepro/app\";\nimport { CollectionActionsProps, EntityTableController, SelectionController, SelectionQuery, AdminCollection, ViewMode } from \"@rebasepro/cms-types\";\nimport { ErrorBoundary, iconSize } from \"@rebasepro/ui\";\nimport { Badge, Button, cls, FilterIcon, IconButton, Skeleton, Tooltip, XIcon } from \"@rebasepro/ui\";\nimport { ClearFilterSortButton } from \"../ClearFilterSortButton\";\nimport { FiltersDialog } from \"./FiltersDialog\";\nimport { FilterPresetsButton } from \"./FilterPresetsButton\";\nimport { SortButton } from \"./SortButton\";\nimport { toArray } from \"@rebasepro/utils\";\nimport { useNavigate } from \"react-router\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { useAdminContext } from \"../../hooks/useAdminContext\";\nimport { withListState } from \"../../util/view_mode\";\nimport { useSplitView } from \"./SplitViewContext\";\nimport { SelectionMenu } from \"../../selection\";\n\nexport type CollectionViewStartActionsProps<M extends Record<string, unknown>> = {\n collection: AdminCollection<M>;\n path: string;\n relativePath: string;\n parentCollectionSlugs: string[], parentEntityIds: string[];\n selectionController: SelectionController<M>;\n tableController: EntityTableController<M>;\n collectionEntitiesCount?: number;\n /**\n * Number of records the current filters and search resolve to, rendered at\n * the end of this group.\n * - `undefined`: not applicable\n * - `null`: still counting\n * - number: the count\n */\n entitiesCount?: number | null;\n /**\n * Resolved properties from the collection for the filters dialog\n */\n resolvedProperties?: Properties;\n /**\n * Which view is being displayed. Decides whether the sort control is\n * offered — see `sortButton`.\n */\n viewMode?: ViewMode;\n /** Whether rows can be selected at all in this mount. */\n selectionEnabled?: boolean;\n /** The view's live query — what the menu's \"all matching\" item stands for. */\n selectionQuery?: SelectionQuery<M>;\n compact?: boolean;\n openNewDocument: (defaultValues?: Record<string, unknown>) => void;\n}\n\nexport function CollectionViewStartActions<M extends Record<string, unknown>>({\n collection,\n relativePath,\n parentCollectionSlugs, parentEntityIds,\n path,\n selectionController,\n tableController,\n collectionEntitiesCount,\n entitiesCount,\n resolvedProperties,\n viewMode,\n selectionEnabled,\n selectionQuery,\n compact,\n openNewDocument\n}: CollectionViewStartActionsProps<M>) {\n\n const context = useAdminContext();\n const largeLayout = useLargeLayout();\n const { t } = useTranslation();\n\n const navigate = useNavigate();\n const urlController = useUrlController();\n const splitView = useSplitView();\n\n // Filters dialog state\n const [filtersDialogOpen, setFiltersDialogOpen] = useState(false);\n\n // Count active filters (excluding force filters)\n const filterValues = tableController.filterValues;\n const fixedFilter = collection.fixedFilter;\n const activeFilterCount = filterValues\n ? Object.keys(filterValues).filter(key => !fixedFilter || !(key in fixedFilter)).length\n : 0;\n\n const actionProps: CollectionActionsProps<M> = {\n path,\n relativePath,\n parentCollectionSlugs,\nparentEntityIds,\n collection,\n selectionController,\n context,\n tableController,\n collectionEntitiesCount,\n openNewDocument\n };\n\n const handleBackClick = useCallback(() => {\n navigate(withListState(urlController.buildUrlCollectionPath(path)));\n }, [navigate, urlController, path]);\n\n // In a split view the control that closes the list lives at the leading\n // edge of the record's app bar (`SplitListCloseButton`), not here.\n //\n // Outside one — a compact list with no record open beside it — the only\n // thing this can mean is \"leave the record behind\".\n const backButton = compact && !splitView?.detailOpen && (\n <Tooltip title={t(\"close\")} key={\"close_tooltip\"}>\n <IconButton\n size=\"small\"\n onClick={handleBackClick}\n aria-label={t(\"close\")}\n className=\"mr-1\"\n >\n <XIcon size={iconSize.smallest}/>\n </IconButton>\n </Tooltip>\n );\n\n // Whether the toolbar is showing icon-only controls. The filters button\n // drops its label — and its icon a size with it — on a narrow layout as\n // well as in the split view, and the sort and clear controls beside it\n // follow: keyed on `compact` alone they stayed 20px next to a 16px filter\n // icon at every width below `largeLayout`.\n const iconOnlyToolbar = !largeLayout || Boolean(compact);\n\n const filtersButton = resolvedProperties && tableController.setFilterValues && (\n <Tooltip title={t(\"filters\")}\n key={\"filters_tooltip\"}>\n <Badge\n color=\"primary\"\n invisible={activeFilterCount === 0}\n >\n {largeLayout && !compact ? (\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setFiltersDialogOpen(true)}\n startIcon={<FilterIcon size={iconSize.small}/>}\n className={cls(activeFilterCount > 0 && \"text-primary\")}\n >\n {activeFilterCount > 0 ? `(${activeFilterCount})` : t(\"filters\")}\n </Button>\n ) : (\n <IconButton aria-label={t(\"filters\")}\n size={\"small\"}\n onClick={() => setFiltersDialogOpen(true)}\n className={cls(activeFilterCount > 0 && \"text-primary\")}\n >\n <FilterIcon size={iconSize.smallest}/>\n </IconButton>\n )}\n </Badge>\n </Tooltip>\n );\n\n // Everywhere a `sortBy` means something — which is every view but the\n // board, whose columns are ordered by their own order key and which ignores\n // `sortBy` entirely, so the control would appear to do nothing.\n //\n // Including the table, whose headers were once thought to cover it. They\n // build a multi-key sort (shift-click) and they show its ranks, but they\n // cannot *re-rank* it: promoting the third key above the first means\n // clearing the sort and shift-clicking all three back in the new order.\n // Nor can they remove a middle key without cycling it through descending\n // first. This popover is the only place either is one click, and a table\n // with a three-key sort needs it more than a card grid does, not less.\n const sortButton = resolvedProperties && viewMode !== \"kanban\" && (\n <SortButton\n key={\"sort_button\"}\n tableController={tableController}\n properties={resolvedProperties}\n compact={iconOnlyToolbar}\n />\n );\n\n // Not in the split view. The toolbar there is a strip a few hundred pixels\n // wide above the list, and a row of preset chips crowded out the controls\n // that act on what you are looking at. The presets are still one click away\n // inside the filters dialog.\n const filterPresetsButton = !compact && collection.filterPresets?.length ? (\n <FilterPresetsButton\n key={\"filter_presets\"}\n filterPresets={collection.filterPresets}\n tableController={tableController}\n compact={compact}\n />\n ) : null;\n\n // The count closes the group the filter, sort and preset controls open: it\n // is what they resolve to. It used to live in the breadcrumb trail, which\n // the app bar owns — and a collection rendered without an app bar has no\n // breadcrumbs, so the number simply disappeared.\n //\n // Hidden on the same layouts the trail was (`hidden lg:block` there) and in\n // the split view, where this toolbar is a few hundred pixels wide and\n // scrolls: a passive readout is the first thing that should give up its\n // room to the controls.\n const countBadge = !iconOnlyToolbar && entitiesCount !== undefined ? (\n <Tooltip title={t(\"records_in_view\")} key={\"entities_count\"}>\n {entitiesCount === null\n ? <Skeleton className={\"w-8 h-4 rounded-md mx-1\"}/>\n : <span\n className={\"mx-1 text-xs font-mono tabular-nums text-text-secondary dark:text-text-secondary-dark\"}>\n {entitiesCount.toLocaleString()}\n </span>}\n </Tooltip>\n ) : null;\n\n // One control, in one place, for every view — the leading edge of the\n // toolbar, which in a table sits directly above the checkbox column anyway.\n // The table used to carry its own in the ID column header, which meant two\n // controls that did different amounts.\n const selectionMenu = selectionEnabled && selectionQuery ? (\n <div key={\"select_all\"} className={\"mr-1 flex items-center\"}>\n <SelectionMenu\n selectionController={selectionController}\n loadedEntities={tableController.data}\n query={selectionQuery}\n collectionEntitiesCount={collectionEntitiesCount}\n collectionName={collection.name}/>\n </div>\n ) : null;\n\n const actions: React.ReactNode[] = [\n backButton,\n selectionMenu,\n filtersButton,\n sortButton,\n <ClearFilterSortButton\n key={\"clear_filter\"}\n tableController={tableController}\n compact={iconOnlyToolbar}\n fixedFilter={collection.fixedFilter}\n enabled={true}/>,\n filterPresetsButton,\n countBadge\n ];\n\n const pluginActionsStart = useSlot(\"collection.actions.start\", actionProps);\n\n return (\n <>\n {actions}\n {pluginActionsStart}\n\n {/* Filters Dialog */}\n {resolvedProperties && tableController.setFilterValues && (\n <FiltersDialog\n open={filtersDialogOpen}\n onOpenChange={setFiltersDialogOpen}\n properties={resolvedProperties}\n filterValues={tableController.filterValues}\n setFilterValues={(filterValues) => tableController.setFilterValues?.(filterValues ?? {})}\n fixedFilter={collection.fixedFilter}\n />\n )}\n </>\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;AAoDA,SAAgB,2BAA8D,EAC1E,YACA,cACA,uBAAuB,iBACvB,MACA,qBACA,iBACA,yBACA,eACA,oBACA,UACA,kBACA,gBACA,SACA,mBACmC;CAEnC,MAAM,UAAU,gBAAgB;CAChC,MAAM,cAAc,eAAe;CACnC,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,WAAW,YAAY;CAC7B,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,YAAY,aAAa;CAG/B,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,KAAK;CAGhE,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,WAAW;CAC/B,MAAM,oBAAoB,eACpB,OAAO,KAAK,YAAY,CAAC,CAAC,QAAO,QAAO,CAAC,eAAe,EAAE,OAAO,YAAY,CAAC,CAAC,SAC/E;CAEN,MAAM,cAAyC;EAC3C;EACA;EACA;EACR;EACQ;EACA;EACA;EACA;EACA;EACA;CACJ;CAEA,MAAM,kBAAkB,kBAAkB;EACtC,SAAS,cAAc,cAAc,uBAAuB,IAAI,CAAC,CAAC;CACtE,GAAG;EAAC;EAAU;EAAe;CAAI,CAAC;CAOlC,MAAM,aAAa,WAAW,CAAC,WAAW,cACtC,oBAAC,SAAD;EAAS,OAAO,EAAE,OAAO;YACrB,oBAAC,YAAD;GACI,MAAK;GACL,SAAS;GACT,cAAY,EAAE,OAAO;GACrB,WA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L;GAZkB,oBAAoB,iBACtC,oBAAC,OAAD;IAAwB,WAAW;cAC/B,oBAAC,eAAD;KACyB;KACrB,gBAAgB,gBAAgB;KAChC,OAAO;KACkB;KACzB,gBAAgB,WAAW;IAAM,CAAA;GACpC,GAPK,YAOL,IACL;GAKA;GACA;GACA,oBAAC,uBAAD;IAEqB;IACjB,SAAS;IACT,aAAa,WAAW;IACxB,SAAS;GAAM,GAJV,cAIU;GACnB;GACA;EAOK;EAJkB,QAAQ,4BAA4B,WAKtD;EAGA,sBAAsB,gBAAgB,mBACnC,oBAAC,eAAD;GACI,MAAM;GACN,cAAc;GACd,YAAY;GACZ,cAAc,gBAAgB;GAC9B,kBAAkB,iBAAiB,gBAAgB,kBAAkB,gBAAgB,CAAC,CAAC;GACvF,aAAa,WAAW;EAC3B,CAAA;CAEP,EAAA,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"CollectionViewStartActions.js","names":[],"sources":["../../../src/components/CollectionViewBinding/CollectionViewStartActions.tsx"],"sourcesContent":["import type { Properties } from \"@rebasepro/types\";\n\nimport React, { useState, useCallback } from \"react\";\nimport { useAuthController, useLargeLayout, useTranslation, useSlot } from \"@rebasepro/app\";\nimport { CollectionActionsProps, EntityTableController, SelectionController, SelectionQuery, AdminCollection, ViewMode } from \"@rebasepro/cms-types\";\nimport { ErrorBoundary, iconSize } from \"@rebasepro/ui\";\nimport { Badge, Button, cls, FilterIcon, IconButton, Skeleton, Tooltip, XIcon } from \"@rebasepro/ui\";\nimport { ClearFilterSortButton } from \"../ClearFilterSortButton\";\nimport { FiltersDialog } from \"./FiltersDialog\";\nimport { FilterPresetsButton } from \"./FilterPresetsButton\";\nimport { SortButton } from \"./SortButton\";\nimport { toArray } from \"@rebasepro/utils\";\nimport { useNavigate } from \"react-router\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { useAdminContext } from \"../../hooks/useAdminContext\";\nimport { withListState } from \"../../util/view_mode\";\nimport { useSplitView } from \"./SplitViewContext\";\nimport { SelectionMenu } from \"../../selection\";\nimport { useToolbarLabels } from \"../CollectionTableBinding/internal/CollectionTableToolbar\";\n\nexport type CollectionViewStartActionsProps<M extends Record<string, unknown>> = {\n collection: AdminCollection<M>;\n path: string;\n relativePath: string;\n parentCollectionSlugs: string[], parentEntityIds: string[];\n selectionController: SelectionController<M>;\n tableController: EntityTableController<M>;\n collectionEntitiesCount?: number;\n /**\n * Number of records the current filters and search resolve to, rendered at\n * the end of this group.\n * - `undefined`: not applicable\n * - `null`: still counting\n * - number: the count\n */\n entitiesCount?: number | null;\n /**\n * Resolved properties from the collection for the filters dialog\n */\n resolvedProperties?: Properties;\n /**\n * Which view is being displayed. Decides whether the sort control is\n * offered — see `sortButton`.\n */\n viewMode?: ViewMode;\n /** Whether rows can be selected at all in this mount. */\n selectionEnabled?: boolean;\n /** The view's live query — what the menu's \"all matching\" item stands for. */\n selectionQuery?: SelectionQuery<M>;\n compact?: boolean;\n openNewDocument: (defaultValues?: Record<string, unknown>) => void;\n}\n\nexport function CollectionViewStartActions<M extends Record<string, unknown>>({\n collection,\n relativePath,\n parentCollectionSlugs, parentEntityIds,\n path,\n selectionController,\n tableController,\n collectionEntitiesCount,\n entitiesCount,\n resolvedProperties,\n viewMode,\n selectionEnabled,\n selectionQuery,\n compact,\n openNewDocument\n}: CollectionViewStartActionsProps<M>) {\n\n const context = useAdminContext();\n const largeLayout = useLargeLayout();\n const toolbarLabels = useToolbarLabels();\n const { t } = useTranslation();\n\n const navigate = useNavigate();\n const urlController = useUrlController();\n const splitView = useSplitView();\n\n // Filters dialog state\n const [filtersDialogOpen, setFiltersDialogOpen] = useState(false);\n\n // Count active filters (excluding force filters)\n const filterValues = tableController.filterValues;\n const fixedFilter = collection.fixedFilter;\n const activeFilterCount = filterValues\n ? Object.keys(filterValues).filter(key => !fixedFilter || !(key in fixedFilter)).length\n : 0;\n\n const actionProps: CollectionActionsProps<M> = {\n path,\n relativePath,\n parentCollectionSlugs,\nparentEntityIds,\n collection,\n selectionController,\n context,\n tableController,\n collectionEntitiesCount,\n openNewDocument\n };\n\n const handleBackClick = useCallback(() => {\n navigate(withListState(urlController.buildUrlCollectionPath(path)));\n }, [navigate, urlController, path]);\n\n // In a split view the control that closes the list lives at the leading\n // edge of the record's app bar (`SplitListCloseButton`), not here.\n //\n // Outside one — a compact list with no record open beside it — the only\n // thing this can mean is \"leave the record behind\".\n const backButton = compact && !splitView?.detailOpen && (\n <Tooltip title={t(\"close\")} key={\"close_tooltip\"}>\n <IconButton\n size=\"small\"\n onClick={handleBackClick}\n aria-label={t(\"close\")}\n className=\"mr-1\"\n >\n <XIcon size={iconSize.smallest}/>\n </IconButton>\n </Tooltip>\n );\n\n // Whether the toolbar is showing icon-only controls. The filters button\n // drops its label — and its icon a size with it — on a narrow layout as\n // well as in the split view, and the sort and clear controls beside it\n // follow: keyed on `compact` alone they stayed 20px next to a 16px filter\n // icon at every width below `largeLayout`. A toolbar too narrow for its\n // labels (`useToolbarLabels`) is a narrow layout too, whatever the window.\n const iconOnlyToolbar = !largeLayout || Boolean(compact) || !toolbarLabels;\n\n const filtersButton = resolvedProperties && tableController.setFilterValues && (\n <Tooltip title={t(\"filters\")}\n key={\"filters_tooltip\"}>\n <Badge\n color=\"primary\"\n invisible={activeFilterCount === 0}\n >\n {!iconOnlyToolbar ? (\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setFiltersDialogOpen(true)}\n startIcon={<FilterIcon size={iconSize.small}/>}\n className={cls(activeFilterCount > 0 && \"text-primary\")}\n >\n {activeFilterCount > 0 ? `(${activeFilterCount})` : t(\"filters\")}\n </Button>\n ) : (\n <IconButton aria-label={t(\"filters\")}\n size={\"small\"}\n onClick={() => setFiltersDialogOpen(true)}\n className={cls(activeFilterCount > 0 && \"text-primary\")}\n >\n <FilterIcon size={iconSize.smallest}/>\n </IconButton>\n )}\n </Badge>\n </Tooltip>\n );\n\n // Everywhere a `sortBy` means something — which is every view but the\n // board, whose columns are ordered by their own order key and which ignores\n // `sortBy` entirely, so the control would appear to do nothing.\n //\n // Including the table, whose headers were once thought to cover it. They\n // build a multi-key sort (shift-click) and they show its ranks, but they\n // cannot *re-rank* it: promoting the third key above the first means\n // clearing the sort and shift-clicking all three back in the new order.\n // Nor can they remove a middle key without cycling it through descending\n // first. This popover is the only place either is one click, and a table\n // with a three-key sort needs it more than a card grid does, not less.\n const sortButton = resolvedProperties && viewMode !== \"kanban\" && (\n <SortButton\n key={\"sort_button\"}\n tableController={tableController}\n properties={resolvedProperties}\n compact={iconOnlyToolbar}\n />\n );\n\n // Not in the split view. The toolbar there is a strip a few hundred pixels\n // wide above the list, and a row of preset chips crowded out the controls\n // that act on what you are looking at. The presets are still one click away\n // inside the filters dialog.\n const filterPresetsButton = !compact && collection.filterPresets?.length ? (\n <FilterPresetsButton\n key={\"filter_presets\"}\n filterPresets={collection.filterPresets}\n tableController={tableController}\n compact={compact}\n />\n ) : null;\n\n // The count closes the group the filter, sort and preset controls open: it\n // is what they resolve to. It used to live in the breadcrumb trail, which\n // the app bar owns — and a collection rendered without an app bar has no\n // breadcrumbs, so the number simply disappeared.\n //\n // Hidden on the same layouts the trail was (`hidden lg:block` there) and in\n // the split view, where this toolbar is a few hundred pixels wide and\n // scrolls: a passive readout is the first thing that should give up its\n // room to the controls.\n const countBadge = !iconOnlyToolbar && entitiesCount !== undefined ? (\n <Tooltip title={t(\"records_in_view\")} key={\"entities_count\"}>\n {entitiesCount === null\n ? <Skeleton className={\"w-8 h-4 rounded-md mx-1\"}/>\n : <span\n className={\"mx-1 text-xs font-mono tabular-nums text-text-secondary dark:text-text-secondary-dark\"}>\n {entitiesCount.toLocaleString()}\n </span>}\n </Tooltip>\n ) : null;\n\n // One control, in one place, for every view — the leading edge of the\n // toolbar, which in a table sits directly above the checkbox column anyway.\n // The table used to carry its own in the ID column header, which meant two\n // controls that did different amounts.\n const selectionMenu = selectionEnabled && selectionQuery ? (\n <div key={\"select_all\"} className={\"mr-1 flex items-center\"}>\n <SelectionMenu\n selectionController={selectionController}\n loadedEntities={tableController.data}\n query={selectionQuery}\n collectionEntitiesCount={collectionEntitiesCount}\n collectionName={collection.name}/>\n </div>\n ) : null;\n\n const actions: React.ReactNode[] = [\n backButton,\n selectionMenu,\n filtersButton,\n sortButton,\n <ClearFilterSortButton\n key={\"clear_filter\"}\n tableController={tableController}\n compact={iconOnlyToolbar}\n fixedFilter={collection.fixedFilter}\n enabled={true}/>,\n filterPresetsButton,\n countBadge\n ];\n\n const pluginActionsStart = useSlot(\"collection.actions.start\", actionProps);\n\n return (\n <>\n {actions}\n {pluginActionsStart}\n\n {/* Filters Dialog */}\n {resolvedProperties && tableController.setFilterValues && (\n <FiltersDialog\n open={filtersDialogOpen}\n onOpenChange={setFiltersDialogOpen}\n properties={resolvedProperties}\n filterValues={tableController.filterValues}\n setFilterValues={(filterValues) => tableController.setFilterValues?.(filterValues ?? {})}\n fixedFilter={collection.fixedFilter}\n />\n )}\n </>\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;AAqDA,SAAgB,2BAA8D,EAC1E,YACA,cACA,uBAAuB,iBACvB,MACA,qBACA,iBACA,yBACA,eACA,oBACA,UACA,kBACA,gBACA,SACA,mBACmC;CAEnC,MAAM,UAAU,gBAAgB;CAChC,MAAM,cAAc,eAAe;CACnC,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,WAAW,YAAY;CAC7B,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,YAAY,aAAa;CAG/B,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,KAAK;CAGhE,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,WAAW;CAC/B,MAAM,oBAAoB,eACpB,OAAO,KAAK,YAAY,CAAC,CAAC,QAAO,QAAO,CAAC,eAAe,EAAE,OAAO,YAAY,CAAC,CAAC,SAC/E;CAEN,MAAM,cAAyC;EAC3C;EACA;EACA;EACR;EACQ;EACA;EACA;EACA;EACA;EACA;CACJ;CAE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M,aAAa,CAAC,mBAAmB,kBAAkB,KAAA,IACrD,oBAAC,SAAD;EAAS,OAAO,EAAE,iBAAiB;YAC9B,kBAAkB,OACb,oBAAC,UAAD,EAAU,WAAW,0BAA2B,CAAA,IAChD,oBAAC,QAAD;GACE,WAAW;aACV,cAAc,eAAe;EAC5B,CAAA;CACL,GAPkC,gBAOlC,IACT;CAkCJ,OACI,qBAAA,UAAA,EAAA,UAAA;EACK;GAlBL;GAZkB,oBAAoB,iBACtC,oBAAC,OAAD;IAAwB,WAAW;cAC/B,oBAAC,eAAD;KACyB;KACrB,gBAAgB,gBAAgB;KAChC,OAAO;KACkB;KACzB,gBAAgB,WAAW;IAAM,CAAA;GACpC,GAPK,YAOL,IACL;GAKA;GACA;GACA,oBAAC,uBAAD;IAEqB;IACjB,SAAS;IACT,aAAa,WAAW;IACxB,SAAS;GAAM,GAJV,cAIU;GACnB;GACA;EAOK;EAJkB,QAAQ,4BAA4B,WAKtD;EAGA,sBAAsB,gBAAgB,mBACnC,oBAAC,eAAD;GACI,MAAM;GACN,cAAc;GACd,YAAY;GACZ,cAAc,gBAAgB;GAC9B,kBAAkB,iBAAiB,gBAAgB,kBAAkB,gBAAgB,CAAC,CAAC;GACvF,aAAa,WAAW;EAC3B,CAAA;CAEP,EAAA,CAAA;AAEV"}
|
|
@@ -24,6 +24,14 @@ function FiltersDialog({ open, onOpenChange, properties, filterValues, setFilter
|
|
|
24
24
|
const engine = useCollectionScope()?.engine;
|
|
25
25
|
const [localFilters, setLocalFilters] = useState(filterValues ?? {});
|
|
26
26
|
const [hiddenFields, setHiddenFields] = useState({});
|
|
27
|
+
/**
|
|
28
|
+
* Bumped by "Clear all", and part of each field's key, so every field
|
|
29
|
+
* starts again from no value. A field keeps what it shows in its own
|
|
30
|
+
* state — an operator picked before any value is not a filter yet — and
|
|
31
|
+
* seeds it from `value` once, so emptying the filters alone left every
|
|
32
|
+
* field showing the value it had.
|
|
33
|
+
*/
|
|
34
|
+
const [fieldsGeneration, setFieldsGeneration] = useState(0);
|
|
27
35
|
React.useEffect(() => {
|
|
28
36
|
if (open) setLocalFilters(filterValues ?? {});
|
|
29
37
|
}, [open, filterValues]);
|
|
@@ -54,6 +62,7 @@ function FiltersDialog({ open, onOpenChange, properties, filterValues, setFilter
|
|
|
54
62
|
]);
|
|
55
63
|
const handleClearAll = useCallback(() => {
|
|
56
64
|
setLocalFilters({});
|
|
65
|
+
setFieldsGeneration((generation) => generation + 1);
|
|
57
66
|
}, []);
|
|
58
67
|
const setHiddenForField = useCallback((propertyKey, hidden) => {
|
|
59
68
|
setHiddenFields((prev) => ({
|
|
@@ -74,13 +83,14 @@ function FiltersDialog({ open, onOpenChange, properties, filterValues, setFilter
|
|
|
74
83
|
setValue,
|
|
75
84
|
hidden: hiddenFields[propertyKey] ?? false,
|
|
76
85
|
setHidden: (hidden) => setHiddenForField(propertyKey, hidden)
|
|
77
|
-
});
|
|
86
|
+
}, `${propertyKey}:${fieldsGeneration}`);
|
|
78
87
|
}, [
|
|
79
88
|
localFilters,
|
|
80
89
|
handleFilterChange,
|
|
81
90
|
hiddenFields,
|
|
82
91
|
setHiddenForField,
|
|
83
|
-
engine
|
|
92
|
+
engine,
|
|
93
|
+
fieldsGeneration
|
|
84
94
|
]);
|
|
85
95
|
return /* @__PURE__ */ jsxs(Dialog, {
|
|
86
96
|
open,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiltersDialog.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FiltersDialog.tsx"],"sourcesContent":["\nimport type { Property } from \"@rebasepro/types\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { FilterValues, WhereFilterOp } from \"@rebasepro/types\";\nimport { Button, Chip, cls, defaultBorderMixin, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport { FilterIcon, VirtualTableWhereFilterOp } from \"@rebasepro/ui\";\nimport { isPropertyFilterable } from \"@rebasepro/app\";\nimport { useCollectionScope, useTranslation } from \"@rebasepro/app\";\nimport { FilterFieldBinding } from \"../SelectableTable/filters/FilterFieldBinding\";\n\n/**\n * `WhereFilterOp` is declared twice: once in `@rebasepro/types` as the canonical\n * operator set every driver translates, and once in `@rebasepro/ui` for the\n * table's own props. That is deliberate — `ui` is a standalone design system and\n * depends on no Rebase package, so it cannot import the canonical one (and a\n * type-only import would not help: `ui` emits declarations with `tsc`, which\n * references external types rather than inlining them, so its published `.d.ts`\n * would demand `@rebasepro/types` from every consumer).\n *\n * This file is where the two meet and get cast into each other, so it is where\n * their agreement is checked. Adding an operator to one and not the other stops\n * this line compiling instead of silently producing a filter the table can build\n * and no driver can run — or one a driver supports and the table cannot offer.\n */\ntype MutuallyAssignable<A, B> = [A] extends [B] ? ([B] extends [A] ? true : never) : never;\nconst _whereFilterOpDefinitionsAgree: MutuallyAssignable<WhereFilterOp, VirtualTableWhereFilterOp> = true;\nvoid _whereFilterOpDefinitionsAgree;\n\n/**\n * The properties the dialog lists, each with a filter field: every property\n * that can be filtered, bar the collection's fixed-filter fields.\n */\nexport function getFilterableProperties(\n properties: Record<string, Property>,\n fixedFilter?: FilterValues<string>,\n engine?: string\n): [string, Property][] {\n return Object.entries(properties).filter(([key, property]) => {\n if (!property) return false;\n // Force filter properties should not be editable\n if (fixedFilter && key in fixedFilter) return false;\n // The table header asks the same question, so the two cannot list\n // different properties.\n return isPropertyFilterable(property, engine);\n });\n}\n\nexport interface FiltersDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n properties: Record<string, Property>;\n filterValues: FilterValues<any> | undefined;\n setFilterValues: (filterValues?: FilterValues<any>) => void;\n fixedFilter?: FilterValues<any>;\n}\n\n/**\n * Dialog that displays all filterable properties from a collection\n * and allows setting filter values for each.\n */\nexport function FiltersDialog({\n open,\n onOpenChange,\n properties,\n filterValues,\n setFilterValues,\n fixedFilter\n}: FiltersDialogProps) {\n const { t } = useTranslation();\n // Engine of the collection this dialog filters — read from the\n // surrounding CollectionScopeProvider mounted by the collection view.\n const engine = useCollectionScope()?.engine;\n // Local state for filters being edited\n const [localFilters, setLocalFilters] = useState<FilterValues<any>>(filterValues ?? {});\n\n // Track hidden state for reference fields (when reference dialog is open)\n const [hiddenFields, setHiddenFields] = useState<Record<string, boolean>>({});\n\n // Reset local state when dialog opens\n React.useEffect(() => {\n if (open) {\n setLocalFilters(filterValues ?? {});\n }\n }, [open, filterValues]);\n\n // Get list of filterable properties\n const filterableProperties = useMemo(\n () => getFilterableProperties(properties, fixedFilter, engine),\n [properties, fixedFilter, engine]);\n\n const handleFilterChange = useCallback((propertyKey: string, value?: [VirtualTableWhereFilterOp, any]) => {\n setLocalFilters(prev => {\n const newFilters = { ...prev };\n if (value) {\n newFilters[propertyKey] = value as [WhereFilterOp, any];\n } else {\n delete newFilters[propertyKey];\n }\n return newFilters;\n });\n }, []);\n\n const handleApply = useCallback(() => {\n const hasFilters = Object.keys(localFilters).length > 0;\n setFilterValues(hasFilters ? { ...localFilters,\n...fixedFilter } : (fixedFilter || undefined));\n onOpenChange(false);\n }, [localFilters, setFilterValues, fixedFilter, onOpenChange]);\n\n const handleClearAll = useCallback(() => {\n setLocalFilters({});\n }, []);\n\n const setHiddenForField = useCallback((propertyKey: string, hidden: boolean) => {\n setHiddenFields(prev => ({\n ...prev,\n [propertyKey]: hidden\n }));\n }, []);\n\n // Check if any reference field's dialog is currently open (should hide this dialog)\n const isAnyFieldHidden = Object.values(hiddenFields).some(hidden => hidden);\n const activeFilterCount = Object.keys(localFilters).length;\n\n const renderFilterField = useCallback((propertyKey: string, property: Property) => {\n const filterValue = localFilters[propertyKey] as [WhereFilterOp, any] | undefined;\n const setValue = (value?: [WhereFilterOp, any]) => handleFilterChange(propertyKey, value as [VirtualTableWhereFilterOp, any] | undefined);\n\n return (\n <FilterFieldBinding\n propertyKey={propertyKey}\n property={property}\n engine={engine}\n value={filterValue}\n setValue={setValue}\n hidden={hiddenFields[propertyKey] ?? false}\n setHidden={(hidden) => setHiddenForField(propertyKey, hidden)}\n />\n );\n }, [localFilters, handleFilterChange, hiddenFields, setHiddenForField, engine]);\n\n return (\n <Dialog\n open={open}\n onOpenChange={onOpenChange}\n maxWidth=\"3xl\"\n fullWidth\n containerClassName={isAnyFieldHidden ? \"hidden\" : undefined}\n >\n <DialogTitle className=\"flex items-center gap-2\" variant=\"h6\">\n {t(\"filters\")}\n {activeFilterCount > 0 && (\n <Chip size=\"small\" className=\"ml-2\">\n {activeFilterCount}\n </Chip>\n )}\n </DialogTitle>\n\n <DialogContent >\n {filterableProperties.length === 0 ? (\n <Typography color=\"secondary\" className=\"py-8 text-center\">\n {t(\"no_filterable_properties\")}\n </Typography>\n ) : (\n <div className=\"grid grid-cols-[160px_minmax(0,1fr)] items-center\">\n {filterableProperties.map(([propertyKey, property], index) => {\n const hasFilter = propertyKey in localFilters;\n const rowBorder = index > 0 && cls(\"border-t\", defaultBorderMixin);\n return (\n <React.Fragment key={propertyKey}>\n {/* Property name on the left */}\n <div className={cls(\"py-3 pr-4 self-stretch flex items-center\", rowBorder)}>\n <Typography\n variant=\"body2\"\n className={cls(\n \"font-medium\",\n hasFilter && \"text-primary\"\n )}\n >\n {property.name || propertyKey}\n </Typography>\n </div>\n\n {/* The filter field on the right */}\n <div className={cls(\"py-3\", rowBorder)}>\n {renderFilterField(propertyKey, property)}\n </div>\n </React.Fragment>\n );\n })}\n </div>\n )}\n </DialogContent>\n\n <DialogActions>\n <Button\n variant=\"text\"\n onClick={handleClearAll}\n disabled={activeFilterCount === 0}\n >\n {t(\"clear_all\")}\n </Button>\n <div className=\"flex-grow\"/>\n <Button\n variant=\"text\"\n onClick={() => onOpenChange(false)}\n >\n {t(\"cancel\")}\n </Button>\n <Button\n variant=\"filled\"\n onClick={handleApply}\n >\n {t(\"apply_filters\")}\n </Button>\n </DialogActions>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,wBACZ,YACA,aACA,QACoB;CACpB,OAAO,OAAO,QAAQ,UAAU,CAAC,CAAC,QAAQ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AAA,EAEE,CAAA;GAEf,qBAAC,eAAD,EAAA,UAAA;IACI,oBAAC,QAAD;KACI,SAAQ;KACR,SAAS;KACT,UAAU,sBAAsB;eAE/B,EAAE,WAAW;IACV,CAAA;IACR,oBAAC,OAAD,EAAK,WAAU,YAAY,CAAA;IAC3B,oBAAC,QAAD;KACI,SAAQ;KACR,eAAe,aAAa,KAAK;eAEhC,EAAE,QAAQ;IACP,CAAA;IACR,oBAAC,QAAD;KACI,SAAQ;KACR,SAAS;eAER,EAAE,eAAe;IACd,CAAA;GACG,EAAA,CAAA;EACX;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"FiltersDialog.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FiltersDialog.tsx"],"sourcesContent":["\nimport type { Property } from \"@rebasepro/types\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { FilterValues, WhereFilterOp } from \"@rebasepro/types\";\nimport { Button, Chip, cls, defaultBorderMixin, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport { FilterIcon, VirtualTableWhereFilterOp } from \"@rebasepro/ui\";\nimport { isPropertyFilterable } from \"@rebasepro/app\";\nimport { useCollectionScope, useTranslation } from \"@rebasepro/app\";\nimport { FilterFieldBinding } from \"../SelectableTable/filters/FilterFieldBinding\";\n\n/**\n * `WhereFilterOp` is declared twice: once in `@rebasepro/types` as the canonical\n * operator set every driver translates, and once in `@rebasepro/ui` for the\n * table's own props. That is deliberate — `ui` is a standalone design system and\n * depends on no Rebase package, so it cannot import the canonical one (and a\n * type-only import would not help: `ui` emits declarations with `tsc`, which\n * references external types rather than inlining them, so its published `.d.ts`\n * would demand `@rebasepro/types` from every consumer).\n *\n * This file is where the two meet and get cast into each other, so it is where\n * their agreement is checked. Adding an operator to one and not the other stops\n * this line compiling instead of silently producing a filter the table can build\n * and no driver can run — or one a driver supports and the table cannot offer.\n */\ntype MutuallyAssignable<A, B> = [A] extends [B] ? ([B] extends [A] ? true : never) : never;\nconst _whereFilterOpDefinitionsAgree: MutuallyAssignable<WhereFilterOp, VirtualTableWhereFilterOp> = true;\nvoid _whereFilterOpDefinitionsAgree;\n\n/**\n * The properties the dialog lists, each with a filter field: every property\n * that can be filtered, bar the collection's fixed-filter fields.\n */\nexport function getFilterableProperties(\n properties: Record<string, Property>,\n fixedFilter?: FilterValues<string>,\n engine?: string\n): [string, Property][] {\n return Object.entries(properties).filter(([key, property]) => {\n if (!property) return false;\n // Force filter properties should not be editable\n if (fixedFilter && key in fixedFilter) return false;\n // The table header asks the same question, so the two cannot list\n // different properties.\n return isPropertyFilterable(property, engine);\n });\n}\n\nexport interface FiltersDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n properties: Record<string, Property>;\n filterValues: FilterValues<any> | undefined;\n setFilterValues: (filterValues?: FilterValues<any>) => void;\n fixedFilter?: FilterValues<any>;\n}\n\n/**\n * Dialog that displays all filterable properties from a collection\n * and allows setting filter values for each.\n */\nexport function FiltersDialog({\n open,\n onOpenChange,\n properties,\n filterValues,\n setFilterValues,\n fixedFilter\n}: FiltersDialogProps) {\n const { t } = useTranslation();\n // Engine of the collection this dialog filters — read from the\n // surrounding CollectionScopeProvider mounted by the collection view.\n const engine = useCollectionScope()?.engine;\n // Local state for filters being edited\n const [localFilters, setLocalFilters] = useState<FilterValues<any>>(filterValues ?? {});\n\n // Track hidden state for reference fields (when reference dialog is open)\n const [hiddenFields, setHiddenFields] = useState<Record<string, boolean>>({});\n\n /**\n * Bumped by \"Clear all\", and part of each field's key, so every field\n * starts again from no value. A field keeps what it shows in its own\n * state — an operator picked before any value is not a filter yet — and\n * seeds it from `value` once, so emptying the filters alone left every\n * field showing the value it had.\n */\n const [fieldsGeneration, setFieldsGeneration] = useState(0);\n\n // Reset local state when dialog opens\n React.useEffect(() => {\n if (open) {\n setLocalFilters(filterValues ?? {});\n }\n }, [open, filterValues]);\n\n // Get list of filterable properties\n const filterableProperties = useMemo(\n () => getFilterableProperties(properties, fixedFilter, engine),\n [properties, fixedFilter, engine]);\n\n const handleFilterChange = useCallback((propertyKey: string, value?: [VirtualTableWhereFilterOp, any]) => {\n setLocalFilters(prev => {\n const newFilters = { ...prev };\n if (value) {\n newFilters[propertyKey] = value as [WhereFilterOp, any];\n } else {\n delete newFilters[propertyKey];\n }\n return newFilters;\n });\n }, []);\n\n const handleApply = useCallback(() => {\n const hasFilters = Object.keys(localFilters).length > 0;\n setFilterValues(hasFilters ? { ...localFilters,\n...fixedFilter } : (fixedFilter || undefined));\n onOpenChange(false);\n }, [localFilters, setFilterValues, fixedFilter, onOpenChange]);\n\n const handleClearAll = useCallback(() => {\n setLocalFilters({});\n setFieldsGeneration(generation => generation + 1);\n }, []);\n\n const setHiddenForField = useCallback((propertyKey: string, hidden: boolean) => {\n setHiddenFields(prev => ({\n ...prev,\n [propertyKey]: hidden\n }));\n }, []);\n\n // Check if any reference field's dialog is currently open (should hide this dialog)\n const isAnyFieldHidden = Object.values(hiddenFields).some(hidden => hidden);\n const activeFilterCount = Object.keys(localFilters).length;\n\n const renderFilterField = useCallback((propertyKey: string, property: Property) => {\n const filterValue = localFilters[propertyKey] as [WhereFilterOp, any] | undefined;\n const setValue = (value?: [WhereFilterOp, any]) => handleFilterChange(propertyKey, value as [VirtualTableWhereFilterOp, any] | undefined);\n\n return (\n <FilterFieldBinding\n key={`${propertyKey}:${fieldsGeneration}`}\n propertyKey={propertyKey}\n property={property}\n engine={engine}\n value={filterValue}\n setValue={setValue}\n hidden={hiddenFields[propertyKey] ?? false}\n setHidden={(hidden) => setHiddenForField(propertyKey, hidden)}\n />\n );\n }, [localFilters, handleFilterChange, hiddenFields, setHiddenForField, engine, fieldsGeneration]);\n\n return (\n <Dialog\n open={open}\n onOpenChange={onOpenChange}\n maxWidth=\"3xl\"\n fullWidth\n containerClassName={isAnyFieldHidden ? \"hidden\" : undefined}\n >\n <DialogTitle className=\"flex items-center gap-2\" variant=\"h6\">\n {t(\"filters\")}\n {activeFilterCount > 0 && (\n <Chip size=\"small\" className=\"ml-2\">\n {activeFilterCount}\n </Chip>\n )}\n </DialogTitle>\n\n <DialogContent >\n {filterableProperties.length === 0 ? (\n <Typography color=\"secondary\" className=\"py-8 text-center\">\n {t(\"no_filterable_properties\")}\n </Typography>\n ) : (\n <div className=\"grid grid-cols-[160px_minmax(0,1fr)] items-center\">\n {filterableProperties.map(([propertyKey, property], index) => {\n const hasFilter = propertyKey in localFilters;\n const rowBorder = index > 0 && cls(\"border-t\", defaultBorderMixin);\n return (\n <React.Fragment key={propertyKey}>\n {/* Property name on the left */}\n <div className={cls(\"py-3 pr-4 self-stretch flex items-center\", rowBorder)}>\n <Typography\n variant=\"body2\"\n className={cls(\n \"font-medium\",\n hasFilter && \"text-primary\"\n )}\n >\n {property.name || propertyKey}\n </Typography>\n </div>\n\n {/* The filter field on the right */}\n <div className={cls(\"py-3\", rowBorder)}>\n {renderFilterField(propertyKey, property)}\n </div>\n </React.Fragment>\n );\n })}\n </div>\n )}\n </DialogContent>\n\n <DialogActions>\n <Button\n variant=\"text\"\n onClick={handleClearAll}\n disabled={activeFilterCount === 0}\n >\n {t(\"clear_all\")}\n </Button>\n <div className=\"flex-grow\"/>\n <Button\n variant=\"text\"\n onClick={() => onOpenChange(false)}\n >\n {t(\"cancel\")}\n </Button>\n <Button\n variant=\"filled\"\n onClick={handleApply}\n >\n {t(\"apply_filters\")}\n </Button>\n </DialogActions>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,wBACZ,YACA,aACA,QACoB;CACpB,OAAO,OAAO,QAAQ,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,cAAc;EAC1D,IAAI,CAAC,UAAU,OAAO;EAEtB,IAAI,eAAe,OAAO,aAAa,OAAO;EAG9C,OAAO,qBAAqB,UAAU,MAAM;CAChD,CAAC;AACL;;;;;AAeA,SAAgB,cAAc,EAC1B,MACA,cACA,YACA,cACA,iBACA,eACmB;CACnB,MAAM,EAAE,MAAM,eAAe;CAG7B,MAAM,SA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WAAW;IACV,CAAA;IACR,oBAAC,OAAD,EAAK,WAAU,YAAY,CAAA;IAC3B,oBAAC,QAAD;KACI,SAAQ;KACR,eAAe,aAAa,KAAK;eAEhC,EAAE,QAAQ;IACP,CAAA;IACR,oBAAC,QAAD;KACI,SAAQ;KACR,SAAS;eAER,EAAE,eAAe;IACd,CAAA;GACG,EAAA,CAAA;EACX;;AAEhB"}
|
package/dist/editor/editor.js
CHANGED
|
@@ -220,31 +220,39 @@ var cssStyles = `
|
|
|
220
220
|
padding-left: 2rem;
|
|
221
221
|
padding-right: 2rem;
|
|
222
222
|
min-height: 100%;
|
|
223
|
+
/* What prosemirror-view's style/prosemirror.css sets on its root: the
|
|
224
|
+
document's spaces are read back from the DOM, so they must not collapse. */
|
|
225
|
+
word-wrap: break-word;
|
|
226
|
+
white-space: pre-wrap;
|
|
227
|
+
white-space: break-spaces;
|
|
228
|
+
font-variant-ligatures: none;
|
|
229
|
+
font-feature-settings: "liga" 0;
|
|
230
|
+
}
|
|
231
|
+
.ProseMirror pre {
|
|
232
|
+
white-space: pre-wrap;
|
|
223
233
|
}
|
|
224
234
|
.ProseMirror .is-editor-empty:first-child::before {
|
|
225
235
|
content: attr(data-placeholder);
|
|
226
236
|
float: left;
|
|
227
|
-
color: rgb(100 116 139);
|
|
237
|
+
color: rgb(100 116 139); /* 500 */
|
|
228
238
|
pointer-events: none;
|
|
229
239
|
height: 0;
|
|
230
240
|
}
|
|
231
241
|
.ProseMirror .is-empty::before {
|
|
232
242
|
content: attr(data-placeholder);
|
|
233
243
|
float: left;
|
|
234
|
-
color: rgb(100 116 139);
|
|
244
|
+
color: rgb(100 116 139); /* 500 */
|
|
235
245
|
pointer-events: none;
|
|
236
246
|
height: 0;
|
|
237
247
|
}
|
|
238
248
|
|
|
239
|
-
[data-theme="dark"] {
|
|
240
|
-
|
|
241
|
-
color: rgb(100 116 139); //500
|
|
242
|
-
}
|
|
249
|
+
[data-theme="dark"] .ProseMirror .is-empty::before {
|
|
250
|
+
color: rgb(100 116 139); /* 500 */
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
.is-empty {
|
|
246
254
|
cursor: text;
|
|
247
|
-
color: rgb(100 116 139);
|
|
255
|
+
color: rgb(100 116 139); /* 500 */
|
|
248
256
|
}
|
|
249
257
|
|
|
250
258
|
.ProseMirror img {
|
|
@@ -304,12 +312,10 @@ ul[data-type="taskList"] li > label input[type="checkbox"]::before {
|
|
|
304
312
|
}
|
|
305
313
|
ul[data-type="taskList"] li > label input[type="checkbox"]:checked::before { transform: scale(1); }
|
|
306
314
|
|
|
307
|
-
[data-theme="dark"] {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
text-decoration-thickness: 2px;
|
|
312
|
-
}
|
|
315
|
+
[data-theme="dark"] ul[data-type="taskList"] li[data-checked="true"] > div > p {
|
|
316
|
+
color: rgb(226 232 240);
|
|
317
|
+
text-decoration: line-through;
|
|
318
|
+
text-decoration-thickness: 2px;
|
|
313
319
|
}
|
|
314
320
|
ul[data-type="taskList"] li[data-checked="true"] > div > p {
|
|
315
321
|
color: rgb(51 65 85);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","names":[],"sources":["../../src/editor/editor.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useState, useRef, useMemo } from \"react\";\nimport { EditorState, Selection } from \"prosemirror-state\";\nimport { cls, defaultBorderMixin, Separator, TextareaAutosize, useInjectStyles } from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { EditorBubble, ImageBubble, SlashCommandMenu, TableBubble, type JSONContent } from \"./components\";\nimport { NodeSelector } from \"./selectors/node-selector\";\nimport { LinkSelector } from \"./selectors/link-selector\";\nimport { TextButtons } from \"./selectors/text-buttons\";\nimport { removeClassesFromJson } from \"./utils/remove_classes\";\nimport { parser, serializer } from \"./markdown\";\nimport { EditorAIController } from \"./types\";\nimport { useProseMirror } from \"./hooks/useProseMirror\";\nimport { ProseMirrorContext } from \"./hooks/useProseMirrorContext\";\nimport { highlightCommands } from \"./extensions/HighlightDecorationExtension\";\nimport { schema } from \"./schema\";\n\nexport type CustomEditorComponent = {\n name: string,\n component: React.FC\n};\n\nexport type RichTextEditorTextSize = \"sm\" | \"base\" | \"lg\";\n\n\nexport type RichTextEditorProps = {\n content?: JSONContent | string,\n onMarkdownContentChange?: (content: string) => void,\n onJsonContentChange?: (content: JSONContent | null) => void,\n onHtmlContentChange?: (content: string) => void,\n handleImageUpload: (file: File) => Promise<string>,\n /**\n * Turns an image's stored `src` into a URL to show. `handleImageUpload`\n * returns a `rebase-storage:` reference to keep in the text — a private\n * object's URL expires — and the editor asks this for a URL to display it.\n */\n resolveImageSrc?: (src: string) => Promise<string | null | undefined>,\n version?: number,\n textSize?: RichTextEditorTextSize,\n highlight?: { from: number, to: number },\n aiController?: EditorAIController,\n customComponents?: CustomEditorComponent[];\n disabled?: boolean;\n};\n\n\nconst proseClasses = {\n \"sm\": \"prose-sm\",\n \"base\": \"prose-base\",\n \"lg\": \"prose-lg\"\n}\n\nexport const RichTextEditor = ({\n content,\n onJsonContentChange,\n onHtmlContentChange,\n onMarkdownContentChange,\n version,\n textSize = \"base\",\n highlight,\n handleImageUpload,\n resolveImageSrc,\n aiController,\n disabled\n}: RichTextEditorProps) => {\n\n const { t } = useTranslation();\n\n const [openNode, setOpenNode] = useState(false);\n const [openLink, setOpenLink] = useState(false);\n\n const [isMarkdownMode, setIsMarkdownMode] = useState(false);\n const [internalMarkdown, setInternalMarkdown] = useState<string>(\"\");\n\n useEffect(() => {\n if (!isMarkdownMode) return;\n const timeout = setTimeout(() => {\n if (callbacksRef.current.onMarkdownContentChange) {\n callbacksRef.current.onMarkdownContentChange(internalMarkdown);\n }\n }, 250);\n return () => clearTimeout(timeout);\n }, [internalMarkdown, isMarkdownMode]);\n\n const handleToggleMarkdown = () => {\n if (!isMarkdownMode) {\n if (view) {\n setInternalMarkdown(serializer.serialize(view.state.doc));\n }\n setIsMarkdownMode(true);\n } else {\n if (view) {\n const newDoc = parser.parse(internalMarkdown);\n if (newDoc) {\n const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, newDoc.content);\n view.dispatch(tr);\n }\n }\n setIsMarkdownMode(false);\n }\n };\n\n const handleMarkdownChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n setInternalMarkdown(e.target.value);\n };\n\n const handleMarkdownBlur = () => {\n const { onMarkdownContentChange, onJsonContentChange } = callbacksRef.current;\n if (onMarkdownContentChange) {\n onMarkdownContentChange(internalMarkdown);\n }\n if (onJsonContentChange) {\n try {\n const newDoc = parser.parse(internalMarkdown);\n if (newDoc) {\n onJsonContentChange(removeClassesFromJson(newDoc.toJSON()) as JSONContent);\n }\n } catch (e) {\n console.warn(\"Could not parse markdown to JSON\", e);\n }\n }\n };\n\n useInjectStyles(\"Editor\", cssStyles);\n\n const callbacksRef = useRef({ onMarkdownContentChange,\nonJsonContentChange });\n useEffect(() => {\n callbacksRef.current = { onMarkdownContentChange,\nonJsonContentChange };\n }, [onMarkdownContentChange, onJsonContentChange]);\n\n const flushChanges = (currentState: EditorState) => {\n const { onMarkdownContentChange, onJsonContentChange } = callbacksRef.current;\n if (onMarkdownContentChange) {\n try {\n const markdown = serializer.serialize(currentState.doc);\n onMarkdownContentChange(markdown);\n } catch (e) {\n console.warn(\"[RichTextEditor] Could not serialize editor state to markdown:\", e);\n }\n }\n if (onJsonContentChange) {\n const jsonContent = removeClassesFromJson(currentState.doc.toJSON()) as JSONContent;\n onJsonContentChange(jsonContent);\n }\n };\n\n const { state, view, editorRef } = useProseMirror({\n initialContent: content,\n editable: !disabled,\n handleImageUpload,\n resolveImageSrc\n });\n\n // When `version` changes externally (e.g. form discard/reset), re-parse the\n // `content` prop and replace the ProseMirror document so the editor reflects\n // the reverted value.\n const versionRef = useRef(version);\n useEffect(() => {\n if (versionRef.current === version) return; // skip initial render\n versionRef.current = version;\n if (!view) return;\n try {\n const newDoc = typeof content === \"string\"\n ? parser.parse(content ?? \"\")\n : content\n ? schema.nodeFromJSON(content)\n : schema.node(\"doc\", null, [schema.node(\"paragraph\")]);\n if (newDoc) {\n const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, newDoc.content);\n view.dispatch(tr);\n }\n } catch (e) {\n console.warn(\"[RichTextEditor] Could not reset editor content:\", e);\n }\n // Also reset raw-markdown textarea if the user is in source mode\n if (isMarkdownMode) {\n setInternalMarkdown(typeof content === \"string\" ? content : \"\");\n }\n // Reset the settling window so the replacement dispatch above is NOT\n // treated as a user edit (which would fire onChange back to the form).\n mountTimeRef.current = Date.now();\n hasUserEditedRef.current = false;\n }, [version]);\n\n const doc = state?.doc;\n // Use a time-based settling window instead of a single-skip flag.\n // The trailingNodePlugin fires appendTransaction on mount (adding a trailing\n // paragraph), which creates a second doc change after the initial parse.\n // A single-skip flag misses that second change. Instead, we skip ALL doc\n // changes within the first 500ms after the view is created.\n const mountTimeRef = useRef(Date.now());\n const hasUserEditedRef = useRef(false);\n useEffect(() => {\n if (!state) return;\n // Skip all doc changes during the initial settling window (500ms).\n // This covers both the initial parse AND the trailingNodePlugin's\n // appendTransaction that adds a trailing paragraph.\n const elapsed = Date.now() - mountTimeRef.current;\n if (elapsed < 500 && !hasUserEditedRef.current) {\n return;\n }\n hasUserEditedRef.current = true;\n const timeout = setTimeout(() => {\n flushChanges(state);\n }, 250);\n return () => clearTimeout(timeout);\n }, [doc]);\n\n useEffect(() => {\n if (!view) return;\n const dom = view.dom;\n const handleBlur = () => {\n // Don't flush during the initial settling window — the editor\n // hasn't been interacted with yet, and the serialized output\n // may differ from the input due to parse→serialize normalization.\n if (!hasUserEditedRef.current) {\n const elapsed = Date.now() - mountTimeRef.current;\n if (elapsed < 500) return;\n }\n flushChanges(view.state);\n };\n dom.addEventListener(\"blur\", handleBlur);\n return () => dom.removeEventListener(\"blur\", handleBlur);\n }, [view]);\n\n\n useEffect(() => {\n if (view) {\n if (highlight) {\n highlightCommands.toggleAutocompleteHighlight(highlight)(view.state, view.dispatch);\n } else {\n highlightCommands.removeAutocompleteHighlight()(view.state, view.dispatch);\n }\n }\n }, [highlight?.from, highlight?.to]);\n\n const proseClass = proseClasses[textSize];\n\n\n return (\n <div className=\"relative min-h-[200px] w-full flex flex-col\">\n <button\n type=\"button\"\n onClick={handleToggleMarkdown}\n title={isMarkdownMode ? \"Switch to Visual Editor\" : \"Switch to Markdown\"}\n className=\"absolute top-2 right-2 z-10 px-2 py-1 text-xs font-medium text-surface-400 hover:text-surface-700 dark:text-surface-600 dark:hover:text-surface-300 transition-colors opacity-50 hover:opacity-100 bg-transparent rounded\"\n >\n {isMarkdownMode ? \"Visual\" : \"Markdown\"}\n </button>\n\n <ProseMirrorContext.Provider value={useMemo(() => ({ state,\nview }), [state, view])}>\n\n <div style={{ display: isMarkdownMode ? \"none\" : \"flex\" }} className=\"flex-1 flex flex-col\">\n <div\n ref={editorRef}\n onClick={(e) => {\n // If the click landed on the wrapper padding (not on the ProseMirror\n // content), focus the editor and place the cursor at the nearest position.\n if (view && e.target === e.currentTarget) {\n view.focus();\n // Place cursor at end of the document\n const end = view.state.doc.content.size;\n const tr = view.state.tr.setSelection(\n Selection.near(view.state.doc.resolve(end), -1)\n );\n view.dispatch(tr);\n }\n }}\n className={cls(\"relative prose dark:prose-invert cursor-text flex-1\", proseClass, \"prose-headings:font-title prose-headings:font-normal prose-strong:font-semibold prose-code:font-normal prose-blockquote:font-normal prose-a:font-normal font-default focus:outline-none max-w-full py-4\")}\n />\n\n {view && (\n <>\n <EditorBubble\n options={{\n placement: \"top\",\n offset: 6\n }}\n className={cls(\"flex w-fit max-w-[90vw] h-10 overflow-hidden rounded border bg-surface-card shadow\", defaultBorderMixin)}\n >\n <NodeSelector portalContainer={editorRef.current} open={openNode} onOpenChange={setOpenNode}/>\n <Separator orientation=\"vertical\"/>\n <LinkSelector open={openLink} onOpenChange={setOpenLink}/>\n <Separator orientation=\"vertical\"/>\n <TextButtons/>\n </EditorBubble>\n\n <ImageBubble\n options={{\n placement: \"bottom\",\n offset: 6\n }}\n />\n <TableBubble/>\n </>\n )}\n\n <SlashCommandMenu upload={handleImageUpload} aiController={aiController}/>\n </div>\n\n {isMarkdownMode && (\n <TextareaAutosize\n value={internalMarkdown}\n onChange={handleMarkdownChange}\n onBlur={handleMarkdownBlur}\n className={cls(\n \"w-full h-full min-h-[200px] px-12 py-4 bg-transparent resize-none font-mono focus:ring-0\",\n proseClass\n )}\n style={{\n tabSize: 4,\n outline: \"none\",\n border: \"none\",\n boxShadow: \"none\"\n }}\n />\n )}\n\n </ProseMirrorContext.Provider>\n </div>\n );\n};\n\n\nconst cssStyles = `\n.ProseMirror {\n box-shadow: none !important;\n padding-left: 2rem;\n padding-right: 2rem;\n min-height: 100%;\n}\n.ProseMirror .is-editor-empty:first-child::before {\n content: attr(data-placeholder);\n float: left;\n color: rgb(100 116 139); //500\n pointer-events: none;\n height: 0;\n}\n.ProseMirror .is-empty::before {\n content: attr(data-placeholder);\n float: left;\n color: rgb(100 116 139); //500\n pointer-events: none;\n height: 0;\n}\n\n[data-theme=\"dark\"] {\n .ProseMirror .is-empty::before {\n color: rgb(100 116 139); //500\n }\n}\n\n.is-empty {\n cursor: text;\n color: rgb(100 116 139); //500\n}\n\n.ProseMirror img {\n transition: filter 0.1s ease-in-out;\n}\n.ProseMirror img:hover {\n cursor: pointer;\n filter: brightness(90%);\n}\n.ProseMirror img.ProseMirror-selectednode {\n filter: brightness(90%);\n box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000) !important;\n}\n\nul[data-type=\"taskList\"] li > label {\n margin-right: 0.2rem;\n user-select: none;\n}\n@media screen and (max-width: 768px) {\n ul[data-type=\"taskList\"] li > label {\n margin-right: 0.5rem;\n }\n}\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li > label input[type=\"checkbox\"] {\n background-color: rgb(30 41 59);\n border: 2px solid #666;\n}\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:hover { background-color: rgb(51 65 85); }\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:active { background-color: rgb(71 85 105); }\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"] {\n -webkit-appearance: none;\n appearance: none;\n background-color: white;\n margin: 0;\n cursor: pointer;\n width: 1.2em;\n height: 1.2em;\n position: relative;\n top: 5px;\n border: 2px solid #777;\n border-radius: 0.25em;\n margin-right: 0.3rem;\n display: grid;\n place-content: center;\n}\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:hover { background-color: rgb(241 245 249); }\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:active { background-color: rgb(226 232 240); }\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]::before {\n content: \"\";\n width: 0.65em;\n height: 0.65em;\n transform: scale(0);\n transition: 120ms transform ease-in-out;\n box-shadow: inset 1em 1em;\n transform-origin: center;\n clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);\n}\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:checked::before { transform: scale(1); }\n\n[data-theme=\"dark\"] {\n ul[data-type=\"taskList\"] li[data-checked=\"true\"] > div > p {\n color: rgb(226 232 240);\n text-decoration: line-through;\n text-decoration-thickness: 2px;\n }\n}\nul[data-type=\"taskList\"] li[data-checked=\"true\"] > div > p {\n color: rgb(51 65 85);\n text-decoration: line-through;\n text-decoration-thickness: 2px;\n}\n.tippy-box { max-width: 400px !important; }\n\n.ProseMirror:not(.dragging) .ProseMirror-selectednode {\n background-color: rgb(219 234 254);\n transition: background-color 0.2s;\n box-shadow: none;\n}\n[data-theme=\"dark\"] .ProseMirror:not(.dragging) .ProseMirror-selectednode {\n background-color: rgb(51 65 85);\n}\n.prose-base table p { margin: 0; }\n\n.drag-handle {\n position: absolute;\n opacity: 1;\n transition: opacity ease-in 0.2s;\n border-radius: 0.25rem;\n background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' style='fill: rgba(128, 128, 128, 0.9)'%3E%3Cpath d='M3,2 C2.44771525,2 2,1.55228475 2,1 C2,0.44771525 2.44771525,0 3,0 C3.55228475,0 4,0.44771525 4,1 C4,1.55228475 3.55228475,2 3,2 Z M3,6 C2.44771525,6 2,5.55228475 2,5 C2,4.44771525 2.44771525,4 3,4 C3.55228475,4 4,4.44771525 4,5 C4,5.55228475 3.55228475,6 3,6 Z M3,10 C2.44771525,10 2,9.55228475 2,9 C2,8.44771525 2.44771525,8 3,8 C3.55228475,8 4,8.44771525 4,9 C4,9.55228475 3.55228475,10 3,10 Z M7,2 C6.44771525,2 6,1.55228475 6,1 C6,0.44771525 6.44771525,0 7,0 C7.55228475,0 8,0.44771525 8,1 C8,1.55228475 7.55228475,2 7,2 Z M7,6 C6.44771525,6 6,5.55228475 6,5 C6,4.44771525 6.44771525,4 7,4 C7.55228475,4 8,4.44771525 8,5 C8,5.55228475 7.55228475,6 7,6 Z M7,10 C6.44771525,10 6,9.55228475 6,9 C6,8.44771525 6.44771525,8 7,8 C7,8.44771525 7,9 7,9 C7,9.55228475 7,10 7,10 Z'%3E%3C/path%3E%3C/svg%3E\");\n background-size: calc(0.5em + 0.375rem) calc(0.5em + 0.375rem);\n background-repeat: no-repeat;\n background-position: center;\n width: 1.2rem;\n height: 1.5rem;\n z-index: 100;\n cursor: grab;\n}\n.drag-handle::before {\n content: '';\n position: absolute;\n top: -10px;\n bottom: -10px;\n left: -20px; \n right: 0px;\n z-index: -1;\n}\n.drag-handle:hover { background-color: rgb(241 245 249); transition: background-color 0.2s; }\n.drag-handle:active { background-color: rgb(226 232 240); transition: background-color 0.2s; }\n.drag-handle.hide { opacity: 0; pointer-events: none; }\n@media screen and (max-width: 600px) { .drag-handle { display: none; pointer-events: none; } }\n[data-theme=\"dark\"] .drag-handle:hover { background-color: rgb(51 65 85); }\n[data-theme=\"dark\"] .drag-handle:active { background-color: rgb(51 65 85); }\n.prosemirror-dropcursor-block {\n background-color: var(--color-surface-accent-600);\n}\n[data-theme=\"dark\"] .prosemirror-dropcursor-block {\n background-color: var(--color-surface-accent-300);\n}\n\n.ProseMirror table {\n border-collapse: separate;\n border-spacing: 0;\n table-layout: fixed;\n width: 100%;\n margin: 1em 0;\n overflow: hidden;\n border-radius: 0.375rem;\n border: 1px solid #e5e7eb;\n}\n[data-theme=\"dark\"] .ProseMirror table {\n border-color: #374151;\n}\n\n.ProseMirror td, .ProseMirror th {\n min-width: 1em;\n padding: 8px 10px;\n vertical-align: top;\n box-sizing: border-box;\n position: relative;\n border-right: 1px solid #e5e7eb;\n border-bottom: 1px solid #e5e7eb;\n}\n[data-theme=\"dark\"] .ProseMirror td, [data-theme=\"dark\"] .ProseMirror th {\n border-right-color: #374151;\n border-bottom-color: #374151;\n}\n\n.ProseMirror tr:last-child td, .ProseMirror tr:last-child th {\n border-bottom: none;\n}\n.ProseMirror th:last-child, .ProseMirror td:last-child {\n border-right: none;\n}\n\n.ProseMirror td {\n background-color: transparent;\n}\n\n.ProseMirror th {\n font-weight: 600;\n text-align: left;\n background-color: #f3f4f6;\n color: #374151;\n}\n[data-theme=\"dark\"] .ProseMirror td {\n background-color: transparent;\n}\n[data-theme=\"dark\"] .ProseMirror th {\n background-color: rgba(255, 255, 255, 0.05);\n color: #d1d5db;\n}\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8CA,IAAM,eAAe;CACnB,MAAM;CACN,QAAQ;CACR,MAAM;AACR;AAEA,IAAa,kBAAkB,EAC7B,SACA,qBACA,qBACA,yBACA,SACA,WAAW,QACX,WACA,mBACA,iBACA,cACA,eACyB;CAEzB,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAE9C,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,KAAK;CAC1D,MAAM,CAAC,kBAAkB,uBAAuB,SAAiB,EAAE;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E,SAAS;QACP,WAAW;QACX,QAAQ;OACV;OACA,WAAW,IAAI,sFAAsF,kBAAkB;iBALzH;QAOE,oBAAC,cAAD;SAAc,iBAAiB,UAAU;SAAS,MAAM;SAAU,cAAc;QAAa,CAAA;QAC7F,oBAAC,WAAD,EAAW,aAAY,WAAW,CAAA;QAClC,oBAAC,cAAD;SAAc,MAAM;SAAU,cAAc;QAAa,CAAA;QACzD,oBAAC,WAAD,EAAW,aAAY,WAAW,CAAA;QAClC,oBAAC,aAAD,CAAa,CAAA;OACD;;MAEd,oBAAC,aAAD,EACG,SAAS;OACR,WAAW;OACX,QAAQ;MACV,EACD,CAAA;MACD,oBAAC,aAAD,CAAa,CAAA;KACb,EAAA,CAAA;KAGJ,oBAAC,kBAAD;MAAkB,QAAQ;MAAiC;KAAc,CAAA;IACpE;OAEJ,kBACC,oBAAC,kBAAD;IACE,OAAO;IACP,UAAU;IACV,QAAQ;IACR,WAAW,IACT,4FACA,UACF;IACA,OAAO;KACL,SAAS;KACT,SAAS;KACT,QAAQ;KACR,WAAW;IACb;GACD,CAAA,CAGwB;IAC1B;;AAET;AAGA,IAAM,YAAY"}
|
|
1
|
+
{"version":3,"file":"editor.js","names":[],"sources":["../../src/editor/editor.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, useState, useRef, useMemo } from \"react\";\nimport { EditorState, Selection } from \"prosemirror-state\";\nimport { cls, defaultBorderMixin, Separator, TextareaAutosize, useInjectStyles } from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { EditorBubble, ImageBubble, SlashCommandMenu, TableBubble, type JSONContent } from \"./components\";\nimport { NodeSelector } from \"./selectors/node-selector\";\nimport { LinkSelector } from \"./selectors/link-selector\";\nimport { TextButtons } from \"./selectors/text-buttons\";\nimport { removeClassesFromJson } from \"./utils/remove_classes\";\nimport { parser, serializer } from \"./markdown\";\nimport { EditorAIController } from \"./types\";\nimport { useProseMirror } from \"./hooks/useProseMirror\";\nimport { ProseMirrorContext } from \"./hooks/useProseMirrorContext\";\nimport { highlightCommands } from \"./extensions/HighlightDecorationExtension\";\nimport { schema } from \"./schema\";\n\nexport type CustomEditorComponent = {\n name: string,\n component: React.FC\n};\n\nexport type RichTextEditorTextSize = \"sm\" | \"base\" | \"lg\";\n\n\nexport type RichTextEditorProps = {\n content?: JSONContent | string,\n onMarkdownContentChange?: (content: string) => void,\n onJsonContentChange?: (content: JSONContent | null) => void,\n onHtmlContentChange?: (content: string) => void,\n handleImageUpload: (file: File) => Promise<string>,\n /**\n * Turns an image's stored `src` into a URL to show. `handleImageUpload`\n * returns a `rebase-storage:` reference to keep in the text — a private\n * object's URL expires — and the editor asks this for a URL to display it.\n */\n resolveImageSrc?: (src: string) => Promise<string | null | undefined>,\n version?: number,\n textSize?: RichTextEditorTextSize,\n highlight?: { from: number, to: number },\n aiController?: EditorAIController,\n customComponents?: CustomEditorComponent[];\n disabled?: boolean;\n};\n\n\nconst proseClasses = {\n \"sm\": \"prose-sm\",\n \"base\": \"prose-base\",\n \"lg\": \"prose-lg\"\n}\n\nexport const RichTextEditor = ({\n content,\n onJsonContentChange,\n onHtmlContentChange,\n onMarkdownContentChange,\n version,\n textSize = \"base\",\n highlight,\n handleImageUpload,\n resolveImageSrc,\n aiController,\n disabled\n}: RichTextEditorProps) => {\n\n const { t } = useTranslation();\n\n const [openNode, setOpenNode] = useState(false);\n const [openLink, setOpenLink] = useState(false);\n\n const [isMarkdownMode, setIsMarkdownMode] = useState(false);\n const [internalMarkdown, setInternalMarkdown] = useState<string>(\"\");\n\n useEffect(() => {\n if (!isMarkdownMode) return;\n const timeout = setTimeout(() => {\n if (callbacksRef.current.onMarkdownContentChange) {\n callbacksRef.current.onMarkdownContentChange(internalMarkdown);\n }\n }, 250);\n return () => clearTimeout(timeout);\n }, [internalMarkdown, isMarkdownMode]);\n\n const handleToggleMarkdown = () => {\n if (!isMarkdownMode) {\n if (view) {\n setInternalMarkdown(serializer.serialize(view.state.doc));\n }\n setIsMarkdownMode(true);\n } else {\n if (view) {\n const newDoc = parser.parse(internalMarkdown);\n if (newDoc) {\n const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, newDoc.content);\n view.dispatch(tr);\n }\n }\n setIsMarkdownMode(false);\n }\n };\n\n const handleMarkdownChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n setInternalMarkdown(e.target.value);\n };\n\n const handleMarkdownBlur = () => {\n const { onMarkdownContentChange, onJsonContentChange } = callbacksRef.current;\n if (onMarkdownContentChange) {\n onMarkdownContentChange(internalMarkdown);\n }\n if (onJsonContentChange) {\n try {\n const newDoc = parser.parse(internalMarkdown);\n if (newDoc) {\n onJsonContentChange(removeClassesFromJson(newDoc.toJSON()) as JSONContent);\n }\n } catch (e) {\n console.warn(\"Could not parse markdown to JSON\", e);\n }\n }\n };\n\n useInjectStyles(\"Editor\", cssStyles);\n\n const callbacksRef = useRef({ onMarkdownContentChange,\nonJsonContentChange });\n useEffect(() => {\n callbacksRef.current = { onMarkdownContentChange,\nonJsonContentChange };\n }, [onMarkdownContentChange, onJsonContentChange]);\n\n const flushChanges = (currentState: EditorState) => {\n const { onMarkdownContentChange, onJsonContentChange } = callbacksRef.current;\n if (onMarkdownContentChange) {\n try {\n const markdown = serializer.serialize(currentState.doc);\n onMarkdownContentChange(markdown);\n } catch (e) {\n console.warn(\"[RichTextEditor] Could not serialize editor state to markdown:\", e);\n }\n }\n if (onJsonContentChange) {\n const jsonContent = removeClassesFromJson(currentState.doc.toJSON()) as JSONContent;\n onJsonContentChange(jsonContent);\n }\n };\n\n const { state, view, editorRef } = useProseMirror({\n initialContent: content,\n editable: !disabled,\n handleImageUpload,\n resolveImageSrc\n });\n\n // When `version` changes externally (e.g. form discard/reset), re-parse the\n // `content` prop and replace the ProseMirror document so the editor reflects\n // the reverted value.\n const versionRef = useRef(version);\n useEffect(() => {\n if (versionRef.current === version) return; // skip initial render\n versionRef.current = version;\n if (!view) return;\n try {\n const newDoc = typeof content === \"string\"\n ? parser.parse(content ?? \"\")\n : content\n ? schema.nodeFromJSON(content)\n : schema.node(\"doc\", null, [schema.node(\"paragraph\")]);\n if (newDoc) {\n const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, newDoc.content);\n view.dispatch(tr);\n }\n } catch (e) {\n console.warn(\"[RichTextEditor] Could not reset editor content:\", e);\n }\n // Also reset raw-markdown textarea if the user is in source mode\n if (isMarkdownMode) {\n setInternalMarkdown(typeof content === \"string\" ? content : \"\");\n }\n // Reset the settling window so the replacement dispatch above is NOT\n // treated as a user edit (which would fire onChange back to the form).\n mountTimeRef.current = Date.now();\n hasUserEditedRef.current = false;\n }, [version]);\n\n const doc = state?.doc;\n // Use a time-based settling window instead of a single-skip flag.\n // The trailingNodePlugin fires appendTransaction on mount (adding a trailing\n // paragraph), which creates a second doc change after the initial parse.\n // A single-skip flag misses that second change. Instead, we skip ALL doc\n // changes within the first 500ms after the view is created.\n const mountTimeRef = useRef(Date.now());\n const hasUserEditedRef = useRef(false);\n useEffect(() => {\n if (!state) return;\n // Skip all doc changes during the initial settling window (500ms).\n // This covers both the initial parse AND the trailingNodePlugin's\n // appendTransaction that adds a trailing paragraph.\n const elapsed = Date.now() - mountTimeRef.current;\n if (elapsed < 500 && !hasUserEditedRef.current) {\n return;\n }\n hasUserEditedRef.current = true;\n const timeout = setTimeout(() => {\n flushChanges(state);\n }, 250);\n return () => clearTimeout(timeout);\n }, [doc]);\n\n useEffect(() => {\n if (!view) return;\n const dom = view.dom;\n const handleBlur = () => {\n // Don't flush during the initial settling window — the editor\n // hasn't been interacted with yet, and the serialized output\n // may differ from the input due to parse→serialize normalization.\n if (!hasUserEditedRef.current) {\n const elapsed = Date.now() - mountTimeRef.current;\n if (elapsed < 500) return;\n }\n flushChanges(view.state);\n };\n dom.addEventListener(\"blur\", handleBlur);\n return () => dom.removeEventListener(\"blur\", handleBlur);\n }, [view]);\n\n\n useEffect(() => {\n if (view) {\n if (highlight) {\n highlightCommands.toggleAutocompleteHighlight(highlight)(view.state, view.dispatch);\n } else {\n highlightCommands.removeAutocompleteHighlight()(view.state, view.dispatch);\n }\n }\n }, [highlight?.from, highlight?.to]);\n\n const proseClass = proseClasses[textSize];\n\n\n return (\n <div className=\"relative min-h-[200px] w-full flex flex-col\">\n <button\n type=\"button\"\n onClick={handleToggleMarkdown}\n title={isMarkdownMode ? \"Switch to Visual Editor\" : \"Switch to Markdown\"}\n className=\"absolute top-2 right-2 z-10 px-2 py-1 text-xs font-medium text-surface-400 hover:text-surface-700 dark:text-surface-600 dark:hover:text-surface-300 transition-colors opacity-50 hover:opacity-100 bg-transparent rounded\"\n >\n {isMarkdownMode ? \"Visual\" : \"Markdown\"}\n </button>\n\n <ProseMirrorContext.Provider value={useMemo(() => ({ state,\nview }), [state, view])}>\n\n <div style={{ display: isMarkdownMode ? \"none\" : \"flex\" }} className=\"flex-1 flex flex-col\">\n <div\n ref={editorRef}\n onClick={(e) => {\n // If the click landed on the wrapper padding (not on the ProseMirror\n // content), focus the editor and place the cursor at the nearest position.\n if (view && e.target === e.currentTarget) {\n view.focus();\n // Place cursor at end of the document\n const end = view.state.doc.content.size;\n const tr = view.state.tr.setSelection(\n Selection.near(view.state.doc.resolve(end), -1)\n );\n view.dispatch(tr);\n }\n }}\n className={cls(\"relative prose dark:prose-invert cursor-text flex-1\", proseClass, \"prose-headings:font-title prose-headings:font-normal prose-strong:font-semibold prose-code:font-normal prose-blockquote:font-normal prose-a:font-normal font-default focus:outline-none max-w-full py-4\")}\n />\n\n {view && (\n <>\n <EditorBubble\n options={{\n placement: \"top\",\n offset: 6\n }}\n className={cls(\"flex w-fit max-w-[90vw] h-10 overflow-hidden rounded border bg-surface-card shadow\", defaultBorderMixin)}\n >\n <NodeSelector portalContainer={editorRef.current} open={openNode} onOpenChange={setOpenNode}/>\n <Separator orientation=\"vertical\"/>\n <LinkSelector open={openLink} onOpenChange={setOpenLink}/>\n <Separator orientation=\"vertical\"/>\n <TextButtons/>\n </EditorBubble>\n\n <ImageBubble\n options={{\n placement: \"bottom\",\n offset: 6\n }}\n />\n <TableBubble/>\n </>\n )}\n\n <SlashCommandMenu upload={handleImageUpload} aiController={aiController}/>\n </div>\n\n {isMarkdownMode && (\n <TextareaAutosize\n value={internalMarkdown}\n onChange={handleMarkdownChange}\n onBlur={handleMarkdownBlur}\n className={cls(\n \"w-full h-full min-h-[200px] px-12 py-4 bg-transparent resize-none font-mono focus:ring-0\",\n proseClass\n )}\n style={{\n tabSize: 4,\n outline: \"none\",\n border: \"none\",\n boxShadow: \"none\"\n }}\n />\n )}\n\n </ProseMirrorContext.Provider>\n </div>\n );\n};\n\n\nconst cssStyles = `\n.ProseMirror {\n box-shadow: none !important;\n padding-left: 2rem;\n padding-right: 2rem;\n min-height: 100%;\n /* What prosemirror-view's style/prosemirror.css sets on its root: the\n document's spaces are read back from the DOM, so they must not collapse. */\n word-wrap: break-word;\n white-space: pre-wrap;\n white-space: break-spaces;\n font-variant-ligatures: none;\n font-feature-settings: \"liga\" 0;\n}\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n.ProseMirror .is-editor-empty:first-child::before {\n content: attr(data-placeholder);\n float: left;\n color: rgb(100 116 139); /* 500 */\n pointer-events: none;\n height: 0;\n}\n.ProseMirror .is-empty::before {\n content: attr(data-placeholder);\n float: left;\n color: rgb(100 116 139); /* 500 */\n pointer-events: none;\n height: 0;\n}\n\n[data-theme=\"dark\"] .ProseMirror .is-empty::before {\n color: rgb(100 116 139); /* 500 */\n}\n\n.is-empty {\n cursor: text;\n color: rgb(100 116 139); /* 500 */\n}\n\n.ProseMirror img {\n transition: filter 0.1s ease-in-out;\n}\n.ProseMirror img:hover {\n cursor: pointer;\n filter: brightness(90%);\n}\n.ProseMirror img.ProseMirror-selectednode {\n filter: brightness(90%);\n box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000) !important;\n}\n\nul[data-type=\"taskList\"] li > label {\n margin-right: 0.2rem;\n user-select: none;\n}\n@media screen and (max-width: 768px) {\n ul[data-type=\"taskList\"] li > label {\n margin-right: 0.5rem;\n }\n}\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li > label input[type=\"checkbox\"] {\n background-color: rgb(30 41 59);\n border: 2px solid #666;\n}\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:hover { background-color: rgb(51 65 85); }\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:active { background-color: rgb(71 85 105); }\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"] {\n -webkit-appearance: none;\n appearance: none;\n background-color: white;\n margin: 0;\n cursor: pointer;\n width: 1.2em;\n height: 1.2em;\n position: relative;\n top: 5px;\n border: 2px solid #777;\n border-radius: 0.25em;\n margin-right: 0.3rem;\n display: grid;\n place-content: center;\n}\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:hover { background-color: rgb(241 245 249); }\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:active { background-color: rgb(226 232 240); }\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]::before {\n content: \"\";\n width: 0.65em;\n height: 0.65em;\n transform: scale(0);\n transition: 120ms transform ease-in-out;\n box-shadow: inset 1em 1em;\n transform-origin: center;\n clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);\n}\nul[data-type=\"taskList\"] li > label input[type=\"checkbox\"]:checked::before { transform: scale(1); }\n\n[data-theme=\"dark\"] ul[data-type=\"taskList\"] li[data-checked=\"true\"] > div > p {\n color: rgb(226 232 240);\n text-decoration: line-through;\n text-decoration-thickness: 2px;\n}\nul[data-type=\"taskList\"] li[data-checked=\"true\"] > div > p {\n color: rgb(51 65 85);\n text-decoration: line-through;\n text-decoration-thickness: 2px;\n}\n.tippy-box { max-width: 400px !important; }\n\n.ProseMirror:not(.dragging) .ProseMirror-selectednode {\n background-color: rgb(219 234 254);\n transition: background-color 0.2s;\n box-shadow: none;\n}\n[data-theme=\"dark\"] .ProseMirror:not(.dragging) .ProseMirror-selectednode {\n background-color: rgb(51 65 85);\n}\n.prose-base table p { margin: 0; }\n\n.drag-handle {\n position: absolute;\n opacity: 1;\n transition: opacity ease-in 0.2s;\n border-radius: 0.25rem;\n background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' style='fill: rgba(128, 128, 128, 0.9)'%3E%3Cpath d='M3,2 C2.44771525,2 2,1.55228475 2,1 C2,0.44771525 2.44771525,0 3,0 C3.55228475,0 4,0.44771525 4,1 C4,1.55228475 3.55228475,2 3,2 Z M3,6 C2.44771525,6 2,5.55228475 2,5 C2,4.44771525 2.44771525,4 3,4 C3.55228475,4 4,4.44771525 4,5 C4,5.55228475 3.55228475,6 3,6 Z M3,10 C2.44771525,10 2,9.55228475 2,9 C2,8.44771525 2.44771525,8 3,8 C3.55228475,8 4,8.44771525 4,9 C4,9.55228475 3.55228475,10 3,10 Z M7,2 C6.44771525,2 6,1.55228475 6,1 C6,0.44771525 6.44771525,0 7,0 C7.55228475,0 8,0.44771525 8,1 C8,1.55228475 7.55228475,2 7,2 Z M7,6 C6.44771525,6 6,5.55228475 6,5 C6,4.44771525 6.44771525,4 7,4 C7.55228475,4 8,4.44771525 8,5 C8,5.55228475 7.55228475,6 7,6 Z M7,10 C6.44771525,10 6,9.55228475 6,9 C6,8.44771525 6.44771525,8 7,8 C7,8.44771525 7,9 7,9 C7,9.55228475 7,10 7,10 Z'%3E%3C/path%3E%3C/svg%3E\");\n background-size: calc(0.5em + 0.375rem) calc(0.5em + 0.375rem);\n background-repeat: no-repeat;\n background-position: center;\n width: 1.2rem;\n height: 1.5rem;\n z-index: 100;\n cursor: grab;\n}\n.drag-handle::before {\n content: '';\n position: absolute;\n top: -10px;\n bottom: -10px;\n left: -20px; \n right: 0px;\n z-index: -1;\n}\n.drag-handle:hover { background-color: rgb(241 245 249); transition: background-color 0.2s; }\n.drag-handle:active { background-color: rgb(226 232 240); transition: background-color 0.2s; }\n.drag-handle.hide { opacity: 0; pointer-events: none; }\n@media screen and (max-width: 600px) { .drag-handle { display: none; pointer-events: none; } }\n[data-theme=\"dark\"] .drag-handle:hover { background-color: rgb(51 65 85); }\n[data-theme=\"dark\"] .drag-handle:active { background-color: rgb(51 65 85); }\n.prosemirror-dropcursor-block {\n background-color: var(--color-surface-accent-600);\n}\n[data-theme=\"dark\"] .prosemirror-dropcursor-block {\n background-color: var(--color-surface-accent-300);\n}\n\n.ProseMirror table {\n border-collapse: separate;\n border-spacing: 0;\n table-layout: fixed;\n width: 100%;\n margin: 1em 0;\n overflow: hidden;\n border-radius: 0.375rem;\n border: 1px solid #e5e7eb;\n}\n[data-theme=\"dark\"] .ProseMirror table {\n border-color: #374151;\n}\n\n.ProseMirror td, .ProseMirror th {\n min-width: 1em;\n padding: 8px 10px;\n vertical-align: top;\n box-sizing: border-box;\n position: relative;\n border-right: 1px solid #e5e7eb;\n border-bottom: 1px solid #e5e7eb;\n}\n[data-theme=\"dark\"] .ProseMirror td, [data-theme=\"dark\"] .ProseMirror th {\n border-right-color: #374151;\n border-bottom-color: #374151;\n}\n\n.ProseMirror tr:last-child td, .ProseMirror tr:last-child th {\n border-bottom: none;\n}\n.ProseMirror th:last-child, .ProseMirror td:last-child {\n border-right: none;\n}\n\n.ProseMirror td {\n background-color: transparent;\n}\n\n.ProseMirror th {\n font-weight: 600;\n text-align: left;\n background-color: #f3f4f6;\n color: #374151;\n}\n[data-theme=\"dark\"] .ProseMirror td {\n background-color: transparent;\n}\n[data-theme=\"dark\"] .ProseMirror th {\n background-color: rgba(255, 255, 255, 0.05);\n color: #d1d5db;\n}\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8CA,IAAM,eAAe;CACnB,MAAM;CACN,QAAQ;CACR,MAAM;AACR;AAEA,IAAa,kBAAkB,EAC7B,SACA,qBACA,qBACA,yBACA,SACA,WAAW,QACX,WACA,mBACA,iBACA,cACA,eACyB;CAEzB,MAAM,EAAE,MAAM,eAAe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AAM,IAAI,QAAQ,GAAG,GAAG,EAAE,CAChD;QACA,KAAK,SAAS,EAAE;OAClB;MACF;MACA,WAAW,IAAI,uDAAuD,YAAY,yMAAyM;KAC5R,CAAA;KAEA,QACD,qBAAA,UAAA,EAAA,UAAA;MACE,qBAAC,cAAD;OACE,SAAS;QACP,WAAW;QACX,QAAQ;OACV;OACA,WAAW,IAAI,sFAAsF,kBAAkB;iBALzH;QAOE,oBAAC,cAAD;SAAc,iBAAiB,UAAU;SAAS,MAAM;SAAU,cAAc;QAAa,CAAA;QAC7F,oBAAC,WAAD,EAAW,aAAY,WAAW,CAAA;QAClC,oBAAC,cAAD;SAAc,MAAM;SAAU,cAAc;QAAa,CAAA;QACzD,oBAAC,WAAD,EAAW,aAAY,WAAW,CAAA;QAClC,oBAAC,aAAD,CAAa,CAAA;OACD;;MAEd,oBAAC,aAAD,EACG,SAAS;OACR,WAAW;OACX,QAAQ;MACV,EACD,CAAA;MACD,oBAAC,aAAD,CAAa,CAAA;KACb,EAAA,CAAA;KAGJ,oBAAC,kBAAD;MAAkB,QAAQ;MAAiC;KAAc,CAAA;IACpE;OAEJ,kBACC,oBAAC,kBAAD;IACE,OAAO;IACP,UAAU;IACV,QAAQ;IACR,WAAW,IACT,4FACA,UACF;IACA,OAAO;KACL,SAAS;KACT,SAAS;KACT,QAAQ;KACR,WAAW;IACb;GACD,CAAA,CAGwB;IAC1B;;AAET;AAGA,IAAM,YAAY"}
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
* Firebase or custom source's URL, or an external one, is left as it is — and
|
|
10
10
|
* only for an image the server would transform (not SVG, not GIF).
|
|
11
11
|
*
|
|
12
|
-
* The resize needs `sharp`, which is optional: without it the route
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* The resize needs `sharp`, which is optional: without it the route serves the
|
|
13
|
+
* original image in place of the rendition (one warning in the server log), so a
|
|
14
|
+
* thumbnail still loads, only at full size. Whether a server resizes is learned
|
|
15
|
+
* once per page load from one probe image, and no thumbnail asks for a
|
|
16
|
+
* rendition before that is known; an older server that answers 500 there costs
|
|
17
|
+
* one failed request per page load, not one per row.
|
|
16
18
|
*/
|
|
17
19
|
/** Rendition widths, about twice the rendered box (high-density screens). */
|
|
18
20
|
var RENDITION_WIDTHS = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storageRenditions.js","names":[],"sources":["../../../src/preview/components/storageRenditions.ts"],"sourcesContent":["import type { DownloadConfig } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\n\n/**\n * Thumbnails of stored images through the storage file route's resize\n * (`?width=…&format=webp`) instead of the full-size original. A table page of\n * 100 rows showing 3 MB photos at 40 px downloaded ~300 MB; as 96 px webp\n * renditions it is ~1 MB.\n *\n * Only for a URL of the Rebase storage file route (`…/storage/file/…`) — a\n * Firebase or custom source's URL, or an external one, is left as it is — and\n * only for an image the server would transform (not SVG, not GIF).\n *\n * The resize needs `sharp`, which is optional: without it the route
|
|
1
|
+
{"version":3,"file":"storageRenditions.js","names":[],"sources":["../../../src/preview/components/storageRenditions.ts"],"sourcesContent":["import type { DownloadConfig } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\n\n/**\n * Thumbnails of stored images through the storage file route's resize\n * (`?width=…&format=webp`) instead of the full-size original. A table page of\n * 100 rows showing 3 MB photos at 40 px downloaded ~300 MB; as 96 px webp\n * renditions it is ~1 MB.\n *\n * Only for a URL of the Rebase storage file route (`…/storage/file/…`) — a\n * Firebase or custom source's URL, or an external one, is left as it is — and\n * only for an image the server would transform (not SVG, not GIF).\n *\n * The resize needs `sharp`, which is optional: without it the route serves the\n * original image in place of the rendition (one warning in the server log), so a\n * thumbnail still loads, only at full size. Whether a server resizes is learned\n * once per page load from one probe image, and no thumbnail asks for a\n * rendition before that is known; an older server that answers 500 there costs\n * one failed request per page load, not one per row.\n */\n\n/** Rendition widths, about twice the rendered box (high-density screens). */\nconst RENDITION_WIDTHS: Record<PreviewSize | \"fill\", number> = {\n small: 96,\n medium: 200,\n large: 400,\n fill: 800\n};\n\n/** How long a thumbnail waits for the probe before showing the original. */\nconst PROBE_PATIENCE_MS = 3_000;\n\nconst STORAGE_FILE_ROUTE = \"/storage/file/\";\n\n/**\n * What each server (`<origin><api path>`) is known to do: `true`/`false` once\n * its probe settled, the probe itself while it runs. Per page load; a server\n * that gains or loses `sharp` is re-learned on the next one.\n */\nconst resizeSupport = new Map<string, boolean | Promise<boolean>>();\n\n/** The same rule as the server's `isTransformableImage`. */\nfunction transformableImage(contentType: string | undefined): boolean {\n return !!contentType\n && contentType.startsWith(\"image/\")\n && !contentType.includes(\"svg\")\n && !contentType.includes(\"gif\");\n}\n\n/** The server a storage file URL belongs to, or undefined if it is not one / already transformed. */\nfunction storageServer(url: string): string | undefined {\n const route = url.indexOf(STORAGE_FILE_ROUTE);\n if (route < 0 || url.includes(\"#\")) return undefined;\n if (/[?&](width|height|format|quality|fit)=/.test(url)) return undefined;\n return url.slice(0, route);\n}\n\nfunction withResize(url: string, width: number): string {\n return `${url}${url.includes(\"?\") ? \"&\" : \"?\"}width=${width}&format=webp`;\n}\n\nfunction probe(server: string, renditionUrl: string): Promise<boolean> {\n const running = new Promise<boolean>(resolve => {\n const image = new Image();\n image.onload = () => resolve(true);\n image.onerror = () => resolve(false);\n image.src = renditionUrl;\n }).then(supported => {\n resizeSupport.set(server, supported);\n return supported;\n });\n resizeSupport.set(server, running);\n return running;\n}\n\n/**\n * The rendition URL to show for a stored file, or undefined to show the\n * original. Resolves at once when the server's support is known; otherwise\n * waits for the probe (at most {@link PROBE_PATIENCE_MS}, then the original).\n */\nexport async function storageRenditionUrl(\n config: DownloadConfig,\n size: PreviewSize,\n fill?: boolean\n): Promise<string | undefined> {\n const url = config.url;\n if (!url || !transformableImage(config.metadata?.contentType)) return undefined;\n const server = storageServer(url);\n if (server === undefined) return undefined;\n\n const renditionUrl = withResize(url, RENDITION_WIDTHS[fill ? \"fill\" : size]);\n const known = resizeSupport.get(server);\n if (known === true) return renditionUrl;\n if (known === false) return undefined;\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const supported = await Promise.race([\n known ?? probe(server, renditionUrl),\n new Promise<false>(resolve => {\n timer = setTimeout(() => resolve(false), PROBE_PATIENCE_MS);\n })\n ]).finally(() => clearTimeout(timer));\n return supported ? renditionUrl : undefined;\n}\n\n/** {@link storageRenditionUrl} when it can answer without waiting; `null` when it would have to wait. */\nexport function knownStorageRenditionUrl(\n config: DownloadConfig,\n size: PreviewSize,\n fill?: boolean\n): string | undefined | null {\n const url = config.url;\n if (!url || !transformableImage(config.metadata?.contentType)) return undefined;\n const server = storageServer(url);\n if (server === undefined) return undefined;\n const known = resizeSupport.get(server);\n if (known === true) return withResize(url, RENDITION_WIDTHS[fill ? \"fill\" : size]);\n if (known === false) return undefined;\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,IAAM,mBAAyD;CAC3D,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;AACV;;AAGA,IAAM,oBAAoB;AAE1B,IAAM,qBAAqB;;;;;;AAO3B,IAAM,gCAAgB,IAAI,IAAwC;;AAGlE,SAAS,mBAAmB,aAA0C;CAClE,OAAO,CAAC,CAAC,eACF,YAAY,WAAW,QAAQ,KAC/B,CAAC,YAAY,SAAS,KAAK,KAC3B,CAAC,YAAY,SAAS,KAAK;AACtC;;AAGA,SAAS,cAAc,KAAiC;CACpD,MAAM,QAAQ,IAAI,QAAQ,kBAAkB;CAC5C,IAAI,QAAQ,KAAK,IAAI,SAAS,GAAG,GAAG,OAAO,KAAA;CAC3C,IAAI,yCAAyC,KAAK,GAAG,GAAG,OAAO,KAAA;CAC/D,OAAO,IAAI,MAAM,GAAG,KAAK;AAC7B;AAEA,SAAS,WAAW,KAAa,OAAuB;CACpD,OAAO,GAAG,MAAM,IAAI,SAAS,GAAG,IAAI,MAAM,IAAI,QAAQ,MAAM;AAChE;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,OAAO,SAAS,KAAK;CACjF,IAAI,UAAU,OAAO,OAAO,KAAA;CAC5B,OAAO;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0-canary.ge06257e",
|
|
4
4
|
"description": "Rebase CMS — content management views, forms, and routing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rebase",
|
|
@@ -93,14 +93,14 @@
|
|
|
93
93
|
"react-use-measure": "^2.1.7",
|
|
94
94
|
"read-excel-file": "^9.3.10",
|
|
95
95
|
"zod": "^4.4.3",
|
|
96
|
-
"@rebasepro/
|
|
97
|
-
"@rebasepro/
|
|
98
|
-
"@rebasepro/common": "0.
|
|
99
|
-
"@rebasepro/
|
|
100
|
-
"@rebasepro/
|
|
101
|
-
"@rebasepro/ui": "0.
|
|
102
|
-
"@rebasepro/
|
|
103
|
-
"@rebasepro/
|
|
96
|
+
"@rebasepro/cms-types": "0.25.0-canary.ge06257e",
|
|
97
|
+
"@rebasepro/app": "0.25.0-canary.ge06257e",
|
|
98
|
+
"@rebasepro/common": "0.25.0-canary.ge06257e",
|
|
99
|
+
"@rebasepro/inference": "0.25.0-canary.ge06257e",
|
|
100
|
+
"@rebasepro/forms": "0.25.0-canary.ge06257e",
|
|
101
|
+
"@rebasepro/ui": "0.25.0-canary.ge06257e",
|
|
102
|
+
"@rebasepro/types": "0.25.0-canary.ge06257e",
|
|
103
|
+
"@rebasepro/utils": "0.25.0-canary.ge06257e"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"react": "^19.2.7",
|