intlayer-editor 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/bin/start-server.js +16 -0
- package/dist/cjs/client/ContentEditionLayout.cjs +46 -0
- package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -0
- package/dist/cjs/client/ContentEditionLayout.d.ts +12 -0
- package/dist/cjs/client/ContentSelectorWrapper.cjs +49 -0
- package/dist/cjs/client/ContentSelectorWrapper.cjs.map +1 -0
- package/dist/cjs/client/ContentSelectorWrapper.d.ts +12 -0
- package/dist/cjs/client/EditionPanel/EditionPanel.cjs +101 -0
- package/dist/cjs/client/EditionPanel/EditionPanel.cjs.map +1 -0
- package/dist/cjs/client/EditionPanel/EditionPanel.d.ts +11 -0
- package/dist/cjs/client/EditionPanel/index.cjs +27 -0
- package/dist/cjs/client/EditionPanel/index.cjs.map +1 -0
- package/dist/cjs/client/EditionPanel/index.d.ts +9 -0
- package/dist/cjs/client/EditionPanel/useEditedContentStore.cjs +90 -0
- package/dist/cjs/client/EditionPanel/useEditedContentStore.cjs.map +1 -0
- package/dist/cjs/client/EditionPanel/useEditedContentStore.d.ts +28 -0
- package/dist/cjs/client/EditionPanel/useEditionPanelStore.cjs +33 -0
- package/dist/cjs/client/EditionPanel/useEditionPanelStore.cjs.map +1 -0
- package/dist/cjs/client/EditionPanel/useEditionPanelStore.d.ts +16 -0
- package/dist/cjs/client/index.cjs +29 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/client/index.d.ts +13 -0
- package/dist/cjs/client/renderContentSelector.cjs +39 -0
- package/dist/cjs/client/renderContentSelector.cjs.map +1 -0
- package/dist/cjs/client/renderContentSelector.d.ts +6 -0
- package/dist/cjs/client/useEditorServer.cjs +53 -0
- package/dist/cjs/client/useEditorServer.cjs.map +1 -0
- package/dist/cjs/client/useEditorServer.d.ts +5 -0
- package/dist/cjs/server/content-editor.cjs +156 -0
- package/dist/cjs/server/content-editor.cjs.map +1 -0
- package/dist/cjs/server/content-editor.d.ts +12 -0
- package/dist/cjs/server/index.cjs +68 -0
- package/dist/cjs/server/index.cjs.map +1 -0
- package/dist/cjs/server/index.d.ts +3 -0
- package/dist/esm/client/ContentEditionLayout.d.mts +12 -0
- package/dist/esm/client/ContentEditionLayout.mjs +22 -0
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -0
- package/dist/esm/client/ContentSelectorWrapper.d.mts +12 -0
- package/dist/esm/client/ContentSelectorWrapper.mjs +25 -0
- package/dist/esm/client/ContentSelectorWrapper.mjs.map +1 -0
- package/dist/esm/client/EditionPanel/EditionPanel.d.mts +11 -0
- package/dist/esm/client/EditionPanel/EditionPanel.mjs +72 -0
- package/dist/esm/client/EditionPanel/EditionPanel.mjs.map +1 -0
- package/dist/esm/client/EditionPanel/index.d.mts +9 -0
- package/dist/esm/client/EditionPanel/index.mjs +4 -0
- package/dist/esm/client/EditionPanel/index.mjs.map +1 -0
- package/dist/esm/client/EditionPanel/useEditedContentStore.d.mts +28 -0
- package/dist/esm/client/EditionPanel/useEditedContentStore.mjs +66 -0
- package/dist/esm/client/EditionPanel/useEditedContentStore.mjs.map +1 -0
- package/dist/esm/client/EditionPanel/useEditionPanelStore.d.mts +16 -0
- package/dist/esm/client/EditionPanel/useEditionPanelStore.mjs +9 -0
- package/dist/esm/client/EditionPanel/useEditionPanelStore.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +13 -0
- package/dist/esm/client/index.mjs +5 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/client/renderContentSelector.d.mts +6 -0
- package/dist/esm/client/renderContentSelector.mjs +15 -0
- package/dist/esm/client/renderContentSelector.mjs.map +1 -0
- package/dist/esm/client/useEditorServer.d.mts +5 -0
- package/dist/esm/client/useEditorServer.mjs +29 -0
- package/dist/esm/client/useEditorServer.mjs.map +1 -0
- package/dist/esm/server/content-editor.d.mts +12 -0
- package/dist/esm/server/content-editor.mjs +123 -0
- package/dist/esm/server/content-editor.mjs.map +1 -0
- package/dist/esm/server/index.d.mts +3 -0
- package/dist/esm/server/index.mjs +34 -0
- package/dist/esm/server/index.mjs.map +1 -0
- package/package.json +109 -0
- package/src/client/ContentEditionLayout.tsx +26 -0
- package/src/client/ContentSelectorWrapper.tsx +38 -0
- package/src/client/EditionPanel/EditionPanel.tsx +90 -0
- package/src/client/EditionPanel/index.ts +3 -0
- package/src/client/EditionPanel/useEditedContentStore.ts +98 -0
- package/src/client/EditionPanel/useEditionPanelStore.ts +19 -0
- package/src/client/index.ts +4 -0
- package/src/client/renderContentSelector.tsx +17 -0
- package/src/client/useEditorServer.ts +31 -0
- package/src/server/content-editor.ts +209 -0
- package/src/server/index.ts +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2021 Sébastien Vanvelthem
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Intlayer: Next-Level Content Management in JavaScript
|
|
2
|
+
|
|
3
|
+
**Intlayer** is an innovative Content Management System (CMS) designed specifically for JavaScript developers. It enables seamless transpilation of JavaScript content into structured dictionaries, making integration into your codebase straightforward and efficient.
|
|
4
|
+
|
|
5
|
+
## Why Choose Intlayer?
|
|
6
|
+
|
|
7
|
+
- **JavaScript-Powered Content Management**: Harness the flexibility of JavaScript to define and manage your content efficiently.
|
|
8
|
+
- **Type-Safe Environment**: Leverage TypeScript to ensure all your content definitions are precise and error-free.
|
|
9
|
+
- **Integrated Content Files**: Keep your translations close to their respective components, enhancing maintainability and clarity.
|
|
10
|
+
|
|
11
|
+
## intlayer package
|
|
12
|
+
|
|
13
|
+
`intlayer` package intend to declare your content in a structured way, using JavaScript.
|
|
14
|
+
|
|
15
|
+
To build dictionaries from this declaration, you can use [intlayer-cli](https://github.com/aypineau/intlayer/blob/main/packages/intlayer-cli/readme.md).
|
|
16
|
+
And to interpret intlayer dictionaries you can interpreters, such as [react-intlayer](https://github.com/aypineau/intlayer/blob/main/packages/react-intlayer/readme.md), or [next-intlayer](https://github.com/aypineau/intlayer/blob/main/packages/next-intlayer/readme.md)
|
|
17
|
+
|
|
18
|
+
## Getting Started with Intlayer
|
|
19
|
+
|
|
20
|
+
[See how to use intlayer with NextJS](https://github.com/aypineau/intlayer/blob/main/readme.md)
|
|
21
|
+
|
|
22
|
+
### Install Package
|
|
23
|
+
|
|
24
|
+
Install the necessary packages using npm:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install intlayer
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn install intlayer
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm install intlayer
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Manage Your Content
|
|
39
|
+
|
|
40
|
+
Create and manage your content dictionaries:
|
|
41
|
+
|
|
42
|
+
#### Using typescript
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// src/app/[locale]/page.content.ts
|
|
46
|
+
import { t, enu, type ContentModule } from "intlayer";
|
|
47
|
+
|
|
48
|
+
const pageContent: ContentModule = {
|
|
49
|
+
id: "page",
|
|
50
|
+
getStarted: {
|
|
51
|
+
main: t({
|
|
52
|
+
en: "Get started by editing",
|
|
53
|
+
fr: "Commencez par éditer",
|
|
54
|
+
es: "Comience por editar",
|
|
55
|
+
}),
|
|
56
|
+
pageLink: "src/app/page.tsx",
|
|
57
|
+
},
|
|
58
|
+
nestedContent: {
|
|
59
|
+
id: "enumeration",
|
|
60
|
+
numberOfCar: enu({
|
|
61
|
+
"<-1": "Less than minus one car",
|
|
62
|
+
"-1": "Minus one car",
|
|
63
|
+
"0": "No cars",
|
|
64
|
+
"1": "One car",
|
|
65
|
+
">5": "Some cars",
|
|
66
|
+
">19": "Many cars",
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Content should be exported as default
|
|
72
|
+
export default pageContent;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Using ECMAScript modules
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
// src/app/[locale]/page.content.mjs
|
|
79
|
+
|
|
80
|
+
import { t } from "intlayer";
|
|
81
|
+
|
|
82
|
+
/** @type {import('intlayer').ContentModule} */
|
|
83
|
+
const pageContent = {
|
|
84
|
+
id: "page",
|
|
85
|
+
getStarted: {
|
|
86
|
+
main: t({
|
|
87
|
+
en: "Get started by editing",
|
|
88
|
+
fr: "Commencez par éditer",
|
|
89
|
+
es: "Comience por editar",
|
|
90
|
+
}),
|
|
91
|
+
pageLink: "src/app/page.tsx",
|
|
92
|
+
},
|
|
93
|
+
nestedContent: {
|
|
94
|
+
id: "enumeration",
|
|
95
|
+
numberOfCar: enu({
|
|
96
|
+
"<-1": "Less than minus one car",
|
|
97
|
+
"-1": "Minus one car",
|
|
98
|
+
"0": "No cars",
|
|
99
|
+
"1": "One car",
|
|
100
|
+
">5": "Some cars",
|
|
101
|
+
">19": "Many cars",
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Content should be exported as default
|
|
107
|
+
export default pageContent;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Using CommonJS modules
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
// src/app/[locale]/page.content.cjs
|
|
114
|
+
|
|
115
|
+
const { t } = require("intlayer");
|
|
116
|
+
|
|
117
|
+
/** @type {import('intlayer').ContentModule} */
|
|
118
|
+
const pageContent = {
|
|
119
|
+
id: "page",
|
|
120
|
+
getStarted: {
|
|
121
|
+
main: t({
|
|
122
|
+
en: "Get started by editing",
|
|
123
|
+
fr: "Commencez par éditer",
|
|
124
|
+
es: "Comience por editar",
|
|
125
|
+
}),
|
|
126
|
+
pageLink: "src/app/page.tsx",
|
|
127
|
+
},
|
|
128
|
+
nestedContent: {
|
|
129
|
+
id: "enumeration",
|
|
130
|
+
numberOfCar: enu({
|
|
131
|
+
"<-1": "Less than minus one car",
|
|
132
|
+
"-1": "Minus one car",
|
|
133
|
+
"0": "No cars",
|
|
134
|
+
"1": "One car",
|
|
135
|
+
">5": "Some cars",
|
|
136
|
+
">19": "Many cars",
|
|
137
|
+
}),
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Content should be exported as default
|
|
142
|
+
module.exports = pageContent;
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Using JSON
|
|
146
|
+
|
|
147
|
+
```json5
|
|
148
|
+
// src/app/[locale]/page.content.json
|
|
149
|
+
{
|
|
150
|
+
"id": "page",
|
|
151
|
+
"getStarted": {
|
|
152
|
+
"main": {
|
|
153
|
+
"nodeType": "translation",
|
|
154
|
+
"en": "Get started by editing",
|
|
155
|
+
"fr": "Commencez par éditer",
|
|
156
|
+
"es": "Comience por editar",
|
|
157
|
+
},
|
|
158
|
+
"pageLink": "src/app/page.tsx",
|
|
159
|
+
},
|
|
160
|
+
"nestedContent": {
|
|
161
|
+
"id": "enumeration",
|
|
162
|
+
"nodeType": "enumeration",
|
|
163
|
+
"numberOfCar": {
|
|
164
|
+
"<-1": "Less than minus one car",
|
|
165
|
+
"-1": "Minus one car",
|
|
166
|
+
"0": "No cars",
|
|
167
|
+
"1": "One car",
|
|
168
|
+
">5": "Some cars",
|
|
169
|
+
">19": "Many cars",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
This version emphasizes ease of use, practical steps, and the professional application of Intlayer in a Next.js environment.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const { startIntlayerEditor } = require('../dist/cjs/server/index.cjs');
|
|
5
|
+
const pkg = require('../package.json');
|
|
6
|
+
|
|
7
|
+
program
|
|
8
|
+
.version(pkg.version)
|
|
9
|
+
.description('Command-line interface to start the Intlayer Editor server');
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.command('start')
|
|
13
|
+
.description('Start the Intlayer editor server')
|
|
14
|
+
.action(() => startIntlayerEditor());
|
|
15
|
+
|
|
16
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ContentEditionLayout_exports = {};
|
|
20
|
+
__export(ContentEditionLayout_exports, {
|
|
21
|
+
ContentEditionLayout: () => ContentEditionLayout
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ContentEditionLayout_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_EditionPanel = require('./EditionPanel/index.cjs');
|
|
26
|
+
const ContentEditionLayout = ({
|
|
27
|
+
children,
|
|
28
|
+
locale,
|
|
29
|
+
setLocale,
|
|
30
|
+
localeList
|
|
31
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
32
|
+
children,
|
|
33
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
import_EditionPanel.EditionPanel,
|
|
35
|
+
{
|
|
36
|
+
locale,
|
|
37
|
+
localeList,
|
|
38
|
+
setLocale
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
] });
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
ContentEditionLayout
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=ContentEditionLayout.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { FC, ReactNode } from 'react';\nimport { EditionPanel } from './EditionPanel/index';\n\nexport type ContentEditionLayoutProps = {\n children?: ReactNode;\n locale: Locales;\n localeList: Locales[];\n setLocale: (locale: Locales) => void;\n};\n\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> = ({\n children,\n locale,\n setLocale,\n localeList,\n}) => (\n <>\n {children}\n <EditionPanel\n locale={locale}\n localeList={localeList}\n setLocale={setLocale}\n />\n </>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBE;AAfF,0BAA6B;AAStB,MAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACE,4EACG;AAAA;AAAA,EACD;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAAA,GACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { ReactNode, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
type ContentEditionLayoutProps = {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
locale: Locales;
|
|
7
|
+
localeList: Locales[];
|
|
8
|
+
setLocale: (locale: Locales) => void;
|
|
9
|
+
};
|
|
10
|
+
declare const ContentEditionLayout: FC<ContentEditionLayoutProps>;
|
|
11
|
+
|
|
12
|
+
export { ContentEditionLayout, type ContentEditionLayoutProps };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var ContentSelectorWrapper_exports = {};
|
|
21
|
+
__export(ContentSelectorWrapper_exports, {
|
|
22
|
+
ContentSelectorWrapper: () => ContentSelectorWrapper
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ContentSelectorWrapper_exports);
|
|
25
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_design_system = require("@intlayer/design-system");
|
|
27
|
+
var import_useEditedContentStore = require('./EditionPanel/useEditedContentStore.cjs');
|
|
28
|
+
var import_useEditionPanelStore = require('./EditionPanel/useEditionPanelStore.cjs');
|
|
29
|
+
const ContentSelectorWrapper = ({
|
|
30
|
+
children,
|
|
31
|
+
dictionaryId,
|
|
32
|
+
dictionaryPath,
|
|
33
|
+
keyPath
|
|
34
|
+
}) => {
|
|
35
|
+
const { setFocusedContent } = (0, import_useEditionPanelStore.useEditionPanelStore)();
|
|
36
|
+
const handleSelect = () => setFocusedContent({
|
|
37
|
+
dictionaryId,
|
|
38
|
+
dictionaryPath,
|
|
39
|
+
keyPath
|
|
40
|
+
});
|
|
41
|
+
const { getEditedContentValue } = (0, import_useEditedContentStore.useEditedContentStore)();
|
|
42
|
+
const editedValue = getEditedContentValue(dictionaryPath, keyPath);
|
|
43
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_design_system.ContentSelector, { onSelect: handleSelect, children: editedValue ?? children });
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
ContentSelectorWrapper
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=ContentSelectorWrapper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { ContentSelector } from '@intlayer/design-system';\nimport type { FC } from 'react';\nimport { useEditedContentStore } from './EditionPanel/useEditedContentStore';\nimport { useEditionPanelStore } from './EditionPanel/useEditionPanelStore';\n\ntype ContentSelectorWrapperProps = {\n children: string;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryId,\n dictionaryPath,\n keyPath,\n}) => {\n const { setFocusedContent } = useEditionPanelStore();\n const handleSelect = () =>\n setFocusedContent({\n dictionaryId,\n dictionaryPath,\n keyPath,\n });\n\n const { getEditedContentValue } = useEditedContentStore();\n const editedValue = getEditedContentValue(dictionaryPath, keyPath);\n\n return (\n <ContentSelector onSelect={handleSelect}>\n {editedValue ?? children}\n </ContentSelector>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCI;AA9BJ,2BAAgC;AAEhC,mCAAsC;AACtC,kCAAqC;AAS9B,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,kBAAkB,QAAI,kDAAqB;AACnD,QAAM,eAAe,MACnB,kBAAkB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAEH,QAAM,EAAE,sBAAsB,QAAI,oDAAsB;AACxD,QAAM,cAAc,sBAAsB,gBAAgB,OAAO;AAEjE,SACE,4CAAC,wCAAgB,UAAU,cACxB,yBAAe,UAClB;AAEJ;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { KeyPath } from '@intlayer/core';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
|
|
4
|
+
type ContentSelectorWrapperProps = {
|
|
5
|
+
children: string;
|
|
6
|
+
dictionaryId: string;
|
|
7
|
+
dictionaryPath: string;
|
|
8
|
+
keyPath: KeyPath[];
|
|
9
|
+
};
|
|
10
|
+
declare const ContentSelectorWrapper: FC<ContentSelectorWrapperProps>;
|
|
11
|
+
|
|
12
|
+
export { ContentSelectorWrapper };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var EditionPanel_exports = {};
|
|
31
|
+
__export(EditionPanel_exports, {
|
|
32
|
+
EditionPanel: () => EditionPanel
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(EditionPanel_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var import_design_system = require("@intlayer/design-system");
|
|
37
|
+
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_useEditorServer = require('../useEditorServer.cjs');
|
|
40
|
+
var import_useEditedContentStore = require('./useEditedContentStore.cjs');
|
|
41
|
+
var import_useEditionPanelStore = require('./useEditionPanelStore.cjs');
|
|
42
|
+
const EditionPanel = ({
|
|
43
|
+
locale,
|
|
44
|
+
localeList,
|
|
45
|
+
setLocale
|
|
46
|
+
}) => {
|
|
47
|
+
const { open } = (0, import_design_system.useRightDrawerStore)();
|
|
48
|
+
const { focusedContent, setFocusedContent } = (0, import_useEditionPanelStore.useEditionPanelStore)();
|
|
49
|
+
const { editedContent, addEditedContent, clearEditedDictionaryContent } = (0, import_useEditedContentStore.useEditedContentStore)();
|
|
50
|
+
const { editContentRequest } = (0, import_useEditorServer.useEditorServer)();
|
|
51
|
+
(0, import_react.useEffect)(() => {
|
|
52
|
+
if (focusedContent !== null) {
|
|
53
|
+
open();
|
|
54
|
+
}
|
|
55
|
+
}, [focusedContent, open]);
|
|
56
|
+
if (!focusedContent) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const dictionary = import_dictionaries_entry.default[focusedContent.dictionaryId];
|
|
60
|
+
if (!dictionary?.filePath) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const dictionaryPath = dictionary.filePath;
|
|
64
|
+
const editedDictionaryContent = editedContent[dictionaryPath] ?? [];
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
66
|
+
import_design_system.RightDrawer,
|
|
67
|
+
{
|
|
68
|
+
title: dictionary.id,
|
|
69
|
+
label: `Edit dictionary ${dictionary.id}`,
|
|
70
|
+
header: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
71
|
+
import_design_system.LocaleSwitcher,
|
|
72
|
+
{
|
|
73
|
+
setLocale,
|
|
74
|
+
locale,
|
|
75
|
+
localeList
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
79
|
+
import_design_system.DictionaryEditor,
|
|
80
|
+
{
|
|
81
|
+
dictionary,
|
|
82
|
+
locale,
|
|
83
|
+
focusedKeyPath: focusedContent.keyPath,
|
|
84
|
+
editedContent: editedDictionaryContent,
|
|
85
|
+
onFocusKeyPath: (keyPath) => setFocusedContent({ ...focusedContent, keyPath }),
|
|
86
|
+
onContentChange: (keyPath, newValue) => addEditedContent(dictionaryPath, keyPath, newValue),
|
|
87
|
+
onValidEdition: editContentRequest,
|
|
88
|
+
onCancelEdition: () => {
|
|
89
|
+
clearEditedDictionaryContent(dictionaryPath);
|
|
90
|
+
setFocusedContent(null);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
EditionPanel
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=EditionPanel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/EditionPanel/EditionPanel.tsx"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { ContentModule } from '@intlayer/core';\nimport {\n useRightDrawerStore,\n RightDrawer,\n DictionaryEditor,\n LocaleSwitcher,\n} from '@intlayer/design-system';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport { type FC, useEffect } from 'react';\nimport { useEditorServer } from '../useEditorServer';\nimport { useEditedContentStore } from './useEditedContentStore';\nimport { useEditionPanelStore } from './useEditionPanelStore';\n\ntype EditionPanelProps = {\n locale: Locales;\n localeList: Locales[];\n setLocale: (locale: Locales) => void;\n};\n\nexport const EditionPanel: FC<EditionPanelProps> = ({\n locale,\n localeList,\n setLocale,\n}) => {\n const { open } = useRightDrawerStore();\n const { focusedContent, setFocusedContent } = useEditionPanelStore();\n const { editedContent, addEditedContent, clearEditedDictionaryContent } =\n useEditedContentStore();\n const { editContentRequest } = useEditorServer();\n\n // Use effect to react to changes in focusedContent\n useEffect(() => {\n if (focusedContent !== null) {\n open(); // Call the open function from useRightDrawerStore\n }\n }, [focusedContent, open]); // Depend on focusedContent and open to trigger the effect\n\n if (!focusedContent) {\n return null;\n }\n\n const dictionary: ContentModule = dictionaries[focusedContent.dictionaryId];\n\n if (!dictionary?.filePath) {\n return null;\n }\n\n const dictionaryPath = dictionary.filePath;\n const editedDictionaryContent = editedContent[dictionaryPath] ?? [];\n\n return (\n <RightDrawer\n title={dictionary.id}\n label={`Edit dictionary ${dictionary.id}`}\n header={\n <LocaleSwitcher\n setLocale={setLocale}\n locale={locale}\n localeList={localeList}\n />\n }\n >\n <DictionaryEditor\n dictionary={dictionary}\n locale={locale}\n focusedKeyPath={focusedContent.keyPath}\n editedContent={editedDictionaryContent}\n onFocusKeyPath={(keyPath) =>\n setFocusedContent({ ...focusedContent, keyPath })\n }\n onContentChange={(keyPath, newValue) =>\n addEditedContent(dictionaryPath, keyPath, newValue)\n }\n onValidEdition={editContentRequest}\n onCancelEdition={() => {\n clearEditedDictionaryContent(dictionaryPath);\n setFocusedContent(null);\n }}\n />\n </RightDrawer>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+DQ;AA3DR,2BAKO;AAMP,gCAAyB;AACzB,mBAAmC;AACnC,6BAAgC;AAChC,mCAAsC;AACtC,kCAAqC;AAQ9B,MAAM,eAAsC,CAAC;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,KAAK,QAAI,0CAAoB;AACrC,QAAM,EAAE,gBAAgB,kBAAkB,QAAI,kDAAqB;AACnE,QAAM,EAAE,eAAe,kBAAkB,6BAA6B,QACpE,oDAAsB;AACxB,QAAM,EAAE,mBAAmB,QAAI,wCAAgB;AAG/C,8BAAU,MAAM;AACd,QAAI,mBAAmB,MAAM;AAC3B,WAAK;AAAA,IACP;AAAA,EACF,GAAG,CAAC,gBAAgB,IAAI,CAAC;AAEzB,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AAEA,QAAM,aAA4B,0BAAAA,QAAa,eAAe,YAAY;AAE1E,MAAI,CAAC,YAAY,UAAU;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,WAAW;AAClC,QAAM,0BAA0B,cAAc,cAAc,KAAK,CAAC;AAElE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,WAAW;AAAA,MAClB,OAAO,mBAAmB,WAAW,EAAE;AAAA,MACvC,QACE;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACF;AAAA,MAGF;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,gBAAgB,eAAe;AAAA,UAC/B,eAAe;AAAA,UACf,gBAAgB,CAAC,YACf,kBAAkB,EAAE,GAAG,gBAAgB,QAAQ,CAAC;AAAA,UAElD,iBAAiB,CAAC,SAAS,aACzB,iBAAiB,gBAAgB,SAAS,QAAQ;AAAA,UAEpD,gBAAgB;AAAA,UAChB,iBAAiB,MAAM;AACrB,yCAA6B,cAAc;AAC3C,8BAAkB,IAAI;AAAA,UACxB;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;","names":["dictionaries"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
|
|
4
|
+
type EditionPanelProps = {
|
|
5
|
+
locale: Locales;
|
|
6
|
+
localeList: Locales[];
|
|
7
|
+
setLocale: (locale: Locales) => void;
|
|
8
|
+
};
|
|
9
|
+
declare const EditionPanel: FC<EditionPanelProps>;
|
|
10
|
+
|
|
11
|
+
export { EditionPanel };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var EditionPanel_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(EditionPanel_exports);
|
|
18
|
+
__reExport(EditionPanel_exports, require('./EditionPanel.cjs'), module.exports);
|
|
19
|
+
__reExport(EditionPanel_exports, require('./useEditionPanelStore.cjs'), module.exports);
|
|
20
|
+
__reExport(EditionPanel_exports, require('./useEditedContentStore.cjs'), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require('./EditionPanel.cjs'),
|
|
24
|
+
...require('./useEditionPanelStore.cjs'),
|
|
25
|
+
...require('./useEditedContentStore.cjs')
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/EditionPanel/index.ts"],"sourcesContent":["export * from './EditionPanel';\nexport * from './useEditionPanelStore';\nexport * from './useEditedContentStore';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,iCAAc,2BAAd;AACA,iCAAc,mCADd;AAEA,iCAAc,oCAFd;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { EditionPanel } from './EditionPanel.js';
|
|
2
|
+
export { useEditionPanelStore } from './useEditionPanelStore.js';
|
|
3
|
+
export { EditedContent, useEditedContentStore } from './useEditedContentStore.js';
|
|
4
|
+
import '@intlayer/config/client';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'zustand';
|
|
7
|
+
import '@intlayer/core';
|
|
8
|
+
import 'zustand/middleware';
|
|
9
|
+
import '@intlayer/design-system';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useEditedContentStore_exports = {};
|
|
20
|
+
__export(useEditedContentStore_exports, {
|
|
21
|
+
useEditedContentStore: () => useEditedContentStore
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useEditedContentStore_exports);
|
|
24
|
+
var import_zustand = require("zustand");
|
|
25
|
+
var import_middleware = require("zustand/middleware");
|
|
26
|
+
const isSameKeyPath = (keyPath1, keyPath2) => keyPath1.every(
|
|
27
|
+
(element, index) => keyPath2[index] && keyPath2[index].key === element.key && keyPath2[index].type === element.type
|
|
28
|
+
);
|
|
29
|
+
const useEditedContentStore = (0, import_zustand.create)(
|
|
30
|
+
(0, import_middleware.persist)(
|
|
31
|
+
(set, get) => ({
|
|
32
|
+
editedContent: {},
|
|
33
|
+
addEditedContent: (dictionaryPath, keyPath, newValue) => {
|
|
34
|
+
set((state) => {
|
|
35
|
+
const editedContent = state.editedContent[dictionaryPath] ?? [];
|
|
36
|
+
return {
|
|
37
|
+
editedContent: {
|
|
38
|
+
...state.editedContent,
|
|
39
|
+
[dictionaryPath]: [
|
|
40
|
+
...editedContent.filter(
|
|
41
|
+
(content) => !isSameKeyPath(content.keyPath, keyPath)
|
|
42
|
+
),
|
|
43
|
+
{
|
|
44
|
+
keyPath,
|
|
45
|
+
newValue
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
removeEditedContent: (dictionaryPath, keyPath) => {
|
|
53
|
+
set((state) => {
|
|
54
|
+
const editedContent = state.editedContent[dictionaryPath] ?? [];
|
|
55
|
+
return {
|
|
56
|
+
editedContent: {
|
|
57
|
+
...state.editedContent,
|
|
58
|
+
[dictionaryPath]: editedContent.filter(
|
|
59
|
+
(content) => content.keyPath !== keyPath
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
clearEditedDictionaryContent: (dictionaryPath) => {
|
|
66
|
+
set((state) => ({
|
|
67
|
+
editedContent: {
|
|
68
|
+
...state.editedContent,
|
|
69
|
+
[dictionaryPath]: []
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
clearEditedContent: () => {
|
|
74
|
+
set({ editedContent: {} });
|
|
75
|
+
},
|
|
76
|
+
getEditedContentValue: (dictionaryPath, keyPath) => get().editedContent[dictionaryPath]?.find(
|
|
77
|
+
(content) => isSameKeyPath(content.keyPath, keyPath)
|
|
78
|
+
)?.newValue
|
|
79
|
+
}),
|
|
80
|
+
{
|
|
81
|
+
name: "edited-content-store",
|
|
82
|
+
storage: (0, import_middleware.createJSONStorage)(() => sessionStorage)
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
useEditedContentStore
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=useEditedContentStore.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/EditionPanel/useEditedContentStore.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport type { FileContent } from '@intlayer/design-system';\nimport { create } from 'zustand';\nimport { persist, createJSONStorage } from 'zustand/middleware';\n\ntype DictionaryPath = string;\n\nexport type EditedContent = Record<DictionaryPath, FileContent[]>;\n\ntype EditedContentStore = {\n editedContent: EditedContent;\n addEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[],\n newValue: string\n ) => void;\n removeEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => void;\n clearEditedDictionaryContent: (dictionaryPath: DictionaryPath) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => string | undefined;\n};\n\nconst isSameKeyPath = (keyPath1: KeyPath[], keyPath2: KeyPath[]) =>\n keyPath1.every(\n (element, index) =>\n keyPath2[index] &&\n keyPath2[index].key === element.key &&\n keyPath2[index].type === element.type\n );\n\nexport const useEditedContentStore = create(\n persist<EditedContentStore>(\n (set, get) => ({\n editedContent: {},\n addEditedContent: (dictionaryPath, keyPath, newValue) => {\n set((state) => {\n const editedContent = state.editedContent[dictionaryPath] ?? [];\n return {\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: [\n ...editedContent.filter(\n (content) => !isSameKeyPath(content.keyPath, keyPath)\n ),\n {\n keyPath,\n newValue,\n },\n ],\n },\n };\n });\n },\n\n removeEditedContent: (dictionaryPath, keyPath) => {\n set((state) => {\n const editedContent = state.editedContent[dictionaryPath] ?? [];\n return {\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: editedContent.filter(\n (content) => content.keyPath !== keyPath\n ),\n },\n };\n });\n },\n\n clearEditedDictionaryContent: (dictionaryPath) => {\n set((state) => ({\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: [],\n },\n }));\n },\n\n clearEditedContent: () => {\n set({ editedContent: {} });\n },\n\n getEditedContentValue: (dictionaryPath, keyPath): string | undefined =>\n get().editedContent[dictionaryPath]?.find((content) =>\n isSameKeyPath(content.keyPath, keyPath)\n )?.newValue,\n }),\n {\n name: 'edited-content-store',\n storage: createJSONStorage(() => sessionStorage),\n }\n )\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAuB;AACvB,wBAA2C;AAyB3C,MAAM,gBAAgB,CAAC,UAAqB,aAC1C,SAAS;AAAA,EACP,CAAC,SAAS,UACR,SAAS,KAAK,KACd,SAAS,KAAK,EAAE,QAAQ,QAAQ,OAChC,SAAS,KAAK,EAAE,SAAS,QAAQ;AACrC;AAEK,MAAM,4BAAwB;AAAA,MACnC;AAAA,IACE,CAAC,KAAK,SAAS;AAAA,MACb,eAAe,CAAC;AAAA,MAChB,kBAAkB,CAAC,gBAAgB,SAAS,aAAa;AACvD,YAAI,CAAC,UAAU;AACb,gBAAM,gBAAgB,MAAM,cAAc,cAAc,KAAK,CAAC;AAC9D,iBAAO;AAAA,YACL,eAAe;AAAA,cACb,GAAG,MAAM;AAAA,cACT,CAAC,cAAc,GAAG;AAAA,gBAChB,GAAG,cAAc;AAAA,kBACf,CAAC,YAAY,CAAC,cAAc,QAAQ,SAAS,OAAO;AAAA,gBACtD;AAAA,gBACA;AAAA,kBACE;AAAA,kBACA;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MAEA,qBAAqB,CAAC,gBAAgB,YAAY;AAChD,YAAI,CAAC,UAAU;AACb,gBAAM,gBAAgB,MAAM,cAAc,cAAc,KAAK,CAAC;AAC9D,iBAAO;AAAA,YACL,eAAe;AAAA,cACb,GAAG,MAAM;AAAA,cACT,CAAC,cAAc,GAAG,cAAc;AAAA,gBAC9B,CAAC,YAAY,QAAQ,YAAY;AAAA,cACnC;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MAEA,8BAA8B,CAAC,mBAAmB;AAChD,YAAI,CAAC,WAAW;AAAA,UACd,eAAe;AAAA,YACb,GAAG,MAAM;AAAA,YACT,CAAC,cAAc,GAAG,CAAC;AAAA,UACrB;AAAA,QACF,EAAE;AAAA,MACJ;AAAA,MAEA,oBAAoB,MAAM;AACxB,YAAI,EAAE,eAAe,CAAC,EAAE,CAAC;AAAA,MAC3B;AAAA,MAEA,uBAAuB,CAAC,gBAAgB,YACtC,IAAI,EAAE,cAAc,cAAc,GAAG;AAAA,QAAK,CAAC,YACzC,cAAc,QAAQ,SAAS,OAAO;AAAA,MACxC,GAAG;AAAA,IACP;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,aAAS,qCAAkB,MAAM,cAAc;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
2
|
+
import * as zustand from 'zustand';
|
|
3
|
+
import { KeyPath } from '@intlayer/core';
|
|
4
|
+
import { FileContent } from '@intlayer/design-system';
|
|
5
|
+
|
|
6
|
+
type DictionaryPath = string;
|
|
7
|
+
type EditedContent = Record<DictionaryPath, FileContent[]>;
|
|
8
|
+
type EditedContentStore = {
|
|
9
|
+
editedContent: EditedContent;
|
|
10
|
+
addEditedContent: (dictionaryPath: DictionaryPath, keyPath: KeyPath[], newValue: string) => void;
|
|
11
|
+
removeEditedContent: (dictionaryPath: DictionaryPath, keyPath: KeyPath[]) => void;
|
|
12
|
+
clearEditedDictionaryContent: (dictionaryPath: DictionaryPath) => void;
|
|
13
|
+
clearEditedContent: () => void;
|
|
14
|
+
getEditedContentValue: (dictionaryPath: DictionaryPath, keyPath: KeyPath[]) => string | undefined;
|
|
15
|
+
};
|
|
16
|
+
declare const useEditedContentStore: zustand.UseBoundStore<Omit<zustand.StoreApi<EditedContentStore>, "persist"> & {
|
|
17
|
+
persist: {
|
|
18
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<EditedContentStore, EditedContentStore>>) => void;
|
|
19
|
+
clearStorage: () => void;
|
|
20
|
+
rehydrate: () => void | Promise<void>;
|
|
21
|
+
hasHydrated: () => boolean;
|
|
22
|
+
onHydrate: (fn: (state: EditedContentStore) => void) => () => void;
|
|
23
|
+
onFinishHydration: (fn: (state: EditedContentStore) => void) => () => void;
|
|
24
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<EditedContentStore, EditedContentStore>>;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
export { type EditedContent, useEditedContentStore };
|