react-intlayer 4.0.0 → 4.0.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/README.md +97 -193
- package/dist/cjs/UI/ContentSelector.cjs +126 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
- package/dist/cjs/UI/PressableSpan/index.cjs +23 -0
- package/dist/cjs/UI/PressableSpan/index.cjs.map +1 -0
- package/dist/cjs/client/IntlayerProvider.cjs +5 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/{utils/PoweredByMeta/index.cjs → client/PoweredByMeta.cjs} +1 -1
- package/dist/cjs/client/PoweredByMeta.cjs.map +1 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +39 -2
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +11 -6
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +0 -2
- package/dist/cjs/editor/index.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +2 -2
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +107 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -0
- package/dist/esm/UI/PressableSpan/index.mjs +2 -0
- package/dist/esm/UI/PressableSpan/index.mjs.map +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +6 -2
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/{utils/PoweredByMeta/index.mjs → client/PoweredByMeta.mjs} +1 -1
- package/dist/esm/client/PoweredByMeta.mjs.map +1 -0
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +48 -3
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +12 -7
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +0 -1
- package/dist/esm/editor/index.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +2 -2
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts +10 -0
- package/dist/types/UI/ContentSelector.d.ts.map +1 -0
- package/dist/types/UI/PressableSpan/index.d.ts +2 -0
- package/dist/types/UI/PressableSpan/index.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/{utils/PoweredByMeta/index.d.ts → client/PoweredByMeta.d.ts} +1 -1
- package/dist/types/client/PoweredByMeta.d.ts.map +1 -0
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -3
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +0 -1
- package/dist/types/editor/index.d.ts.map +1 -1
- package/package.json +16 -23
- package/dist/cjs/editor/ContentSelectorConnector.cjs +0 -58
- package/dist/cjs/editor/ContentSelectorConnector.cjs.map +0 -1
- package/dist/cjs/utils/PoweredByMeta/index.cjs.map +0 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs +0 -38
- package/dist/esm/editor/ContentSelectorConnector.mjs.map +0 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +0 -1
- package/dist/types/editor/ContentSelectorConnector.d.ts +0 -14
- package/dist/types/editor/ContentSelectorConnector.d.ts.map +0 -1
- package/dist/types/utils/PoweredByMeta/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -17,259 +17,163 @@
|
|
|
17
17
|
</a>
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
#
|
|
20
|
+
# react-intlayer: Internationalize (i18n) an React application
|
|
21
21
|
|
|
22
|
-
**Intlayer** is
|
|
22
|
+
**Intlayer** is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, React, and Express.js.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
.
|
|
28
|
-
├── Component1
|
|
29
|
-
│ ├── index.content.ts
|
|
30
|
-
│ └── index.tsx
|
|
31
|
-
└── Component2
|
|
32
|
-
├── index.content.ts
|
|
33
|
-
└── index.tsx
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
// ./Component1/index.content.ts
|
|
38
|
-
|
|
39
|
-
import { type DeclarationContent, t } from "intlayer";
|
|
40
|
-
|
|
41
|
-
const component1Content = {
|
|
42
|
-
key: "component1",
|
|
43
|
-
content: {
|
|
44
|
-
myTranslatedContent: t({
|
|
45
|
-
en: "Hello World",
|
|
46
|
-
fr: "Bonjour le monde",
|
|
47
|
-
es: "Hola Mundo",
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
50
|
-
} satisfies DeclarationContent;
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
// ./Component1/index.tsx
|
|
55
|
-
|
|
56
|
-
import { useIntlayer } from "react-intlayer";
|
|
24
|
+
**The `react-intlayer` package** allows you to internationalize your React application. It provides context providers and hooks for React internationalization.
|
|
57
25
|
|
|
58
|
-
|
|
59
|
-
const { myTranslatedContent } = useIntlayer("component1");
|
|
26
|
+
## Why Internationalize Your React Application?
|
|
60
27
|
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
```
|
|
28
|
+
Internationalizing your React application is essential for serving a global audience effectively. It allows your application to deliver content and messages in the preferred language of each user. This capability enhances user experience and broadens your application's reach by making it more accessible and relevant to people from different linguistic backgrounds.
|
|
64
29
|
|
|
65
|
-
## Why
|
|
30
|
+
## Why to integrate Intlayer?
|
|
66
31
|
|
|
67
32
|
- **JavaScript-Powered Content Management**: Harness the flexibility of JavaScript to define and manage your content efficiently.
|
|
68
33
|
- **Type-Safe Environment**: Leverage TypeScript to ensure all your content definitions are precise and error-free.
|
|
69
34
|
- **Integrated Content Files**: Keep your translations close to their respective components, enhancing maintainability and clarity.
|
|
70
|
-
- **Simplified Setup**: Get up and running quickly with minimal configuration, especially optimized for Next.js projects.
|
|
71
|
-
- **Server Component Support**: Perfectly suited for Next.js server components, ensuring smooth server-side rendering.
|
|
72
|
-
- **Enhanced Routing**: Full support for Next.js app routing, adapting seamlessly to complex application structures.
|
|
73
|
-
|
|
74
|
-
# Getting Started with Intlayer and React Create App
|
|
75
|
-
|
|
76
|
-
Setting up Intlayer in a Create React App application is straightforward:
|
|
77
35
|
|
|
78
|
-
##
|
|
36
|
+
## Installation
|
|
79
37
|
|
|
80
|
-
Install the necessary
|
|
38
|
+
Install the necessary package using your preferred package manager:
|
|
81
39
|
|
|
82
|
-
```bash
|
|
83
|
-
npm install
|
|
40
|
+
```bash packageManager="npm"
|
|
41
|
+
npm install react-intlayer
|
|
84
42
|
```
|
|
85
43
|
|
|
86
|
-
```bash
|
|
87
|
-
yarn add
|
|
44
|
+
```bash packageManager="yarn"
|
|
45
|
+
yarn add react-intlayer
|
|
88
46
|
```
|
|
89
47
|
|
|
90
|
-
```bash
|
|
91
|
-
pnpm add
|
|
48
|
+
```bash packageManager="pnpm"
|
|
49
|
+
pnpm add react-intlayer
|
|
92
50
|
```
|
|
93
51
|
|
|
94
|
-
##
|
|
95
|
-
|
|
96
|
-
Create a config file to configure the languages of your application:
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
// intlayer.config.ts
|
|
100
|
-
|
|
101
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
102
|
-
|
|
103
|
-
const config: IntlayerConfig = {
|
|
104
|
-
internationalization: {
|
|
105
|
-
locales: [
|
|
106
|
-
Locales.ENGLISH,
|
|
107
|
-
Locales.FRENCH,
|
|
108
|
-
Locales.SPANISH,
|
|
109
|
-
// Your other locales
|
|
110
|
-
],
|
|
111
|
-
defaultLocale: Locales.ENGLISH,
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export default config;
|
|
116
|
-
```
|
|
52
|
+
## Example of usage
|
|
117
53
|
|
|
118
|
-
|
|
54
|
+
With Intlayer, you can declare your content in a structured way anywhere in your codebase.
|
|
119
55
|
|
|
120
|
-
|
|
56
|
+
By default, Intlayer scans for files with the extension `.content.{ts,tsx,js,jsx,mjs,cjs}`.
|
|
121
57
|
|
|
122
|
-
|
|
58
|
+
> You can modify the default extension by setting the `contentDir` property in the [configuration file](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
|
|
123
59
|
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
60
|
+
```bash codeFormat="typescript"
|
|
61
|
+
.
|
|
62
|
+
├── intlayer.config.ts
|
|
63
|
+
└── src
|
|
64
|
+
└── components
|
|
65
|
+
├── Component1
|
|
66
|
+
│ ├── index.content.ts
|
|
67
|
+
│ └── index.tsx
|
|
68
|
+
└── Component2
|
|
69
|
+
├── index.content.ts
|
|
70
|
+
└── index.tsx
|
|
130
71
|
```
|
|
131
72
|
|
|
132
|
-
|
|
73
|
+
### Declare your content
|
|
133
74
|
|
|
134
|
-
|
|
75
|
+
`react-intlayer` is made to work with the [`intlayer` package](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/index.md).`intlayer` is a package that allows you to declare your content anywhere in your code. It converts multilingual content declarations into structured dictionaries that integrate seamlessly into your application.
|
|
135
76
|
|
|
136
|
-
|
|
77
|
+
Here’s an example of content declaration:
|
|
137
78
|
|
|
138
|
-
```tsx
|
|
139
|
-
|
|
140
|
-
import { t, type DeclarationContent } from "intlayer";
|
|
141
|
-
import { type ReactNode } from "react";
|
|
79
|
+
```tsx filePath="src/Component1/index.content.ts" codeFormat="typescript"
|
|
80
|
+
import { type DeclarationContent, t } from "intlayer";
|
|
142
81
|
|
|
143
|
-
const
|
|
144
|
-
key: "
|
|
82
|
+
const component1Content = {
|
|
83
|
+
key: "component-1",
|
|
145
84
|
content: {
|
|
146
|
-
|
|
147
|
-
en:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<>
|
|
159
|
-
Edita <code>src/App.tsx</code> y guarda para recargar
|
|
160
|
-
</>
|
|
161
|
-
),
|
|
85
|
+
myTranslatedContent: t({
|
|
86
|
+
en: "Hello World",
|
|
87
|
+
fr: "Bonjour le monde",
|
|
88
|
+
es: "Hola Mundo",
|
|
89
|
+
}),
|
|
90
|
+
numberOfCar: enu({
|
|
91
|
+
"<-1": "Less than minus one car",
|
|
92
|
+
"-1": "Minus one car",
|
|
93
|
+
"0": "No cars",
|
|
94
|
+
"1": "One car",
|
|
95
|
+
">5": "Some cars",
|
|
96
|
+
">19": "Many cars",
|
|
162
97
|
}),
|
|
163
|
-
reactLink: {
|
|
164
|
-
href: "https://reactjs.org",
|
|
165
|
-
content: t({
|
|
166
|
-
en: "Learn React",
|
|
167
|
-
fr: "Apprendre React",
|
|
168
|
-
es: "Aprender React",
|
|
169
|
-
}),
|
|
170
|
-
},
|
|
171
98
|
},
|
|
172
99
|
} satisfies DeclarationContent;
|
|
173
100
|
|
|
174
|
-
export default
|
|
101
|
+
export default component1Content;
|
|
175
102
|
```
|
|
176
103
|
|
|
177
|
-
|
|
104
|
+
### Utilize Content in Your Code
|
|
178
105
|
|
|
179
|
-
|
|
106
|
+
Once you have declared your content, you can use it in your code. Here's an example of how to use the content in a React component:
|
|
180
107
|
|
|
181
|
-
|
|
108
|
+
```tsx {4,7} fileName="src/components/Component1Example.tsx" codeFormat="typescript"
|
|
109
|
+
"use client";
|
|
182
110
|
|
|
183
|
-
|
|
184
|
-
import
|
|
185
|
-
import "./App.css";
|
|
186
|
-
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
187
|
-
import { LocaleSwitcher } from "./components/LangSwitcherDropDown";
|
|
111
|
+
import type { FC } from "react";
|
|
112
|
+
import { useIntlayer } from "react-intlayer";
|
|
188
113
|
|
|
189
|
-
|
|
190
|
-
const
|
|
114
|
+
export const Component1Example: FC = () => {
|
|
115
|
+
const { myTranslatedContent } = useIntlayer("component-1"); // Create related content declaration
|
|
191
116
|
|
|
192
117
|
return (
|
|
193
|
-
<
|
|
194
|
-
<
|
|
195
|
-
|
|
196
|
-
{content.getStarted}
|
|
197
|
-
<a
|
|
198
|
-
className="App-link"
|
|
199
|
-
href={content.reactLink.href.value}
|
|
200
|
-
target="_blank"
|
|
201
|
-
rel="noopener noreferrer"
|
|
202
|
-
>
|
|
203
|
-
{content.reactLink.content}
|
|
204
|
-
</a>
|
|
205
|
-
</header>
|
|
118
|
+
<div>
|
|
119
|
+
<p>{myTranslatedContent}</p>
|
|
120
|
+
</div>
|
|
206
121
|
);
|
|
207
|
-
}
|
|
122
|
+
};
|
|
123
|
+
```
|
|
208
124
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
<IntlayerProvider>
|
|
212
|
-
<div className="App">
|
|
213
|
-
{/* To use the useIntlayer hook properly, you should access your data in a children component */}
|
|
214
|
-
<AppContent />
|
|
215
|
-
</div>
|
|
216
|
-
<div className="absolute bottom-5 right-5 z-50">
|
|
217
|
-
<LocaleSwitcher />
|
|
218
|
-
</div>
|
|
219
|
-
</IntlayerProvider>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
125
|
+
```jsx {3,6} fileName="src/components/Component1Example.mjx" codeFormat="esm"
|
|
126
|
+
"use client";
|
|
222
127
|
|
|
223
|
-
|
|
224
|
-
```
|
|
128
|
+
import { useIntlayer } from "react-intlayer";
|
|
225
129
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
> ```tsx
|
|
229
|
-
> <img src={content.image.src.value} alt={content.image.value} />
|
|
230
|
-
> ```
|
|
130
|
+
const Component1Example = () => {
|
|
131
|
+
const { myTranslatedContent } = useIntlayer("component-1"); // Create related content declaration
|
|
231
132
|
|
|
232
|
-
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<p>{myTranslatedContent}</p>
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
```
|
|
233
140
|
|
|
234
|
-
|
|
141
|
+
```jsx {3,6} fileName="src/components/Component1Example.csx" codeFormat="commonjs"
|
|
142
|
+
"use client";
|
|
235
143
|
|
|
236
|
-
|
|
237
|
-
import { Locales } from "intlayer";
|
|
238
|
-
import { useLocale } from "react-intlayer";
|
|
144
|
+
const { useIntlayer } = require("react-intlayer");
|
|
239
145
|
|
|
240
|
-
const
|
|
241
|
-
const {
|
|
146
|
+
const Component1Example = () => {
|
|
147
|
+
const { myTranslatedContent } = useIntlayer("component-1"); // Create related content declaration
|
|
242
148
|
|
|
243
149
|
return (
|
|
244
|
-
<
|
|
245
|
-
|
|
246
|
-
</
|
|
150
|
+
<div>
|
|
151
|
+
<p>{myTranslatedContent}</p>
|
|
152
|
+
</div>
|
|
247
153
|
);
|
|
248
154
|
};
|
|
249
155
|
```
|
|
250
156
|
|
|
251
|
-
##
|
|
157
|
+
## Mastering the internationalization of your React application
|
|
252
158
|
|
|
253
|
-
Intlayer
|
|
159
|
+
Intlayer provides a lot of features to help you internationalize your React application.
|
|
254
160
|
|
|
255
|
-
|
|
161
|
+
**To learn more about these features, refer to the [React Internationalization (i18n) with Intlayer and Vite and React](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_with_vite+react.md) guide for Vite and React Application, or the [React Internationalization (i18n) with Intlayer and React (CRA)](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_with_create_react_app.md) guide for React Create App.**
|
|
256
162
|
|
|
257
|
-
|
|
163
|
+
## Functions provided by `react-intlayer` package
|
|
258
164
|
|
|
259
|
-
|
|
165
|
+
The `react-intlayer` package also provides some functions to help you to internationalize your application.
|
|
260
166
|
|
|
261
|
-
|
|
262
|
-
|
|
167
|
+
- [`t()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/react-intlayer/t.md)
|
|
168
|
+
- [`useIntlayer()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/react-intlayer/useIntlayer.md)
|
|
169
|
+
- [`useDictionary()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/react-intlayer/useDictionary.md)
|
|
170
|
+
- [`useLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/react-intlayer/useLocale.md)
|
|
171
|
+
- [`useIntlayerAsync()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/react-intlayer/useIntlayerAsync.md)
|
|
263
172
|
|
|
264
|
-
|
|
265
|
-
// your custom config
|
|
266
|
-
"include": [
|
|
267
|
-
"src",
|
|
268
|
-
"types", // <- Include the auto generated types
|
|
269
|
-
],
|
|
270
|
-
}
|
|
271
|
-
```
|
|
173
|
+
## Read about Intlayer
|
|
272
174
|
|
|
273
|
-
|
|
175
|
+
- [Intlayer Website](https://intlayer.org)
|
|
176
|
+
- [Intlayer Documentation](https://intlayer.org/docs)
|
|
177
|
+
- [Intlayer GitHub](https://github.com/aymericzip/intlayer)
|
|
274
178
|
|
|
275
|
-
|
|
179
|
+
- [Ask your questions to our smart documentation](https://intlayer.org/docs/chat)
|
|
@@ -0,0 +1,126 @@
|
|
|
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 ContentSelector_exports = {};
|
|
21
|
+
__export(ContentSelector_exports, {
|
|
22
|
+
ContentSelector: () => ContentSelector
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ContentSelector_exports);
|
|
25
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
const DEFAULT_PRESS_DETECT_DURATION = 400;
|
|
28
|
+
const ContentSelector = ({
|
|
29
|
+
children,
|
|
30
|
+
onPress: onSelect,
|
|
31
|
+
onClickOutside: onUnselect,
|
|
32
|
+
pressDuration = DEFAULT_PRESS_DETECT_DURATION,
|
|
33
|
+
isSelecting: isSelectingProp,
|
|
34
|
+
...props
|
|
35
|
+
}) => {
|
|
36
|
+
const divRef = (0, import_react.useRef)(null);
|
|
37
|
+
const [isHovered, setIsHovered] = (0, import_react.useState)(false);
|
|
38
|
+
const [isSelectingState, setIsSelectingState] = (0, import_react.useState)(isSelectingProp);
|
|
39
|
+
const pressTimerRef = (0, import_react.useRef)(null);
|
|
40
|
+
const handleOnLongPress = () => {
|
|
41
|
+
setIsSelectingState(true);
|
|
42
|
+
onSelect();
|
|
43
|
+
};
|
|
44
|
+
const startPressTimer = () => {
|
|
45
|
+
pressTimerRef.current = setTimeout(() => {
|
|
46
|
+
handleOnLongPress();
|
|
47
|
+
}, pressDuration);
|
|
48
|
+
};
|
|
49
|
+
const clearPressTimer = () => {
|
|
50
|
+
if (pressTimerRef.current) {
|
|
51
|
+
clearTimeout(pressTimerRef.current);
|
|
52
|
+
pressTimerRef.current = null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const handleMouseDown = () => {
|
|
56
|
+
clearPressTimer();
|
|
57
|
+
startPressTimer();
|
|
58
|
+
};
|
|
59
|
+
const handleMouseEnter = () => {
|
|
60
|
+
setIsHovered(true);
|
|
61
|
+
};
|
|
62
|
+
const handleMouseUp = () => {
|
|
63
|
+
setIsHovered(false);
|
|
64
|
+
clearPressTimer();
|
|
65
|
+
};
|
|
66
|
+
const handleClickOutside = (0, import_react.useCallback)(
|
|
67
|
+
(event) => {
|
|
68
|
+
if (divRef.current && !divRef.current.contains(event.target)) {
|
|
69
|
+
setIsSelectingState(false);
|
|
70
|
+
onUnselect?.();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[onUnselect]
|
|
74
|
+
);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
77
|
+
return () => {
|
|
78
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
79
|
+
};
|
|
80
|
+
}, [handleClickOutside]);
|
|
81
|
+
const handleOnClick = (e) => {
|
|
82
|
+
if (isSelectingState) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const handleOnBlur = () => {
|
|
88
|
+
setIsSelectingState(false);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
style: {
|
|
94
|
+
display: "inline",
|
|
95
|
+
cursor: "pointer",
|
|
96
|
+
userSelect: "none",
|
|
97
|
+
borderRadius: "0.375rem",
|
|
98
|
+
outlineWidth: "2px",
|
|
99
|
+
outlineOffset: "4px",
|
|
100
|
+
outlineStyle: "solid",
|
|
101
|
+
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
102
|
+
transition: "all 200ms 100ms ease-in-out"
|
|
103
|
+
},
|
|
104
|
+
role: "button",
|
|
105
|
+
tabIndex: 0,
|
|
106
|
+
onKeyUp: () => null,
|
|
107
|
+
onClick: handleOnClick,
|
|
108
|
+
onMouseDown: handleMouseDown,
|
|
109
|
+
onMouseUp: handleMouseUp,
|
|
110
|
+
onMouseLeave: handleMouseUp,
|
|
111
|
+
onTouchStart: handleMouseDown,
|
|
112
|
+
onTouchEnd: handleMouseUp,
|
|
113
|
+
onTouchCancel: handleMouseUp,
|
|
114
|
+
onBlur: handleOnBlur,
|
|
115
|
+
onMouseEnter: handleMouseEnter,
|
|
116
|
+
ref: divRef,
|
|
117
|
+
...props,
|
|
118
|
+
children
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
ContentSelector
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=ContentSelector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n useEffect,\n useState,\n useRef,\n useCallback,\n type FC,\n type MouseEventHandler,\n type HTMLAttributes,\n} from 'react';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 400;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & HTMLAttributes<HTMLDivElement>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n };\n\n const handleMouseUp = () => {\n setIsHovered(false);\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: 'inline',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 200ms 100ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqGI;AAnGJ,mBAQO;AAEP,MAAM,gCAAgC;AAS/B,MAAM,kBAA4C,CAAC;AAAA,EACxD;AAAA,EACA,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,GAAG;AACL,MAAM;AACJ,QAAM,aAAS,qBAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,CAAC,kBAAkB,mBAAmB,QAAI,uBAAS,eAAe;AACxE,QAAM,oBAAgB,qBAA6C,IAAI;AAEvE,QAAM,oBAAoB,MAAM;AAC9B,wBAAoB,IAAI;AACxB,aAAS;AAAA,EACX;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,aAAa;AAAA,EAClB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,mBAAmB,MAAM;AAC7B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,iBAAa,KAAK;AAClB,oBAAgB;AAAA,EAClB;AAGA,QAAM,yBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,4BAAoB,KAAK;AACzB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,8BAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAE9D;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,kBAAkB;AACpB,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,wBAAoB,KAAK;AAAA,EAC3B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,cAAc;AAAA,QACd,eAAe;AAAA,QACf,cAAc;AAAA,QACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,KAAK;AAAA,MACJ,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 PressableSpan_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(PressableSpan_exports);
|
|
18
|
+
__reExport(PressableSpan_exports, require('../ContentSelector.cjs'), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require('../ContentSelector.cjs')
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/UI/PressableSpan/index.ts"],"sourcesContent":["export * from '../ContentSelector';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kCAAc,+BAAd;","names":[]}
|
|
@@ -29,6 +29,7 @@ var import_client = require("@intlayer/config/client");
|
|
|
29
29
|
var import_react = require("react");
|
|
30
30
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
31
31
|
var import_IntlayerEditorProvider = require('../editor/IntlayerEditorProvider.cjs');
|
|
32
|
+
var import_PoweredByMeta = require('./PoweredByMeta.cjs');
|
|
32
33
|
const IntlayerClientContext = (0, import_react.createContext)({
|
|
33
34
|
locale: import_useLocaleCookie.localeCookie ?? (0, import_client.getConfiguration)().internationalization.defaultLocale,
|
|
34
35
|
setLocale: () => null
|
|
@@ -61,7 +62,10 @@ const IntlayerProvider = ({
|
|
|
61
62
|
() => ({ locale: currentLocale, setLocale }),
|
|
62
63
|
[currentLocale, setLocale]
|
|
63
64
|
);
|
|
64
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(IntlayerClientContext.Provider, { value, children: [
|
|
66
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PoweredByMeta.PoweredByMeta, {}),
|
|
67
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerEditorProvider.IntlayerEditorProvider, { children })
|
|
68
|
+
] });
|
|
65
69
|
};
|
|
66
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
71
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { PoweredByMeta } from './PoweredByMeta';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <PoweredByMeta />\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EI;AA3EJ,oBAA+C;AAC/C,mBAQO;AACP,6BAA8C;AAC9C,oCAAuC;AACvC,2BAA8B;AAUvB,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAUjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,qBAAqB,QAAI,gCAAiB;AAClD,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAErD,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC,UAAU,uCAAgB;AAAA,EAC5B;AAEA,QAAM,oBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,kDAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,6CAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,gDAAC,sCAAc;AAAA,IACf,4CAAC,wDAAwB,UAAS;AAAA,KACpC;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/PoweredByMeta.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n const metaTag = document.createElement('meta');\n metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\n }, []);\n\n return null; // This component does not render anything visible\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAmC;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,8BAAU,MAAM;AACd,UAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,YAAQ,OAAO;AACf,YAAQ,UAAU;AAClB,aAAS,KAAK,YAAY,OAAO;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAG/B,oBAAiC;AAM1B,MAAM,yBAAyB,OACpC,
|
|
1
|
+
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI | undefined> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAG/B,oBAAiC;AAM1B,MAAM,yBAAyB,OACpC,kBACuC;AACvC,MAAI;AACF,UAAM,aAAS,gCAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,kBAAc,2BAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAGlD,UAAM,sBAAsB,MAAM,YAAY,WAAW;AAAA,MACvD;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,MAC1D;AAAA,IACF;AAEA,UAAM,oBAAoB,oBAAoB;AAE9C,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -22,9 +23,45 @@ __export(ContentSelectorWrapper_exports, {
|
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(ContentSelectorWrapper_exports);
|
|
24
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_core = require("@intlayer/core");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_editor_react = require("@intlayer/editor-react");
|
|
29
|
+
var import_ContentSelector = require('../UI/ContentSelector.cjs');
|
|
25
30
|
const ContentSelectorWrapper = ({
|
|
26
|
-
children
|
|
27
|
-
|
|
31
|
+
children,
|
|
32
|
+
dictionaryKey,
|
|
33
|
+
dictionaryPath,
|
|
34
|
+
keyPath,
|
|
35
|
+
...props
|
|
36
|
+
}) => {
|
|
37
|
+
const { focusedContent, setFocusedContent } = (0, import_editor_react.useFocusDictionary)();
|
|
38
|
+
const { getEditedContentValue } = (0, import_editor_react.useEditedContentActions)();
|
|
39
|
+
const editedValue = (0, import_react.useMemo)(
|
|
40
|
+
() => getEditedContentValue(dictionaryKey, keyPath),
|
|
41
|
+
[dictionaryKey, keyPath, getEditedContentValue]
|
|
42
|
+
);
|
|
43
|
+
const [displayedChildren, setDisplayedChildren] = (0, import_react.useState)(children);
|
|
44
|
+
const handleSelect = (0, import_react.useCallback)(
|
|
45
|
+
() => setFocusedContent({
|
|
46
|
+
dictionaryKey,
|
|
47
|
+
dictionaryPath,
|
|
48
|
+
keyPath
|
|
49
|
+
}),
|
|
50
|
+
[dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
|
|
51
|
+
);
|
|
52
|
+
const isSelected = (0, import_react.useMemo)(
|
|
53
|
+
() => ((focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
54
|
+
[focusedContent, keyPath]
|
|
55
|
+
);
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
if (editedValue && typeof editedValue === "string") {
|
|
58
|
+
setDisplayedChildren(editedValue);
|
|
59
|
+
} else {
|
|
60
|
+
setDisplayedChildren(children);
|
|
61
|
+
}
|
|
62
|
+
}, [editedValue, focusedContent, children]);
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelector.ContentSelector, { onPress: handleSelect, isSelecting: isSelected, ...props, children: displayedChildren });
|
|
64
|
+
};
|
|
28
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
66
|
0 && (module.exports = {
|
|
30
67
|
ContentSelectorWrapper
|