@littlebox/strapi-suite 1.0.51 → 1.0.54
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 +29 -0
- package/dist/_chunks/{App-C7RgdLC-.js → App-B7_8BaVG.js} +557 -35
- package/dist/_chunks/{App-b_1MuDrk.mjs → App-BfGB2pF_.mjs} +550 -28
- package/dist/_chunks/{SlugInput-DlOanbzA.mjs → SlugInput-CvgVtZza.mjs} +1 -2
- package/dist/_chunks/{SlugInput-DvQWzpBu.js → SlugInput-eCwgqJtH.js} +3 -4
- package/dist/_chunks/{en-CGJcJfk1.js → en-D89cXiov.js} +46 -1
- package/dist/_chunks/{en-CRSiVe4w.mjs → en-knG97mCH.mjs} +46 -1
- package/dist/_chunks/{index-C3MUddO-.mjs → index-97f0S4q6.mjs} +2270 -73
- package/dist/_chunks/{index-UZTUyNY3.js → index-DnXsi_Ar.js} +2292 -78
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/src/components/DocumentTranslateBox.d.ts +5 -0
- package/dist/admin/src/components/DocumentTranslateModal.d.ts +11 -0
- package/dist/admin/src/components/TranslationAiModal.d.ts +8 -0
- package/dist/admin/src/components/TranslationSettingsModal.d.ts +6 -0
- package/dist/admin/src/contexts/settings.d.ts +1 -0
- package/dist/admin/src/core/config.d.ts +1 -0
- package/dist/admin/src/core/gateways/aiGateway.d.ts +19 -0
- package/dist/admin/src/core/gateways/documentGateway.d.ts +15 -0
- package/dist/admin/src/core/gateways/translationGateway.d.ts +13 -0
- package/dist/admin/src/core/usecases/translateDocument.d.ts +33 -0
- package/dist/admin/src/core/usecases/translateWithAi.d.ts +17 -0
- package/dist/admin/src/core/utils/documentFields.d.ts +23 -0
- package/dist/admin/src/core/utils/tabs.d.ts +53 -0
- package/dist/admin/src/ctb/TabSelect.d.ts +31 -0
- package/dist/admin/src/ctb/TabsEditor.d.ts +21 -0
- package/dist/admin/src/ctb/registerTabsInContentTypeBuilder.d.ts +1 -0
- package/dist/admin/src/ctb/tabBadges.d.ts +14 -0
- package/dist/admin/src/editView/TabSection.d.ts +6 -0
- package/dist/admin/src/editView/TabsBar.d.ts +10 -0
- package/dist/admin/src/editView/mutateEditViewLayout.d.ts +12 -0
- package/dist/admin/src/editView/sectionVisibility.d.ts +7 -0
- package/dist/admin/src/editView/tabsStore.d.ts +13 -0
- package/dist/server/index.js +812 -392
- package/dist/server/index.mjs +812 -392
- package/dist/server/src/config/index.d.ts +4 -0
- package/dist/server/src/controllers/index.d.ts +6 -0
- package/dist/server/src/controllers/modules/ai-translation.d.ts +7 -0
- package/dist/server/src/controllers/modules/translation.d.ts +1 -0
- package/dist/server/src/index.d.ts +22 -1
- package/dist/server/src/middlewares/tabs.d.ts +4 -0
- package/dist/server/src/services/app/setting.d.ts +3 -1
- package/dist/server/src/services/index.d.ts +16 -1
- package/dist/server/src/services/modules/ai-translation.d.ts +35 -0
- package/dist/server/src/utils/groupByContentTypeTabs.d.ts +7 -0
- package/dist/server/src/utils/tabs.d.ts +17 -0
- package/package.json +6 -3
- package/dist/_chunks/convertToSlug-DmgViUjP.mjs +0 -84
- package/dist/_chunks/convertToSlug-DqHa9ej4.js +0 -83
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { getFetchClient, unstable_useContentManagerContext } from "@strapi/strapi/admin";
|
|
2
|
-
import
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import React__default, { useRef, useEffect, useState, useSyncExternalStore, useMemo, useLayoutEffect } from "react";
|
|
3
4
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
4
5
|
import { useLocation } from "react-router-dom";
|
|
5
|
-
import { Dialog, Button, Box, Typography, SingleSelect, SingleSelectOption } from "@strapi/design-system";
|
|
6
|
+
import { Dialog, Button, Box, Typography, SingleSelect, SingleSelectOption, Flex, IconButton, Toggle, Card, Loader, Divider, Field, TextInput, Tabs, Badge } from "@strapi/design-system";
|
|
6
7
|
import { useIntl } from "react-intl";
|
|
7
|
-
import { WarningCircle } from "@strapi/icons";
|
|
8
|
+
import { WarningCircle, Cross, Sparkle, Plus, Drag, Trash } from "@strapi/icons";
|
|
9
|
+
import styled from "styled-components";
|
|
10
|
+
import { useSensors, useSensor, PointerSensor, DndContext, closestCenter } from "@dnd-kit/core";
|
|
11
|
+
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
12
|
+
import { SortableContext, verticalListSortingStrategy, arrayMove, useSortable } from "@dnd-kit/sortable";
|
|
13
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
8
14
|
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
9
15
|
const v = glob[path];
|
|
10
16
|
if (v) {
|
|
@@ -70,7 +76,7 @@ function baseClone(src, circulars, clones) {
|
|
|
70
76
|
function clone(src) {
|
|
71
77
|
return baseClone(src, [], []);
|
|
72
78
|
}
|
|
73
|
-
const toString$
|
|
79
|
+
const toString$6 = Object.prototype.toString;
|
|
74
80
|
const errorToString = Error.prototype.toString;
|
|
75
81
|
const regExpToString = RegExp.prototype.toString;
|
|
76
82
|
const symbolToString$1 = typeof Symbol !== "undefined" ? Symbol.prototype.toString : () => "";
|
|
@@ -87,7 +93,7 @@ function printSimpleValue(val, quoteStrings = false) {
|
|
|
87
93
|
if (typeOf === "string") return quoteStrings ? `"${val}"` : val;
|
|
88
94
|
if (typeOf === "function") return "[Function " + (val.name || "anonymous") + "]";
|
|
89
95
|
if (typeOf === "symbol") return symbolToString$1.call(val).replace(SYMBOL_REGEXP, "Symbol($1)");
|
|
90
|
-
const tag = toString$
|
|
96
|
+
const tag = toString$6.call(val).slice(8, -1);
|
|
91
97
|
if (tag === "Date") return isNaN(val.getTime()) ? "" + val : val.toISOString(val);
|
|
92
98
|
if (tag === "Error" || val instanceof Error) return "[" + errorToString.call(val) + "]";
|
|
93
99
|
if (tag === "RegExp") return regExpToString.call(val);
|
|
@@ -251,15 +257,15 @@ function isKey$3(value, object2) {
|
|
|
251
257
|
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object2 != null && value in Object(object2);
|
|
252
258
|
}
|
|
253
259
|
var _isKey = isKey$3;
|
|
254
|
-
function isObject$
|
|
260
|
+
function isObject$4(value) {
|
|
255
261
|
var type = typeof value;
|
|
256
262
|
return value != null && (type == "object" || type == "function");
|
|
257
263
|
}
|
|
258
|
-
var isObject_1 = isObject$
|
|
259
|
-
var baseGetTag$3 = _baseGetTag, isObject$
|
|
264
|
+
var isObject_1 = isObject$4;
|
|
265
|
+
var baseGetTag$3 = _baseGetTag, isObject$3 = isObject_1;
|
|
260
266
|
var asyncTag = "[object AsyncFunction]", funcTag$1 = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
|
|
261
267
|
function isFunction$2(value) {
|
|
262
|
-
if (!isObject$
|
|
268
|
+
if (!isObject$3(value)) {
|
|
263
269
|
return false;
|
|
264
270
|
}
|
|
265
271
|
var tag = baseGetTag$3(value);
|
|
@@ -294,7 +300,7 @@ function toSource$2(func) {
|
|
|
294
300
|
return "";
|
|
295
301
|
}
|
|
296
302
|
var _toSource = toSource$2;
|
|
297
|
-
var isFunction$1 = isFunction_1, isMasked = _isMasked, isObject$
|
|
303
|
+
var isFunction$1 = isFunction_1, isMasked = _isMasked, isObject$2 = isObject_1, toSource$1 = _toSource;
|
|
298
304
|
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
299
305
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
300
306
|
var funcProto = Function.prototype, objectProto$9 = Object.prototype;
|
|
@@ -304,7 +310,7 @@ var reIsNative = RegExp(
|
|
|
304
310
|
"^" + funcToString.call(hasOwnProperty$7).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
305
311
|
);
|
|
306
312
|
function baseIsNative$1(value) {
|
|
307
|
-
if (!isObject$
|
|
313
|
+
if (!isObject$2(value) || isMasked(value)) {
|
|
308
314
|
return false;
|
|
309
315
|
}
|
|
310
316
|
var pattern = isFunction$1(value) ? reIsNative : reIsHostCtor;
|
|
@@ -593,16 +599,16 @@ function baseToString$1(value) {
|
|
|
593
599
|
}
|
|
594
600
|
var _baseToString = baseToString$1;
|
|
595
601
|
var baseToString = _baseToString;
|
|
596
|
-
function toString$
|
|
602
|
+
function toString$5(value) {
|
|
597
603
|
return value == null ? "" : baseToString(value);
|
|
598
604
|
}
|
|
599
|
-
var toString_1 = toString$
|
|
600
|
-
var isArray$5 = isArray_1, isKey$2 = _isKey, stringToPath = _stringToPath, toString = toString_1;
|
|
605
|
+
var toString_1 = toString$5;
|
|
606
|
+
var isArray$5 = isArray_1, isKey$2 = _isKey, stringToPath = _stringToPath, toString$4 = toString_1;
|
|
601
607
|
function castPath$2(value, object2) {
|
|
602
608
|
if (isArray$5(value)) {
|
|
603
609
|
return value;
|
|
604
610
|
}
|
|
605
|
-
return isKey$2(value, object2) ? [value] : stringToPath(toString(value));
|
|
611
|
+
return isKey$2(value, object2) ? [value] : stringToPath(toString$4(value));
|
|
606
612
|
}
|
|
607
613
|
var _castPath = castPath$2;
|
|
608
614
|
var baseGetTag$2 = _baseGetTag, isObjectLike$3 = isObjectLike_1;
|
|
@@ -704,8 +710,8 @@ class Condition {
|
|
|
704
710
|
function toArray(value) {
|
|
705
711
|
return value == null ? [] : [].concat(value);
|
|
706
712
|
}
|
|
707
|
-
function _extends$
|
|
708
|
-
_extends$
|
|
713
|
+
function _extends$4() {
|
|
714
|
+
_extends$4 = Object.assign || function(target) {
|
|
709
715
|
for (var i = 1; i < arguments.length; i++) {
|
|
710
716
|
var source = arguments[i];
|
|
711
717
|
for (var key in source) {
|
|
@@ -716,13 +722,13 @@ function _extends$2() {
|
|
|
716
722
|
}
|
|
717
723
|
return target;
|
|
718
724
|
};
|
|
719
|
-
return _extends$
|
|
725
|
+
return _extends$4.apply(this, arguments);
|
|
720
726
|
}
|
|
721
727
|
let strReg = /\$\{\s*(\w+)\s*\}/g;
|
|
722
728
|
class ValidationError extends Error {
|
|
723
729
|
static formatError(message, params) {
|
|
724
730
|
const path = params.label || params.path || "this";
|
|
725
|
-
if (path !== params.path) params = _extends$
|
|
731
|
+
if (path !== params.path) params = _extends$4({}, params, {
|
|
726
732
|
path
|
|
727
733
|
});
|
|
728
734
|
if (typeof message === "string") return message.replace(strReg, (_, key) => printValue(params[key]));
|
|
@@ -814,7 +820,7 @@ var defineProperty$1 = function() {
|
|
|
814
820
|
}();
|
|
815
821
|
var _defineProperty = defineProperty$1;
|
|
816
822
|
var defineProperty = _defineProperty;
|
|
817
|
-
function baseAssignValue$
|
|
823
|
+
function baseAssignValue$2(object2, key, value) {
|
|
818
824
|
if (key == "__proto__" && defineProperty) {
|
|
819
825
|
defineProperty(object2, key, {
|
|
820
826
|
"configurable": true,
|
|
@@ -826,7 +832,7 @@ function baseAssignValue$1(object2, key, value) {
|
|
|
826
832
|
object2[key] = value;
|
|
827
833
|
}
|
|
828
834
|
}
|
|
829
|
-
var _baseAssignValue = baseAssignValue$
|
|
835
|
+
var _baseAssignValue = baseAssignValue$2;
|
|
830
836
|
function createBaseFor$1(fromRight) {
|
|
831
837
|
return function(object2, iteratee, keysFunc) {
|
|
832
838
|
var index2 = -1, iterable = Object(object2), props = keysFunc(object2), length = props.length;
|
|
@@ -968,10 +974,10 @@ function keys$3(object2) {
|
|
|
968
974
|
}
|
|
969
975
|
var keys_1 = keys$3;
|
|
970
976
|
var baseFor = _baseFor, keys$2 = keys_1;
|
|
971
|
-
function baseForOwn$
|
|
977
|
+
function baseForOwn$2(object2, iteratee) {
|
|
972
978
|
return object2 && baseFor(object2, iteratee, keys$2);
|
|
973
979
|
}
|
|
974
|
-
var _baseForOwn = baseForOwn$
|
|
980
|
+
var _baseForOwn = baseForOwn$2;
|
|
975
981
|
var ListCache$2 = _ListCache;
|
|
976
982
|
function stackClear$1() {
|
|
977
983
|
this.__data__ = new ListCache$2();
|
|
@@ -1388,9 +1394,9 @@ function baseIsMatch$1(object2, source, matchData, customizer) {
|
|
|
1388
1394
|
return true;
|
|
1389
1395
|
}
|
|
1390
1396
|
var _baseIsMatch = baseIsMatch$1;
|
|
1391
|
-
var isObject = isObject_1;
|
|
1397
|
+
var isObject$1 = isObject_1;
|
|
1392
1398
|
function isStrictComparable$2(value) {
|
|
1393
|
-
return value === value && !isObject(value);
|
|
1399
|
+
return value === value && !isObject$1(value);
|
|
1394
1400
|
}
|
|
1395
1401
|
var _isStrictComparable = isStrictComparable$2;
|
|
1396
1402
|
var isStrictComparable$1 = _isStrictComparable, keys = keys_1;
|
|
@@ -1483,7 +1489,7 @@ function property$1(path) {
|
|
|
1483
1489
|
}
|
|
1484
1490
|
var property_1 = property$1;
|
|
1485
1491
|
var baseMatches = _baseMatches, baseMatchesProperty = _baseMatchesProperty, identity = identity_1, isArray = isArray_1, property = property_1;
|
|
1486
|
-
function baseIteratee$
|
|
1492
|
+
function baseIteratee$2(value) {
|
|
1487
1493
|
if (typeof value == "function") {
|
|
1488
1494
|
return value;
|
|
1489
1495
|
}
|
|
@@ -1495,13 +1501,13 @@ function baseIteratee$1(value) {
|
|
|
1495
1501
|
}
|
|
1496
1502
|
return property(value);
|
|
1497
1503
|
}
|
|
1498
|
-
var _baseIteratee = baseIteratee$
|
|
1499
|
-
var baseAssignValue = _baseAssignValue, baseForOwn = _baseForOwn, baseIteratee = _baseIteratee;
|
|
1504
|
+
var _baseIteratee = baseIteratee$2;
|
|
1505
|
+
var baseAssignValue$1 = _baseAssignValue, baseForOwn$1 = _baseForOwn, baseIteratee$1 = _baseIteratee;
|
|
1500
1506
|
function mapValues(object2, iteratee) {
|
|
1501
1507
|
var result = {};
|
|
1502
|
-
iteratee = baseIteratee(iteratee);
|
|
1503
|
-
baseForOwn(object2, function(value, key, object3) {
|
|
1504
|
-
baseAssignValue(result, key, iteratee(value, key, object3));
|
|
1508
|
+
iteratee = baseIteratee$1(iteratee);
|
|
1509
|
+
baseForOwn$1(object2, function(value, key, object3) {
|
|
1510
|
+
baseAssignValue$1(result, key, iteratee(value, key, object3));
|
|
1505
1511
|
});
|
|
1506
1512
|
return result;
|
|
1507
1513
|
}
|
|
@@ -1652,8 +1658,8 @@ class Reference {
|
|
|
1652
1658
|
}
|
|
1653
1659
|
}
|
|
1654
1660
|
Reference.prototype.__isYupRef = true;
|
|
1655
|
-
function _extends$
|
|
1656
|
-
_extends$
|
|
1661
|
+
function _extends$3() {
|
|
1662
|
+
_extends$3 = Object.assign || function(target) {
|
|
1657
1663
|
for (var i = 1; i < arguments.length; i++) {
|
|
1658
1664
|
var source = arguments[i];
|
|
1659
1665
|
for (var key in source) {
|
|
@@ -1664,7 +1670,7 @@ function _extends$1() {
|
|
|
1664
1670
|
}
|
|
1665
1671
|
return target;
|
|
1666
1672
|
};
|
|
1667
|
-
return _extends$
|
|
1673
|
+
return _extends$3.apply(this, arguments);
|
|
1668
1674
|
}
|
|
1669
1675
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
1670
1676
|
if (source == null) return {};
|
|
@@ -1702,7 +1708,7 @@ function createValidation(config2) {
|
|
|
1702
1708
|
return Reference.isRef(item) ? item.getValue(value, parent, context) : item;
|
|
1703
1709
|
}
|
|
1704
1710
|
function createError(overrides = {}) {
|
|
1705
|
-
const nextParams = mapValues$1(_extends$
|
|
1711
|
+
const nextParams = mapValues$1(_extends$3({
|
|
1706
1712
|
value,
|
|
1707
1713
|
originalValue,
|
|
1708
1714
|
label,
|
|
@@ -1712,7 +1718,7 @@ function createValidation(config2) {
|
|
|
1712
1718
|
error.params = nextParams;
|
|
1713
1719
|
return error;
|
|
1714
1720
|
}
|
|
1715
|
-
let ctx = _extends$
|
|
1721
|
+
let ctx = _extends$3({
|
|
1716
1722
|
path,
|
|
1717
1723
|
parent,
|
|
1718
1724
|
type: name,
|
|
@@ -1834,8 +1840,8 @@ class ReferenceSet {
|
|
|
1834
1840
|
return next;
|
|
1835
1841
|
}
|
|
1836
1842
|
}
|
|
1837
|
-
function _extends() {
|
|
1838
|
-
_extends = Object.assign || function(target) {
|
|
1843
|
+
function _extends$2() {
|
|
1844
|
+
_extends$2 = Object.assign || function(target) {
|
|
1839
1845
|
for (var i = 1; i < arguments.length; i++) {
|
|
1840
1846
|
var source = arguments[i];
|
|
1841
1847
|
for (var key in source) {
|
|
@@ -1846,7 +1852,7 @@ function _extends() {
|
|
|
1846
1852
|
}
|
|
1847
1853
|
return target;
|
|
1848
1854
|
};
|
|
1849
|
-
return _extends.apply(this, arguments);
|
|
1855
|
+
return _extends$2.apply(this, arguments);
|
|
1850
1856
|
}
|
|
1851
1857
|
class BaseSchema {
|
|
1852
1858
|
constructor(options) {
|
|
@@ -1861,7 +1867,7 @@ class BaseSchema {
|
|
|
1861
1867
|
this.typeError(mixed.notType);
|
|
1862
1868
|
});
|
|
1863
1869
|
this.type = (options == null ? void 0 : options.type) || "mixed";
|
|
1864
|
-
this.spec = _extends({
|
|
1870
|
+
this.spec = _extends$2({
|
|
1865
1871
|
strip: false,
|
|
1866
1872
|
strict: false,
|
|
1867
1873
|
abortEarly: true,
|
|
@@ -1889,12 +1895,12 @@ class BaseSchema {
|
|
|
1889
1895
|
next._blacklistError = this._blacklistError;
|
|
1890
1896
|
next._whitelist = this._whitelist.clone();
|
|
1891
1897
|
next._blacklist = this._blacklist.clone();
|
|
1892
|
-
next.exclusiveTests = _extends({}, this.exclusiveTests);
|
|
1898
|
+
next.exclusiveTests = _extends$2({}, this.exclusiveTests);
|
|
1893
1899
|
next.deps = [...this.deps];
|
|
1894
1900
|
next.conditions = [...this.conditions];
|
|
1895
1901
|
next.tests = [...this.tests];
|
|
1896
1902
|
next.transforms = [...this.transforms];
|
|
1897
|
-
next.spec = clone(_extends({}, this.spec, spec));
|
|
1903
|
+
next.spec = clone(_extends$2({}, this.spec, spec));
|
|
1898
1904
|
return next;
|
|
1899
1905
|
}
|
|
1900
1906
|
label(label) {
|
|
@@ -1927,7 +1933,7 @@ class BaseSchema {
|
|
|
1927
1933
|
if (schema.type !== this.type && this.type !== "mixed") throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
|
|
1928
1934
|
let base = this;
|
|
1929
1935
|
let combined = schema.clone();
|
|
1930
|
-
const mergedSpec = _extends({}, base.spec, combined.spec);
|
|
1936
|
+
const mergedSpec = _extends$2({}, base.spec, combined.spec);
|
|
1931
1937
|
combined.spec = mergedSpec;
|
|
1932
1938
|
combined._typeError || (combined._typeError = base._typeError);
|
|
1933
1939
|
combined._whitelistError || (combined._whitelistError = base._whitelistError);
|
|
@@ -1966,7 +1972,7 @@ class BaseSchema {
|
|
|
1966
1972
|
* @param {*=} options.context
|
|
1967
1973
|
*/
|
|
1968
1974
|
cast(value, options = {}) {
|
|
1969
|
-
let resolvedSchema = this.resolve(_extends({
|
|
1975
|
+
let resolvedSchema = this.resolve(_extends$2({
|
|
1970
1976
|
value
|
|
1971
1977
|
}, options));
|
|
1972
1978
|
let result = resolvedSchema._cast(value, options);
|
|
@@ -1998,7 +2004,7 @@ attempted value: ${formattedValue}
|
|
|
1998
2004
|
} = options;
|
|
1999
2005
|
let value = _value;
|
|
2000
2006
|
if (!strict) {
|
|
2001
|
-
value = this._cast(value, _extends({
|
|
2007
|
+
value = this._cast(value, _extends$2({
|
|
2002
2008
|
assert: false
|
|
2003
2009
|
}, options));
|
|
2004
2010
|
}
|
|
@@ -2035,7 +2041,7 @@ attempted value: ${formattedValue}
|
|
|
2035
2041
|
});
|
|
2036
2042
|
}
|
|
2037
2043
|
validate(value, options, maybeCb) {
|
|
2038
|
-
let schema = this.resolve(_extends({}, options, {
|
|
2044
|
+
let schema = this.resolve(_extends$2({}, options, {
|
|
2039
2045
|
value
|
|
2040
2046
|
}));
|
|
2041
2047
|
return typeof maybeCb === "function" ? schema._validate(value, options, maybeCb) : new Promise((resolve, reject) => schema._validate(value, options, (err, value2) => {
|
|
@@ -2044,11 +2050,11 @@ attempted value: ${formattedValue}
|
|
|
2044
2050
|
}));
|
|
2045
2051
|
}
|
|
2046
2052
|
validateSync(value, options) {
|
|
2047
|
-
let schema = this.resolve(_extends({}, options, {
|
|
2053
|
+
let schema = this.resolve(_extends$2({}, options, {
|
|
2048
2054
|
value
|
|
2049
2055
|
}));
|
|
2050
2056
|
let result;
|
|
2051
|
-
schema._validate(value, _extends({}, options, {
|
|
2057
|
+
schema._validate(value, _extends$2({}, options, {
|
|
2052
2058
|
sync: true
|
|
2053
2059
|
}), (err, value2) => {
|
|
2054
2060
|
if (err) throw err;
|
|
@@ -2296,7 +2302,7 @@ for (const method of ["validate", "validateSync"]) BaseSchema.prototype[`${metho
|
|
|
2296
2302
|
parentPath,
|
|
2297
2303
|
schema
|
|
2298
2304
|
} = getIn(this, path, value, options.context);
|
|
2299
|
-
return schema[method](parent && parent[parentPath], _extends({}, options, {
|
|
2305
|
+
return schema[method](parent && parent[parentPath], _extends$2({}, options, {
|
|
2300
2306
|
parent,
|
|
2301
2307
|
path
|
|
2302
2308
|
}));
|
|
@@ -2310,7 +2316,7 @@ let rUrl = /^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFD
|
|
|
2310
2316
|
let rUUID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
2311
2317
|
let isTrimmed = (value) => isAbsent(value) || value === value.trim();
|
|
2312
2318
|
let objStringTag = {}.toString();
|
|
2313
|
-
function create() {
|
|
2319
|
+
function create$2() {
|
|
2314
2320
|
return new StringSchema();
|
|
2315
2321
|
}
|
|
2316
2322
|
class StringSchema extends BaseSchema {
|
|
@@ -2447,7 +2453,7 @@ class StringSchema extends BaseSchema {
|
|
|
2447
2453
|
});
|
|
2448
2454
|
}
|
|
2449
2455
|
}
|
|
2450
|
-
create.prototype = StringSchema.prototype;
|
|
2456
|
+
create$2.prototype = StringSchema.prototype;
|
|
2451
2457
|
var isoReg = /^(\d{4}|[+\-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,\.](\d{1,}))?)?(?:(Z)|([+\-])(\d{2})(?::?(\d{2}))?)?)?$/;
|
|
2452
2458
|
function parseIsoDate(date2) {
|
|
2453
2459
|
var numericKeys = [1, 4, 5, 6, 7, 10, 11], minutesOffset = 0, timestamp, struct;
|
|
@@ -2526,11 +2532,373 @@ class DateSchema extends BaseSchema {
|
|
|
2526
2532
|
}
|
|
2527
2533
|
}
|
|
2528
2534
|
DateSchema.INVALID_DATE = invalidDate;
|
|
2529
|
-
|
|
2530
|
-
|
|
2535
|
+
function arrayReduce$1(array2, iteratee, accumulator, initAccum) {
|
|
2536
|
+
var index2 = -1, length = array2 == null ? 0 : array2.length;
|
|
2537
|
+
if (initAccum && length) {
|
|
2538
|
+
accumulator = array2[++index2];
|
|
2539
|
+
}
|
|
2540
|
+
while (++index2 < length) {
|
|
2541
|
+
accumulator = iteratee(accumulator, array2[index2], index2, array2);
|
|
2542
|
+
}
|
|
2543
|
+
return accumulator;
|
|
2544
|
+
}
|
|
2545
|
+
var _arrayReduce = arrayReduce$1;
|
|
2546
|
+
function basePropertyOf$1(object2) {
|
|
2547
|
+
return function(key) {
|
|
2548
|
+
return object2 == null ? void 0 : object2[key];
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
var _basePropertyOf = basePropertyOf$1;
|
|
2552
|
+
var basePropertyOf = _basePropertyOf;
|
|
2553
|
+
var deburredLetters = {
|
|
2554
|
+
// Latin-1 Supplement block.
|
|
2555
|
+
"À": "A",
|
|
2556
|
+
"Á": "A",
|
|
2557
|
+
"Â": "A",
|
|
2558
|
+
"Ã": "A",
|
|
2559
|
+
"Ä": "A",
|
|
2560
|
+
"Å": "A",
|
|
2561
|
+
"à": "a",
|
|
2562
|
+
"á": "a",
|
|
2563
|
+
"â": "a",
|
|
2564
|
+
"ã": "a",
|
|
2565
|
+
"ä": "a",
|
|
2566
|
+
"å": "a",
|
|
2567
|
+
"Ç": "C",
|
|
2568
|
+
"ç": "c",
|
|
2569
|
+
"Ð": "D",
|
|
2570
|
+
"ð": "d",
|
|
2571
|
+
"È": "E",
|
|
2572
|
+
"É": "E",
|
|
2573
|
+
"Ê": "E",
|
|
2574
|
+
"Ë": "E",
|
|
2575
|
+
"è": "e",
|
|
2576
|
+
"é": "e",
|
|
2577
|
+
"ê": "e",
|
|
2578
|
+
"ë": "e",
|
|
2579
|
+
"Ì": "I",
|
|
2580
|
+
"Í": "I",
|
|
2581
|
+
"Î": "I",
|
|
2582
|
+
"Ï": "I",
|
|
2583
|
+
"ì": "i",
|
|
2584
|
+
"í": "i",
|
|
2585
|
+
"î": "i",
|
|
2586
|
+
"ï": "i",
|
|
2587
|
+
"Ñ": "N",
|
|
2588
|
+
"ñ": "n",
|
|
2589
|
+
"Ò": "O",
|
|
2590
|
+
"Ó": "O",
|
|
2591
|
+
"Ô": "O",
|
|
2592
|
+
"Õ": "O",
|
|
2593
|
+
"Ö": "O",
|
|
2594
|
+
"Ø": "O",
|
|
2595
|
+
"ò": "o",
|
|
2596
|
+
"ó": "o",
|
|
2597
|
+
"ô": "o",
|
|
2598
|
+
"õ": "o",
|
|
2599
|
+
"ö": "o",
|
|
2600
|
+
"ø": "o",
|
|
2601
|
+
"Ù": "U",
|
|
2602
|
+
"Ú": "U",
|
|
2603
|
+
"Û": "U",
|
|
2604
|
+
"Ü": "U",
|
|
2605
|
+
"ù": "u",
|
|
2606
|
+
"ú": "u",
|
|
2607
|
+
"û": "u",
|
|
2608
|
+
"ü": "u",
|
|
2609
|
+
"Ý": "Y",
|
|
2610
|
+
"ý": "y",
|
|
2611
|
+
"ÿ": "y",
|
|
2612
|
+
"Æ": "Ae",
|
|
2613
|
+
"æ": "ae",
|
|
2614
|
+
"Þ": "Th",
|
|
2615
|
+
"þ": "th",
|
|
2616
|
+
"ß": "ss",
|
|
2617
|
+
// Latin Extended-A block.
|
|
2618
|
+
"Ā": "A",
|
|
2619
|
+
"Ă": "A",
|
|
2620
|
+
"Ą": "A",
|
|
2621
|
+
"ā": "a",
|
|
2622
|
+
"ă": "a",
|
|
2623
|
+
"ą": "a",
|
|
2624
|
+
"Ć": "C",
|
|
2625
|
+
"Ĉ": "C",
|
|
2626
|
+
"Ċ": "C",
|
|
2627
|
+
"Č": "C",
|
|
2628
|
+
"ć": "c",
|
|
2629
|
+
"ĉ": "c",
|
|
2630
|
+
"ċ": "c",
|
|
2631
|
+
"č": "c",
|
|
2632
|
+
"Ď": "D",
|
|
2633
|
+
"Đ": "D",
|
|
2634
|
+
"ď": "d",
|
|
2635
|
+
"đ": "d",
|
|
2636
|
+
"Ē": "E",
|
|
2637
|
+
"Ĕ": "E",
|
|
2638
|
+
"Ė": "E",
|
|
2639
|
+
"Ę": "E",
|
|
2640
|
+
"Ě": "E",
|
|
2641
|
+
"ē": "e",
|
|
2642
|
+
"ĕ": "e",
|
|
2643
|
+
"ė": "e",
|
|
2644
|
+
"ę": "e",
|
|
2645
|
+
"ě": "e",
|
|
2646
|
+
"Ĝ": "G",
|
|
2647
|
+
"Ğ": "G",
|
|
2648
|
+
"Ġ": "G",
|
|
2649
|
+
"Ģ": "G",
|
|
2650
|
+
"ĝ": "g",
|
|
2651
|
+
"ğ": "g",
|
|
2652
|
+
"ġ": "g",
|
|
2653
|
+
"ģ": "g",
|
|
2654
|
+
"Ĥ": "H",
|
|
2655
|
+
"Ħ": "H",
|
|
2656
|
+
"ĥ": "h",
|
|
2657
|
+
"ħ": "h",
|
|
2658
|
+
"Ĩ": "I",
|
|
2659
|
+
"Ī": "I",
|
|
2660
|
+
"Ĭ": "I",
|
|
2661
|
+
"Į": "I",
|
|
2662
|
+
"İ": "I",
|
|
2663
|
+
"ĩ": "i",
|
|
2664
|
+
"ī": "i",
|
|
2665
|
+
"ĭ": "i",
|
|
2666
|
+
"į": "i",
|
|
2667
|
+
"ı": "i",
|
|
2668
|
+
"Ĵ": "J",
|
|
2669
|
+
"ĵ": "j",
|
|
2670
|
+
"Ķ": "K",
|
|
2671
|
+
"ķ": "k",
|
|
2672
|
+
"ĸ": "k",
|
|
2673
|
+
"Ĺ": "L",
|
|
2674
|
+
"Ļ": "L",
|
|
2675
|
+
"Ľ": "L",
|
|
2676
|
+
"Ŀ": "L",
|
|
2677
|
+
"Ł": "L",
|
|
2678
|
+
"ĺ": "l",
|
|
2679
|
+
"ļ": "l",
|
|
2680
|
+
"ľ": "l",
|
|
2681
|
+
"ŀ": "l",
|
|
2682
|
+
"ł": "l",
|
|
2683
|
+
"Ń": "N",
|
|
2684
|
+
"Ņ": "N",
|
|
2685
|
+
"Ň": "N",
|
|
2686
|
+
"Ŋ": "N",
|
|
2687
|
+
"ń": "n",
|
|
2688
|
+
"ņ": "n",
|
|
2689
|
+
"ň": "n",
|
|
2690
|
+
"ŋ": "n",
|
|
2691
|
+
"Ō": "O",
|
|
2692
|
+
"Ŏ": "O",
|
|
2693
|
+
"Ő": "O",
|
|
2694
|
+
"ō": "o",
|
|
2695
|
+
"ŏ": "o",
|
|
2696
|
+
"ő": "o",
|
|
2697
|
+
"Ŕ": "R",
|
|
2698
|
+
"Ŗ": "R",
|
|
2699
|
+
"Ř": "R",
|
|
2700
|
+
"ŕ": "r",
|
|
2701
|
+
"ŗ": "r",
|
|
2702
|
+
"ř": "r",
|
|
2703
|
+
"Ś": "S",
|
|
2704
|
+
"Ŝ": "S",
|
|
2705
|
+
"Ş": "S",
|
|
2706
|
+
"Š": "S",
|
|
2707
|
+
"ś": "s",
|
|
2708
|
+
"ŝ": "s",
|
|
2709
|
+
"ş": "s",
|
|
2710
|
+
"š": "s",
|
|
2711
|
+
"Ţ": "T",
|
|
2712
|
+
"Ť": "T",
|
|
2713
|
+
"Ŧ": "T",
|
|
2714
|
+
"ţ": "t",
|
|
2715
|
+
"ť": "t",
|
|
2716
|
+
"ŧ": "t",
|
|
2717
|
+
"Ũ": "U",
|
|
2718
|
+
"Ū": "U",
|
|
2719
|
+
"Ŭ": "U",
|
|
2720
|
+
"Ů": "U",
|
|
2721
|
+
"Ű": "U",
|
|
2722
|
+
"Ų": "U",
|
|
2723
|
+
"ũ": "u",
|
|
2724
|
+
"ū": "u",
|
|
2725
|
+
"ŭ": "u",
|
|
2726
|
+
"ů": "u",
|
|
2727
|
+
"ű": "u",
|
|
2728
|
+
"ų": "u",
|
|
2729
|
+
"Ŵ": "W",
|
|
2730
|
+
"ŵ": "w",
|
|
2731
|
+
"Ŷ": "Y",
|
|
2732
|
+
"ŷ": "y",
|
|
2733
|
+
"Ÿ": "Y",
|
|
2734
|
+
"Ź": "Z",
|
|
2735
|
+
"Ż": "Z",
|
|
2736
|
+
"Ž": "Z",
|
|
2737
|
+
"ź": "z",
|
|
2738
|
+
"ż": "z",
|
|
2739
|
+
"ž": "z",
|
|
2740
|
+
"IJ": "IJ",
|
|
2741
|
+
"ij": "ij",
|
|
2742
|
+
"Œ": "Oe",
|
|
2743
|
+
"œ": "oe",
|
|
2744
|
+
"ʼn": "'n",
|
|
2745
|
+
"ſ": "s"
|
|
2746
|
+
};
|
|
2747
|
+
var deburrLetter$1 = basePropertyOf(deburredLetters);
|
|
2748
|
+
var _deburrLetter = deburrLetter$1;
|
|
2749
|
+
var deburrLetter = _deburrLetter, toString$3 = toString_1;
|
|
2750
|
+
var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
|
|
2751
|
+
var rsComboMarksRange$3 = "\\u0300-\\u036f", reComboHalfMarksRange$3 = "\\ufe20-\\ufe2f", rsComboSymbolsRange$3 = "\\u20d0-\\u20ff", rsComboRange$3 = rsComboMarksRange$3 + reComboHalfMarksRange$3 + rsComboSymbolsRange$3;
|
|
2752
|
+
var rsCombo$2 = "[" + rsComboRange$3 + "]";
|
|
2753
|
+
var reComboMark = RegExp(rsCombo$2, "g");
|
|
2754
|
+
function deburr$1(string2) {
|
|
2755
|
+
string2 = toString$3(string2);
|
|
2756
|
+
return string2 && string2.replace(reLatin, deburrLetter).replace(reComboMark, "");
|
|
2757
|
+
}
|
|
2758
|
+
var deburr_1 = deburr$1;
|
|
2759
|
+
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
2760
|
+
function asciiWords$1(string2) {
|
|
2761
|
+
return string2.match(reAsciiWord) || [];
|
|
2762
|
+
}
|
|
2763
|
+
var _asciiWords = asciiWords$1;
|
|
2764
|
+
var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
|
|
2765
|
+
function hasUnicodeWord$1(string2) {
|
|
2766
|
+
return reHasUnicodeWord.test(string2);
|
|
2767
|
+
}
|
|
2768
|
+
var _hasUnicodeWord = hasUnicodeWord$1;
|
|
2769
|
+
var rsAstralRange$2 = "\\ud800-\\udfff", rsComboMarksRange$2 = "\\u0300-\\u036f", reComboHalfMarksRange$2 = "\\ufe20-\\ufe2f", rsComboSymbolsRange$2 = "\\u20d0-\\u20ff", rsComboRange$2 = rsComboMarksRange$2 + reComboHalfMarksRange$2 + rsComboSymbolsRange$2, rsDingbatRange = "\\u2700-\\u27bf", rsLowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff", rsMathOpRange = "\\xac\\xb1\\xd7\\xf7", rsNonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf", rsPunctuationRange = "\\u2000-\\u206f", rsSpaceRange = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000", rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde", rsVarRange$2 = "\\ufe0e\\ufe0f", rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
|
|
2770
|
+
var rsApos$1 = "['’]", rsBreak = "[" + rsBreakRange + "]", rsCombo$1 = "[" + rsComboRange$2 + "]", rsDigits = "\\d+", rsDingbat = "[" + rsDingbatRange + "]", rsLower = "[" + rsLowerRange + "]", rsMisc = "[^" + rsAstralRange$2 + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + "]", rsFitz$1 = "\\ud83c[\\udffb-\\udfff]", rsModifier$1 = "(?:" + rsCombo$1 + "|" + rsFitz$1 + ")", rsNonAstral$1 = "[^" + rsAstralRange$2 + "]", rsRegional$1 = "(?:\\ud83c[\\udde6-\\uddff]){2}", rsSurrPair$1 = "[\\ud800-\\udbff][\\udc00-\\udfff]", rsUpper = "[" + rsUpperRange + "]", rsZWJ$2 = "\\u200d";
|
|
2771
|
+
var rsMiscLower = "(?:" + rsLower + "|" + rsMisc + ")", rsMiscUpper = "(?:" + rsUpper + "|" + rsMisc + ")", rsOptContrLower = "(?:" + rsApos$1 + "(?:d|ll|m|re|s|t|ve))?", rsOptContrUpper = "(?:" + rsApos$1 + "(?:D|LL|M|RE|S|T|VE))?", reOptMod$1 = rsModifier$1 + "?", rsOptVar$1 = "[" + rsVarRange$2 + "]?", rsOptJoin$1 = "(?:" + rsZWJ$2 + "(?:" + [rsNonAstral$1, rsRegional$1, rsSurrPair$1].join("|") + ")" + rsOptVar$1 + reOptMod$1 + ")*", rsOrdLower = "\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])", rsOrdUpper = "\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])", rsSeq$1 = rsOptVar$1 + reOptMod$1 + rsOptJoin$1, rsEmoji = "(?:" + [rsDingbat, rsRegional$1, rsSurrPair$1].join("|") + ")" + rsSeq$1;
|
|
2772
|
+
var reUnicodeWord = RegExp([
|
|
2773
|
+
rsUpper + "?" + rsLower + "+" + rsOptContrLower + "(?=" + [rsBreak, rsUpper, "$"].join("|") + ")",
|
|
2774
|
+
rsMiscUpper + "+" + rsOptContrUpper + "(?=" + [rsBreak, rsUpper + rsMiscLower, "$"].join("|") + ")",
|
|
2775
|
+
rsUpper + "?" + rsMiscLower + "+" + rsOptContrLower,
|
|
2776
|
+
rsUpper + "+" + rsOptContrUpper,
|
|
2777
|
+
rsOrdUpper,
|
|
2778
|
+
rsOrdLower,
|
|
2779
|
+
rsDigits,
|
|
2780
|
+
rsEmoji
|
|
2781
|
+
].join("|"), "g");
|
|
2782
|
+
function unicodeWords$1(string2) {
|
|
2783
|
+
return string2.match(reUnicodeWord) || [];
|
|
2784
|
+
}
|
|
2785
|
+
var _unicodeWords = unicodeWords$1;
|
|
2786
|
+
var asciiWords = _asciiWords, hasUnicodeWord = _hasUnicodeWord, toString$2 = toString_1, unicodeWords = _unicodeWords;
|
|
2787
|
+
function words$1(string2, pattern, guard) {
|
|
2788
|
+
string2 = toString$2(string2);
|
|
2789
|
+
pattern = guard ? void 0 : pattern;
|
|
2790
|
+
if (pattern === void 0) {
|
|
2791
|
+
return hasUnicodeWord(string2) ? unicodeWords(string2) : asciiWords(string2);
|
|
2792
|
+
}
|
|
2793
|
+
return string2.match(pattern) || [];
|
|
2794
|
+
}
|
|
2795
|
+
var words_1 = words$1;
|
|
2796
|
+
var arrayReduce = _arrayReduce, deburr = deburr_1, words = words_1;
|
|
2797
|
+
var rsApos = "['’]";
|
|
2798
|
+
var reApos = RegExp(rsApos, "g");
|
|
2799
|
+
function createCompounder$2(callback) {
|
|
2800
|
+
return function(string2) {
|
|
2801
|
+
return arrayReduce(words(deburr(string2).replace(reApos, "")), callback, "");
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
var _createCompounder = createCompounder$2;
|
|
2805
|
+
var createCompounder$1 = _createCompounder;
|
|
2806
|
+
var snakeCase = createCompounder$1(function(result, word, index2) {
|
|
2807
|
+
return result + (index2 ? "_" : "") + word.toLowerCase();
|
|
2808
|
+
});
|
|
2809
|
+
var snakeCase_1 = snakeCase;
|
|
2810
|
+
const snakeCase$1 = /* @__PURE__ */ getDefaultExportFromCjs(snakeCase_1);
|
|
2811
|
+
function baseSlice$1(array2, start, end) {
|
|
2812
|
+
var index2 = -1, length = array2.length;
|
|
2813
|
+
if (start < 0) {
|
|
2814
|
+
start = -start > length ? 0 : length + start;
|
|
2815
|
+
}
|
|
2816
|
+
end = end > length ? length : end;
|
|
2817
|
+
if (end < 0) {
|
|
2818
|
+
end += length;
|
|
2819
|
+
}
|
|
2820
|
+
length = start > end ? 0 : end - start >>> 0;
|
|
2821
|
+
start >>>= 0;
|
|
2822
|
+
var result = Array(length);
|
|
2823
|
+
while (++index2 < length) {
|
|
2824
|
+
result[index2] = array2[index2 + start];
|
|
2825
|
+
}
|
|
2826
|
+
return result;
|
|
2827
|
+
}
|
|
2828
|
+
var _baseSlice = baseSlice$1;
|
|
2829
|
+
var baseSlice = _baseSlice;
|
|
2830
|
+
function castSlice$1(array2, start, end) {
|
|
2831
|
+
var length = array2.length;
|
|
2832
|
+
end = end === void 0 ? length : end;
|
|
2833
|
+
return !start && end >= length ? array2 : baseSlice(array2, start, end);
|
|
2834
|
+
}
|
|
2835
|
+
var _castSlice = castSlice$1;
|
|
2836
|
+
var rsAstralRange$1 = "\\ud800-\\udfff", rsComboMarksRange$1 = "\\u0300-\\u036f", reComboHalfMarksRange$1 = "\\ufe20-\\ufe2f", rsComboSymbolsRange$1 = "\\u20d0-\\u20ff", rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1, rsVarRange$1 = "\\ufe0e\\ufe0f";
|
|
2837
|
+
var rsZWJ$1 = "\\u200d";
|
|
2838
|
+
var reHasUnicode = RegExp("[" + rsZWJ$1 + rsAstralRange$1 + rsComboRange$1 + rsVarRange$1 + "]");
|
|
2839
|
+
function hasUnicode$2(string2) {
|
|
2840
|
+
return reHasUnicode.test(string2);
|
|
2841
|
+
}
|
|
2842
|
+
var _hasUnicode = hasUnicode$2;
|
|
2843
|
+
function asciiToArray$1(string2) {
|
|
2844
|
+
return string2.split("");
|
|
2845
|
+
}
|
|
2846
|
+
var _asciiToArray = asciiToArray$1;
|
|
2847
|
+
var rsAstralRange = "\\ud800-\\udfff", rsComboMarksRange = "\\u0300-\\u036f", reComboHalfMarksRange = "\\ufe20-\\ufe2f", rsComboSymbolsRange = "\\u20d0-\\u20ff", rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, rsVarRange = "\\ufe0e\\ufe0f";
|
|
2848
|
+
var rsAstral = "[" + rsAstralRange + "]", rsCombo = "[" + rsComboRange + "]", rsFitz = "\\ud83c[\\udffb-\\udfff]", rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")", rsNonAstral = "[^" + rsAstralRange + "]", rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}", rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]", rsZWJ = "\\u200d";
|
|
2849
|
+
var reOptMod = rsModifier + "?", rsOptVar = "[" + rsVarRange + "]?", rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*", rsSeq = rsOptVar + reOptMod + rsOptJoin, rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
|
|
2850
|
+
var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
|
|
2851
|
+
function unicodeToArray$1(string2) {
|
|
2852
|
+
return string2.match(reUnicode) || [];
|
|
2853
|
+
}
|
|
2854
|
+
var _unicodeToArray = unicodeToArray$1;
|
|
2855
|
+
var asciiToArray = _asciiToArray, hasUnicode$1 = _hasUnicode, unicodeToArray = _unicodeToArray;
|
|
2856
|
+
function stringToArray$1(string2) {
|
|
2857
|
+
return hasUnicode$1(string2) ? unicodeToArray(string2) : asciiToArray(string2);
|
|
2858
|
+
}
|
|
2859
|
+
var _stringToArray = stringToArray$1;
|
|
2860
|
+
var castSlice = _castSlice, hasUnicode = _hasUnicode, stringToArray = _stringToArray, toString$1 = toString_1;
|
|
2861
|
+
function createCaseFirst$1(methodName) {
|
|
2862
|
+
return function(string2) {
|
|
2863
|
+
string2 = toString$1(string2);
|
|
2864
|
+
var strSymbols = hasUnicode(string2) ? stringToArray(string2) : void 0;
|
|
2865
|
+
var chr = strSymbols ? strSymbols[0] : string2.charAt(0);
|
|
2866
|
+
var trailing = strSymbols ? castSlice(strSymbols, 1).join("") : string2.slice(1);
|
|
2867
|
+
return chr[methodName]() + trailing;
|
|
2868
|
+
};
|
|
2869
|
+
}
|
|
2870
|
+
var _createCaseFirst = createCaseFirst$1;
|
|
2871
|
+
var createCaseFirst = _createCaseFirst;
|
|
2872
|
+
var upperFirst$1 = createCaseFirst("toUpperCase");
|
|
2873
|
+
var upperFirst_1 = upperFirst$1;
|
|
2874
|
+
var toString = toString_1, upperFirst = upperFirst_1;
|
|
2875
|
+
function capitalize$1(string2) {
|
|
2876
|
+
return upperFirst(toString(string2).toLowerCase());
|
|
2877
|
+
}
|
|
2878
|
+
var capitalize_1 = capitalize$1;
|
|
2879
|
+
var capitalize = capitalize_1, createCompounder = _createCompounder;
|
|
2880
|
+
var camelCase = createCompounder(function(result, word, index2) {
|
|
2881
|
+
word = word.toLowerCase();
|
|
2882
|
+
return result + (index2 ? capitalize(word) : word);
|
|
2883
|
+
});
|
|
2884
|
+
var camelCase_1 = camelCase;
|
|
2885
|
+
const camelCase$1 = /* @__PURE__ */ getDefaultExportFromCjs(camelCase_1);
|
|
2886
|
+
var baseAssignValue = _baseAssignValue, baseForOwn = _baseForOwn, baseIteratee = _baseIteratee;
|
|
2887
|
+
function mapKeys(object2, iteratee) {
|
|
2888
|
+
var result = {};
|
|
2889
|
+
iteratee = baseIteratee(iteratee);
|
|
2890
|
+
baseForOwn(object2, function(value, key, object3) {
|
|
2891
|
+
baseAssignValue(result, iteratee(value, key, object3), value);
|
|
2892
|
+
});
|
|
2893
|
+
return result;
|
|
2894
|
+
}
|
|
2895
|
+
var mapKeys_1 = mapKeys;
|
|
2896
|
+
const mapKeys$1 = /* @__PURE__ */ getDefaultExportFromCjs(mapKeys_1);
|
|
2897
|
+
var toposort$2 = { exports: {} };
|
|
2898
|
+
toposort$2.exports = function(edges) {
|
|
2531
2899
|
return toposort(uniqueNodes(edges), edges);
|
|
2532
2900
|
};
|
|
2533
|
-
toposort$
|
|
2901
|
+
toposort$2.exports.array = toposort;
|
|
2534
2902
|
function toposort(nodes, edges) {
|
|
2535
2903
|
var cursor = nodes.length, sorted = new Array(cursor), visited = {}, i = cursor, outgoingEdges = makeOutgoingEdges(edges), nodesHash = makeNodesHash(nodes);
|
|
2536
2904
|
edges.forEach(function(edge) {
|
|
@@ -2596,9 +2964,514 @@ function makeNodesHash(arr) {
|
|
|
2596
2964
|
}
|
|
2597
2965
|
return res;
|
|
2598
2966
|
}
|
|
2967
|
+
var toposortExports = toposort$2.exports;
|
|
2968
|
+
const toposort$1 = /* @__PURE__ */ getDefaultExportFromCjs(toposortExports);
|
|
2969
|
+
function sortFields(fields, excludes = []) {
|
|
2970
|
+
let edges = [];
|
|
2971
|
+
let nodes = [];
|
|
2972
|
+
function addNode(depPath, key) {
|
|
2973
|
+
var node = propertyExpr.split(depPath)[0];
|
|
2974
|
+
if (!~nodes.indexOf(node)) nodes.push(node);
|
|
2975
|
+
if (!~excludes.indexOf(`${key}-${node}`)) edges.push([key, node]);
|
|
2976
|
+
}
|
|
2977
|
+
for (const key in fields) if (has$1(fields, key)) {
|
|
2978
|
+
let value = fields[key];
|
|
2979
|
+
if (!~nodes.indexOf(key)) nodes.push(key);
|
|
2980
|
+
if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);
|
|
2981
|
+
else if (isSchema(value) && "deps" in value) value.deps.forEach((path) => addNode(path, key));
|
|
2982
|
+
}
|
|
2983
|
+
return toposort$1.array(nodes, edges).reverse();
|
|
2984
|
+
}
|
|
2985
|
+
function findIndex(arr, err) {
|
|
2986
|
+
let idx = Infinity;
|
|
2987
|
+
arr.some((key, ii) => {
|
|
2988
|
+
var _err$path;
|
|
2989
|
+
if (((_err$path = err.path) == null ? void 0 : _err$path.indexOf(key)) !== -1) {
|
|
2990
|
+
idx = ii;
|
|
2991
|
+
return true;
|
|
2992
|
+
}
|
|
2993
|
+
});
|
|
2994
|
+
return idx;
|
|
2995
|
+
}
|
|
2996
|
+
function sortByKeyOrder(keys2) {
|
|
2997
|
+
return (a, b) => {
|
|
2998
|
+
return findIndex(keys2, a) - findIndex(keys2, b);
|
|
2999
|
+
};
|
|
3000
|
+
}
|
|
3001
|
+
function _extends$1() {
|
|
3002
|
+
_extends$1 = Object.assign || function(target) {
|
|
3003
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
3004
|
+
var source = arguments[i];
|
|
3005
|
+
for (var key in source) {
|
|
3006
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
3007
|
+
target[key] = source[key];
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
return target;
|
|
3012
|
+
};
|
|
3013
|
+
return _extends$1.apply(this, arguments);
|
|
3014
|
+
}
|
|
3015
|
+
let isObject = (obj) => Object.prototype.toString.call(obj) === "[object Object]";
|
|
3016
|
+
function unknown(ctx, value) {
|
|
3017
|
+
let known = Object.keys(ctx.fields);
|
|
3018
|
+
return Object.keys(value).filter((key) => known.indexOf(key) === -1);
|
|
3019
|
+
}
|
|
3020
|
+
const defaultSort = sortByKeyOrder([]);
|
|
3021
|
+
class ObjectSchema extends BaseSchema {
|
|
3022
|
+
constructor(spec) {
|
|
3023
|
+
super({
|
|
3024
|
+
type: "object"
|
|
3025
|
+
});
|
|
3026
|
+
this.fields = /* @__PURE__ */ Object.create(null);
|
|
3027
|
+
this._sortErrors = defaultSort;
|
|
3028
|
+
this._nodes = [];
|
|
3029
|
+
this._excludedEdges = [];
|
|
3030
|
+
this.withMutation(() => {
|
|
3031
|
+
this.transform(function coerce(value) {
|
|
3032
|
+
if (typeof value === "string") {
|
|
3033
|
+
try {
|
|
3034
|
+
value = JSON.parse(value);
|
|
3035
|
+
} catch (err) {
|
|
3036
|
+
value = null;
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
if (this.isType(value)) return value;
|
|
3040
|
+
return null;
|
|
3041
|
+
});
|
|
3042
|
+
if (spec) {
|
|
3043
|
+
this.shape(spec);
|
|
3044
|
+
}
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3047
|
+
_typeCheck(value) {
|
|
3048
|
+
return isObject(value) || typeof value === "function";
|
|
3049
|
+
}
|
|
3050
|
+
_cast(_value, options = {}) {
|
|
3051
|
+
var _options$stripUnknown;
|
|
3052
|
+
let value = super._cast(_value, options);
|
|
3053
|
+
if (value === void 0) return this.getDefault();
|
|
3054
|
+
if (!this._typeCheck(value)) return value;
|
|
3055
|
+
let fields = this.fields;
|
|
3056
|
+
let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
|
|
3057
|
+
let props = this._nodes.concat(Object.keys(value).filter((v) => this._nodes.indexOf(v) === -1));
|
|
3058
|
+
let intermediateValue = {};
|
|
3059
|
+
let innerOptions = _extends$1({}, options, {
|
|
3060
|
+
parent: intermediateValue,
|
|
3061
|
+
__validating: options.__validating || false
|
|
3062
|
+
});
|
|
3063
|
+
let isChanged = false;
|
|
3064
|
+
for (const prop of props) {
|
|
3065
|
+
let field = fields[prop];
|
|
3066
|
+
let exists = has$1(value, prop);
|
|
3067
|
+
if (field) {
|
|
3068
|
+
let fieldValue;
|
|
3069
|
+
let inputValue = value[prop];
|
|
3070
|
+
innerOptions.path = (options.path ? `${options.path}.` : "") + prop;
|
|
3071
|
+
field = field.resolve({
|
|
3072
|
+
value: inputValue,
|
|
3073
|
+
context: options.context,
|
|
3074
|
+
parent: intermediateValue
|
|
3075
|
+
});
|
|
3076
|
+
let fieldSpec = "spec" in field ? field.spec : void 0;
|
|
3077
|
+
let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
|
|
3078
|
+
if (fieldSpec == null ? void 0 : fieldSpec.strip) {
|
|
3079
|
+
isChanged = isChanged || prop in value;
|
|
3080
|
+
continue;
|
|
3081
|
+
}
|
|
3082
|
+
fieldValue = !options.__validating || !strict ? (
|
|
3083
|
+
// TODO: use _cast, this is double resolving
|
|
3084
|
+
field.cast(value[prop], innerOptions)
|
|
3085
|
+
) : value[prop];
|
|
3086
|
+
if (fieldValue !== void 0) {
|
|
3087
|
+
intermediateValue[prop] = fieldValue;
|
|
3088
|
+
}
|
|
3089
|
+
} else if (exists && !strip) {
|
|
3090
|
+
intermediateValue[prop] = value[prop];
|
|
3091
|
+
}
|
|
3092
|
+
if (intermediateValue[prop] !== value[prop]) {
|
|
3093
|
+
isChanged = true;
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return isChanged ? intermediateValue : value;
|
|
3097
|
+
}
|
|
3098
|
+
_validate(_value, opts = {}, callback) {
|
|
3099
|
+
let errors = [];
|
|
3100
|
+
let {
|
|
3101
|
+
sync,
|
|
3102
|
+
from = [],
|
|
3103
|
+
originalValue = _value,
|
|
3104
|
+
abortEarly = this.spec.abortEarly,
|
|
3105
|
+
recursive = this.spec.recursive
|
|
3106
|
+
} = opts;
|
|
3107
|
+
from = [{
|
|
3108
|
+
schema: this,
|
|
3109
|
+
value: originalValue
|
|
3110
|
+
}, ...from];
|
|
3111
|
+
opts.__validating = true;
|
|
3112
|
+
opts.originalValue = originalValue;
|
|
3113
|
+
opts.from = from;
|
|
3114
|
+
super._validate(_value, opts, (err, value) => {
|
|
3115
|
+
if (err) {
|
|
3116
|
+
if (!ValidationError.isError(err) || abortEarly) {
|
|
3117
|
+
return void callback(err, value);
|
|
3118
|
+
}
|
|
3119
|
+
errors.push(err);
|
|
3120
|
+
}
|
|
3121
|
+
if (!recursive || !isObject(value)) {
|
|
3122
|
+
callback(errors[0] || null, value);
|
|
3123
|
+
return;
|
|
3124
|
+
}
|
|
3125
|
+
originalValue = originalValue || value;
|
|
3126
|
+
let tests = this._nodes.map((key) => (_, cb) => {
|
|
3127
|
+
let path = key.indexOf(".") === -1 ? (opts.path ? `${opts.path}.` : "") + key : `${opts.path || ""}["${key}"]`;
|
|
3128
|
+
let field = this.fields[key];
|
|
3129
|
+
if (field && "validate" in field) {
|
|
3130
|
+
field.validate(value[key], _extends$1({}, opts, {
|
|
3131
|
+
// @ts-ignore
|
|
3132
|
+
path,
|
|
3133
|
+
from,
|
|
3134
|
+
// inner fields are always strict:
|
|
3135
|
+
// 1. this isn't strict so the casting will also have cast inner values
|
|
3136
|
+
// 2. this is strict in which case the nested values weren't cast either
|
|
3137
|
+
strict: true,
|
|
3138
|
+
parent: value,
|
|
3139
|
+
originalValue: originalValue[key]
|
|
3140
|
+
}), cb);
|
|
3141
|
+
return;
|
|
3142
|
+
}
|
|
3143
|
+
cb(null);
|
|
3144
|
+
});
|
|
3145
|
+
runTests({
|
|
3146
|
+
tests,
|
|
3147
|
+
value,
|
|
3148
|
+
errors,
|
|
3149
|
+
endEarly: abortEarly,
|
|
3150
|
+
sort: this._sortErrors,
|
|
3151
|
+
path: opts.path
|
|
3152
|
+
}, callback);
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
clone(spec) {
|
|
3156
|
+
const next = super.clone(spec);
|
|
3157
|
+
next.fields = _extends$1({}, this.fields);
|
|
3158
|
+
next._nodes = this._nodes;
|
|
3159
|
+
next._excludedEdges = this._excludedEdges;
|
|
3160
|
+
next._sortErrors = this._sortErrors;
|
|
3161
|
+
return next;
|
|
3162
|
+
}
|
|
3163
|
+
concat(schema) {
|
|
3164
|
+
let next = super.concat(schema);
|
|
3165
|
+
let nextFields = next.fields;
|
|
3166
|
+
for (let [field, schemaOrRef] of Object.entries(this.fields)) {
|
|
3167
|
+
const target = nextFields[field];
|
|
3168
|
+
if (target === void 0) {
|
|
3169
|
+
nextFields[field] = schemaOrRef;
|
|
3170
|
+
} else if (target instanceof BaseSchema && schemaOrRef instanceof BaseSchema) {
|
|
3171
|
+
nextFields[field] = schemaOrRef.concat(target);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
return next.withMutation(() => next.shape(nextFields));
|
|
3175
|
+
}
|
|
3176
|
+
getDefaultFromShape() {
|
|
3177
|
+
let dft = {};
|
|
3178
|
+
this._nodes.forEach((key) => {
|
|
3179
|
+
const field = this.fields[key];
|
|
3180
|
+
dft[key] = "default" in field ? field.getDefault() : void 0;
|
|
3181
|
+
});
|
|
3182
|
+
return dft;
|
|
3183
|
+
}
|
|
3184
|
+
_getDefault() {
|
|
3185
|
+
if ("default" in this.spec) {
|
|
3186
|
+
return super._getDefault();
|
|
3187
|
+
}
|
|
3188
|
+
if (!this._nodes.length) {
|
|
3189
|
+
return void 0;
|
|
3190
|
+
}
|
|
3191
|
+
return this.getDefaultFromShape();
|
|
3192
|
+
}
|
|
3193
|
+
shape(additions, excludes = []) {
|
|
3194
|
+
let next = this.clone();
|
|
3195
|
+
let fields = Object.assign(next.fields, additions);
|
|
3196
|
+
next.fields = fields;
|
|
3197
|
+
next._sortErrors = sortByKeyOrder(Object.keys(fields));
|
|
3198
|
+
if (excludes.length) {
|
|
3199
|
+
if (!Array.isArray(excludes[0])) excludes = [excludes];
|
|
3200
|
+
let keys2 = excludes.map(([first, second]) => `${first}-${second}`);
|
|
3201
|
+
next._excludedEdges = next._excludedEdges.concat(keys2);
|
|
3202
|
+
}
|
|
3203
|
+
next._nodes = sortFields(fields, next._excludedEdges);
|
|
3204
|
+
return next;
|
|
3205
|
+
}
|
|
3206
|
+
pick(keys2) {
|
|
3207
|
+
const picked = {};
|
|
3208
|
+
for (const key of keys2) {
|
|
3209
|
+
if (this.fields[key]) picked[key] = this.fields[key];
|
|
3210
|
+
}
|
|
3211
|
+
return this.clone().withMutation((next) => {
|
|
3212
|
+
next.fields = {};
|
|
3213
|
+
return next.shape(picked);
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
omit(keys2) {
|
|
3217
|
+
const next = this.clone();
|
|
3218
|
+
const fields = next.fields;
|
|
3219
|
+
next.fields = {};
|
|
3220
|
+
for (const key of keys2) {
|
|
3221
|
+
delete fields[key];
|
|
3222
|
+
}
|
|
3223
|
+
return next.withMutation(() => next.shape(fields));
|
|
3224
|
+
}
|
|
3225
|
+
from(from, to, alias) {
|
|
3226
|
+
let fromGetter = propertyExpr.getter(from, true);
|
|
3227
|
+
return this.transform((obj) => {
|
|
3228
|
+
if (obj == null) return obj;
|
|
3229
|
+
let newObj = obj;
|
|
3230
|
+
if (has$1(obj, from)) {
|
|
3231
|
+
newObj = _extends$1({}, obj);
|
|
3232
|
+
if (!alias) delete newObj[from];
|
|
3233
|
+
newObj[to] = fromGetter(obj);
|
|
3234
|
+
}
|
|
3235
|
+
return newObj;
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
noUnknown(noAllow = true, message = object.noUnknown) {
|
|
3239
|
+
if (typeof noAllow === "string") {
|
|
3240
|
+
message = noAllow;
|
|
3241
|
+
noAllow = true;
|
|
3242
|
+
}
|
|
3243
|
+
let next = this.test({
|
|
3244
|
+
name: "noUnknown",
|
|
3245
|
+
exclusive: true,
|
|
3246
|
+
message,
|
|
3247
|
+
test(value) {
|
|
3248
|
+
if (value == null) return true;
|
|
3249
|
+
const unknownKeys = unknown(this.schema, value);
|
|
3250
|
+
return !noAllow || unknownKeys.length === 0 || this.createError({
|
|
3251
|
+
params: {
|
|
3252
|
+
unknown: unknownKeys.join(", ")
|
|
3253
|
+
}
|
|
3254
|
+
});
|
|
3255
|
+
}
|
|
3256
|
+
});
|
|
3257
|
+
next.spec.noUnknown = noAllow;
|
|
3258
|
+
return next;
|
|
3259
|
+
}
|
|
3260
|
+
unknown(allow = true, message = object.noUnknown) {
|
|
3261
|
+
return this.noUnknown(!allow, message);
|
|
3262
|
+
}
|
|
3263
|
+
transformKeys(fn) {
|
|
3264
|
+
return this.transform((obj) => obj && mapKeys$1(obj, (_, key) => fn(key)));
|
|
3265
|
+
}
|
|
3266
|
+
camelCase() {
|
|
3267
|
+
return this.transformKeys(camelCase$1);
|
|
3268
|
+
}
|
|
3269
|
+
snakeCase() {
|
|
3270
|
+
return this.transformKeys(snakeCase$1);
|
|
3271
|
+
}
|
|
3272
|
+
constantCase() {
|
|
3273
|
+
return this.transformKeys((key) => snakeCase$1(key).toUpperCase());
|
|
3274
|
+
}
|
|
3275
|
+
describe() {
|
|
3276
|
+
let base = super.describe();
|
|
3277
|
+
base.fields = mapValues$1(this.fields, (value) => value.describe());
|
|
3278
|
+
return base;
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
function create$1(spec) {
|
|
3282
|
+
return new ObjectSchema(spec);
|
|
3283
|
+
}
|
|
3284
|
+
create$1.prototype = ObjectSchema.prototype;
|
|
3285
|
+
function _extends() {
|
|
3286
|
+
_extends = Object.assign || function(target) {
|
|
3287
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
3288
|
+
var source = arguments[i];
|
|
3289
|
+
for (var key in source) {
|
|
3290
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
3291
|
+
target[key] = source[key];
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
return target;
|
|
3296
|
+
};
|
|
3297
|
+
return _extends.apply(this, arguments);
|
|
3298
|
+
}
|
|
3299
|
+
function create(type) {
|
|
3300
|
+
return new ArraySchema(type);
|
|
3301
|
+
}
|
|
3302
|
+
class ArraySchema extends BaseSchema {
|
|
3303
|
+
constructor(type) {
|
|
3304
|
+
super({
|
|
3305
|
+
type: "array"
|
|
3306
|
+
});
|
|
3307
|
+
this.innerType = type;
|
|
3308
|
+
this.withMutation(() => {
|
|
3309
|
+
this.transform(function(values) {
|
|
3310
|
+
if (typeof values === "string") try {
|
|
3311
|
+
values = JSON.parse(values);
|
|
3312
|
+
} catch (err) {
|
|
3313
|
+
values = null;
|
|
3314
|
+
}
|
|
3315
|
+
return this.isType(values) ? values : null;
|
|
3316
|
+
});
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
_typeCheck(v) {
|
|
3320
|
+
return Array.isArray(v);
|
|
3321
|
+
}
|
|
3322
|
+
get _subType() {
|
|
3323
|
+
return this.innerType;
|
|
3324
|
+
}
|
|
3325
|
+
_cast(_value, _opts) {
|
|
3326
|
+
const value = super._cast(_value, _opts);
|
|
3327
|
+
if (!this._typeCheck(value) || !this.innerType) return value;
|
|
3328
|
+
let isChanged = false;
|
|
3329
|
+
const castArray = value.map((v, idx) => {
|
|
3330
|
+
const castElement = this.innerType.cast(v, _extends({}, _opts, {
|
|
3331
|
+
path: `${_opts.path || ""}[${idx}]`
|
|
3332
|
+
}));
|
|
3333
|
+
if (castElement !== v) {
|
|
3334
|
+
isChanged = true;
|
|
3335
|
+
}
|
|
3336
|
+
return castElement;
|
|
3337
|
+
});
|
|
3338
|
+
return isChanged ? castArray : value;
|
|
3339
|
+
}
|
|
3340
|
+
_validate(_value, options = {}, callback) {
|
|
3341
|
+
var _options$abortEarly, _options$recursive;
|
|
3342
|
+
let errors = [];
|
|
3343
|
+
options.sync;
|
|
3344
|
+
let path = options.path;
|
|
3345
|
+
let innerType = this.innerType;
|
|
3346
|
+
let endEarly = (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly;
|
|
3347
|
+
let recursive = (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive;
|
|
3348
|
+
let originalValue = options.originalValue != null ? options.originalValue : _value;
|
|
3349
|
+
super._validate(_value, options, (err, value) => {
|
|
3350
|
+
if (err) {
|
|
3351
|
+
if (!ValidationError.isError(err) || endEarly) {
|
|
3352
|
+
return void callback(err, value);
|
|
3353
|
+
}
|
|
3354
|
+
errors.push(err);
|
|
3355
|
+
}
|
|
3356
|
+
if (!recursive || !innerType || !this._typeCheck(value)) {
|
|
3357
|
+
callback(errors[0] || null, value);
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3360
|
+
originalValue = originalValue || value;
|
|
3361
|
+
let tests = new Array(value.length);
|
|
3362
|
+
for (let idx = 0; idx < value.length; idx++) {
|
|
3363
|
+
let item = value[idx];
|
|
3364
|
+
let path2 = `${options.path || ""}[${idx}]`;
|
|
3365
|
+
let innerOptions = _extends({}, options, {
|
|
3366
|
+
path: path2,
|
|
3367
|
+
strict: true,
|
|
3368
|
+
parent: value,
|
|
3369
|
+
index: idx,
|
|
3370
|
+
originalValue: originalValue[idx]
|
|
3371
|
+
});
|
|
3372
|
+
tests[idx] = (_, cb) => innerType.validate(item, innerOptions, cb);
|
|
3373
|
+
}
|
|
3374
|
+
runTests({
|
|
3375
|
+
path,
|
|
3376
|
+
value,
|
|
3377
|
+
errors,
|
|
3378
|
+
endEarly,
|
|
3379
|
+
tests
|
|
3380
|
+
}, callback);
|
|
3381
|
+
});
|
|
3382
|
+
}
|
|
3383
|
+
clone(spec) {
|
|
3384
|
+
const next = super.clone(spec);
|
|
3385
|
+
next.innerType = this.innerType;
|
|
3386
|
+
return next;
|
|
3387
|
+
}
|
|
3388
|
+
concat(schema) {
|
|
3389
|
+
let next = super.concat(schema);
|
|
3390
|
+
next.innerType = this.innerType;
|
|
3391
|
+
if (schema.innerType) next.innerType = next.innerType ? (
|
|
3392
|
+
// @ts-expect-error Lazy doesn't have concat()
|
|
3393
|
+
next.innerType.concat(schema.innerType)
|
|
3394
|
+
) : schema.innerType;
|
|
3395
|
+
return next;
|
|
3396
|
+
}
|
|
3397
|
+
of(schema) {
|
|
3398
|
+
let next = this.clone();
|
|
3399
|
+
if (!isSchema(schema)) throw new TypeError("`array.of()` sub-schema must be a valid yup schema not: " + printValue(schema));
|
|
3400
|
+
next.innerType = schema;
|
|
3401
|
+
return next;
|
|
3402
|
+
}
|
|
3403
|
+
length(length, message = array.length) {
|
|
3404
|
+
return this.test({
|
|
3405
|
+
message,
|
|
3406
|
+
name: "length",
|
|
3407
|
+
exclusive: true,
|
|
3408
|
+
params: {
|
|
3409
|
+
length
|
|
3410
|
+
},
|
|
3411
|
+
test(value) {
|
|
3412
|
+
return isAbsent(value) || value.length === this.resolve(length);
|
|
3413
|
+
}
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
min(min, message) {
|
|
3417
|
+
message = message || array.min;
|
|
3418
|
+
return this.test({
|
|
3419
|
+
message,
|
|
3420
|
+
name: "min",
|
|
3421
|
+
exclusive: true,
|
|
3422
|
+
params: {
|
|
3423
|
+
min
|
|
3424
|
+
},
|
|
3425
|
+
// FIXME(ts): Array<typeof T>
|
|
3426
|
+
test(value) {
|
|
3427
|
+
return isAbsent(value) || value.length >= this.resolve(min);
|
|
3428
|
+
}
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
max(max, message) {
|
|
3432
|
+
message = message || array.max;
|
|
3433
|
+
return this.test({
|
|
3434
|
+
message,
|
|
3435
|
+
name: "max",
|
|
3436
|
+
exclusive: true,
|
|
3437
|
+
params: {
|
|
3438
|
+
max
|
|
3439
|
+
},
|
|
3440
|
+
test(value) {
|
|
3441
|
+
return isAbsent(value) || value.length <= this.resolve(max);
|
|
3442
|
+
}
|
|
3443
|
+
});
|
|
3444
|
+
}
|
|
3445
|
+
ensure() {
|
|
3446
|
+
return this.default(() => []).transform((val, original) => {
|
|
3447
|
+
if (this._typeCheck(val)) return val;
|
|
3448
|
+
return original == null ? [] : [].concat(original);
|
|
3449
|
+
});
|
|
3450
|
+
}
|
|
3451
|
+
compact(rejector) {
|
|
3452
|
+
let reject = !rejector ? (v) => !!v : (v, i, a) => !rejector(v, i, a);
|
|
3453
|
+
return this.transform((values) => values != null ? values.filter(reject) : values);
|
|
3454
|
+
}
|
|
3455
|
+
describe() {
|
|
3456
|
+
let base = super.describe();
|
|
3457
|
+
if (this.innerType) base.innerType = this.innerType.describe();
|
|
3458
|
+
return base;
|
|
3459
|
+
}
|
|
3460
|
+
nullable(isNullable = true) {
|
|
3461
|
+
return super.nullable(isNullable);
|
|
3462
|
+
}
|
|
3463
|
+
defined() {
|
|
3464
|
+
return super.defined();
|
|
3465
|
+
}
|
|
3466
|
+
required(msg) {
|
|
3467
|
+
return super.required(msg);
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
create.prototype = ArraySchema.prototype;
|
|
2599
3471
|
const PLUGIN_ID = "littlebox-strapi-suite";
|
|
2600
3472
|
const SLUG_LANGUAGE_STRATEGY = "language";
|
|
2601
3473
|
const SLUG_CONTENT_STRATEGY = "content";
|
|
3474
|
+
const AI_TRANSLATION_DEFAULT_MODEL = "gpt-4o";
|
|
2602
3475
|
const config = {
|
|
2603
3476
|
pluginId: PLUGIN_ID,
|
|
2604
3477
|
uuid: {
|
|
@@ -2891,6 +3764,32 @@ class TranslationGatewayHttp {
|
|
|
2891
3764
|
async edit(uid, params) {
|
|
2892
3765
|
return this.httpClient.put(`/${config.pluginId}/admin/translations/${uid}`, params);
|
|
2893
3766
|
}
|
|
3767
|
+
async aiTranslate(params) {
|
|
3768
|
+
return this.httpClient.post(
|
|
3769
|
+
`/${config.pluginId}/admin/translations/actions/ai-translate`,
|
|
3770
|
+
params
|
|
3771
|
+
);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
class DocumentGatewayHttp {
|
|
3775
|
+
httpClient;
|
|
3776
|
+
constructor() {
|
|
3777
|
+
this.httpClient = Registry.getInstance().inject("httpClient");
|
|
3778
|
+
}
|
|
3779
|
+
async fetch({ collectionType, model, documentId, params }) {
|
|
3780
|
+
const path = documentId ? `/content-manager/${collectionType}/${model}/${documentId}` : `/content-manager/${collectionType}/${model}`;
|
|
3781
|
+
const response = await this.httpClient.get(`${path}${objectToQueryString(params)}`);
|
|
3782
|
+
return response ? response.data : null;
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
class AiGatewayHttp {
|
|
3786
|
+
httpClient;
|
|
3787
|
+
constructor() {
|
|
3788
|
+
this.httpClient = Registry.getInstance().inject("httpClient");
|
|
3789
|
+
}
|
|
3790
|
+
async translateStrings(input) {
|
|
3791
|
+
return this.httpClient.post(`/${config.pluginId}/admin/ai/strings`, input);
|
|
3792
|
+
}
|
|
2894
3793
|
}
|
|
2895
3794
|
class Mediator {
|
|
2896
3795
|
handlers;
|
|
@@ -3016,7 +3915,7 @@ const DangerModal = ({ open, title, text, button }) => {
|
|
|
3016
3915
|
/* @__PURE__ */ jsx(Dialog.Footer, { children: /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant: "danger-light", children: button }) }) })
|
|
3017
3916
|
] }) }) });
|
|
3018
3917
|
};
|
|
3019
|
-
const PageAttributesBox = ({ document }) => {
|
|
3918
|
+
const PageAttributesBox = ({ document: document2 }) => {
|
|
3020
3919
|
const { formatMessage } = useIntl();
|
|
3021
3920
|
const location = useLocation();
|
|
3022
3921
|
const { form } = unstable_useContentManagerContext();
|
|
@@ -3065,13 +3964,13 @@ const PageAttributesBox = ({ document }) => {
|
|
|
3065
3964
|
form.onChange(mockEvent);
|
|
3066
3965
|
}
|
|
3067
3966
|
async function fectchAttributes() {
|
|
3068
|
-
if (
|
|
3967
|
+
if (document2 && document2.documentId) {
|
|
3069
3968
|
const fetchDocumentAttributes$1 = new fetchDocumentAttributes();
|
|
3070
3969
|
const outputFetchDocumentAttributes = await fetchDocumentAttributes$1.execute(
|
|
3071
|
-
|
|
3970
|
+
document2.documentId,
|
|
3072
3971
|
{
|
|
3073
3972
|
locale: getCurrentLocate(),
|
|
3074
|
-
state:
|
|
3973
|
+
state: document2.publishedAt ? "published" : "draft"
|
|
3075
3974
|
}
|
|
3076
3975
|
);
|
|
3077
3976
|
setAttributes(outputFetchDocumentAttributes);
|
|
@@ -3082,7 +3981,7 @@ const PageAttributesBox = ({ document }) => {
|
|
|
3082
3981
|
const outputFetchSlugs = await fetchSlugs.execute({ locale: getCurrentLocate() });
|
|
3083
3982
|
const filteredParents = [];
|
|
3084
3983
|
outputFetchSlugs.forEach((parent) => {
|
|
3085
|
-
if (!
|
|
3984
|
+
if (!document2 || parent.contentId !== document2.documentId) {
|
|
3086
3985
|
filteredParents.push(parent);
|
|
3087
3986
|
}
|
|
3088
3987
|
});
|
|
@@ -3293,17 +4192,1297 @@ const PageAttributesBox = ({ document }) => {
|
|
|
3293
4192
|
] })
|
|
3294
4193
|
};
|
|
3295
4194
|
};
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
4195
|
+
class FetchLocales {
|
|
4196
|
+
localeGateway;
|
|
4197
|
+
constructor() {
|
|
4198
|
+
this.localeGateway = Registry.getInstance().inject("localeGateway");
|
|
4199
|
+
}
|
|
4200
|
+
async execute() {
|
|
4201
|
+
const result = await this.localeGateway.fetch();
|
|
4202
|
+
const output = result.map((data) => ({
|
|
4203
|
+
id: data.id,
|
|
4204
|
+
code: data.code,
|
|
4205
|
+
name: data.name,
|
|
4206
|
+
isDefault: data.isDefault
|
|
4207
|
+
}));
|
|
4208
|
+
return output;
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
class AbstractSlugHandler {
|
|
4212
|
+
nextHandler = null;
|
|
4213
|
+
setNext(handler) {
|
|
4214
|
+
this.nextHandler = handler;
|
|
4215
|
+
return handler;
|
|
4216
|
+
}
|
|
4217
|
+
handle(text) {
|
|
4218
|
+
if (this.nextHandler) {
|
|
4219
|
+
return this.nextHandler.handle(this.process(text));
|
|
4220
|
+
}
|
|
4221
|
+
return this.process(text);
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
class LowercaseHandler extends AbstractSlugHandler {
|
|
4225
|
+
process(text) {
|
|
4226
|
+
return text.toLowerCase();
|
|
4227
|
+
}
|
|
4228
|
+
}
|
|
4229
|
+
class AccentRemovalHandler extends AbstractSlugHandler {
|
|
4230
|
+
process(text) {
|
|
4231
|
+
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
class SpecialCharsHandler extends AbstractSlugHandler {
|
|
4235
|
+
process(text) {
|
|
4236
|
+
return text.replace(/[^a-z0-9-]+/g, "-");
|
|
4237
|
+
}
|
|
4238
|
+
}
|
|
4239
|
+
class TrimHyphensHandler extends AbstractSlugHandler {
|
|
4240
|
+
process(text) {
|
|
4241
|
+
return text.replace(/^-+|-+$/g, "");
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
class MultipleHyphensHandler extends AbstractSlugHandler {
|
|
4245
|
+
process(text) {
|
|
4246
|
+
return text.replace(/-+/g, "-");
|
|
4247
|
+
}
|
|
4248
|
+
}
|
|
4249
|
+
class LengthLimitHandler extends AbstractSlugHandler {
|
|
4250
|
+
maxLength;
|
|
4251
|
+
constructor(maxLength = 100) {
|
|
4252
|
+
super();
|
|
4253
|
+
this.maxLength = maxLength;
|
|
4254
|
+
}
|
|
4255
|
+
process(text) {
|
|
4256
|
+
if (text.length > this.maxLength) {
|
|
4257
|
+
const truncated = text.substring(0, this.maxLength);
|
|
4258
|
+
return truncated.replace(/-+$/g, "");
|
|
4259
|
+
}
|
|
4260
|
+
return text;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
const convertToSlug = (text, maxLength = 100) => {
|
|
4264
|
+
if (!text) return "";
|
|
4265
|
+
const chain = new LowercaseHandler();
|
|
4266
|
+
const accentHandler = new AccentRemovalHandler();
|
|
4267
|
+
const specialCharsHandler = new SpecialCharsHandler();
|
|
4268
|
+
const trimHandler = new TrimHyphensHandler();
|
|
4269
|
+
const multipleHyphensHandler = new MultipleHyphensHandler();
|
|
4270
|
+
const lengthHandler = new LengthLimitHandler(maxLength);
|
|
4271
|
+
chain.setNext(accentHandler).setNext(specialCharsHandler).setNext(trimHandler).setNext(multipleHyphensHandler).setNext(lengthHandler);
|
|
4272
|
+
return chain.handle(text);
|
|
4273
|
+
};
|
|
4274
|
+
const SLUG_CUSTOM_FIELD = "plugin::littlebox-strapi-suite.ltbslug";
|
|
4275
|
+
const TEXT_TYPES = ["string", "text", "richtext"];
|
|
4276
|
+
const URL_PATTERN = /^(https?:\/\/|\/|mailto:|tel:)\S*$/i;
|
|
4277
|
+
function isFilled(value) {
|
|
4278
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
4279
|
+
}
|
|
4280
|
+
function isTranslatableText(value) {
|
|
4281
|
+
return isFilled(value) && !URL_PATTERN.test(value.trim());
|
|
4282
|
+
}
|
|
4283
|
+
function isLocalized(attribute) {
|
|
4284
|
+
return attribute?.pluginOptions?.i18n?.localized !== false;
|
|
4285
|
+
}
|
|
4286
|
+
function isSlug(attribute) {
|
|
4287
|
+
return attribute?.customField === SLUG_CUSTOM_FIELD || attribute?.type === "uid";
|
|
4288
|
+
}
|
|
4289
|
+
function join(path, segment) {
|
|
4290
|
+
return path ? `${path}.${segment}` : String(segment);
|
|
4291
|
+
}
|
|
4292
|
+
function collectBlocks(nodes, source, path, fields) {
|
|
4293
|
+
if (!Array.isArray(nodes) || !Array.isArray(source)) return;
|
|
4294
|
+
nodes.forEach((node, index2) => {
|
|
4295
|
+
const sourceNode = source[index2];
|
|
4296
|
+
if (!node || !sourceNode) return;
|
|
4297
|
+
if (isTranslatableText(sourceNode.text) && typeof node.text === "string") {
|
|
4298
|
+
fields.push({
|
|
4299
|
+
path: join(path, `${index2}.text`),
|
|
4300
|
+
value: sourceNode.text,
|
|
4301
|
+
current: node.text,
|
|
4302
|
+
kind: "text"
|
|
4303
|
+
});
|
|
4304
|
+
}
|
|
4305
|
+
collectBlocks(node.children, sourceNode.children, join(path, `${index2}.children`), fields);
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4308
|
+
function collectTranslatableFields(attributes, components, target, source, basePath = "") {
|
|
4309
|
+
const fields = [];
|
|
4310
|
+
if (!attributes || !target || !source) return fields;
|
|
4311
|
+
for (const [name, attribute] of Object.entries(attributes)) {
|
|
4312
|
+
if (!isLocalized(attribute)) continue;
|
|
4313
|
+
const path = join(basePath, name);
|
|
4314
|
+
const targetValue = target[name];
|
|
4315
|
+
const sourceValue = source[name];
|
|
4316
|
+
if (isSlug(attribute)) {
|
|
4317
|
+
if (isFilled(sourceValue) && typeof targetValue === "string") {
|
|
4318
|
+
fields.push({ path, value: sourceValue, current: targetValue, kind: "slug" });
|
|
4319
|
+
}
|
|
4320
|
+
continue;
|
|
4321
|
+
}
|
|
4322
|
+
if (TEXT_TYPES.includes(attribute.type)) {
|
|
4323
|
+
if (isTranslatableText(sourceValue) && typeof targetValue === "string") {
|
|
4324
|
+
fields.push({ path, value: sourceValue, current: targetValue, kind: "text" });
|
|
4325
|
+
}
|
|
4326
|
+
continue;
|
|
4327
|
+
}
|
|
4328
|
+
if (attribute.type === "blocks") {
|
|
4329
|
+
collectBlocks(targetValue, sourceValue, path, fields);
|
|
4330
|
+
continue;
|
|
4331
|
+
}
|
|
4332
|
+
if (attribute.type === "component") {
|
|
4333
|
+
const schema = components[attribute.component];
|
|
4334
|
+
if (!schema) continue;
|
|
4335
|
+
if (attribute.repeatable) {
|
|
4336
|
+
if (!Array.isArray(targetValue) || !Array.isArray(sourceValue)) continue;
|
|
4337
|
+
targetValue.forEach((entry, index2) => {
|
|
4338
|
+
fields.push(
|
|
4339
|
+
...collectTranslatableFields(
|
|
4340
|
+
schema.attributes,
|
|
4341
|
+
components,
|
|
4342
|
+
entry,
|
|
4343
|
+
sourceValue[index2],
|
|
4344
|
+
join(path, index2)
|
|
4345
|
+
)
|
|
4346
|
+
);
|
|
4347
|
+
});
|
|
4348
|
+
continue;
|
|
4349
|
+
}
|
|
4350
|
+
fields.push(
|
|
4351
|
+
...collectTranslatableFields(schema.attributes, components, targetValue, sourceValue, path)
|
|
4352
|
+
);
|
|
4353
|
+
continue;
|
|
4354
|
+
}
|
|
4355
|
+
if (attribute.type === "dynamiczone") {
|
|
4356
|
+
if (!Array.isArray(targetValue) || !Array.isArray(sourceValue)) continue;
|
|
4357
|
+
targetValue.forEach((entry, index2) => {
|
|
4358
|
+
const sourceEntry = sourceValue[index2];
|
|
4359
|
+
if (!entry || !sourceEntry) return;
|
|
4360
|
+
if (entry.__component !== sourceEntry.__component) return;
|
|
4361
|
+
const schema = components[entry.__component];
|
|
4362
|
+
if (!schema) return;
|
|
4363
|
+
fields.push(
|
|
4364
|
+
...collectTranslatableFields(
|
|
4365
|
+
schema.attributes,
|
|
4366
|
+
components,
|
|
4367
|
+
entry,
|
|
4368
|
+
sourceEntry,
|
|
4369
|
+
join(path, index2)
|
|
4370
|
+
)
|
|
4371
|
+
);
|
|
4372
|
+
});
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
return fields;
|
|
4376
|
+
}
|
|
4377
|
+
function countTranslatableFields(attributes, components, source) {
|
|
4378
|
+
return collectTranslatableFields(attributes, components, source, source).length;
|
|
4379
|
+
}
|
|
4380
|
+
class TranslateDocument {
|
|
4381
|
+
documentGateway;
|
|
4382
|
+
aiGateway;
|
|
4383
|
+
constructor() {
|
|
4384
|
+
this.documentGateway = Registry.getInstance().inject("documentGateway");
|
|
4385
|
+
this.aiGateway = Registry.getInstance().inject("aiGateway");
|
|
4386
|
+
}
|
|
4387
|
+
async execute(input) {
|
|
4388
|
+
const source = await this.documentGateway.fetch({
|
|
4389
|
+
collectionType: input.collectionType,
|
|
4390
|
+
model: input.model,
|
|
4391
|
+
documentId: input.documentId,
|
|
4392
|
+
params: { locale: input.sourceLocale, status: input.status }
|
|
4393
|
+
});
|
|
4394
|
+
const total = source ? countTranslatableFields(input.attributes, input.components, source) : 0;
|
|
4395
|
+
if (total === 0) {
|
|
4396
|
+
return {
|
|
4397
|
+
results: [],
|
|
4398
|
+
translated: 0,
|
|
4399
|
+
skipped: 0,
|
|
4400
|
+
unmatched: 0,
|
|
4401
|
+
failed: 0,
|
|
4402
|
+
errors: ["no-source"]
|
|
4403
|
+
};
|
|
4404
|
+
}
|
|
4405
|
+
const matched = collectTranslatableFields(
|
|
4406
|
+
input.attributes,
|
|
4407
|
+
input.components,
|
|
4408
|
+
input.values,
|
|
4409
|
+
source
|
|
4410
|
+
);
|
|
4411
|
+
const unmatched = Math.max(0, total - matched.length);
|
|
4412
|
+
const pending = input.overwrite ? matched : matched.filter((field) => field.current.trim().length === 0);
|
|
4413
|
+
const skipped = matched.length - pending.length;
|
|
4414
|
+
if (pending.length === 0) {
|
|
4415
|
+
return { results: [], translated: 0, skipped, unmatched, failed: 0, errors: [] };
|
|
4416
|
+
}
|
|
4417
|
+
const strings = pending.reduce((acc, field, index2) => {
|
|
4418
|
+
acc[String(index2)] = field.kind === "slug" ? field.value.replace(/-/g, " ") : field.value;
|
|
4419
|
+
return acc;
|
|
4420
|
+
}, {});
|
|
4421
|
+
const output = await this.aiGateway.translateStrings({
|
|
4422
|
+
sourceLocale: input.sourceLocale,
|
|
4423
|
+
targetLocale: input.targetLocale,
|
|
4424
|
+
strings
|
|
4425
|
+
});
|
|
4426
|
+
const results = [];
|
|
4427
|
+
pending.forEach((field, index2) => {
|
|
4428
|
+
const translation = output.translations[String(index2)];
|
|
4429
|
+
if (typeof translation !== "string" || translation.trim().length === 0) return;
|
|
4430
|
+
results.push({
|
|
4431
|
+
path: field.path,
|
|
4432
|
+
value: field.kind === "slug" ? convertToSlug(translation) : translation,
|
|
4433
|
+
kind: field.kind
|
|
4434
|
+
});
|
|
4435
|
+
});
|
|
4436
|
+
return {
|
|
4437
|
+
results,
|
|
4438
|
+
translated: results.length,
|
|
4439
|
+
skipped,
|
|
4440
|
+
unmatched,
|
|
4441
|
+
failed: output.failed,
|
|
4442
|
+
errors: output.errors
|
|
4443
|
+
};
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
const BoxInput = styled(Box)`
|
|
4447
|
+
flex: 1;
|
|
4448
|
+
display: flex;
|
|
4449
|
+
width: 100%;
|
|
4450
|
+
flex-direction: column;
|
|
4451
|
+
& > div {
|
|
4452
|
+
width: 100%;
|
|
4453
|
+
}
|
|
4454
|
+
`;
|
|
4455
|
+
const DocumentTranslateModal = ({ open, locales, targetLocale, translate, close }) => {
|
|
4456
|
+
const [module] = useState(config.uuid.modules.translation);
|
|
4457
|
+
const [hidden, setHidden] = useState(true);
|
|
4458
|
+
const [sourceLocale, setSourceLocale] = useState();
|
|
4459
|
+
const [overwrite, setOverwrite] = useState(true);
|
|
4460
|
+
const [translateInProgress, setTranslateInProgress] = useState(false);
|
|
4461
|
+
const [result, setResult] = useState();
|
|
4462
|
+
const [error, setError] = useState("");
|
|
4463
|
+
const { formatMessage } = useIntl();
|
|
4464
|
+
const sources = locales.filter(
|
|
4465
|
+
(locale) => locale.code !== targetLocale?.code
|
|
4466
|
+
);
|
|
4467
|
+
async function run() {
|
|
4468
|
+
if (translateInProgress || !sourceLocale) return;
|
|
4469
|
+
setTranslateInProgress(true);
|
|
4470
|
+
setResult(void 0);
|
|
4471
|
+
setError("");
|
|
4472
|
+
try {
|
|
4473
|
+
const output = await translate(sourceLocale, overwrite);
|
|
4474
|
+
if (output.errors.includes("no-source")) {
|
|
4475
|
+
setError(
|
|
4476
|
+
formatMessage({
|
|
4477
|
+
id: getTranslation(`module.${module}.panel.ai.error.no-source`),
|
|
4478
|
+
defaultMessage: "This entry does not exist yet in the language you picked as the base"
|
|
4479
|
+
})
|
|
4480
|
+
);
|
|
4481
|
+
} else {
|
|
4482
|
+
setResult(output);
|
|
4483
|
+
}
|
|
4484
|
+
} catch (e) {
|
|
4485
|
+
setError(
|
|
4486
|
+
e?.response?.data?.error?.message || e?.message || formatMessage({
|
|
4487
|
+
id: getTranslation(`module.${module}.modal.ai.error`),
|
|
4488
|
+
defaultMessage: "The translation request failed"
|
|
4489
|
+
})
|
|
4490
|
+
);
|
|
4491
|
+
}
|
|
4492
|
+
setTranslateInProgress(false);
|
|
4493
|
+
}
|
|
4494
|
+
function handleClose() {
|
|
4495
|
+
if (translateInProgress) return;
|
|
4496
|
+
setResult(void 0);
|
|
4497
|
+
setError("");
|
|
4498
|
+
close();
|
|
4499
|
+
}
|
|
4500
|
+
useEffect(() => {
|
|
4501
|
+
if (!open) {
|
|
4502
|
+
setHidden(true);
|
|
4503
|
+
return;
|
|
4504
|
+
}
|
|
4505
|
+
setSourceLocale(sources[0]?.code);
|
|
4506
|
+
setOverwrite(true);
|
|
4507
|
+
setResult(void 0);
|
|
4508
|
+
setError("");
|
|
4509
|
+
setHidden(false);
|
|
4510
|
+
}, [open]);
|
|
4511
|
+
return /* @__PURE__ */ jsx(Fragment, { children: !hidden && /* @__PURE__ */ jsx(Dialog.Root, { defaultOpen: true, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
|
4512
|
+
/* @__PURE__ */ jsx(Dialog.Header, { style: { textAlign: "left" }, children: /* @__PURE__ */ jsxs(Flex, { style: { width: "100%", justifyContent: "space-between" }, children: [
|
|
4513
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage({
|
|
4514
|
+
id: getTranslation(`module.${module}.panel.ai.title`),
|
|
4515
|
+
defaultMessage: "Translate with AI"
|
|
4516
|
+
}) }),
|
|
4517
|
+
!translateInProgress && /* @__PURE__ */ jsx(
|
|
4518
|
+
IconButton,
|
|
4519
|
+
{
|
|
4520
|
+
variant: "tertiary",
|
|
4521
|
+
onClick: handleClose,
|
|
4522
|
+
label: "Close",
|
|
4523
|
+
borderWidth: 0,
|
|
4524
|
+
children: /* @__PURE__ */ jsx(Cross, {})
|
|
4525
|
+
}
|
|
4526
|
+
)
|
|
4527
|
+
] }) }),
|
|
4528
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Box, { style: { display: "flex", flexDirection: "column", width: "100%" }, children: [
|
|
4529
|
+
/* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px" }, children: formatMessage({
|
|
4530
|
+
id: getTranslation(`module.${module}.modal.ai.input.source.title`),
|
|
4531
|
+
defaultMessage: "Base language"
|
|
4532
|
+
}) }),
|
|
4533
|
+
/* @__PURE__ */ jsx(
|
|
4534
|
+
Typography,
|
|
4535
|
+
{
|
|
4536
|
+
variant: "pi",
|
|
4537
|
+
style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
|
|
4538
|
+
children: formatMessage(
|
|
4539
|
+
{
|
|
4540
|
+
id: getTranslation(`module.${module}.panel.ai.input.source.description`),
|
|
4541
|
+
defaultMessage: "This entry is translated into {target} from the language you pick here"
|
|
4542
|
+
},
|
|
4543
|
+
{ target: targetLocale?.name || "" }
|
|
4544
|
+
)
|
|
4545
|
+
}
|
|
4546
|
+
),
|
|
4547
|
+
/* @__PURE__ */ jsx(BoxInput, { children: /* @__PURE__ */ jsx(
|
|
4548
|
+
SingleSelect,
|
|
4549
|
+
{
|
|
4550
|
+
onChange: (value) => setSourceLocale(value),
|
|
4551
|
+
value: sourceLocale,
|
|
4552
|
+
disabled: translateInProgress,
|
|
4553
|
+
children: sources.map((locale, index2) => /* @__PURE__ */ jsx(SingleSelectOption, { value: locale.code, children: locale.name }, index2))
|
|
4554
|
+
}
|
|
4555
|
+
) }),
|
|
4556
|
+
/* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px", paddingTop: "24px" }, children: formatMessage({
|
|
4557
|
+
id: getTranslation(`module.${module}.panel.ai.input.overwrite.title`),
|
|
4558
|
+
defaultMessage: "Overwrite fields that already have content"
|
|
4559
|
+
}) }),
|
|
4560
|
+
/* @__PURE__ */ jsx(
|
|
4561
|
+
Typography,
|
|
4562
|
+
{
|
|
4563
|
+
variant: "pi",
|
|
4564
|
+
style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
|
|
4565
|
+
children: formatMessage({
|
|
4566
|
+
id: getTranslation(`module.${module}.panel.ai.input.overwrite.description`),
|
|
4567
|
+
defaultMessage: "When disabled only the empty fields are filled in"
|
|
4568
|
+
})
|
|
4569
|
+
}
|
|
4570
|
+
),
|
|
4571
|
+
/* @__PURE__ */ jsx(
|
|
4572
|
+
Toggle,
|
|
4573
|
+
{
|
|
4574
|
+
onLabel: "True",
|
|
4575
|
+
offLabel: "False",
|
|
4576
|
+
checked: overwrite,
|
|
4577
|
+
disabled: translateInProgress,
|
|
4578
|
+
onChange: (e) => setOverwrite(e.target.checked)
|
|
4579
|
+
}
|
|
4580
|
+
),
|
|
4581
|
+
translateInProgress && /* @__PURE__ */ jsxs(
|
|
4582
|
+
Card,
|
|
4583
|
+
{
|
|
4584
|
+
shadow: false,
|
|
4585
|
+
style: {
|
|
4586
|
+
marginTop: "20px",
|
|
4587
|
+
padding: "10px",
|
|
4588
|
+
display: "flex",
|
|
4589
|
+
alignItems: "center"
|
|
4590
|
+
},
|
|
4591
|
+
children: [
|
|
4592
|
+
/* @__PURE__ */ jsx(Loader, { small: true }),
|
|
4593
|
+
/* @__PURE__ */ jsx(
|
|
4594
|
+
Typography,
|
|
4595
|
+
{
|
|
4596
|
+
variant: "pi",
|
|
4597
|
+
style: { color: "#a5a5ba", display: "flex", marginLeft: "10px" },
|
|
4598
|
+
children: formatMessage({
|
|
4599
|
+
id: getTranslation(`module.${module}.modal.ai.progress`),
|
|
4600
|
+
defaultMessage: "Translating. This can take a few minutes, please keep this window open"
|
|
4601
|
+
})
|
|
4602
|
+
}
|
|
4603
|
+
)
|
|
4604
|
+
]
|
|
4605
|
+
}
|
|
4606
|
+
),
|
|
4607
|
+
result && !translateInProgress && /* @__PURE__ */ jsxs(
|
|
4608
|
+
Card,
|
|
4609
|
+
{
|
|
4610
|
+
shadow: false,
|
|
4611
|
+
style: {
|
|
4612
|
+
marginTop: "20px",
|
|
4613
|
+
padding: "10px",
|
|
4614
|
+
display: "flex",
|
|
4615
|
+
flexDirection: "column",
|
|
4616
|
+
alignItems: "start",
|
|
4617
|
+
gap: "5px"
|
|
4618
|
+
},
|
|
4619
|
+
children: [
|
|
4620
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", style: { display: "flex" }, children: formatMessage(
|
|
4621
|
+
{
|
|
4622
|
+
id: getTranslation(`module.${module}.modal.ai.result`),
|
|
4623
|
+
defaultMessage: "{translated} translated, {skipped} skipped, {failed} failed"
|
|
4624
|
+
},
|
|
4625
|
+
{
|
|
4626
|
+
translated: result.translated,
|
|
4627
|
+
skipped: result.skipped,
|
|
4628
|
+
failed: result.failed
|
|
4629
|
+
}
|
|
4630
|
+
) }),
|
|
4631
|
+
result.translated > 0 && /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#a5a5ba", display: "flex" }, children: formatMessage({
|
|
4632
|
+
id: getTranslation(`module.${module}.panel.ai.result.save`),
|
|
4633
|
+
defaultMessage: "Review the fields and save the entry to keep them"
|
|
4634
|
+
}) }),
|
|
4635
|
+
result.unmatched > 0 && /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: formatMessage(
|
|
4636
|
+
{
|
|
4637
|
+
id: getTranslation(`module.${module}.panel.ai.result.unmatched`),
|
|
4638
|
+
defaultMessage: "{unmatched} fields of the base language have no match here, the two entries have a different structure"
|
|
4639
|
+
},
|
|
4640
|
+
{ unmatched: result.unmatched }
|
|
4641
|
+
) }),
|
|
4642
|
+
result.errors.map((message, index2) => /* @__PURE__ */ jsx(
|
|
4643
|
+
Typography,
|
|
4644
|
+
{
|
|
4645
|
+
variant: "pi",
|
|
4646
|
+
style: { color: "#ee5e52", display: "flex" },
|
|
4647
|
+
children: message
|
|
4648
|
+
},
|
|
4649
|
+
index2
|
|
4650
|
+
))
|
|
4651
|
+
]
|
|
4652
|
+
}
|
|
4653
|
+
),
|
|
4654
|
+
error && !translateInProgress && /* @__PURE__ */ jsx(
|
|
4655
|
+
Card,
|
|
4656
|
+
{
|
|
4657
|
+
shadow: false,
|
|
4658
|
+
style: {
|
|
4659
|
+
marginTop: "20px",
|
|
4660
|
+
padding: "10px",
|
|
4661
|
+
display: "flex",
|
|
4662
|
+
alignItems: "center"
|
|
4663
|
+
},
|
|
4664
|
+
children: /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: error })
|
|
4665
|
+
}
|
|
4666
|
+
)
|
|
4667
|
+
] }) }),
|
|
4668
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { style: { justifyContent: "end", gap: "5px" }, children: [
|
|
4669
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: handleClose, disabled: translateInProgress, children: formatMessage({
|
|
4670
|
+
id: getTranslation(`app.modal.confirm.button.cancel`),
|
|
4671
|
+
defaultMessage: "Cancel"
|
|
4672
|
+
}) }),
|
|
4673
|
+
/* @__PURE__ */ jsx(
|
|
4674
|
+
Button,
|
|
4675
|
+
{
|
|
4676
|
+
style: { marginRight: "5px" },
|
|
4677
|
+
onClick: run,
|
|
4678
|
+
disabled: translateInProgress || !sourceLocale,
|
|
4679
|
+
children: formatMessage({
|
|
4680
|
+
id: getTranslation(`module.${module}.modal.ai.button.translate`),
|
|
4681
|
+
defaultMessage: "Translate"
|
|
4682
|
+
})
|
|
4683
|
+
}
|
|
4684
|
+
)
|
|
4685
|
+
] })
|
|
4686
|
+
] }) }) });
|
|
4687
|
+
};
|
|
4688
|
+
const DocumentTranslateBox = ({ document: document2 }) => {
|
|
4689
|
+
const { formatMessage } = useIntl();
|
|
4690
|
+
const context = unstable_useContentManagerContext();
|
|
4691
|
+
const [appSettings, setAppSettings] = React.useState();
|
|
4692
|
+
const [i18nLocales, setI18nLocales] = React.useState([]);
|
|
4693
|
+
const [showModal, setShowModal] = React.useState(false);
|
|
4694
|
+
const module = config.uuid.modules.translation;
|
|
4695
|
+
function getCurrentLocale() {
|
|
4696
|
+
const queryString = window.location.search.split("?")[1];
|
|
4697
|
+
const searchParams = new URLSearchParams(queryString);
|
|
4698
|
+
return searchParams.get("plugins[i18n][locale]");
|
|
4699
|
+
}
|
|
4700
|
+
function getCurrentStatus() {
|
|
4701
|
+
const queryString = window.location.search.split("?")[1];
|
|
4702
|
+
const searchParams = new URLSearchParams(queryString);
|
|
4703
|
+
return searchParams.get("status") || void 0;
|
|
4704
|
+
}
|
|
4705
|
+
async function fetchSettings() {
|
|
4706
|
+
const fetchModuleSettings = new FetchModuleSettings();
|
|
4707
|
+
setAppSettings(await fetchModuleSettings.execute(module));
|
|
4708
|
+
}
|
|
4709
|
+
async function fetchLocales() {
|
|
4710
|
+
const fetchLocales2 = new FetchLocales();
|
|
4711
|
+
setI18nLocales(await fetchLocales2.execute());
|
|
4712
|
+
}
|
|
4713
|
+
function applyResults(results) {
|
|
4714
|
+
results.forEach((result) => {
|
|
4715
|
+
context.form.onChange(result.path, result.value);
|
|
4716
|
+
if (result.kind === "slug") {
|
|
4717
|
+
context.form.onChange("ltb_slug", result.value);
|
|
4718
|
+
}
|
|
4719
|
+
});
|
|
4720
|
+
}
|
|
4721
|
+
function getDocumentId() {
|
|
4722
|
+
const documentId = document2?.documentId || context.id;
|
|
4723
|
+
return documentId && documentId !== "create" ? documentId : void 0;
|
|
4724
|
+
}
|
|
4725
|
+
async function translate(sourceLocale, overwrite) {
|
|
4726
|
+
const translateDocument = new TranslateDocument();
|
|
4727
|
+
const output = await translateDocument.execute({
|
|
4728
|
+
collectionType: context.collectionType,
|
|
4729
|
+
model: context.model,
|
|
4730
|
+
documentId: context.isSingleType ? void 0 : getDocumentId(),
|
|
4731
|
+
sourceLocale,
|
|
4732
|
+
targetLocale: getCurrentLocale(),
|
|
4733
|
+
status: getCurrentStatus(),
|
|
4734
|
+
attributes: context.contentType?.attributes,
|
|
4735
|
+
components: context.components,
|
|
4736
|
+
values: context.form.values,
|
|
4737
|
+
overwrite
|
|
4738
|
+
});
|
|
4739
|
+
applyResults(output.results);
|
|
4740
|
+
return output;
|
|
4741
|
+
}
|
|
4742
|
+
React.useEffect(() => {
|
|
4743
|
+
fetchSettings();
|
|
4744
|
+
fetchLocales();
|
|
4745
|
+
}, []);
|
|
4746
|
+
const currentLocale = getCurrentLocale();
|
|
4747
|
+
const targetLocale = i18nLocales.find(
|
|
4748
|
+
(locale) => locale.code === currentLocale
|
|
4749
|
+
);
|
|
4750
|
+
const isLocalized2 = context.contentType?.pluginOptions?.i18n?.localized === true;
|
|
4751
|
+
if (!appSettings || !appSettings.active || !appSettings.aiEnabled) return null;
|
|
4752
|
+
if (!isLocalized2 || !currentLocale || i18nLocales.length < 2) return null;
|
|
4753
|
+
if (!context.contentType) return null;
|
|
4754
|
+
if (!context.isSingleType && !getDocumentId()) return null;
|
|
4755
|
+
return {
|
|
4756
|
+
title: formatMessage({
|
|
4757
|
+
id: getTranslation(`module.${module}.panel.title`),
|
|
4758
|
+
defaultMessage: "Translation"
|
|
4759
|
+
}),
|
|
4760
|
+
content: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4761
|
+
/* @__PURE__ */ jsx(Box, { display: "flex", style: { flexDirection: "column", width: "100%" }, children: /* @__PURE__ */ jsx(
|
|
4762
|
+
Button,
|
|
4763
|
+
{
|
|
4764
|
+
variant: "secondary",
|
|
4765
|
+
startIcon: /* @__PURE__ */ jsx(Sparkle, {}),
|
|
4766
|
+
onClick: () => setShowModal(true),
|
|
4767
|
+
disabled: context.form.isSubmitting || context.form.disabled,
|
|
4768
|
+
fullWidth: true,
|
|
4769
|
+
children: formatMessage({
|
|
4770
|
+
id: getTranslation(`module.${module}.button.translate-with-ai`),
|
|
4771
|
+
defaultMessage: "Translate with AI"
|
|
4772
|
+
})
|
|
4773
|
+
}
|
|
4774
|
+
) }),
|
|
4775
|
+
/* @__PURE__ */ jsx(
|
|
4776
|
+
DocumentTranslateModal,
|
|
4777
|
+
{
|
|
4778
|
+
open: showModal,
|
|
4779
|
+
locales: i18nLocales,
|
|
4780
|
+
targetLocale,
|
|
4781
|
+
translate,
|
|
4782
|
+
close: () => setShowModal(false)
|
|
4783
|
+
}
|
|
4784
|
+
)
|
|
4785
|
+
] })
|
|
4786
|
+
};
|
|
4787
|
+
};
|
|
4788
|
+
const TABS_PLUGIN_KEY = "littlebox-strapi-suite";
|
|
4789
|
+
const TABS_HASH_PARAM = "ltbTab";
|
|
4790
|
+
const TABS_BAR_FIELD_TYPE = "ltb-tabs-bar";
|
|
4791
|
+
const TABS_SECTION_FIELD_TYPE = "ltb-tab-section";
|
|
4792
|
+
function toTabKey(name) {
|
|
4793
|
+
return (name ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
4794
|
+
}
|
|
4795
|
+
function generateTabId() {
|
|
4796
|
+
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
4797
|
+
}
|
|
4798
|
+
function readTabs(pluginOptions) {
|
|
4799
|
+
const tabs = pluginOptions?.[TABS_PLUGIN_KEY]?.tabs;
|
|
4800
|
+
if (!Array.isArray(tabs)) return [];
|
|
4801
|
+
return tabs.filter((tab) => tab && typeof tab.id === "string" && typeof tab.name === "string");
|
|
4802
|
+
}
|
|
4803
|
+
function padTabs(next, previous) {
|
|
4804
|
+
const previousLength = Array.isArray(previous) ? previous.length : 0;
|
|
4805
|
+
const padding = Math.max(previousLength - next.length, 0);
|
|
4806
|
+
return [...next, ...Array(padding).fill(null)];
|
|
4807
|
+
}
|
|
4808
|
+
function readAttributeTabId(attribute) {
|
|
4809
|
+
const id = attribute?.pluginOptions?.[TABS_PLUGIN_KEY]?.tab;
|
|
4810
|
+
return typeof id === "string" && id !== "" ? id : null;
|
|
4811
|
+
}
|
|
4812
|
+
const SYSTEM_KEYS = [
|
|
4813
|
+
"id",
|
|
4814
|
+
"documentId",
|
|
4815
|
+
"locale",
|
|
4816
|
+
"createdAt",
|
|
4817
|
+
"updatedAt",
|
|
4818
|
+
"publishedAt",
|
|
4819
|
+
"createdBy",
|
|
4820
|
+
"updatedBy",
|
|
4821
|
+
"localizations"
|
|
4822
|
+
];
|
|
4823
|
+
function attributeNames(attributes) {
|
|
4824
|
+
if (Array.isArray(attributes)) {
|
|
4825
|
+
return attributes.map((attribute) => attribute?.name).filter((name) => typeof name === "string");
|
|
4826
|
+
}
|
|
4827
|
+
return attributes && typeof attributes === "object" ? Object.keys(attributes) : [];
|
|
4828
|
+
}
|
|
4829
|
+
function getConflictingTabIds(tabs, attributes) {
|
|
4830
|
+
const reserved = /* @__PURE__ */ new Set([...SYSTEM_KEYS, ...attributeNames(attributes)]);
|
|
4831
|
+
return new Set(tabs.filter((tab) => reserved.has(toTabKey(tab.name))).map((tab) => tab.id));
|
|
4832
|
+
}
|
|
4833
|
+
function validateTabs(tabs) {
|
|
4834
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
4835
|
+
for (const tab of tabs) {
|
|
4836
|
+
if (!tab.name || tab.name.trim() === "") return "name.required";
|
|
4837
|
+
const key = toTabKey(tab.name);
|
|
4838
|
+
if (key === "") return "key.empty";
|
|
4839
|
+
if (keys2.has(key)) return "key.duplicated";
|
|
4840
|
+
keys2.add(key);
|
|
4841
|
+
}
|
|
4842
|
+
return null;
|
|
4843
|
+
}
|
|
4844
|
+
function omitPluginKey(pluginOptions) {
|
|
4845
|
+
const { [TABS_PLUGIN_KEY]: _removed, ...rest } = pluginOptions;
|
|
4846
|
+
return rest;
|
|
4847
|
+
}
|
|
4848
|
+
function cleanAttribute(attribute, validIds) {
|
|
4849
|
+
if (!attribute?.pluginOptions || !(TABS_PLUGIN_KEY in attribute.pluginOptions)) return attribute;
|
|
4850
|
+
const id = readAttributeTabId(attribute);
|
|
4851
|
+
if (id && validIds.has(id)) return attribute;
|
|
4852
|
+
return { ...attribute, pluginOptions: omitPluginKey(attribute.pluginOptions) };
|
|
4853
|
+
}
|
|
4854
|
+
function cleanContentTypeSchema(schema) {
|
|
4855
|
+
const current = schema;
|
|
4856
|
+
if (!current || typeof current !== "object") return schema;
|
|
4857
|
+
const tabs = readTabs(current.pluginOptions);
|
|
4858
|
+
const validIds = new Set(tabs.map((tab) => tab.id));
|
|
4859
|
+
let changed = false;
|
|
4860
|
+
const next = { ...current };
|
|
4861
|
+
if (current.pluginOptions && TABS_PLUGIN_KEY in current.pluginOptions) {
|
|
4862
|
+
const storedTabs = current.pluginOptions[TABS_PLUGIN_KEY]?.tabs;
|
|
4863
|
+
if (tabs.length === 0) {
|
|
4864
|
+
next.pluginOptions = omitPluginKey(current.pluginOptions);
|
|
4865
|
+
changed = true;
|
|
4866
|
+
} else if (!Array.isArray(storedTabs) || storedTabs.length !== tabs.length) {
|
|
4867
|
+
next.pluginOptions = {
|
|
4868
|
+
...current.pluginOptions,
|
|
4869
|
+
[TABS_PLUGIN_KEY]: { ...current.pluginOptions[TABS_PLUGIN_KEY], tabs }
|
|
4870
|
+
};
|
|
4871
|
+
changed = true;
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
const clean = (attribute) => {
|
|
4875
|
+
const cleaned = cleanAttribute(attribute, validIds);
|
|
4876
|
+
if (cleaned !== attribute) changed = true;
|
|
4877
|
+
return cleaned;
|
|
4878
|
+
};
|
|
4879
|
+
if (Array.isArray(current.attributes)) {
|
|
4880
|
+
next.attributes = current.attributes.map(clean);
|
|
4881
|
+
} else if (current.attributes && typeof current.attributes === "object") {
|
|
4882
|
+
next.attributes = Object.fromEntries(
|
|
4883
|
+
Object.entries(current.attributes).map(([name, attribute]) => [name, clean(attribute)])
|
|
4884
|
+
);
|
|
4885
|
+
}
|
|
4886
|
+
return changed ? next : schema;
|
|
4887
|
+
}
|
|
4888
|
+
function fieldTabId(field, validIds) {
|
|
4889
|
+
const id = readAttributeTabId(field.attribute);
|
|
4890
|
+
return id && validIds.has(id) ? id : null;
|
|
4891
|
+
}
|
|
4892
|
+
function pickFields(panels, predicate) {
|
|
4893
|
+
return panels.map((panel) => panel.map((row) => row.filter(predicate)).filter((row) => row.length > 0)).filter((panel) => panel.length > 0);
|
|
4894
|
+
}
|
|
4895
|
+
function groupLayoutByTabs(panels, tabs) {
|
|
4896
|
+
const validIds = new Set(tabs.map((tab) => tab.id));
|
|
4897
|
+
return {
|
|
4898
|
+
rootPanels: pickFields(panels, (field) => fieldTabId(field, validIds) === null),
|
|
4899
|
+
sections: tabs.map((tab) => ({
|
|
4900
|
+
tab,
|
|
4901
|
+
panels: pickFields(panels, (field) => fieldTabId(field, validIds) === tab.id)
|
|
4902
|
+
}))
|
|
4903
|
+
};
|
|
4904
|
+
}
|
|
4905
|
+
function componentLeafPath(field, components, depth = 0) {
|
|
4906
|
+
const attribute = field.attribute;
|
|
4907
|
+
if (attribute?.type !== "component") return field.name;
|
|
4908
|
+
if (depth > 10) return null;
|
|
4909
|
+
const inner = components[attribute.component]?.layout?.flat() ?? [];
|
|
4910
|
+
for (const child of inner) {
|
|
4911
|
+
const path = componentLeafPath(child, components, depth + 1);
|
|
4912
|
+
if (path) return `${field.name}.${path}`;
|
|
4913
|
+
}
|
|
4914
|
+
return null;
|
|
4915
|
+
}
|
|
4916
|
+
function findAnchorName(panels, components = {}) {
|
|
4917
|
+
const fields = panels.flat(2);
|
|
4918
|
+
const plain = fields.find((field) => field.attribute?.type !== "component");
|
|
4919
|
+
if (plain) return plain.name;
|
|
4920
|
+
for (const field of fields) {
|
|
4921
|
+
const path = componentLeafPath(field, components);
|
|
4922
|
+
if (path) return path;
|
|
4923
|
+
}
|
|
4924
|
+
return null;
|
|
4925
|
+
}
|
|
4926
|
+
function readTabFromHash(hash) {
|
|
4927
|
+
const value = new URLSearchParams((hash ?? "").replace(/^#/, "")).get(TABS_HASH_PARAM);
|
|
4928
|
+
return value ? value : null;
|
|
4929
|
+
}
|
|
4930
|
+
function pickInitialTab(keys2, hashKey, currentKey) {
|
|
4931
|
+
if (hashKey && keys2.includes(hashKey)) return hashKey;
|
|
4932
|
+
if (currentKey && keys2.includes(currentKey)) return currentKey;
|
|
4933
|
+
return keys2[0] ?? null;
|
|
4934
|
+
}
|
|
4935
|
+
function tabHash(key) {
|
|
4936
|
+
return `#${TABS_HASH_PARAM}=${encodeURIComponent(key)}`;
|
|
4937
|
+
}
|
|
4938
|
+
function mapFieldsToTabKeys(panels, tabs) {
|
|
4939
|
+
const keysById = new Map(tabs.map((tab) => [tab.id, toTabKey(tab.name)]));
|
|
4940
|
+
const result = {};
|
|
4941
|
+
panels.flat(2).forEach((field) => {
|
|
4942
|
+
const id = readAttributeTabId(field.attribute);
|
|
4943
|
+
const key = id ? keysById.get(id) : void 0;
|
|
4944
|
+
if (key !== void 0) result[field.name] = key;
|
|
4945
|
+
});
|
|
4946
|
+
return result;
|
|
4947
|
+
}
|
|
4948
|
+
function countErrorsByTab(errors, fieldTabKeys) {
|
|
4949
|
+
const counts = {};
|
|
4950
|
+
if (!errors || typeof errors !== "object") return counts;
|
|
4951
|
+
Object.entries(errors).forEach(([name, error]) => {
|
|
4952
|
+
const key = fieldTabKeys[name];
|
|
4953
|
+
if (key !== void 0 && error) counts[key] = (counts[key] ?? 0) + 1;
|
|
4954
|
+
});
|
|
4955
|
+
return counts;
|
|
4956
|
+
}
|
|
4957
|
+
const EDIT_VIEW_PATH = /\/content-manager\/(collection-types\/[^/]+\/[^/]+|single-types\/[^/]+)\/?$/;
|
|
4958
|
+
const NON_EDIT_SEGMENTS = /* @__PURE__ */ new Set(["history", "preview", "configurations"]);
|
|
4959
|
+
function isEditViewPath(pathname) {
|
|
4960
|
+
if (!EDIT_VIEW_PATH.test(pathname)) return false;
|
|
4961
|
+
const lastSegment = pathname.replace(/\/$/, "").split("/").pop() ?? "";
|
|
4962
|
+
return !NON_EDIT_SEGMENTS.has(lastSegment);
|
|
4963
|
+
}
|
|
4964
|
+
const TabRow = ({
|
|
4965
|
+
tab,
|
|
4966
|
+
onRename,
|
|
4967
|
+
onRemove
|
|
4968
|
+
}) => {
|
|
4969
|
+
const { formatMessage } = useIntl();
|
|
4970
|
+
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: tab.id });
|
|
4971
|
+
return /* @__PURE__ */ jsx(
|
|
4972
|
+
Box,
|
|
4973
|
+
{
|
|
4974
|
+
ref: setNodeRef,
|
|
4975
|
+
style: { transform: CSS.Transform.toString(transform), transition },
|
|
4976
|
+
paddingBottom: 2,
|
|
4977
|
+
children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
4978
|
+
/* @__PURE__ */ jsx(
|
|
4979
|
+
IconButton,
|
|
4980
|
+
{
|
|
4981
|
+
...attributes,
|
|
4982
|
+
...listeners,
|
|
4983
|
+
type: "button",
|
|
4984
|
+
variant: "ghost",
|
|
4985
|
+
label: formatMessage({
|
|
4986
|
+
id: getTranslation("tabs.ctb.reorder"),
|
|
4987
|
+
defaultMessage: "Drag to reorder"
|
|
4988
|
+
}),
|
|
4989
|
+
style: { cursor: "grab" },
|
|
4990
|
+
children: /* @__PURE__ */ jsx(Drag, {})
|
|
4991
|
+
}
|
|
4992
|
+
),
|
|
4993
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
|
|
4994
|
+
TextInput,
|
|
4995
|
+
{
|
|
4996
|
+
"aria-label": formatMessage({
|
|
4997
|
+
id: getTranslation("tabs.ctb.name.placeholder"),
|
|
4998
|
+
defaultMessage: "Tab name"
|
|
4999
|
+
}),
|
|
5000
|
+
placeholder: formatMessage({
|
|
5001
|
+
id: getTranslation("tabs.ctb.name.placeholder"),
|
|
5002
|
+
defaultMessage: "Tab name"
|
|
5003
|
+
}),
|
|
5004
|
+
value: tab.name,
|
|
5005
|
+
onChange: (event) => onRename(event.target.value)
|
|
5006
|
+
}
|
|
5007
|
+
) }),
|
|
5008
|
+
/* @__PURE__ */ jsx(
|
|
5009
|
+
IconButton,
|
|
5010
|
+
{
|
|
5011
|
+
type: "button",
|
|
5012
|
+
variant: "ghost",
|
|
5013
|
+
label: formatMessage({
|
|
5014
|
+
id: getTranslation("tabs.ctb.remove"),
|
|
5015
|
+
defaultMessage: "Remove tab"
|
|
5016
|
+
}),
|
|
5017
|
+
onClick: onRemove,
|
|
5018
|
+
children: /* @__PURE__ */ jsx(Trash, {})
|
|
5019
|
+
}
|
|
5020
|
+
)
|
|
5021
|
+
] })
|
|
5022
|
+
}
|
|
5023
|
+
);
|
|
5024
|
+
};
|
|
5025
|
+
const TabsEditor = ({ name, value, error, intlLabel, description, onChange }) => {
|
|
5026
|
+
const { formatMessage } = useIntl();
|
|
5027
|
+
const tabs = readTabs({ [TABS_PLUGIN_KEY]: { tabs: value } });
|
|
5028
|
+
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));
|
|
5029
|
+
const change = (next) => onChange({ target: { name, value: padTabs(next, value) } });
|
|
5030
|
+
const handleDragEnd = ({ active, over }) => {
|
|
5031
|
+
if (!over || active.id === over.id) return;
|
|
5032
|
+
const oldIndex = tabs.findIndex((tab) => tab.id === active.id);
|
|
5033
|
+
const newIndex = tabs.findIndex((tab) => tab.id === over.id);
|
|
5034
|
+
change(arrayMove(tabs, oldIndex, newIndex));
|
|
5035
|
+
};
|
|
5036
|
+
return /* @__PURE__ */ jsxs(Box, { children: [
|
|
5037
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 2, paddingBottom: 4, children: /* @__PURE__ */ jsx(Divider, {}) }),
|
|
5038
|
+
/* @__PURE__ */ jsxs(Field.Root, { name, id: name, error, children: [
|
|
5039
|
+
/* @__PURE__ */ jsx(Field.Label, { style: { fontSize: "1.4rem" }, children: formatMessage(intlLabel, intlLabel.values) }),
|
|
5040
|
+
description && /* @__PURE__ */ jsx(Box, { paddingBottom: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(description, description.values) }) }),
|
|
5041
|
+
tabs.length === 0 && /* @__PURE__ */ jsx(Box, { paddingBottom: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral500", children: formatMessage({
|
|
5042
|
+
id: getTranslation("tabs.ctb.empty"),
|
|
5043
|
+
defaultMessage: "No tabs yet."
|
|
5044
|
+
}) }) }),
|
|
5045
|
+
/* @__PURE__ */ jsx(
|
|
5046
|
+
DndContext,
|
|
5047
|
+
{
|
|
5048
|
+
sensors,
|
|
5049
|
+
collisionDetection: closestCenter,
|
|
5050
|
+
modifiers: [restrictToVerticalAxis],
|
|
5051
|
+
onDragEnd: handleDragEnd,
|
|
5052
|
+
children: /* @__PURE__ */ jsx(SortableContext, { items: tabs.map((tab) => tab.id), strategy: verticalListSortingStrategy, children: tabs.map((tab) => /* @__PURE__ */ jsx(
|
|
5053
|
+
TabRow,
|
|
5054
|
+
{
|
|
5055
|
+
tab,
|
|
5056
|
+
onRename: (tabName) => change(
|
|
5057
|
+
tabs.map(
|
|
5058
|
+
(current) => current.id === tab.id ? { ...current, name: tabName } : current
|
|
5059
|
+
)
|
|
5060
|
+
),
|
|
5061
|
+
onRemove: () => change(tabs.filter((current) => current.id !== tab.id))
|
|
5062
|
+
},
|
|
5063
|
+
tab.id
|
|
5064
|
+
)) })
|
|
5065
|
+
}
|
|
5066
|
+
),
|
|
5067
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
5068
|
+
Button,
|
|
5069
|
+
{
|
|
5070
|
+
type: "button",
|
|
5071
|
+
variant: "secondary",
|
|
5072
|
+
startIcon: /* @__PURE__ */ jsx(Plus, {}),
|
|
5073
|
+
onClick: () => change([...tabs, { id: generateTabId(), name: "" }]),
|
|
5074
|
+
children: formatMessage({ id: getTranslation("tabs.ctb.add"), defaultMessage: "Add tab" })
|
|
5075
|
+
}
|
|
5076
|
+
) }),
|
|
5077
|
+
/* @__PURE__ */ jsx(Field.Error, {})
|
|
5078
|
+
] })
|
|
5079
|
+
] });
|
|
5080
|
+
};
|
|
5081
|
+
const TabSelect = ({
|
|
5082
|
+
name,
|
|
5083
|
+
value,
|
|
5084
|
+
error,
|
|
5085
|
+
intlLabel,
|
|
5086
|
+
description,
|
|
5087
|
+
options = [],
|
|
5088
|
+
onChange
|
|
5089
|
+
}) => {
|
|
5090
|
+
const { formatMessage } = useIntl();
|
|
5091
|
+
return /* @__PURE__ */ jsxs(
|
|
5092
|
+
Field.Root,
|
|
5093
|
+
{
|
|
5094
|
+
name,
|
|
5095
|
+
id: name,
|
|
5096
|
+
error,
|
|
5097
|
+
hint: description ? formatMessage(description) : void 0,
|
|
5098
|
+
children: [
|
|
5099
|
+
/* @__PURE__ */ jsx(Field.Label, { style: { fontSize: "1.6rem", paddingTop: "11px", paddingBottom: "12px" }, children: formatMessage(intlLabel) }),
|
|
5100
|
+
/* @__PURE__ */ jsx(
|
|
5101
|
+
SingleSelect,
|
|
5102
|
+
{
|
|
5103
|
+
value: value ?? "",
|
|
5104
|
+
onChange: (next) => onChange({ target: { name, value: String(next), type: "select" } }),
|
|
5105
|
+
children: options.map(({ key, value: optionValue, metadatas }) => /* @__PURE__ */ jsx(
|
|
5106
|
+
SingleSelectOption,
|
|
5107
|
+
{
|
|
5108
|
+
value: optionValue,
|
|
5109
|
+
disabled: metadatas.disabled,
|
|
5110
|
+
hidden: metadatas.hidden,
|
|
5111
|
+
children: formatMessage(metadatas.intlLabel)
|
|
5112
|
+
},
|
|
5113
|
+
key
|
|
5114
|
+
))
|
|
5115
|
+
}
|
|
5116
|
+
),
|
|
5117
|
+
/* @__PURE__ */ jsx(Field.Hint, {}),
|
|
5118
|
+
/* @__PURE__ */ jsx(Field.Error, {})
|
|
5119
|
+
]
|
|
5120
|
+
}
|
|
5121
|
+
);
|
|
5122
|
+
};
|
|
5123
|
+
const TABS_EDITOR_INPUT = "ltbTabsEditor";
|
|
5124
|
+
const TAB_SELECT_INPUT = "ltbTabSelect";
|
|
5125
|
+
const TAB_FIELD_TYPES = [
|
|
5126
|
+
"biginteger",
|
|
5127
|
+
"blocks",
|
|
5128
|
+
"boolean",
|
|
5129
|
+
"component",
|
|
5130
|
+
"date",
|
|
5131
|
+
"datetime",
|
|
5132
|
+
"decimal",
|
|
5133
|
+
"dynamiczone",
|
|
5134
|
+
"email",
|
|
5135
|
+
"enumeration",
|
|
5136
|
+
"float",
|
|
5137
|
+
"integer",
|
|
5138
|
+
"json",
|
|
5139
|
+
"media",
|
|
5140
|
+
"password",
|
|
5141
|
+
"relation",
|
|
5142
|
+
"richtext",
|
|
5143
|
+
"string",
|
|
5144
|
+
"text",
|
|
5145
|
+
"time",
|
|
5146
|
+
"uid"
|
|
5147
|
+
];
|
|
5148
|
+
function registerTabsInContentTypeBuilder(app) {
|
|
5149
|
+
const forms = app.getPlugin("content-type-builder")?.apis?.forms;
|
|
5150
|
+
if (!forms) return;
|
|
5151
|
+
forms.components.add({ id: TABS_EDITOR_INPUT, component: TabsEditor });
|
|
5152
|
+
forms.components.add({ id: TAB_SELECT_INPUT, component: TabSelect });
|
|
5153
|
+
forms.addContentTypeSchemaMutation((nextSchema) => cleanContentTypeSchema(nextSchema));
|
|
5154
|
+
forms.extendContentType({
|
|
5155
|
+
validator: () => ({
|
|
5156
|
+
[TABS_PLUGIN_KEY]: create$1().shape({
|
|
5157
|
+
tabs: create().test("ltb-tabs", function(tabs) {
|
|
5158
|
+
const error = validateTabs(readTabs({ [TABS_PLUGIN_KEY]: { tabs } }));
|
|
5159
|
+
return error === null ? true : this.createError({ message: getTranslation(`tabs.ctb.error.${error}`) });
|
|
5160
|
+
})
|
|
5161
|
+
})
|
|
5162
|
+
}),
|
|
5163
|
+
form: {
|
|
5164
|
+
advanced: () => [
|
|
5165
|
+
{
|
|
5166
|
+
name: `pluginOptions.${TABS_PLUGIN_KEY}.tabs`,
|
|
5167
|
+
type: TABS_EDITOR_INPUT,
|
|
5168
|
+
size: 12,
|
|
5169
|
+
intlLabel: { id: getTranslation("tabs.ctb.content-type.label"), defaultMessage: "Tabs" },
|
|
5170
|
+
description: {
|
|
5171
|
+
id: getTranslation("tabs.ctb.content-type.description"),
|
|
5172
|
+
defaultMessage: "Organize the fields of this content type in tabs. Fields in a tab are returned by the REST API inside a property named after the tab."
|
|
5173
|
+
}
|
|
5174
|
+
}
|
|
5175
|
+
]
|
|
5176
|
+
}
|
|
5177
|
+
});
|
|
5178
|
+
forms.extendFields(TAB_FIELD_TYPES, {
|
|
5179
|
+
form: {
|
|
5180
|
+
advanced: ({ contentTypeSchema, forTarget }) => {
|
|
5181
|
+
if (forTarget !== "contentType") return [];
|
|
5182
|
+
const tabs = readTabs(
|
|
5183
|
+
contentTypeSchema?.pluginOptions ?? contentTypeSchema?.schema?.pluginOptions
|
|
5184
|
+
);
|
|
5185
|
+
if (tabs.length === 0) return [];
|
|
5186
|
+
const conflicting = getConflictingTabIds(
|
|
5187
|
+
tabs,
|
|
5188
|
+
contentTypeSchema?.attributes ?? contentTypeSchema?.schema?.attributes
|
|
5189
|
+
);
|
|
5190
|
+
return [
|
|
5191
|
+
{
|
|
5192
|
+
name: `pluginOptions.${TABS_PLUGIN_KEY}.tab`,
|
|
5193
|
+
type: TAB_SELECT_INPUT,
|
|
5194
|
+
size: 12,
|
|
5195
|
+
intlLabel: { id: getTranslation("tabs.ctb.field.label"), defaultMessage: "Tab" },
|
|
5196
|
+
description: {
|
|
5197
|
+
id: getTranslation("tabs.ctb.field.description"),
|
|
5198
|
+
defaultMessage: "Tab where this field is shown. Fields without a tab are always visible."
|
|
5199
|
+
},
|
|
5200
|
+
options: [
|
|
5201
|
+
{
|
|
5202
|
+
key: "__null_reset_value__",
|
|
5203
|
+
value: "",
|
|
5204
|
+
metadatas: {
|
|
5205
|
+
intlLabel: {
|
|
5206
|
+
id: getTranslation("tabs.ctb.field.none"),
|
|
5207
|
+
defaultMessage: "None (always visible)"
|
|
5208
|
+
}
|
|
5209
|
+
}
|
|
5210
|
+
},
|
|
5211
|
+
...tabs.map((tab) => ({
|
|
5212
|
+
key: tab.id,
|
|
5213
|
+
value: tab.id,
|
|
5214
|
+
metadatas: conflicting.has(tab.id) ? {
|
|
5215
|
+
disabled: true,
|
|
5216
|
+
// The CTB select formats option labels without values, so the text is prebuilt.
|
|
5217
|
+
intlLabel: {
|
|
5218
|
+
id: `${TABS_PLUGIN_KEY}.tab.${tab.id}.conflict`,
|
|
5219
|
+
defaultMessage: `${tab.name} (conflicts with a field name)`
|
|
5220
|
+
}
|
|
5221
|
+
} : {
|
|
5222
|
+
intlLabel: {
|
|
5223
|
+
id: `${TABS_PLUGIN_KEY}.tab.${tab.id}`,
|
|
5224
|
+
defaultMessage: tab.name
|
|
5225
|
+
}
|
|
5226
|
+
}
|
|
5227
|
+
}))
|
|
5228
|
+
]
|
|
5229
|
+
}
|
|
5230
|
+
];
|
|
5231
|
+
}
|
|
5232
|
+
}
|
|
5233
|
+
});
|
|
5234
|
+
}
|
|
5235
|
+
const BADGE_ATTRIBUTE = "data-ltb-tab-badge";
|
|
5236
|
+
const ROW_SELECTOR = "li[aria-label]";
|
|
5237
|
+
const CTB_STATE_KEY = "content-type-builder_dataManagerProvider";
|
|
5238
|
+
const CTB_CONTENT_TYPE_PATH = /\/plugins\/content-type-builder\/content-types\/([^/]+)\/?$/;
|
|
5239
|
+
function ctbContentTypeUid(pathname) {
|
|
5240
|
+
const match = pathname.match(CTB_CONTENT_TYPE_PATH);
|
|
5241
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
5242
|
+
}
|
|
5243
|
+
function buildFieldTabNames(contentType) {
|
|
5244
|
+
const tabs = readTabs(contentType?.pluginOptions);
|
|
5245
|
+
if (tabs.length === 0) return {};
|
|
5246
|
+
const namesById = new Map(tabs.map((tab) => [tab.id, tab.name]));
|
|
5247
|
+
const attributes = Array.isArray(contentType?.attributes) ? contentType.attributes.map((attribute) => [attribute?.name, attribute]) : Object.entries(contentType?.attributes ?? {});
|
|
5248
|
+
const result = {};
|
|
5249
|
+
attributes.forEach(([name, attribute]) => {
|
|
5250
|
+
const id = readAttributeTabId(attribute);
|
|
5251
|
+
const tabName = id ? namesById.get(id) : void 0;
|
|
5252
|
+
if (typeof name === "string" && tabName !== void 0) result[name] = tabName;
|
|
5253
|
+
});
|
|
5254
|
+
return result;
|
|
5255
|
+
}
|
|
5256
|
+
function findNameElement(row, name) {
|
|
5257
|
+
const walker = row.ownerDocument.createTreeWalker(row, NodeFilter.SHOW_TEXT);
|
|
5258
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
5259
|
+
if (node.textContent === name) return node.parentElement;
|
|
5260
|
+
}
|
|
5261
|
+
return null;
|
|
5262
|
+
}
|
|
5263
|
+
function createBadge(doc) {
|
|
5264
|
+
const badge = doc.createElement("span");
|
|
5265
|
+
badge.setAttribute(BADGE_ATTRIBUTE, "");
|
|
5266
|
+
Object.assign(badge.style, {
|
|
5267
|
+
flexShrink: "0",
|
|
5268
|
+
marginLeft: "8px",
|
|
5269
|
+
padding: "2px 8px",
|
|
5270
|
+
borderRadius: "4px",
|
|
5271
|
+
fontSize: "1.1rem",
|
|
5272
|
+
fontWeight: "600",
|
|
5273
|
+
lineHeight: "1.6rem",
|
|
5274
|
+
whiteSpace: "nowrap",
|
|
5275
|
+
color: "#7b79ff",
|
|
5276
|
+
backgroundColor: "rgba(123, 121, 255, 0.16)"
|
|
5277
|
+
});
|
|
5278
|
+
return badge;
|
|
5279
|
+
}
|
|
5280
|
+
function syncTabBadges(root2, fieldTabNames) {
|
|
5281
|
+
root2.querySelectorAll(ROW_SELECTOR).forEach((row) => {
|
|
5282
|
+
if (row.parentElement?.closest(ROW_SELECTOR)) return;
|
|
5283
|
+
const name = row.getAttribute("aria-label") ?? "";
|
|
5284
|
+
const nameElement = findNameElement(row, name);
|
|
5285
|
+
if (!nameElement) return;
|
|
5286
|
+
const existing = nameElement.nextElementSibling?.hasAttribute(BADGE_ATTRIBUTE) ? nameElement.nextElementSibling : null;
|
|
5287
|
+
const tabName = fieldTabNames[name];
|
|
5288
|
+
if (!tabName) {
|
|
5289
|
+
existing?.remove();
|
|
5290
|
+
return;
|
|
5291
|
+
}
|
|
5292
|
+
const badge = existing ?? createBadge(row.ownerDocument);
|
|
5293
|
+
if (badge.textContent !== tabName) badge.textContent = tabName;
|
|
5294
|
+
if (!existing) nameElement.after(badge);
|
|
5295
|
+
});
|
|
5296
|
+
}
|
|
5297
|
+
function startTabBadges(app) {
|
|
5298
|
+
if (typeof window === "undefined" || typeof MutationObserver === "undefined") return;
|
|
5299
|
+
let scheduled = false;
|
|
5300
|
+
let storeUnsubscribe = null;
|
|
5301
|
+
const update = () => {
|
|
5302
|
+
scheduled = false;
|
|
5303
|
+
const uid = ctbContentTypeUid(window.location.pathname);
|
|
5304
|
+
if (!uid) return;
|
|
5305
|
+
const store = app?.store;
|
|
5306
|
+
if (store && !storeUnsubscribe) storeUnsubscribe = store.subscribe(schedule);
|
|
5307
|
+
const contentType = store?.getState?.()[CTB_STATE_KEY]?.current?.contentTypes?.[uid];
|
|
5308
|
+
syncTabBadges(document, buildFieldTabNames(contentType));
|
|
5309
|
+
};
|
|
5310
|
+
function schedule() {
|
|
5311
|
+
if (scheduled) return;
|
|
5312
|
+
scheduled = true;
|
|
5313
|
+
requestAnimationFrame(update);
|
|
5314
|
+
}
|
|
5315
|
+
const observer = new MutationObserver((mutations) => {
|
|
5316
|
+
const onlyBadges = mutations.every(
|
|
5317
|
+
(mutation) => [...mutation.addedNodes, ...mutation.removedNodes].every(
|
|
5318
|
+
(node) => node instanceof Element && node.hasAttribute(BADGE_ATTRIBUTE)
|
|
5319
|
+
)
|
|
5320
|
+
);
|
|
5321
|
+
if (!onlyBadges) schedule();
|
|
5322
|
+
});
|
|
5323
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
5324
|
+
}
|
|
5325
|
+
function pseudoField(name, type, extra) {
|
|
5326
|
+
return {
|
|
5327
|
+
name,
|
|
5328
|
+
label: "",
|
|
5329
|
+
type,
|
|
5330
|
+
size: 12,
|
|
5331
|
+
visible: true,
|
|
5332
|
+
disabled: false,
|
|
5333
|
+
required: false,
|
|
5334
|
+
unique: false,
|
|
5335
|
+
hint: "",
|
|
5336
|
+
placeholder: "",
|
|
5337
|
+
attribute: { type },
|
|
5338
|
+
...extra
|
|
5339
|
+
};
|
|
5340
|
+
}
|
|
5341
|
+
function mutateEditViewLayout(args, pathname = typeof window !== "undefined" ? window.location.pathname : "") {
|
|
5342
|
+
const tabs = readTabs(args.layout?.options);
|
|
5343
|
+
const panels = args.layout?.layout ?? [];
|
|
5344
|
+
if (tabs.length === 0 || !isEditViewPath(pathname)) return args;
|
|
5345
|
+
const { rootPanels, sections } = groupLayoutByTabs(panels, tabs);
|
|
5346
|
+
const anchor = findAnchorName(rootPanels, args.layout?.components) ?? findAnchorName(panels, args.layout?.components);
|
|
5347
|
+
if (!anchor) return args;
|
|
5348
|
+
const bar = pseudoField(anchor, TABS_BAR_FIELD_TYPE, {
|
|
5349
|
+
ltbTabs: tabs.map((tab) => ({ ...tab, key: toTabKey(tab.name) })),
|
|
5350
|
+
ltbFieldTabKeys: mapFieldsToTabKeys(panels, tabs)
|
|
5351
|
+
});
|
|
5352
|
+
return {
|
|
5353
|
+
...args,
|
|
5354
|
+
layout: {
|
|
5355
|
+
...args.layout,
|
|
5356
|
+
layout: [
|
|
5357
|
+
...rootPanels,
|
|
5358
|
+
[[bar]],
|
|
5359
|
+
...sections.flatMap(({ tab, panels: tabPanels }) => [
|
|
5360
|
+
[[pseudoField(anchor, TABS_SECTION_FIELD_TYPE, { ltbTabKey: toTabKey(tab.name) })]],
|
|
5361
|
+
...tabPanels
|
|
5362
|
+
])
|
|
5363
|
+
]
|
|
5364
|
+
}
|
|
5365
|
+
};
|
|
5366
|
+
}
|
|
5367
|
+
function createTabsStore() {
|
|
5368
|
+
let active = null;
|
|
5369
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
5370
|
+
return {
|
|
5371
|
+
get: () => active,
|
|
5372
|
+
set(key) {
|
|
5373
|
+
if (key === active) return;
|
|
5374
|
+
active = key;
|
|
5375
|
+
listeners.forEach((listener) => listener());
|
|
5376
|
+
},
|
|
5377
|
+
subscribe(listener) {
|
|
5378
|
+
listeners.add(listener);
|
|
5379
|
+
return () => {
|
|
5380
|
+
listeners.delete(listener);
|
|
5381
|
+
};
|
|
5382
|
+
}
|
|
5383
|
+
};
|
|
5384
|
+
}
|
|
5385
|
+
const tabsStore = createTabsStore();
|
|
5386
|
+
function selectTab(key) {
|
|
5387
|
+
tabsStore.set(key);
|
|
5388
|
+
const { pathname, search } = window.location;
|
|
5389
|
+
window.history.replaceState(window.history.state, "", `${pathname}${search}${tabHash(key)}`);
|
|
5390
|
+
}
|
|
5391
|
+
const TabsBar = ({ ltbTabs = [], ltbFieldTabKeys = {} }) => {
|
|
5392
|
+
const { formatMessage } = useIntl();
|
|
5393
|
+
const { form } = unstable_useContentManagerContext();
|
|
5394
|
+
const errors = form?.errors;
|
|
5395
|
+
const active = useSyncExternalStore(tabsStore.subscribe, tabsStore.get);
|
|
5396
|
+
const keys2 = useMemo(() => ltbTabs.map((tab) => tab.key), [ltbTabs]);
|
|
5397
|
+
const errorCounts = useMemo(
|
|
5398
|
+
() => countErrorsByTab(errors, ltbFieldTabKeys),
|
|
5399
|
+
[errors, ltbFieldTabKeys]
|
|
5400
|
+
);
|
|
5401
|
+
useLayoutEffect(() => {
|
|
5402
|
+
const initial = pickInitialTab(keys2, readTabFromHash(window.location.hash), tabsStore.get());
|
|
5403
|
+
if (initial) tabsStore.set(initial);
|
|
5404
|
+
}, [keys2.join("|")]);
|
|
5405
|
+
const previousErrors = useRef(errors);
|
|
5406
|
+
useEffect(() => {
|
|
5407
|
+
if (previousErrors.current === errors) return;
|
|
5408
|
+
previousErrors.current = errors;
|
|
5409
|
+
if (active && (errorCounts[active] ?? 0) > 0) return;
|
|
5410
|
+
const tabWithErrors = ltbTabs.find((tab) => (errorCounts[tab.key] ?? 0) > 0);
|
|
5411
|
+
if (tabWithErrors) selectTab(tabWithErrors.key);
|
|
5412
|
+
}, [errors]);
|
|
5413
|
+
return /* @__PURE__ */ jsx(Box, { "data-ltb-tabs-bar": "", children: /* @__PURE__ */ jsx(Tabs.Root, { variant: "simple", value: active ?? keys2[0], onValueChange: selectTab, children: /* @__PURE__ */ jsx(
|
|
5414
|
+
Tabs.List,
|
|
5415
|
+
{
|
|
5416
|
+
"aria-label": formatMessage({
|
|
5417
|
+
id: getTranslation("tabs.edit-view.label"),
|
|
5418
|
+
defaultMessage: "Content tabs"
|
|
5419
|
+
}),
|
|
5420
|
+
children: ltbTabs.map((tab) => {
|
|
5421
|
+
const count = errorCounts[tab.key] ?? 0;
|
|
5422
|
+
return /* @__PURE__ */ jsx(Tabs.Trigger, { value: tab.key, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
5423
|
+
tab.name,
|
|
5424
|
+
count > 0 && /* @__PURE__ */ jsx(
|
|
5425
|
+
Badge,
|
|
5426
|
+
{
|
|
5427
|
+
backgroundColor: "danger100",
|
|
5428
|
+
textColor: "danger600",
|
|
5429
|
+
title: formatMessage(
|
|
5430
|
+
{
|
|
5431
|
+
id: getTranslation("tabs.edit-view.errors"),
|
|
5432
|
+
defaultMessage: "{count, plural, one {# error} other {# errors}}"
|
|
5433
|
+
},
|
|
5434
|
+
{ count }
|
|
5435
|
+
),
|
|
5436
|
+
children: count
|
|
5437
|
+
}
|
|
5438
|
+
)
|
|
5439
|
+
] }) }, tab.id);
|
|
5440
|
+
})
|
|
5441
|
+
}
|
|
5442
|
+
) }) });
|
|
5443
|
+
};
|
|
5444
|
+
const BAR_SELECTOR = "[data-ltb-tabs-bar]";
|
|
5445
|
+
const SECTION_SELECTOR = "[data-ltb-tab-section]";
|
|
5446
|
+
function applySectionVisibility(marker, visible) {
|
|
5447
|
+
let panel = marker;
|
|
5448
|
+
while (panel?.parentElement && !panel.parentElement.querySelector(BAR_SELECTOR)) {
|
|
5449
|
+
panel = panel.parentElement;
|
|
5450
|
+
}
|
|
5451
|
+
if (!panel?.parentElement) return null;
|
|
5452
|
+
panel.style.display = "none";
|
|
5453
|
+
let sibling = panel.nextElementSibling;
|
|
5454
|
+
while (sibling && !sibling.querySelector(SECTION_SELECTOR) && !sibling.querySelector(BAR_SELECTOR)) {
|
|
5455
|
+
sibling.style.display = visible ? "" : "none";
|
|
5456
|
+
sibling = sibling.nextElementSibling;
|
|
5457
|
+
}
|
|
5458
|
+
return panel.parentElement;
|
|
5459
|
+
}
|
|
5460
|
+
const TabSection = ({ ltbTabKey = "" }) => {
|
|
5461
|
+
const ref = useRef(null);
|
|
5462
|
+
const active = useSyncExternalStore(tabsStore.subscribe, tabsStore.get);
|
|
5463
|
+
useLayoutEffect(() => {
|
|
5464
|
+
const marker = ref.current;
|
|
5465
|
+
if (!marker || active === null) return;
|
|
5466
|
+
const visible = active === ltbTabKey;
|
|
5467
|
+
const container = applySectionVisibility(marker, visible);
|
|
5468
|
+
if (!container) return;
|
|
5469
|
+
const observer = new MutationObserver(() => applySectionVisibility(marker, visible));
|
|
5470
|
+
observer.observe(container, { childList: true });
|
|
5471
|
+
return () => observer.disconnect();
|
|
5472
|
+
}, [active, ltbTabKey]);
|
|
5473
|
+
return /* @__PURE__ */ jsx("span", { ref, "data-ltb-tab-section": ltbTabKey, hidden: true });
|
|
5474
|
+
};
|
|
5475
|
+
const index = {
|
|
5476
|
+
async register(app) {
|
|
5477
|
+
app.addMenuLink({
|
|
5478
|
+
to: `plugins/${config.pluginId}`,
|
|
5479
|
+
icon: PluginIcon,
|
|
5480
|
+
intlLabel: {
|
|
3302
5481
|
id: `${config.pluginId}.app.name`,
|
|
3303
5482
|
defaultMessage: config.pluginId
|
|
3304
5483
|
},
|
|
3305
5484
|
position: 999,
|
|
3306
|
-
Component: () => import("./App-
|
|
5485
|
+
Component: () => import("./App-BfGB2pF_.mjs")
|
|
3307
5486
|
});
|
|
3308
5487
|
app.customFields.register({
|
|
3309
5488
|
name: "ltbslug",
|
|
@@ -3321,7 +5500,7 @@ const index = {
|
|
|
3321
5500
|
components: {
|
|
3322
5501
|
Input: async () => import(
|
|
3323
5502
|
/* webpackChunkName: "input-slug-component" */
|
|
3324
|
-
"./SlugInput-
|
|
5503
|
+
"./SlugInput-CvgVtZza.mjs"
|
|
3325
5504
|
)
|
|
3326
5505
|
},
|
|
3327
5506
|
options: {
|
|
@@ -3355,13 +5534,18 @@ const index = {
|
|
|
3355
5534
|
],
|
|
3356
5535
|
advanced: [],
|
|
3357
5536
|
validator: (args) => ({
|
|
3358
|
-
targetField: create().required({
|
|
5537
|
+
targetField: create$2().required({
|
|
3359
5538
|
id: getTranslation(`module.${config.uuid.modules.slug}.field.slug.target.error`),
|
|
3360
5539
|
defaultMessage: "The target field is required"
|
|
3361
5540
|
})
|
|
3362
5541
|
})
|
|
3363
5542
|
}
|
|
3364
5543
|
});
|
|
5544
|
+
app.addFields([
|
|
5545
|
+
{ type: TABS_BAR_FIELD_TYPE, Component: TabsBar },
|
|
5546
|
+
{ type: TABS_SECTION_FIELD_TYPE, Component: TabSection }
|
|
5547
|
+
]);
|
|
5548
|
+
startTabBadges(app);
|
|
3365
5549
|
app.registerPlugin({
|
|
3366
5550
|
id: config.pluginId,
|
|
3367
5551
|
initializer: Initializer,
|
|
@@ -3373,7 +5557,7 @@ const index = {
|
|
|
3373
5557
|
return Promise.all(
|
|
3374
5558
|
locales.map(async (locale) => {
|
|
3375
5559
|
try {
|
|
3376
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => import("./en-
|
|
5560
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => import("./en-knG97mCH.mjs") }), `./core/translations/${locale}.json`, 4);
|
|
3377
5561
|
return { data, locale };
|
|
3378
5562
|
} catch {
|
|
3379
5563
|
return { data: {}, locale };
|
|
@@ -3392,10 +5576,21 @@ const index = {
|
|
|
3392
5576
|
Registry.getInstance().provide("menuGateway", new MenuGatewayHttp());
|
|
3393
5577
|
Registry.getInstance().provide("parameterGateway", new ParameterGatewayHttp());
|
|
3394
5578
|
Registry.getInstance().provide("translationGateway", new TranslationGatewayHttp());
|
|
3395
|
-
|
|
5579
|
+
Registry.getInstance().provide("documentGateway", new DocumentGatewayHttp());
|
|
5580
|
+
Registry.getInstance().provide("aiGateway", new AiGatewayHttp());
|
|
5581
|
+
app.getPlugin("content-manager").apis.addEditViewSidePanel([
|
|
5582
|
+
PageAttributesBox,
|
|
5583
|
+
DocumentTranslateBox
|
|
5584
|
+
]);
|
|
5585
|
+
registerTabsInContentTypeBuilder(app);
|
|
5586
|
+
app.registerHook(
|
|
5587
|
+
"Admin/CM/pages/EditView/mutate-edit-view-layout",
|
|
5588
|
+
(args) => mutateEditViewLayout(args)
|
|
5589
|
+
);
|
|
3396
5590
|
}
|
|
3397
5591
|
};
|
|
3398
5592
|
export {
|
|
5593
|
+
AI_TRANSLATION_DEFAULT_MODEL as A,
|
|
3399
5594
|
DocumentCustomFieldStarted as D,
|
|
3400
5595
|
FetchSettings as F,
|
|
3401
5596
|
PageAttributeUpdated as P,
|
|
@@ -3404,9 +5599,11 @@ export {
|
|
|
3404
5599
|
SLUG_CONTENT_STRATEGY as a,
|
|
3405
5600
|
FetchSlugs as b,
|
|
3406
5601
|
config as c,
|
|
3407
|
-
|
|
3408
|
-
|
|
5602
|
+
FetchLocales as d,
|
|
5603
|
+
convertToSlug as e,
|
|
3409
5604
|
fetchTemplates as f,
|
|
3410
5605
|
getTranslation as g,
|
|
3411
|
-
|
|
5606
|
+
PluginIcon as h,
|
|
5607
|
+
FetchModuleSettings as i,
|
|
5608
|
+
index as j
|
|
3412
5609
|
};
|