@intlayer/design-system 4.1.2 → 4.1.3
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/components/DictionaryEditor/ValidDictionaryChangeButtons.cjs +16 -12
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.cjs.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.mjs +18 -14
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs +8 -10
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs +9 -11
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs +15 -11
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs +16 -12
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs.map +1 -1
- package/package.json +19 -19
|
@@ -18,6 +18,7 @@ const components_DictionaryEditor_validDictionaryChangeButtonsSchema = require("
|
|
|
18
18
|
const ValidDictionaryChangeButtons = ({ dictionary, mode }) => {
|
|
19
19
|
const ValidDictionaryChangeButtonsSchemaSchema = components_DictionaryEditor_validDictionaryChangeButtonsSchema.getValidDictionaryChangeButtonsSchemaSchema();
|
|
20
20
|
const { resetButton, saveButton, publishButton, downloadButton } = reactIntlayer.useDictionary(components_DictionaryEditor_validDictionaryChangeButtons_content.validDictionaryChangeButtonsContent);
|
|
21
|
+
const { setLocaleDictionary } = editorReact.useDictionariesRecordActions();
|
|
21
22
|
const { writeDictionary } = hooks_intlayerAPIHooks.useWriteDictionary();
|
|
22
23
|
const { pushDictionaries } = hooks_intlayerAPIHooks.usePushDictionaries();
|
|
23
24
|
const { editedContent, restoreEditedContent } = editorReact.useEditedContent();
|
|
@@ -36,21 +37,24 @@ const ValidDictionaryChangeButtons = ({ dictionary, mode }) => {
|
|
|
36
37
|
() => typeof dictionary?._id === "undefined",
|
|
37
38
|
[dictionary]
|
|
38
39
|
);
|
|
39
|
-
const onSubmitSuccess = async () => {
|
|
40
|
+
const onSubmitSuccess = require$$0.useCallback(async () => {
|
|
41
|
+
if (!editedContent?.[dictionary.key]) return;
|
|
40
42
|
if (mode === "remote") {
|
|
41
|
-
await pushDictionaries([
|
|
42
|
-
{
|
|
43
|
-
...dictionary,
|
|
44
|
-
...editedContent?.[dictionary.key]
|
|
45
|
-
}
|
|
46
|
-
]);
|
|
43
|
+
await pushDictionaries([editedContent?.[dictionary.key]]);
|
|
47
44
|
} else {
|
|
48
|
-
await writeDictionary(
|
|
49
|
-
...dictionary,
|
|
50
|
-
...editedContent?.[dictionary.key]
|
|
51
|
-
});
|
|
45
|
+
await writeDictionary(editedContent?.[dictionary.key]);
|
|
52
46
|
}
|
|
53
|
-
|
|
47
|
+
setLocaleDictionary(editedContent?.[dictionary.key]);
|
|
48
|
+
restoreEditedContent(dictionary.key);
|
|
49
|
+
}, [
|
|
50
|
+
dictionary,
|
|
51
|
+
editedContent,
|
|
52
|
+
pushDictionaries,
|
|
53
|
+
setLocaleDictionary,
|
|
54
|
+
writeDictionary,
|
|
55
|
+
restoreEditedContent,
|
|
56
|
+
mode
|
|
57
|
+
]);
|
|
54
58
|
return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
|
|
55
59
|
components_Form_layout_FormItemLayout.Form,
|
|
56
60
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidDictionaryChangeButtons.cjs","sources":["../../../src/components/DictionaryEditor/ValidDictionaryChangeButtons.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport type { Dictionary } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"file":"ValidDictionaryChangeButtons.cjs","sources":["../../../src/components/DictionaryEditor/ValidDictionaryChangeButtons.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n useDictionariesRecordActions,\n useEditedContent,\n} from '@intlayer/editor-react';\nimport { ArrowUpFromLine, Download, RotateCcw, Save } from 'lucide-react';\nimport { useCallback, useMemo, type FC } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport { usePushDictionaries, useWriteDictionary } from '../../hooks';\nimport { Form, useForm } from '../Form';\nimport { validDictionaryChangeButtonsContent } from './validDictionaryChangeButtons.content';\nimport { getValidDictionaryChangeButtonsSchemaSchema } from './validDictionaryChangeButtonsSchema';\n\ntype ValidDictionaryChangeButtonsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const ValidDictionaryChangeButtons: FC<\n ValidDictionaryChangeButtonsProps\n> = ({ dictionary, mode }) => {\n const ValidDictionaryChangeButtonsSchemaSchema =\n getValidDictionaryChangeButtonsSchemaSchema();\n\n const { resetButton, saveButton, publishButton, downloadButton } =\n useDictionary(validDictionaryChangeButtonsContent);\n\n const { setLocaleDictionary } = useDictionariesRecordActions();\n const { writeDictionary } = useWriteDictionary();\n const { pushDictionaries } = usePushDictionaries();\n\n const { editedContent, restoreEditedContent } = useEditedContent();\n const { form, isSubmitting } = useForm(\n ValidDictionaryChangeButtonsSchemaSchema\n );\n\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n\n const isEdited = useMemo(\n () =>\n editedDictionary &&\n JSON.stringify(editedDictionary?.content) !==\n JSON.stringify(dictionary?.content),\n [editedDictionary, dictionary]\n );\n\n const isLocalDictionary = useMemo(\n () => typeof (dictionary as DistantDictionary)?._id === 'undefined',\n [dictionary]\n );\n\n const onSubmitSuccess = useCallback(async () => {\n if (!editedContent?.[dictionary.key]) return;\n\n if (mode === 'remote') {\n await pushDictionaries([editedContent?.[dictionary.key]]);\n } else {\n await writeDictionary(editedContent?.[dictionary.key]);\n }\n setLocaleDictionary(editedContent?.[dictionary.key]);\n restoreEditedContent(dictionary.key);\n }, [\n dictionary,\n editedContent,\n pushDictionaries,\n setLocaleDictionary,\n writeDictionary,\n restoreEditedContent,\n mode,\n ]);\n\n return (\n <div className=\"mb-4\">\n <Form\n className=\"flex w-full flex-row flex-wrap justify-end gap-3\"\n {...form}\n schema={ValidDictionaryChangeButtonsSchemaSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n {isEdited && (\n <Form.Button\n type=\"button\"\n label={resetButton.label}\n disabled={!isEdited || isSubmitting}\n className=\"ml-auto\"\n Icon={RotateCcw}\n variant=\"outline\"\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n onClick={() => restoreEditedContent(dictionary.key)}\n >\n {resetButton.text}\n </Form.Button>\n )}\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={ArrowUpFromLine}\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Save}\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Download}\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </Form>\n </div>\n );\n};\n"],"names":["getValidDictionaryChangeButtonsSchemaSchema","useDictionary","validDictionaryChangeButtonsContent","useDictionariesRecordActions","useWriteDictionary","usePushDictionaries","useEditedContent","useForm","useMemo","useCallback","jsx","jsxs","Form","RotateCcw","ArrowUpFromLine","Save","Download"],"mappings":";;;;;;;;;;;;;;;;;AAsBO,MAAM,+BAET,CAAC,EAAE,YAAY,WAAW;AAC5B,QAAM,2CACJA,+DAAAA,4CAA4C;AAE9C,QAAM,EAAE,aAAa,YAAY,eAAe,eAAe,IAC7DC,4BAAcC,oGAAmC;AAE7C,QAAA,EAAE,oBAAoB,IAAIC,yCAA6B;AACvD,QAAA,EAAE,gBAAgB,IAAIC,0CAAmB;AACzC,QAAA,EAAE,iBAAiB,IAAIC,2CAAoB;AAEjD,QAAM,EAAE,eAAe,qBAAqB,IAAIC,6BAAiB;AAC3D,QAAA,EAAE,MAAM,aAAA,IAAiBC,yBAAA;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,mBAAmBC,WAAA;AAAA,IACvB,MAAM,gBAAgB,WAAW,GAAG;AAAA,IACpC,CAAC,eAAe,WAAW,GAAG;AAAA,EAChC;AAEA,QAAM,WAAWA,WAAA;AAAA,IACf,MACE,oBACA,KAAK,UAAU,kBAAkB,OAAO,MACtC,KAAK,UAAU,YAAY,OAAO;AAAA,IACtC,CAAC,kBAAkB,UAAU;AAAA,EAC/B;AAEA,QAAM,oBAAoBA,WAAA;AAAA,IACxB,MAAM,OAAQ,YAAkC,QAAQ;AAAA,IACxD,CAAC,UAAU;AAAA,EACb;AAEM,QAAA,kBAAkBC,WAAAA,YAAY,YAAY;AAC9C,QAAI,CAAC,gBAAgB,WAAW,GAAG,EAAG;AAEtC,QAAI,SAAS,UAAU;AACrB,YAAM,iBAAiB,CAAC,gBAAgB,WAAW,GAAG,CAA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AA,YACN,OAAM;AAAA,YACN,aAAW;AAAA,YACX,WAAW;AAAA,YAEV,UAAW,WAAA;AAAA,UAAA;AAAA,QAAA,IAKlBL,2BAAA,kBAAA;AAAA,UAACE,sCAAAA,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,eAAe;AAAA,YACtB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAMI,YAAA;AAAA,YACN,OAAM;AAAA,YACN,aAAW;AAAA,YACX,WAAW;AAAA,YAEV,UAAe,eAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAClB;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidDictionaryChangeButtons.d.ts","sourceRoot":"","sources":["../../../src/components/DictionaryEditor/ValidDictionaryChangeButtons.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ValidDictionaryChangeButtons.d.ts","sourceRoot":"","sources":["../../../src/components/DictionaryEditor/ValidDictionaryChangeButtons.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,OAAO,EAAwB,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAQtD,KAAK,iCAAiC,GAAG;IACvC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,iCAAiC,CA2HlC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { j as jsxRuntimeExports } from "../../jsx-runtime-DQkoUcjV.js";
|
|
3
|
-
import { useEditedContent } from "@intlayer/editor-react";
|
|
3
|
+
import { useDictionariesRecordActions, useEditedContent } from "@intlayer/editor-react";
|
|
4
4
|
import { RotateCcw, ArrowUpFromLine, Save, Download } from "lucide-react";
|
|
5
|
-
import { useMemo } from "react";
|
|
5
|
+
import { useMemo, useCallback } from "react";
|
|
6
6
|
import { useDictionary } from "react-intlayer";
|
|
7
7
|
import "../../hooks/useScrollBlockage/useScrollBlockageStore.mjs";
|
|
8
8
|
import "../../hooks/useAsync/useAsyncStateStore.mjs";
|
|
@@ -16,6 +16,7 @@ import { getValidDictionaryChangeButtonsSchemaSchema } from "./validDictionaryCh
|
|
|
16
16
|
const ValidDictionaryChangeButtons = ({ dictionary, mode }) => {
|
|
17
17
|
const ValidDictionaryChangeButtonsSchemaSchema = getValidDictionaryChangeButtonsSchemaSchema();
|
|
18
18
|
const { resetButton, saveButton, publishButton, downloadButton } = useDictionary(validDictionaryChangeButtonsContent);
|
|
19
|
+
const { setLocaleDictionary } = useDictionariesRecordActions();
|
|
19
20
|
const { writeDictionary } = useWriteDictionary();
|
|
20
21
|
const { pushDictionaries } = usePushDictionaries();
|
|
21
22
|
const { editedContent, restoreEditedContent } = useEditedContent();
|
|
@@ -34,21 +35,24 @@ const ValidDictionaryChangeButtons = ({ dictionary, mode }) => {
|
|
|
34
35
|
() => typeof dictionary?._id === "undefined",
|
|
35
36
|
[dictionary]
|
|
36
37
|
);
|
|
37
|
-
const onSubmitSuccess = async () => {
|
|
38
|
+
const onSubmitSuccess = useCallback(async () => {
|
|
39
|
+
if (!editedContent?.[dictionary.key]) return;
|
|
38
40
|
if (mode === "remote") {
|
|
39
|
-
await pushDictionaries([
|
|
40
|
-
{
|
|
41
|
-
...dictionary,
|
|
42
|
-
...editedContent?.[dictionary.key]
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
41
|
+
await pushDictionaries([editedContent?.[dictionary.key]]);
|
|
45
42
|
} else {
|
|
46
|
-
await writeDictionary(
|
|
47
|
-
...dictionary,
|
|
48
|
-
...editedContent?.[dictionary.key]
|
|
49
|
-
});
|
|
43
|
+
await writeDictionary(editedContent?.[dictionary.key]);
|
|
50
44
|
}
|
|
51
|
-
|
|
45
|
+
setLocaleDictionary(editedContent?.[dictionary.key]);
|
|
46
|
+
restoreEditedContent(dictionary.key);
|
|
47
|
+
}, [
|
|
48
|
+
dictionary,
|
|
49
|
+
editedContent,
|
|
50
|
+
pushDictionaries,
|
|
51
|
+
setLocaleDictionary,
|
|
52
|
+
writeDictionary,
|
|
53
|
+
restoreEditedContent,
|
|
54
|
+
mode
|
|
55
|
+
]);
|
|
52
56
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
53
57
|
Form,
|
|
54
58
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidDictionaryChangeButtons.mjs","sources":["../../../src/components/DictionaryEditor/ValidDictionaryChangeButtons.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport type { Dictionary } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"file":"ValidDictionaryChangeButtons.mjs","sources":["../../../src/components/DictionaryEditor/ValidDictionaryChangeButtons.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n useDictionariesRecordActions,\n useEditedContent,\n} from '@intlayer/editor-react';\nimport { ArrowUpFromLine, Download, RotateCcw, Save } from 'lucide-react';\nimport { useCallback, useMemo, type FC } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport { usePushDictionaries, useWriteDictionary } from '../../hooks';\nimport { Form, useForm } from '../Form';\nimport { validDictionaryChangeButtonsContent } from './validDictionaryChangeButtons.content';\nimport { getValidDictionaryChangeButtonsSchemaSchema } from './validDictionaryChangeButtonsSchema';\n\ntype ValidDictionaryChangeButtonsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const ValidDictionaryChangeButtons: FC<\n ValidDictionaryChangeButtonsProps\n> = ({ dictionary, mode }) => {\n const ValidDictionaryChangeButtonsSchemaSchema =\n getValidDictionaryChangeButtonsSchemaSchema();\n\n const { resetButton, saveButton, publishButton, downloadButton } =\n useDictionary(validDictionaryChangeButtonsContent);\n\n const { setLocaleDictionary } = useDictionariesRecordActions();\n const { writeDictionary } = useWriteDictionary();\n const { pushDictionaries } = usePushDictionaries();\n\n const { editedContent, restoreEditedContent } = useEditedContent();\n const { form, isSubmitting } = useForm(\n ValidDictionaryChangeButtonsSchemaSchema\n );\n\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n\n const isEdited = useMemo(\n () =>\n editedDictionary &&\n JSON.stringify(editedDictionary?.content) !==\n JSON.stringify(dictionary?.content),\n [editedDictionary, dictionary]\n );\n\n const isLocalDictionary = useMemo(\n () => typeof (dictionary as DistantDictionary)?._id === 'undefined',\n [dictionary]\n );\n\n const onSubmitSuccess = useCallback(async () => {\n if (!editedContent?.[dictionary.key]) return;\n\n if (mode === 'remote') {\n await pushDictionaries([editedContent?.[dictionary.key]]);\n } else {\n await writeDictionary(editedContent?.[dictionary.key]);\n }\n setLocaleDictionary(editedContent?.[dictionary.key]);\n restoreEditedContent(dictionary.key);\n }, [\n dictionary,\n editedContent,\n pushDictionaries,\n setLocaleDictionary,\n writeDictionary,\n restoreEditedContent,\n mode,\n ]);\n\n return (\n <div className=\"mb-4\">\n <Form\n className=\"flex w-full flex-row flex-wrap justify-end gap-3\"\n {...form}\n schema={ValidDictionaryChangeButtonsSchemaSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n {isEdited && (\n <Form.Button\n type=\"button\"\n label={resetButton.label}\n disabled={!isEdited || isSubmitting}\n className=\"ml-auto\"\n Icon={RotateCcw}\n variant=\"outline\"\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n onClick={() => restoreEditedContent(dictionary.key)}\n >\n {resetButton.text}\n </Form.Button>\n )}\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={ArrowUpFromLine}\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Save}\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Download}\n color=\"text\"\n isFullWidth\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </Form>\n </div>\n );\n};\n"],"names":["jsx","jsxs"],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,+BAET,CAAC,EAAE,YAAY,WAAW;AAC5B,QAAM,2CACJ,4CAA4C;AAE9C,QAAM,EAAE,aAAa,YAAY,eAAe,eAAe,IAC7D,cAAc,mCAAmC;AAE7C,QAAA,EAAE,oBAAoB,IAAI,6BAA6B;AACvD,QAAA,EAAE,gBAAgB,IAAI,mBAAmB;AACzC,QAAA,EAAE,iBAAiB,IAAI,oBAAoB;AAEjD,QAAM,EAAE,eAAe,qBAAqB,IAAI,iBAAiB;AAC3D,QAAA,EAAE,MAAM,aAAA,IAAiB;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,mBAAmB;AAAA,IACvB,MAAM,gBAAgB,WAAW,GAAG;AAAA,IACpC,CAAC,eAAe,WAAW,GAAG;AAAA,EAChC;AAEA,QAAM,WAAW;AAAA,IACf,MACE,oBACA,KAAK,UAAU,kBAAkB,OAAO,MACtC,KAAK,UAAU,YAAY,OAAO;AAAA,IACtC,CAAC,kBAAkB,UAAU;AAAA,EAC/B;AAEA,QAAM,oBAAoB;AAAA,IACxB,MAAM,OAAQ,YAAkC,QAAQ;AAAA,IACxD,CAAC,UAAU;AAAA,EACb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,OAAO,WAAW;AAAA,YAClB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAM;AAAA,YACN,OAAM;AAAA,YACN,aAAW;AAAA,YACX,WAAW;AAAA,YAEV,UAAW,WAAA;AAAA,UAAA;AAAA,QAAA,IAKlBA,kCAAA;AAAA,UAAC,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,eAAe;AAAA,YACtB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAM;AAAA,YACN,OAAM;AAAA,YACN,aAAW;AAAA,YACX,WAAW;AAAA,YAEV,UAAe,eAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAClB;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ;"}
|
|
@@ -39,6 +39,7 @@ const DictionaryDetailsForm = ({
|
|
|
39
39
|
}) => {
|
|
40
40
|
const { session } = components_Auth_useAuth_index.useAuth();
|
|
41
41
|
const { project } = session ?? {};
|
|
42
|
+
const { setLocaleDictionary } = editorReact.useDictionariesRecordActions();
|
|
42
43
|
const { pushDictionaries } = hooks_intlayerAPIHooks.usePushDictionaries();
|
|
43
44
|
const { data: projects, isLoading: isLoadingProjects } = hooks_intlayerAPIHooks.useGetProjects();
|
|
44
45
|
const { data: tags, isLoading: isLoadingTags } = hooks_intlayerAPIHooks.useGetTags();
|
|
@@ -72,19 +73,16 @@ const DictionaryDetailsForm = ({
|
|
|
72
73
|
const isFormEdited = form.formState.isDirty;
|
|
73
74
|
const isLocalDictionary = typeof dictionary?._id === "undefined";
|
|
74
75
|
const onSubmitSuccess = async (data) => {
|
|
76
|
+
const updatedDictionary = {
|
|
77
|
+
...dictionary,
|
|
78
|
+
...data
|
|
79
|
+
};
|
|
75
80
|
if (mode === "remote") {
|
|
76
|
-
await pushDictionaries([
|
|
77
|
-
{
|
|
78
|
-
...dictionary,
|
|
79
|
-
...data
|
|
80
|
-
}
|
|
81
|
-
]);
|
|
81
|
+
await pushDictionaries([updatedDictionary]);
|
|
82
82
|
} else {
|
|
83
|
-
await writeDictionary(
|
|
84
|
-
...dictionary,
|
|
85
|
-
...data
|
|
86
|
-
});
|
|
83
|
+
await writeDictionary(updatedDictionary);
|
|
87
84
|
}
|
|
85
|
+
setLocaleDictionary(updatedDictionary);
|
|
88
86
|
};
|
|
89
87
|
const handleOnAuditFile = async () => {
|
|
90
88
|
const updatedDictionary = form.getValues();
|
package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionaryDetailsForm.cjs","sources":["../../../../src/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.tsx"],"sourcesContent":["'use client';\n\nimport {\n DictionaryAPI,\n Dictionary as DistantDictionary,\n} from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport { useEditedContent } from '@intlayer/editor-react';\nimport { ArrowUpFromLine, Download, Save, WandSparkles } from 'lucide-react';\nimport { type FC, useEffect, useMemo } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport {\n useAuditContentDeclarationMetadata,\n useGetProjects,\n useGetTags,\n usePushDictionaries,\n useWriteDictionary,\n} from '../../../hooks';\nimport { useAuth } from '../../Auth';\nimport { Form, useForm } from '../../Form';\nimport { Loader } from '../../Loader';\nimport { MultiSelect, Select } from '../../Select';\nimport { dictionaryDetailsContent } from './dictionaryDetails.content';\nimport {\n useDictionaryDetailsSchema,\n DictionaryDetailsFormData,\n} from './useDictionaryDetailsSchema';\n\ntype DictionaryDetailsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const DictionaryDetailsForm: FC<DictionaryDetailsProps> = ({\n dictionary,\n mode,\n}) => {\n const { session } = useAuth();\n const { project } = session ?? {};\n const { pushDictionaries } = usePushDictionaries();\n const { data: projects, isLoading: isLoadingProjects } = useGetProjects();\n const { data: tags, isLoading: isLoadingTags } = useGetTags();\n const dictionaryValue = {\n ...dictionary,\n publishedVersion: dictionary.publishedVersion ?? '-1',\n };\n\n const DictionaryDetailsSchema = useDictionaryDetailsSchema(\n String(project?._id)\n );\n const { form, isSubmitting } = useForm(DictionaryDetailsSchema, {\n defaultValues: dictionaryValue,\n });\n const {\n titleInput,\n keyInput,\n descriptionInput,\n publishedVersionSelect,\n publishButton,\n saveButton,\n projectInput,\n tagsSelect,\n auditButton,\n downloadButton,\n } = useDictionary(dictionaryDetailsContent);\n const { auditContentDeclaration, isLoading: isAuditing } =\n useAuditContentDeclarationMetadata();\n const { writeDictionary } = useWriteDictionary();\n\n useEffect(() => {\n form.reset(dictionaryValue);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dictionary, form?.reset]);\n\n const isFormEdited = form.formState.isDirty;\n const isLocalDictionary =\n typeof (dictionary as DistantDictionary)?._id === 'undefined';\n\n const onSubmitSuccess = async (data: DictionaryDetailsFormData) => {\n if (mode === 'remote') {\n await pushDictionaries([\n {\n ...dictionary,\n ...data,\n },\n ]);\n } else {\n await writeDictionary({\n ...dictionary,\n ...data,\n });\n }\n };\n\n const handleOnAuditFile = async () => {\n const updatedDictionary = form.getValues();\n await auditContentDeclaration({\n fileContent: JSON.stringify({ ...dictionary, ...updatedDictionary }),\n }).then((response) => {\n if (!response.data) return;\n\n try {\n const editedDictionary = JSON.parse(response.data.fileContent) as\n | Partial<Dictionary>\n | undefined;\n\n form.reset({\n ...updatedDictionary,\n ...editedDictionary,\n publishedVersion: updatedDictionary.publishedVersion ?? '-1',\n });\n } catch (error) {\n console.error(error);\n }\n });\n };\n\n const isLoading = isSubmitting || isLoadingTags;\n\n const { editedContent } = useEditedContent();\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n const isEdited = useMemo(\n () =>\n editedDictionary &&\n dictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(dictionary.content),\n [dictionary, editedDictionary]\n );\n\n return (\n <Form\n className=\"flex size-full flex-1 flex-col gap-8\"\n {...form}\n schema={DictionaryDetailsSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.EditableFieldInput\n name=\"key\"\n label={keyInput.label}\n placeholder={keyInput.label}\n description={keyInput.description}\n disabled={isSubmitting}\n isRequired\n />\n <Form.EditableFieldInput\n name=\"title\"\n label={titleInput.label}\n placeholder={titleInput.placeholder}\n description={titleInput.description}\n disabled={isSubmitting}\n />\n </div>\n <Form.EditableFieldTextArea\n name=\"description\"\n label={descriptionInput.label}\n placeholder={descriptionInput.placeholder}\n description={descriptionInput.description}\n disabled={isSubmitting}\n />\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.MultiSelect\n name=\"projectIds\"\n label={projectInput.label}\n description={projectInput.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={projectInput.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {projects?.data?.map((project) => (\n <MultiSelect.Item\n key={String(project._id)}\n value={String(project._id)}\n >\n {project.name}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n\n <Form.MultiSelect\n name=\"tags\"\n label={tagsSelect.label}\n description={tagsSelect.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={tagsSelect.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {tags?.data?.map((tag) => (\n <MultiSelect.Item\n key={String(tag.key)}\n value={String(tag.key)}\n >\n {tag.name ?? tag.key}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n </div>\n {((dictionary as DictionaryAPI).availableVersions?.length ?? 0) > 1 && (\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.Select\n name=\"publishedVersion\"\n description={publishedVersionSelect.description}\n label={publishedVersionSelect.label}\n >\n <Select.Trigger>\n <Select.Value placeholder={publishedVersionSelect.placeholder} />\n </Select.Trigger>\n <Select.Content>\n <Select.Item value=\"-1\">LTS</Select.Item>\n {(dictionary as DictionaryAPI).availableVersions?.map(\n (version) => (\n <Select.Item value={version} key={version}>\n {version}\n </Select.Item>\n )\n )}\n </Select.Content>\n </Form.Select>\n <div className=\"w-full\" />\n </div>\n )}\n\n <div className=\"flex flex-wrap items-center justify-end gap-2 max-md:flex-col\">\n <Form.Button\n type=\"button\"\n label={auditButton.label}\n Icon={WandSparkles}\n variant=\"outline\"\n color=\"text\"\n className=\"max-md:w-full\"\n onClick={handleOnAuditFile}\n disabled={isSubmitting || isAuditing}\n isLoading={isAuditing}\n >\n {auditButton.text}\n </Form.Button>\n\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={ArrowUpFromLine}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Save}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Download}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </div>\n </Form>\n );\n};\n"],"names":["useAuth","usePushDictionaries","useGetProjects","useGetTags","useDictionaryDetailsSchema","useForm","useDictionary","dictionaryDetailsContent","useAuditContentDeclarationMetadata","useWriteDictionary","useEffect","editedDictionary","useEditedContent","useMemo","jsxs","Form","jsx","MultiSelect","project","Loader","Select","WandSparkles","ArrowUpFromLine","Save","Download"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,MAAM,wBAAoD,CAAC;AAAA,EAChE;AAAA,EACA;AACF,MAAM;AACE,QAAA,EAAE,QAAQ,IAAIA,sCAAQ;AAC5B,QAAM,EAAE,YAAY,WAAW,CAAC;AAC1B,QAAA,EAAE,iBAAiB,IAAIC,2CAAoB;AACjD,QAAM,EAAE,MAAM,UAAU,WAAW,kBAAA,IAAsBC,uBAAAA,eAAe;AACxE,QAAM,EAAE,MAAM,MAAM,WAAW,cAAA,IAAkBC,uBAAAA,WAAW;AAC5D,QAAM,kBAAkB;AAAA,IACtB,GAAG;AAAA,IACH,kBAAkB,WAAW,oBAAoB;AAAA,EACnD;AAEA,QAAM,0BAA0BC,8EAAA;AAAA,IAC9B,OAAO,SAAS,GAAG;AAAA,EACrB;AACA,QAAM,EAAE,MAAM,iBAAiBC,yBAAAA,QAAQ,yBAAyB;AAAA,IAC9D,eAAe;AAAA,EAAA,CAChB;AACK,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACEC,cAAAA,cAAcC,6EAAAA,wBAAwB;AAC1C,QAAM,EAAE,yBAAyB,WAAW,WAAA,IAC1CC,uBAAAA,mCAAmC;AAC/B,QAAA,EAAE,gBAAgB,IAAIC,0CAAmB;AAE/CC,aAAAA,UAAU,MAAM;AACd,SAAK,MAAM,eAAe;AAAA,EAEzB,GAAA,CAAC,YAAY,MAAM,KAAK,CAAC;AAEtB,QAAA,eAAe,KAAK,UAAU;AAC9B,QAAA,oBACJ,OAAQ,YAAkC,QAAQ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A,UACf;AAAA,UAEC,SAAS,WACR,oBACEL,2BAAA,kBAAA;AAAA,YAACD,sCAAAA,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,cAAc;AAAA,cACrB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAMO,YAAA;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAc,cAAA;AAAA,YAAA;AAAA,cAGjB,YACEN,2BAAA,kBAAA;AAAA,YAACD,sCAAAA,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,WAAW;AAAA,cAClB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAMQ,YAAA;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAW,WAAA;AAAA,YAAA;AAAA,UAAA,IAKlBP,2BAAA,kBAAA;AAAA,YAACD,sCAAAA,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,eAAe;AAAA,cACtB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAMS,YAAA;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAe,eAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAClB,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;;"}
|
|
1
|
+
{"version":3,"file":"DictionaryDetailsForm.cjs","sources":["../../../../src/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.tsx"],"sourcesContent":["'use client';\n\nimport {\n DictionaryAPI,\n Dictionary as DistantDictionary,\n} from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport {\n useDictionariesRecordActions,\n useEditedContent,\n} from '@intlayer/editor-react';\nimport { ArrowUpFromLine, Download, Save, WandSparkles } from 'lucide-react';\nimport { type FC, useEffect, useMemo } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport {\n useAuditContentDeclarationMetadata,\n useGetProjects,\n useGetTags,\n usePushDictionaries,\n useWriteDictionary,\n} from '../../../hooks';\nimport { useAuth } from '../../Auth';\nimport { Form, useForm } from '../../Form';\nimport { Loader } from '../../Loader';\nimport { MultiSelect, Select } from '../../Select';\nimport { dictionaryDetailsContent } from './dictionaryDetails.content';\nimport {\n useDictionaryDetailsSchema,\n DictionaryDetailsFormData,\n} from './useDictionaryDetailsSchema';\n\ntype DictionaryDetailsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const DictionaryDetailsForm: FC<DictionaryDetailsProps> = ({\n dictionary,\n mode,\n}) => {\n const { session } = useAuth();\n const { project } = session ?? {};\n const { setLocaleDictionary } = useDictionariesRecordActions();\n const { pushDictionaries } = usePushDictionaries();\n const { data: projects, isLoading: isLoadingProjects } = useGetProjects();\n const { data: tags, isLoading: isLoadingTags } = useGetTags();\n const dictionaryValue = {\n ...dictionary,\n publishedVersion: dictionary.publishedVersion ?? '-1',\n };\n\n const DictionaryDetailsSchema = useDictionaryDetailsSchema(\n String(project?._id)\n );\n const { form, isSubmitting } = useForm(DictionaryDetailsSchema, {\n defaultValues: dictionaryValue,\n });\n const {\n titleInput,\n keyInput,\n descriptionInput,\n publishedVersionSelect,\n publishButton,\n saveButton,\n projectInput,\n tagsSelect,\n auditButton,\n downloadButton,\n } = useDictionary(dictionaryDetailsContent);\n const { auditContentDeclaration, isLoading: isAuditing } =\n useAuditContentDeclarationMetadata();\n const { writeDictionary } = useWriteDictionary();\n\n useEffect(() => {\n form.reset(dictionaryValue);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dictionary, form?.reset]);\n\n const isFormEdited = form.formState.isDirty;\n const isLocalDictionary =\n typeof (dictionary as DistantDictionary)?._id === 'undefined';\n\n const onSubmitSuccess = async (data: DictionaryDetailsFormData) => {\n const updatedDictionary = {\n ...dictionary,\n ...data,\n };\n\n if (mode === 'remote') {\n await pushDictionaries([updatedDictionary]);\n } else {\n await writeDictionary(updatedDictionary);\n }\n\n setLocaleDictionary(updatedDictionary);\n };\n\n const handleOnAuditFile = async () => {\n const updatedDictionary = form.getValues();\n await auditContentDeclaration({\n fileContent: JSON.stringify({ ...dictionary, ...updatedDictionary }),\n }).then((response) => {\n if (!response.data) return;\n\n try {\n const editedDictionary = JSON.parse(response.data.fileContent) as\n | Partial<Dictionary>\n | undefined;\n\n form.reset({\n ...updatedDictionary,\n ...editedDictionary,\n publishedVersion: updatedDictionary.publishedVersion ?? '-1',\n });\n } catch (error) {\n console.error(error);\n }\n });\n };\n\n const isLoading = isSubmitting || isLoadingTags;\n\n const { editedContent } = useEditedContent();\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n const isEdited = useMemo(\n () =>\n editedDictionary &&\n dictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(dictionary.content),\n [dictionary, editedDictionary]\n );\n\n return (\n <Form\n className=\"flex size-full flex-1 flex-col gap-8\"\n {...form}\n schema={DictionaryDetailsSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.EditableFieldInput\n name=\"key\"\n label={keyInput.label}\n placeholder={keyInput.label}\n description={keyInput.description}\n disabled={isSubmitting}\n isRequired\n />\n <Form.EditableFieldInput\n name=\"title\"\n label={titleInput.label}\n placeholder={titleInput.placeholder}\n description={titleInput.description}\n disabled={isSubmitting}\n />\n </div>\n <Form.EditableFieldTextArea\n name=\"description\"\n label={descriptionInput.label}\n placeholder={descriptionInput.placeholder}\n description={descriptionInput.description}\n disabled={isSubmitting}\n />\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.MultiSelect\n name=\"projectIds\"\n label={projectInput.label}\n description={projectInput.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={projectInput.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {projects?.data?.map((project) => (\n <MultiSelect.Item\n key={String(project._id)}\n value={String(project._id)}\n >\n {project.name}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n\n <Form.MultiSelect\n name=\"tags\"\n label={tagsSelect.label}\n description={tagsSelect.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={tagsSelect.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {tags?.data?.map((tag) => (\n <MultiSelect.Item\n key={String(tag.key)}\n value={String(tag.key)}\n >\n {tag.name ?? tag.key}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n </div>\n {((dictionary as DictionaryAPI).availableVersions?.length ?? 0) > 1 && (\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.Select\n name=\"publishedVersion\"\n description={publishedVersionSelect.description}\n label={publishedVersionSelect.label}\n >\n <Select.Trigger>\n <Select.Value placeholder={publishedVersionSelect.placeholder} />\n </Select.Trigger>\n <Select.Content>\n <Select.Item value=\"-1\">LTS</Select.Item>\n {(dictionary as DictionaryAPI).availableVersions?.map(\n (version) => (\n <Select.Item value={version} key={version}>\n {version}\n </Select.Item>\n )\n )}\n </Select.Content>\n </Form.Select>\n <div className=\"w-full\" />\n </div>\n )}\n\n <div className=\"flex flex-wrap items-center justify-end gap-2 max-md:flex-col\">\n <Form.Button\n type=\"button\"\n label={auditButton.label}\n Icon={WandSparkles}\n variant=\"outline\"\n color=\"text\"\n className=\"max-md:w-full\"\n onClick={handleOnAuditFile}\n disabled={isSubmitting || isAuditing}\n isLoading={isAuditing}\n >\n {auditButton.text}\n </Form.Button>\n\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={ArrowUpFromLine}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Save}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Download}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </div>\n </Form>\n );\n};\n"],"names":["useAuth","useDictionariesRecordActions","usePushDictionaries","useGetProjects","useGetTags","useDictionaryDetailsSchema","useForm","useDictionary","dictionaryDetailsContent","useAuditContentDeclarationMetadata","useWriteDictionary","useEffect","editedDictionary","useEditedContent","useMemo","jsxs","Form","jsx","MultiSelect","project","Loader","Select","WandSparkles","ArrowUpFromLine","Save","Download"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCO,MAAM,wBAAoD,CAAC;AAAA,EAChE;AAAA,EACA;AACF,MAAM;AACE,QAAA,EAAE,QAAQ,IAAIA,sCAAQ;AAC5B,QAAM,EAAE,YAAY,WAAW,CAAC;AAC1B,QAAA,EAAE,oBAAoB,IAAIC,yCAA6B;AACvD,QAAA,EAAE,iBAAiB,IAAIC,2CAAoB;AACjD,QAAM,EAAE,MAAM,UAAU,WAAW,kBAAA,IAAsBC,uBAAAA,eAAe;AACxE,QAAM,EAAE,MAAM,MAAM,W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cACV,WAAW;AAAA,cAEV,UAAW,WAAA;AAAA,YAAA;AAAA,UAAA,IAKlBP,2BAAA,kBAAA;AAAA,YAACD,sCAAAA,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,eAAe;AAAA,cACtB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAMS,YAAA;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAe,eAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAClB,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;;"}
|
package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionaryDetailsForm.d.ts","sourceRoot":"","sources":["../../../../src/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"DictionaryDetailsForm.d.ts","sourceRoot":"","sources":["../../../../src/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM5C,OAAO,EAAE,KAAK,EAAE,EAAsB,MAAM,OAAO,CAAC;AAoBpD,KAAK,sBAAsB,GAAG;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,sBAAsB,CAkR5D,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { j as jsxRuntimeExports } from "../../../jsx-runtime-DQkoUcjV.js";
|
|
3
|
-
import { useEditedContent } from "@intlayer/editor-react";
|
|
3
|
+
import { useDictionariesRecordActions, useEditedContent } from "@intlayer/editor-react";
|
|
4
4
|
import { WandSparkles, ArrowUpFromLine, Save, Download } from "lucide-react";
|
|
5
5
|
import { useEffect, useMemo } from "react";
|
|
6
6
|
import { useDictionary } from "react-intlayer";
|
|
@@ -37,6 +37,7 @@ const DictionaryDetailsForm = ({
|
|
|
37
37
|
}) => {
|
|
38
38
|
const { session } = useAuth();
|
|
39
39
|
const { project } = session ?? {};
|
|
40
|
+
const { setLocaleDictionary } = useDictionariesRecordActions();
|
|
40
41
|
const { pushDictionaries } = usePushDictionaries();
|
|
41
42
|
const { data: projects, isLoading: isLoadingProjects } = useGetProjects();
|
|
42
43
|
const { data: tags, isLoading: isLoadingTags } = useGetTags();
|
|
@@ -70,19 +71,16 @@ const DictionaryDetailsForm = ({
|
|
|
70
71
|
const isFormEdited = form.formState.isDirty;
|
|
71
72
|
const isLocalDictionary = typeof dictionary?._id === "undefined";
|
|
72
73
|
const onSubmitSuccess = async (data) => {
|
|
74
|
+
const updatedDictionary = {
|
|
75
|
+
...dictionary,
|
|
76
|
+
...data
|
|
77
|
+
};
|
|
73
78
|
if (mode === "remote") {
|
|
74
|
-
await pushDictionaries([
|
|
75
|
-
{
|
|
76
|
-
...dictionary,
|
|
77
|
-
...data
|
|
78
|
-
}
|
|
79
|
-
]);
|
|
79
|
+
await pushDictionaries([updatedDictionary]);
|
|
80
80
|
} else {
|
|
81
|
-
await writeDictionary(
|
|
82
|
-
...dictionary,
|
|
83
|
-
...data
|
|
84
|
-
});
|
|
81
|
+
await writeDictionary(updatedDictionary);
|
|
85
82
|
}
|
|
83
|
+
setLocaleDictionary(updatedDictionary);
|
|
86
84
|
};
|
|
87
85
|
const handleOnAuditFile = async () => {
|
|
88
86
|
const updatedDictionary = form.getValues();
|
package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionaryDetailsForm.mjs","sources":["../../../../src/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.tsx"],"sourcesContent":["'use client';\n\nimport {\n DictionaryAPI,\n Dictionary as DistantDictionary,\n} from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport { useEditedContent } from '@intlayer/editor-react';\nimport { ArrowUpFromLine, Download, Save, WandSparkles } from 'lucide-react';\nimport { type FC, useEffect, useMemo } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport {\n useAuditContentDeclarationMetadata,\n useGetProjects,\n useGetTags,\n usePushDictionaries,\n useWriteDictionary,\n} from '../../../hooks';\nimport { useAuth } from '../../Auth';\nimport { Form, useForm } from '../../Form';\nimport { Loader } from '../../Loader';\nimport { MultiSelect, Select } from '../../Select';\nimport { dictionaryDetailsContent } from './dictionaryDetails.content';\nimport {\n useDictionaryDetailsSchema,\n DictionaryDetailsFormData,\n} from './useDictionaryDetailsSchema';\n\ntype DictionaryDetailsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const DictionaryDetailsForm: FC<DictionaryDetailsProps> = ({\n dictionary,\n mode,\n}) => {\n const { session } = useAuth();\n const { project } = session ?? {};\n const { pushDictionaries } = usePushDictionaries();\n const { data: projects, isLoading: isLoadingProjects } = useGetProjects();\n const { data: tags, isLoading: isLoadingTags } = useGetTags();\n const dictionaryValue = {\n ...dictionary,\n publishedVersion: dictionary.publishedVersion ?? '-1',\n };\n\n const DictionaryDetailsSchema = useDictionaryDetailsSchema(\n String(project?._id)\n );\n const { form, isSubmitting } = useForm(DictionaryDetailsSchema, {\n defaultValues: dictionaryValue,\n });\n const {\n titleInput,\n keyInput,\n descriptionInput,\n publishedVersionSelect,\n publishButton,\n saveButton,\n projectInput,\n tagsSelect,\n auditButton,\n downloadButton,\n } = useDictionary(dictionaryDetailsContent);\n const { auditContentDeclaration, isLoading: isAuditing } =\n useAuditContentDeclarationMetadata();\n const { writeDictionary } = useWriteDictionary();\n\n useEffect(() => {\n form.reset(dictionaryValue);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dictionary, form?.reset]);\n\n const isFormEdited = form.formState.isDirty;\n const isLocalDictionary =\n typeof (dictionary as DistantDictionary)?._id === 'undefined';\n\n const onSubmitSuccess = async (data: DictionaryDetailsFormData) => {\n if (mode === 'remote') {\n await pushDictionaries([\n {\n ...dictionary,\n ...data,\n },\n ]);\n } else {\n await writeDictionary({\n ...dictionary,\n ...data,\n });\n }\n };\n\n const handleOnAuditFile = async () => {\n const updatedDictionary = form.getValues();\n await auditContentDeclaration({\n fileContent: JSON.stringify({ ...dictionary, ...updatedDictionary }),\n }).then((response) => {\n if (!response.data) return;\n\n try {\n const editedDictionary = JSON.parse(response.data.fileContent) as\n | Partial<Dictionary>\n | undefined;\n\n form.reset({\n ...updatedDictionary,\n ...editedDictionary,\n publishedVersion: updatedDictionary.publishedVersion ?? '-1',\n });\n } catch (error) {\n console.error(error);\n }\n });\n };\n\n const isLoading = isSubmitting || isLoadingTags;\n\n const { editedContent } = useEditedContent();\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n const isEdited = useMemo(\n () =>\n editedDictionary &&\n dictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(dictionary.content),\n [dictionary, editedDictionary]\n );\n\n return (\n <Form\n className=\"flex size-full flex-1 flex-col gap-8\"\n {...form}\n schema={DictionaryDetailsSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.EditableFieldInput\n name=\"key\"\n label={keyInput.label}\n placeholder={keyInput.label}\n description={keyInput.description}\n disabled={isSubmitting}\n isRequired\n />\n <Form.EditableFieldInput\n name=\"title\"\n label={titleInput.label}\n placeholder={titleInput.placeholder}\n description={titleInput.description}\n disabled={isSubmitting}\n />\n </div>\n <Form.EditableFieldTextArea\n name=\"description\"\n label={descriptionInput.label}\n placeholder={descriptionInput.placeholder}\n description={descriptionInput.description}\n disabled={isSubmitting}\n />\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.MultiSelect\n name=\"projectIds\"\n label={projectInput.label}\n description={projectInput.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={projectInput.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {projects?.data?.map((project) => (\n <MultiSelect.Item\n key={String(project._id)}\n value={String(project._id)}\n >\n {project.name}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n\n <Form.MultiSelect\n name=\"tags\"\n label={tagsSelect.label}\n description={tagsSelect.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={tagsSelect.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {tags?.data?.map((tag) => (\n <MultiSelect.Item\n key={String(tag.key)}\n value={String(tag.key)}\n >\n {tag.name ?? tag.key}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n </div>\n {((dictionary as DictionaryAPI).availableVersions?.length ?? 0) > 1 && (\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.Select\n name=\"publishedVersion\"\n description={publishedVersionSelect.description}\n label={publishedVersionSelect.label}\n >\n <Select.Trigger>\n <Select.Value placeholder={publishedVersionSelect.placeholder} />\n </Select.Trigger>\n <Select.Content>\n <Select.Item value=\"-1\">LTS</Select.Item>\n {(dictionary as DictionaryAPI).availableVersions?.map(\n (version) => (\n <Select.Item value={version} key={version}>\n {version}\n </Select.Item>\n )\n )}\n </Select.Content>\n </Form.Select>\n <div className=\"w-full\" />\n </div>\n )}\n\n <div className=\"flex flex-wrap items-center justify-end gap-2 max-md:flex-col\">\n <Form.Button\n type=\"button\"\n label={auditButton.label}\n Icon={WandSparkles}\n variant=\"outline\"\n color=\"text\"\n className=\"max-md:w-full\"\n onClick={handleOnAuditFile}\n disabled={isSubmitting || isAuditing}\n isLoading={isAuditing}\n >\n {auditButton.text}\n </Form.Button>\n\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={ArrowUpFromLine}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Save}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Download}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </div>\n </Form>\n );\n};\n"],"names":["editedDictionary","jsxs","jsx","project"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,MAAM,wBAAoD,CAAC;AAAA,EAChE;AAAA,EACA;AACF,MAAM;AACE,QAAA,EAAE,QAAQ,IAAI,QAAQ;AAC5B,QAAM,EAAE,YAAY,WAAW,CAAC;AAC1B,QAAA,EAAE,iBAAiB,IAAI,oBAAoB;AACjD,QAAM,EAAE,MAAM,UAAU,WAAW,kBAAA,IAAsB,eAAe;AACxE,QAAM,EAAE,MAAM,MAAM,WAAW,cAAA,IAAkB,WAAW;AAC5D,QAAM,kBAA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AAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,YAAY;AAAA,cACnB,MAAM;AAAA,cACN,SAAQ;AAAA,cACR,OAAM;AAAA,cACN,WAAU;AAAA,cACV,SAAS;AAAA,cACT,UAAU,gBAAgB;AAAA,cAC1B,WAAW;AAAA,cAEV,UAAY,YAAA;AAAA,YAAA;AAAA,UACf;AAAA,UAEC,SAAS,WACR,oBACEA,kCAAA;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,cAAc;AAAA,cACrB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAM;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAc,cAAA;AAAA,YAAA;AAAA,cAGjB,YACEA,kCAAA;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,WAAW;AAAA,cAClB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAM;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAW,WAAA;AAAA,YAAA;AAAA,UAAA,IAKlBA,kCAAA;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,eAAe;AAAA,cACtB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAM;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAe,eAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAClB,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"DictionaryDetailsForm.mjs","sources":["../../../../src/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.tsx"],"sourcesContent":["'use client';\n\nimport {\n DictionaryAPI,\n Dictionary as DistantDictionary,\n} from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport {\n useDictionariesRecordActions,\n useEditedContent,\n} from '@intlayer/editor-react';\nimport { ArrowUpFromLine, Download, Save, WandSparkles } from 'lucide-react';\nimport { type FC, useEffect, useMemo } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport {\n useAuditContentDeclarationMetadata,\n useGetProjects,\n useGetTags,\n usePushDictionaries,\n useWriteDictionary,\n} from '../../../hooks';\nimport { useAuth } from '../../Auth';\nimport { Form, useForm } from '../../Form';\nimport { Loader } from '../../Loader';\nimport { MultiSelect, Select } from '../../Select';\nimport { dictionaryDetailsContent } from './dictionaryDetails.content';\nimport {\n useDictionaryDetailsSchema,\n DictionaryDetailsFormData,\n} from './useDictionaryDetailsSchema';\n\ntype DictionaryDetailsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const DictionaryDetailsForm: FC<DictionaryDetailsProps> = ({\n dictionary,\n mode,\n}) => {\n const { session } = useAuth();\n const { project } = session ?? {};\n const { setLocaleDictionary } = useDictionariesRecordActions();\n const { pushDictionaries } = usePushDictionaries();\n const { data: projects, isLoading: isLoadingProjects } = useGetProjects();\n const { data: tags, isLoading: isLoadingTags } = useGetTags();\n const dictionaryValue = {\n ...dictionary,\n publishedVersion: dictionary.publishedVersion ?? '-1',\n };\n\n const DictionaryDetailsSchema = useDictionaryDetailsSchema(\n String(project?._id)\n );\n const { form, isSubmitting } = useForm(DictionaryDetailsSchema, {\n defaultValues: dictionaryValue,\n });\n const {\n titleInput,\n keyInput,\n descriptionInput,\n publishedVersionSelect,\n publishButton,\n saveButton,\n projectInput,\n tagsSelect,\n auditButton,\n downloadButton,\n } = useDictionary(dictionaryDetailsContent);\n const { auditContentDeclaration, isLoading: isAuditing } =\n useAuditContentDeclarationMetadata();\n const { writeDictionary } = useWriteDictionary();\n\n useEffect(() => {\n form.reset(dictionaryValue);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dictionary, form?.reset]);\n\n const isFormEdited = form.formState.isDirty;\n const isLocalDictionary =\n typeof (dictionary as DistantDictionary)?._id === 'undefined';\n\n const onSubmitSuccess = async (data: DictionaryDetailsFormData) => {\n const updatedDictionary = {\n ...dictionary,\n ...data,\n };\n\n if (mode === 'remote') {\n await pushDictionaries([updatedDictionary]);\n } else {\n await writeDictionary(updatedDictionary);\n }\n\n setLocaleDictionary(updatedDictionary);\n };\n\n const handleOnAuditFile = async () => {\n const updatedDictionary = form.getValues();\n await auditContentDeclaration({\n fileContent: JSON.stringify({ ...dictionary, ...updatedDictionary }),\n }).then((response) => {\n if (!response.data) return;\n\n try {\n const editedDictionary = JSON.parse(response.data.fileContent) as\n | Partial<Dictionary>\n | undefined;\n\n form.reset({\n ...updatedDictionary,\n ...editedDictionary,\n publishedVersion: updatedDictionary.publishedVersion ?? '-1',\n });\n } catch (error) {\n console.error(error);\n }\n });\n };\n\n const isLoading = isSubmitting || isLoadingTags;\n\n const { editedContent } = useEditedContent();\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n const isEdited = useMemo(\n () =>\n editedDictionary &&\n dictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(dictionary.content),\n [dictionary, editedDictionary]\n );\n\n return (\n <Form\n className=\"flex size-full flex-1 flex-col gap-8\"\n {...form}\n schema={DictionaryDetailsSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.EditableFieldInput\n name=\"key\"\n label={keyInput.label}\n placeholder={keyInput.label}\n description={keyInput.description}\n disabled={isSubmitting}\n isRequired\n />\n <Form.EditableFieldInput\n name=\"title\"\n label={titleInput.label}\n placeholder={titleInput.placeholder}\n description={titleInput.description}\n disabled={isSubmitting}\n />\n </div>\n <Form.EditableFieldTextArea\n name=\"description\"\n label={descriptionInput.label}\n placeholder={descriptionInput.placeholder}\n description={descriptionInput.description}\n disabled={isSubmitting}\n />\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.MultiSelect\n name=\"projectIds\"\n label={projectInput.label}\n description={projectInput.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={projectInput.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {projects?.data?.map((project) => (\n <MultiSelect.Item\n key={String(project._id)}\n value={String(project._id)}\n >\n {project.name}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n\n <Form.MultiSelect\n name=\"tags\"\n label={tagsSelect.label}\n description={tagsSelect.description}\n >\n <MultiSelect.Trigger\n getBadgeValue={(value) =>\n projects?.data?.find((project) => String(project._id) === value)\n ?.name ?? value\n }\n >\n <MultiSelect.Input placeholder={tagsSelect.placeholder} />\n </MultiSelect.Trigger>\n <MultiSelect.Content>\n <Loader isLoading={isLoadingProjects}>\n <MultiSelect.List>\n {tags?.data?.map((tag) => (\n <MultiSelect.Item\n key={String(tag.key)}\n value={String(tag.key)}\n >\n {tag.name ?? tag.key}\n </MultiSelect.Item>\n ))}\n </MultiSelect.List>\n </Loader>\n </MultiSelect.Content>\n </Form.MultiSelect>\n </div>\n {((dictionary as DictionaryAPI).availableVersions?.length ?? 0) > 1 && (\n <div className=\"flex size-full flex-1 gap-8 max-md:flex-col\">\n <Form.Select\n name=\"publishedVersion\"\n description={publishedVersionSelect.description}\n label={publishedVersionSelect.label}\n >\n <Select.Trigger>\n <Select.Value placeholder={publishedVersionSelect.placeholder} />\n </Select.Trigger>\n <Select.Content>\n <Select.Item value=\"-1\">LTS</Select.Item>\n {(dictionary as DictionaryAPI).availableVersions?.map(\n (version) => (\n <Select.Item value={version} key={version}>\n {version}\n </Select.Item>\n )\n )}\n </Select.Content>\n </Form.Select>\n <div className=\"w-full\" />\n </div>\n )}\n\n <div className=\"flex flex-wrap items-center justify-end gap-2 max-md:flex-col\">\n <Form.Button\n type=\"button\"\n label={auditButton.label}\n Icon={WandSparkles}\n variant=\"outline\"\n color=\"text\"\n className=\"max-md:w-full\"\n onClick={handleOnAuditFile}\n disabled={isSubmitting || isAuditing}\n isLoading={isAuditing}\n >\n {auditButton.text}\n </Form.Button>\n\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={ArrowUpFromLine}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Save}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={isSubmitting || !isFormEdited || isLoading}\n Icon={Download}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </div>\n </Form>\n );\n};\n"],"names":["editedDictionary","jsxs","jsx","project"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCO,MAAM,wBAAoD,CAAC;AAAA,EAChE;AAAA,EACA;AACF,MAAM;AACE,QAAA,EAAE,QAAQ,IAAI,QAAQ;AAC5B,QAAM,EAAE,YAAY,WAAW,CAAC;AAC1B,QAAA,EAAE,oBAAoB,IAAI,6BAA6B;AACvD,QAAA,EAAE,iBAAiB,IAAI,oBAAoB;AACjD,QAAM,EAAE,MAAM,UAAU,WAAW,kBAAA,IAAsB,eAAe;AACxE,QAAM,EAAE,MAAM,MAAM,WAAW,cAAA,IAAkB,WAAW;AAC5D,QAAM,kBAAkB;AAAA,IACtB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MAAK;AAAA,cACL,OAAO,YAAY;AAAA,cACnB,MAAM;AAAA,cACN,SAAQ;AAAA,cACR,OAAM;AAAA,cACN,WAAU;AAAA,cACV,SAAS;AAAA,cACT,UAAU,gBAAgB;AAAA,cAC1B,WAAW;AAAA,cAEV,UAAY,YAAA;AAAA,YAAA;AAAA,UACf;AAAA,UAEC,SAAS,WACR,oBACEA,kCAAA;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,cAAc;AAAA,cACrB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAM;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAc,cAAA;AAAA,YAAA;AAAA,cAGjB,YACEA,kCAAA;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,WAAW;AAAA,cAClB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAM;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAW,WAAA;AAAA,YAAA;AAAA,UAAA,IAKlBA,kCAAA;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cACC,MAAK;AAAA,cACL,OAAO,eAAe;AAAA,cACtB,UAAU,gBAAgB,CAAC,gBAAgB;AAAA,cAC3C,MAAM;AAAA,cACN,OAAM;AAAA,cACN,WAAU;AAAA,cACV,WAAW;AAAA,cAEV,UAAe,eAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAClB,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -36,6 +36,7 @@ const components_DictionaryFieldEditor_SaveForm_SaveFormSchema = require("./Save
|
|
|
36
36
|
const SaveForm = ({ dictionary, mode }) => {
|
|
37
37
|
const { session } = components_Auth_useAuth_index.useAuth();
|
|
38
38
|
const project = session?.project;
|
|
39
|
+
const { setLocaleDictionary } = editorReact.useDictionariesRecordActions();
|
|
39
40
|
const { pushDictionaries } = hooks_intlayerAPIHooks.usePushDictionaries();
|
|
40
41
|
const { writeDictionary } = hooks_intlayerAPIHooks.useWriteDictionary();
|
|
41
42
|
const SaveFormSchema = components_DictionaryFieldEditor_SaveForm_SaveFormSchema.getSaveFormSchema();
|
|
@@ -69,20 +70,23 @@ const SaveForm = ({ dictionary, mode }) => {
|
|
|
69
70
|
[dictionary]
|
|
70
71
|
);
|
|
71
72
|
const onSubmitSuccess = require$$0.useCallback(async () => {
|
|
73
|
+
if (!editedContent?.[dictionary.key]) return;
|
|
72
74
|
if (mode === "remote") {
|
|
73
|
-
await pushDictionaries([
|
|
74
|
-
{
|
|
75
|
-
...dictionary,
|
|
76
|
-
...editedContent?.[dictionary.key]
|
|
77
|
-
}
|
|
78
|
-
]);
|
|
75
|
+
await pushDictionaries([editedContent?.[dictionary.key]]);
|
|
79
76
|
} else {
|
|
80
|
-
await writeDictionary(
|
|
81
|
-
...dictionary,
|
|
82
|
-
...editedContent?.[dictionary.key]
|
|
83
|
-
});
|
|
77
|
+
await writeDictionary(editedContent?.[dictionary.key]);
|
|
84
78
|
}
|
|
85
|
-
|
|
79
|
+
setLocaleDictionary(editedContent?.[dictionary.key]);
|
|
80
|
+
restoreEditedContent(dictionary.key);
|
|
81
|
+
}, [
|
|
82
|
+
dictionary,
|
|
83
|
+
editedContent,
|
|
84
|
+
pushDictionaries,
|
|
85
|
+
setLocaleDictionary,
|
|
86
|
+
writeDictionary,
|
|
87
|
+
restoreEditedContent,
|
|
88
|
+
mode
|
|
89
|
+
]);
|
|
86
90
|
const handleOnAuditFile = async () => await auditContentDeclaration({
|
|
87
91
|
defaultLocale: project?.defaultLocale ?? intlayer.Locales.ENGLISH,
|
|
88
92
|
locales: project?.locales ?? [intlayer.Locales.ENGLISH],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SaveForm.cjs","sources":["../../../../src/components/DictionaryFieldEditor/SaveForm/SaveForm.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"file":"SaveForm.cjs","sources":["../../../../src/components/DictionaryFieldEditor/SaveForm/SaveForm.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport {\n useDictionariesRecordActions,\n useEditedContent,\n} from '@intlayer/editor-react';\nimport { Locales } from 'intlayer';\nimport {\n ArrowUpFromLine,\n Download,\n RotateCcw,\n Save,\n WandSparkles,\n} from 'lucide-react';\nimport { useCallback, useMemo, type FC } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport {\n usePushDictionaries,\n useGetAllDictionaries,\n useAuditContentDeclaration,\n useWriteDictionary,\n} from '../../../hooks';\nimport { useAuth } from '../../Auth';\nimport { Form, useForm } from '../../Form';\nimport { saveDictionaryContent } from './saveForm.content';\nimport { getSaveFormSchema } from './SaveFormSchema';\n\ntype DictionaryDetailsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const SaveForm: FC<DictionaryDetailsProps> = ({ dictionary, mode }) => {\n const { session } = useAuth();\n const project = session?.project;\n const { setLocaleDictionary } = useDictionariesRecordActions();\n const { pushDictionaries } = usePushDictionaries();\n const { writeDictionary } = useWriteDictionary();\n const SaveFormSchema = getSaveFormSchema();\n const { online } = useGetAllDictionaries();\n const { isLoading: isAuditing, auditContentDeclaration } =\n useAuditContentDeclaration();\n\n const { editedContent, restoreEditedContent, setEditedContent } =\n useEditedContent();\n const { form, isSubmitting } = useForm(SaveFormSchema);\n const {\n auditButton,\n resetButton,\n saveButton,\n publishButton,\n downloadButton,\n } = useDictionary(saveDictionaryContent);\n\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n\n const onlineDictionary = useMemo(() => {\n return online?.[dictionary.key];\n }, [online, dictionary.key]);\n\n const isEdited = useMemo(() => {\n if (mode === 'remote') {\n return (\n editedDictionary &&\n onlineDictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(onlineDictionary.content)\n );\n } else if (mode === 'local') {\n return (\n editedDictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(dictionary.content)\n );\n }\n }, [onlineDictionary, editedDictionary, dictionary, mode]);\n\n const isLocalDictionary = useMemo(\n () => typeof (dictionary as DistantDictionary)?._id === 'undefined',\n [dictionary]\n );\n\n const onSubmitSuccess = useCallback(async () => {\n if (!editedContent?.[dictionary.key]) return;\n\n if (mode === 'remote') {\n await pushDictionaries([editedContent?.[dictionary.key]]);\n } else {\n await writeDictionary(editedContent?.[dictionary.key]);\n }\n setLocaleDictionary(editedContent?.[dictionary.key]);\n restoreEditedContent(dictionary.key);\n }, [\n dictionary,\n editedContent,\n pushDictionaries,\n setLocaleDictionary,\n writeDictionary,\n restoreEditedContent,\n mode,\n ]);\n\n const handleOnAuditFile = async () =>\n await auditContentDeclaration({\n defaultLocale: project?.defaultLocale ?? Locales.ENGLISH,\n locales: project?.locales ?? [Locales.ENGLISH],\n fileContent: JSON.stringify(editedDictionary ?? dictionary),\n }).then((response) => {\n if (!response.data) return;\n\n const editedDictionary = JSON.parse(\n response.data.fileContent\n ) as Dictionary;\n\n setEditedContent(dictionary.key, editedDictionary.content);\n });\n\n return (\n <Form\n className=\"flex w-full flex-1 flex-row flex-wrap justify-end gap-3\"\n {...form}\n schema={SaveFormSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n <Form.Button\n type=\"button\"\n label={auditButton.label}\n disabled={isSubmitting}\n Icon={WandSparkles}\n variant=\"outline\"\n color=\"text\"\n className=\"ml-auto max-md:w-full\"\n isLoading={isAuditing}\n onClick={handleOnAuditFile}\n >\n {auditButton.text}\n </Form.Button>\n {isEdited && (\n <Form.Button\n type=\"button\"\n label={resetButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={RotateCcw}\n variant=\"outline\"\n color=\"text\"\n className=\"max-md:w-full\"\n onClick={() => restoreEditedContent(dictionary.key)}\n >\n {resetButton.text}\n </Form.Button>\n )}\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={ArrowUpFromLine}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Save}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Download}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </Form>\n );\n};\n"],"names":["useAuth","useDictionariesRecordActions","usePushDictionaries","useWriteDictionary","getSaveFormSchema","useGetAllDictionaries","useAuditContentDeclaration","useEditedContent","useForm","useDictionary","saveDictionaryContent","useMemo","useCallback","Locales","editedDictionary","jsxs","Form","jsx","WandSparkles","RotateCcw","ArrowUpFromLine","Save","Download"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCO,MAAM,WAAuC,CAAC,EAAE,YAAY,WAAW;AACtE,QAAA,EAAE,QAAQ,IAAIA,sCAAQ;AAC5B,QAAM,UAAU,SAAS;AACnB,QAAA,EAAE,oBAAoB,IAAIC,yCAA6B;AACvD,QAAA,EAAE,iBAAiB,IAAIC,2CAAoB;AAC3C,QAAA,EAAE,gBAAgB,IAAIC,0CAAmB;AAC/C,QAAM,iBAAiBC,yDAAAA,kBAAkB;AACnC,QAAA,EAAE,OAAO,IAAIC,kDAAsB;AACzC,QAAM,EAAE,WAAW,YAAY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UAAA;AAAA,QACf;AAAA,QAED,SAAS,WACR,oBACEF,2BAAA,kBAAA;AAAA,UAACD,sCAAAA,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,cAAc;AAAA,YACrB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAMI,YAAA;AAAA,YACN,OAAM;AAAA,YACN,WAAU;AAAA,YACV,WAAW;AAAA,YAEV,UAAc,cAAA;AAAA,UAAA;AAAA,YAGjB,YACEH,2BAAA,kBAAA;AAAA,UAACD,sCAAAA,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,WAAW;AAAA,YAClB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAMK,YAAA;AAAA,YACN,OAAM;AAAA,YACN,WAAU;AAAA,YACV,WAAW;AAAA,YAEV,UAAW,WAAA;AAAA,UAAA;AAAA,QAAA,IAKlBJ,2BAAA,kBAAA;AAAA,UAACD,sCAAAA,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,eAAe;AAAA,YACtB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAMM,YAAA;AAAA,YACN,OAAM;AAAA,YACN,WAAU;AAAA,YACV,WAAW;AAAA,YAEV,UAAe,eAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAClB;AAAA,IAAA;AAAA,EAEJ;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SaveForm.d.ts","sourceRoot":"","sources":["../../../../src/components/DictionaryFieldEditor/SaveForm/SaveForm.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"SaveForm.d.ts","sourceRoot":"","sources":["../../../../src/components/DictionaryFieldEditor/SaveForm/SaveForm.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAa5C,OAAO,EAAwB,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AActD,KAAK,sBAAsB,GAAG;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,sBAAsB,CAqK/C,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { j as jsxRuntimeExports } from "../../../jsx-runtime-DQkoUcjV.js";
|
|
3
|
-
import { useEditedContent } from "@intlayer/editor-react";
|
|
3
|
+
import { useDictionariesRecordActions, useEditedContent } from "@intlayer/editor-react";
|
|
4
4
|
import { Locales } from "intlayer";
|
|
5
5
|
import { WandSparkles, RotateCcw, ArrowUpFromLine, Save, Download } from "lucide-react";
|
|
6
6
|
import { useMemo, useCallback } from "react";
|
|
@@ -34,6 +34,7 @@ import { getSaveFormSchema } from "./SaveFormSchema.mjs";
|
|
|
34
34
|
const SaveForm = ({ dictionary, mode }) => {
|
|
35
35
|
const { session } = useAuth();
|
|
36
36
|
const project = session?.project;
|
|
37
|
+
const { setLocaleDictionary } = useDictionariesRecordActions();
|
|
37
38
|
const { pushDictionaries } = usePushDictionaries();
|
|
38
39
|
const { writeDictionary } = useWriteDictionary();
|
|
39
40
|
const SaveFormSchema = getSaveFormSchema();
|
|
@@ -67,20 +68,23 @@ const SaveForm = ({ dictionary, mode }) => {
|
|
|
67
68
|
[dictionary]
|
|
68
69
|
);
|
|
69
70
|
const onSubmitSuccess = useCallback(async () => {
|
|
71
|
+
if (!editedContent?.[dictionary.key]) return;
|
|
70
72
|
if (mode === "remote") {
|
|
71
|
-
await pushDictionaries([
|
|
72
|
-
{
|
|
73
|
-
...dictionary,
|
|
74
|
-
...editedContent?.[dictionary.key]
|
|
75
|
-
}
|
|
76
|
-
]);
|
|
73
|
+
await pushDictionaries([editedContent?.[dictionary.key]]);
|
|
77
74
|
} else {
|
|
78
|
-
await writeDictionary(
|
|
79
|
-
...dictionary,
|
|
80
|
-
...editedContent?.[dictionary.key]
|
|
81
|
-
});
|
|
75
|
+
await writeDictionary(editedContent?.[dictionary.key]);
|
|
82
76
|
}
|
|
83
|
-
|
|
77
|
+
setLocaleDictionary(editedContent?.[dictionary.key]);
|
|
78
|
+
restoreEditedContent(dictionary.key);
|
|
79
|
+
}, [
|
|
80
|
+
dictionary,
|
|
81
|
+
editedContent,
|
|
82
|
+
pushDictionaries,
|
|
83
|
+
setLocaleDictionary,
|
|
84
|
+
writeDictionary,
|
|
85
|
+
restoreEditedContent,
|
|
86
|
+
mode
|
|
87
|
+
]);
|
|
84
88
|
const handleOnAuditFile = async () => await auditContentDeclaration({
|
|
85
89
|
defaultLocale: project?.defaultLocale ?? Locales.ENGLISH,
|
|
86
90
|
locales: project?.locales ?? [Locales.ENGLISH],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SaveForm.mjs","sources":["../../../../src/components/DictionaryFieldEditor/SaveForm/SaveForm.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"file":"SaveForm.mjs","sources":["../../../../src/components/DictionaryFieldEditor/SaveForm/SaveForm.tsx"],"sourcesContent":["'use client';\n\nimport { Dictionary as DistantDictionary } from '@intlayer/backend';\nimport { Dictionary } from '@intlayer/core';\nimport {\n useDictionariesRecordActions,\n useEditedContent,\n} from '@intlayer/editor-react';\nimport { Locales } from 'intlayer';\nimport {\n ArrowUpFromLine,\n Download,\n RotateCcw,\n Save,\n WandSparkles,\n} from 'lucide-react';\nimport { useCallback, useMemo, type FC } from 'react';\n// @ts-ignore react-intlayer not build yet\nimport { useDictionary } from 'react-intlayer';\nimport {\n usePushDictionaries,\n useGetAllDictionaries,\n useAuditContentDeclaration,\n useWriteDictionary,\n} from '../../../hooks';\nimport { useAuth } from '../../Auth';\nimport { Form, useForm } from '../../Form';\nimport { saveDictionaryContent } from './saveForm.content';\nimport { getSaveFormSchema } from './SaveFormSchema';\n\ntype DictionaryDetailsProps = {\n dictionary: Dictionary;\n mode: 'local' | 'remote';\n};\n\nexport const SaveForm: FC<DictionaryDetailsProps> = ({ dictionary, mode }) => {\n const { session } = useAuth();\n const project = session?.project;\n const { setLocaleDictionary } = useDictionariesRecordActions();\n const { pushDictionaries } = usePushDictionaries();\n const { writeDictionary } = useWriteDictionary();\n const SaveFormSchema = getSaveFormSchema();\n const { online } = useGetAllDictionaries();\n const { isLoading: isAuditing, auditContentDeclaration } =\n useAuditContentDeclaration();\n\n const { editedContent, restoreEditedContent, setEditedContent } =\n useEditedContent();\n const { form, isSubmitting } = useForm(SaveFormSchema);\n const {\n auditButton,\n resetButton,\n saveButton,\n publishButton,\n downloadButton,\n } = useDictionary(saveDictionaryContent);\n\n const editedDictionary = useMemo(\n () => editedContent?.[dictionary.key],\n [editedContent, dictionary.key]\n );\n\n const onlineDictionary = useMemo(() => {\n return online?.[dictionary.key];\n }, [online, dictionary.key]);\n\n const isEdited = useMemo(() => {\n if (mode === 'remote') {\n return (\n editedDictionary &&\n onlineDictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(onlineDictionary.content)\n );\n } else if (mode === 'local') {\n return (\n editedDictionary &&\n JSON.stringify(editedDictionary.content) !==\n JSON.stringify(dictionary.content)\n );\n }\n }, [onlineDictionary, editedDictionary, dictionary, mode]);\n\n const isLocalDictionary = useMemo(\n () => typeof (dictionary as DistantDictionary)?._id === 'undefined',\n [dictionary]\n );\n\n const onSubmitSuccess = useCallback(async () => {\n if (!editedContent?.[dictionary.key]) return;\n\n if (mode === 'remote') {\n await pushDictionaries([editedContent?.[dictionary.key]]);\n } else {\n await writeDictionary(editedContent?.[dictionary.key]);\n }\n setLocaleDictionary(editedContent?.[dictionary.key]);\n restoreEditedContent(dictionary.key);\n }, [\n dictionary,\n editedContent,\n pushDictionaries,\n setLocaleDictionary,\n writeDictionary,\n restoreEditedContent,\n mode,\n ]);\n\n const handleOnAuditFile = async () =>\n await auditContentDeclaration({\n defaultLocale: project?.defaultLocale ?? Locales.ENGLISH,\n locales: project?.locales ?? [Locales.ENGLISH],\n fileContent: JSON.stringify(editedDictionary ?? dictionary),\n }).then((response) => {\n if (!response.data) return;\n\n const editedDictionary = JSON.parse(\n response.data.fileContent\n ) as Dictionary;\n\n setEditedContent(dictionary.key, editedDictionary.content);\n });\n\n return (\n <Form\n className=\"flex w-full flex-1 flex-row flex-wrap justify-end gap-3\"\n {...form}\n schema={SaveFormSchema}\n onSubmitSuccess={onSubmitSuccess}\n >\n <Form.Button\n type=\"button\"\n label={auditButton.label}\n disabled={isSubmitting}\n Icon={WandSparkles}\n variant=\"outline\"\n color=\"text\"\n className=\"ml-auto max-md:w-full\"\n isLoading={isAuditing}\n onClick={handleOnAuditFile}\n >\n {auditButton.text}\n </Form.Button>\n {isEdited && (\n <Form.Button\n type=\"button\"\n label={resetButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={RotateCcw}\n variant=\"outline\"\n color=\"text\"\n className=\"max-md:w-full\"\n onClick={() => restoreEditedContent(dictionary.key)}\n >\n {resetButton.text}\n </Form.Button>\n )}\n {mode === 'remote' ? (\n isLocalDictionary ? (\n <Form.Button\n type=\"submit\"\n label={publishButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={ArrowUpFromLine}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {publishButton.text}\n </Form.Button>\n ) : (\n isEdited && (\n <Form.Button\n type=\"submit\"\n label={saveButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Save}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {saveButton.text}\n </Form.Button>\n )\n )\n ) : (\n <Form.Button\n type=\"submit\"\n label={downloadButton.label}\n disabled={!isEdited || isSubmitting}\n Icon={Download}\n color=\"text\"\n className=\"max-md:w-full\"\n isLoading={isSubmitting}\n >\n {downloadButton.text}\n </Form.Button>\n )}\n </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ACCA,kCAAA;AAAA,UAAC,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,YAAY;AAAA,YACnB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAM;AAAA,YACN,SAAQ;AAAA,YACR,OAAM;AAAA,YACN,WAAU;AAAA,YACV,SAAS,MAAM,qBAAqB,WAAW,GAAG;AAAA,YAEjD,UAAY,YAAA;AAAA,UAAA;AAAA,QACf;AAAA,QAED,SAAS,WACR,oBACEA,kCAAA;AAAA,UAAC,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,cAAc;AAAA,YACrB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAM;AAAA,YACN,OAAM;AAAA,YACN,WAAU;AAAA,YACV,WAAW;AAAA,YAEV,UAAc,cAAA;AAAA,UAAA;AAAA,YAGjB,YACEA,kCAAA;AAAA,UAAC,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,WAAW;AAAA,YAClB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAM;AAAA,YACN,OAAM;AAAA,YACN,WAAU;AAAA,YACV,WAAW;AAAA,YAEV,UAAW,WAAA;AAAA,UAAA;AAAA,QAAA,IAKlBA,kCAAA;AAAA,UAAC,KAAK;AAAA,UAAL;AAAA,YACC,MAAK;AAAA,YACL,OAAO,eAAe;AAAA,YACtB,UAAU,CAAC,YAAY;AAAA,YACvB,MAAM;AAAA,YACN,OAAM;AAAA,YACN,WAAU;AAAA,YACV,WAAW;AAAA,YAEV,UAAe,eAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAClB;AAAA,IAAA;AAAA,EAEJ;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/design-system",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Intlayer design system, including UI components used in the Intlayer editor, website, and visual editor/CMS.",
|
|
6
6
|
"keywords": [
|
|
@@ -77,13 +77,13 @@
|
|
|
77
77
|
"tailwind-merge": "^2.6.0",
|
|
78
78
|
"zod": "^3.24.1",
|
|
79
79
|
"zustand": "^4.5.6",
|
|
80
|
-
"@intlayer/
|
|
81
|
-
"@intlayer/
|
|
82
|
-
"@intlayer/
|
|
83
|
-
"@intlayer/editor": "4.1.
|
|
84
|
-
"@intlayer/
|
|
85
|
-
"@intlayer/
|
|
86
|
-
"react-intlayer": "4.1.
|
|
80
|
+
"@intlayer/config": "4.1.3",
|
|
81
|
+
"@intlayer/core": "4.1.3",
|
|
82
|
+
"@intlayer/dictionaries-entry": "4.1.3",
|
|
83
|
+
"@intlayer/editor": "4.1.3",
|
|
84
|
+
"@intlayer/editor-react": "4.1.3",
|
|
85
|
+
"@intlayer/api": "4.1.3",
|
|
86
|
+
"react-intlayer": "4.1.3"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@chromatic-com/storybook": "^3.2.3",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"vite": "^6.0.11",
|
|
117
117
|
"vite-plugin-dts": "^4.5.0",
|
|
118
118
|
"vitest": "^2.1.8",
|
|
119
|
-
"@intlayer/backend": "4.1.
|
|
119
|
+
"@intlayer/backend": "4.1.3",
|
|
120
120
|
"@utils/eslint-config": "1.0.4",
|
|
121
121
|
"@utils/ts-config": "1.0.4",
|
|
122
122
|
"@utils/ts-config-types": "1.0.4",
|
|
@@ -127,18 +127,18 @@
|
|
|
127
127
|
"clsx": "^2.1.1",
|
|
128
128
|
"framer-motion": "^11.18.0",
|
|
129
129
|
"fuse.js": "^7.0.0",
|
|
130
|
-
"react": ">=
|
|
131
|
-
"react-dom": ">=
|
|
130
|
+
"react": ">=16.0.0",
|
|
131
|
+
"react-dom": ">=16.0.0",
|
|
132
132
|
"tailwind-merge": "^2.6.0",
|
|
133
133
|
"zustand": "^4.5.6",
|
|
134
|
-
"@intlayer/
|
|
135
|
-
"@intlayer/
|
|
136
|
-
"@intlayer/
|
|
137
|
-
"intlayer": "4.1.
|
|
138
|
-
"react-intlayer": "4.1.
|
|
139
|
-
"@intlayer/editor-react": "4.1.
|
|
140
|
-
"@intlayer/editor": "4.1.
|
|
141
|
-
"@intlayer/
|
|
134
|
+
"@intlayer/config": "4.1.3",
|
|
135
|
+
"@intlayer/core": "4.1.3",
|
|
136
|
+
"@intlayer/dictionaries-entry": "4.1.3",
|
|
137
|
+
"intlayer": "4.1.3",
|
|
138
|
+
"react-intlayer": "4.1.3",
|
|
139
|
+
"@intlayer/editor-react": "4.1.3",
|
|
140
|
+
"@intlayer/editor": "4.1.3",
|
|
141
|
+
"@intlayer/api": "4.1.3"
|
|
142
142
|
},
|
|
143
143
|
"scripts": {
|
|
144
144
|
"build": "pnpm build:package && pnpm build:css",
|