sanity 5.29.0-next.8 → 5.29.0-next.9
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/lib/_chunks-es/version.js +2 -2
- package/lib/index.js +284 -221
- package/lib/index.js.map +1 -1
- package/package.json +11 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version = "5.29.0-next.
|
|
1
|
+
var version = "5.29.0-next.9+07d4dd910e";
|
|
2
2
|
let buildVersion;
|
|
3
3
|
try {
|
|
4
4
|
buildVersion = process.env.PKG_BUILD_VERSION;
|
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
try {
|
|
8
8
|
buildVersion = buildVersion || // This is replaced by `@sanity/pkg-utils` at build time
|
|
9
9
|
// and must always be references by its full static name, e.g. no optional chaining, no `if (process && process.env)` etc.
|
|
10
|
-
"5.29.0-next.
|
|
10
|
+
"5.29.0-next.9+07d4dd910e";
|
|
11
11
|
} catch {
|
|
12
12
|
}
|
|
13
13
|
const SANITY_VERSION = buildVersion || `${version}-dev`;
|
package/lib/index.js
CHANGED
|
@@ -81485,6 +81485,125 @@ function getHasValidConditions(conditions) {
|
|
|
81485
81485
|
const entries = Object.entries(conditions);
|
|
81486
81486
|
return entries.length > 0 && entries.every(([key, value]) => !!(key.trim() && value.trim()));
|
|
81487
81487
|
}
|
|
81488
|
+
function createVariantsSet(variants2) {
|
|
81489
|
+
return (variants2 ?? []).reduce((acc, variant) => (acc.set(variant._id, variant), acc), /* @__PURE__ */ new Map());
|
|
81490
|
+
}
|
|
81491
|
+
function variantStoreReducer(state, action) {
|
|
81492
|
+
switch (action.type) {
|
|
81493
|
+
case "LOADING_STATE_CHANGED":
|
|
81494
|
+
return {
|
|
81495
|
+
...state,
|
|
81496
|
+
state: action.payload.error ? "error" : action.payload.loading ? "loading" : "loaded",
|
|
81497
|
+
error: action.payload.error
|
|
81498
|
+
};
|
|
81499
|
+
case "VARIANTS_SET": {
|
|
81500
|
+
const variantsById = createVariantsSet(action.payload);
|
|
81501
|
+
return {
|
|
81502
|
+
...state,
|
|
81503
|
+
variants: variantsById
|
|
81504
|
+
};
|
|
81505
|
+
}
|
|
81506
|
+
case "FETCH_SUCCEEDED": {
|
|
81507
|
+
const variantsById = createVariantsSet(action.payload);
|
|
81508
|
+
return {
|
|
81509
|
+
...state,
|
|
81510
|
+
variants: variantsById,
|
|
81511
|
+
state: "loaded",
|
|
81512
|
+
error: void 0
|
|
81513
|
+
};
|
|
81514
|
+
}
|
|
81515
|
+
case "VARIANT_DELETED": {
|
|
81516
|
+
const {
|
|
81517
|
+
id: id2
|
|
81518
|
+
} = action.payload, restVariants = new Map(state.variants);
|
|
81519
|
+
return restVariants.delete(id2), {
|
|
81520
|
+
...state,
|
|
81521
|
+
variants: restVariants
|
|
81522
|
+
};
|
|
81523
|
+
}
|
|
81524
|
+
default:
|
|
81525
|
+
return state;
|
|
81526
|
+
}
|
|
81527
|
+
}
|
|
81528
|
+
const SORT_FIELD = "_createdAt", SORT_ORDER = "desc", QUERY_SORT_ORDER = `order(${SORT_FIELD} ${SORT_ORDER})`, QUERY_FILTER = `_type=="${VARIANT_DOCUMENT_TYPE}" && _id in path("${VARIANT_DOCUMENTS_PATH}.*")`, QUERY_PROJECTION = `{
|
|
81529
|
+
_id,
|
|
81530
|
+
_type,
|
|
81531
|
+
_rev,
|
|
81532
|
+
_createdAt,
|
|
81533
|
+
_updatedAt,
|
|
81534
|
+
name,
|
|
81535
|
+
conditions,
|
|
81536
|
+
"priority": coalesce(priority, 0),
|
|
81537
|
+
metadata,
|
|
81538
|
+
}`, QUERY = `*[${QUERY_FILTER}] ${QUERY_PROJECTION} | ${QUERY_SORT_ORDER}`, INITIAL_STATE$4 = {
|
|
81539
|
+
variants: /* @__PURE__ */ new Map(),
|
|
81540
|
+
state: "initialising"
|
|
81541
|
+
};
|
|
81542
|
+
function createVariantsStore(context) {
|
|
81543
|
+
const {
|
|
81544
|
+
client
|
|
81545
|
+
} = context, dispatch$ = new Subject();
|
|
81546
|
+
function dispatch(action) {
|
|
81547
|
+
dispatch$.next(action);
|
|
81548
|
+
}
|
|
81549
|
+
const listFetch$ = of({
|
|
81550
|
+
type: "LOADING_STATE_CHANGED",
|
|
81551
|
+
payload: {
|
|
81552
|
+
loading: !0,
|
|
81553
|
+
error: void 0
|
|
81554
|
+
}
|
|
81555
|
+
}).pipe(concatWith(listenQuery(client, QUERY, {}, {
|
|
81556
|
+
tag: "variants.listen"
|
|
81557
|
+
}).pipe(map((variants2) => ({
|
|
81558
|
+
type: "FETCH_SUCCEEDED",
|
|
81559
|
+
payload: variants2
|
|
81560
|
+
})))), catchError$1((error) => of({
|
|
81561
|
+
type: "LOADING_STATE_CHANGED",
|
|
81562
|
+
payload: {
|
|
81563
|
+
loading: !1,
|
|
81564
|
+
error
|
|
81565
|
+
}
|
|
81566
|
+
})));
|
|
81567
|
+
return {
|
|
81568
|
+
state$: merge(listFetch$, dispatch$).pipe(scan$1((state, action) => variantStoreReducer(state, action), INITIAL_STATE$4), startWith(INITIAL_STATE$4), shareReplay$1(1)),
|
|
81569
|
+
dispatch
|
|
81570
|
+
};
|
|
81571
|
+
}
|
|
81572
|
+
function useVariantsStore() {
|
|
81573
|
+
const $ = c(4), resourceCache = useResourceCache(), workspace = useWorkspace(), studioClient = useClient(VARIANTS_STUDIO_CLIENT_OPTIONS);
|
|
81574
|
+
let variantStore;
|
|
81575
|
+
return $[0] !== resourceCache || $[1] !== studioClient || $[2] !== workspace ? (variantStore = resourceCache.get({
|
|
81576
|
+
dependencies: [workspace],
|
|
81577
|
+
namespace: "VariantsStore"
|
|
81578
|
+
}) || createVariantsStore({
|
|
81579
|
+
client: studioClient
|
|
81580
|
+
}), resourceCache.set({
|
|
81581
|
+
dependencies: [workspace],
|
|
81582
|
+
namespace: "VariantsStore",
|
|
81583
|
+
value: variantStore
|
|
81584
|
+
}), $[0] = resourceCache, $[1] = studioClient, $[2] = workspace, $[3] = variantStore) : variantStore = $[3], variantStore;
|
|
81585
|
+
}
|
|
81586
|
+
function useAllVariants() {
|
|
81587
|
+
const $ = c(8), {
|
|
81588
|
+
state$
|
|
81589
|
+
} = useVariantsStore(), {
|
|
81590
|
+
variants: variants2,
|
|
81591
|
+
error,
|
|
81592
|
+
state
|
|
81593
|
+
} = useObservable(state$);
|
|
81594
|
+
let t0;
|
|
81595
|
+
$[0] !== variants2 ? (t0 = Array.from(variants2.values()), $[0] = variants2, $[1] = t0) : t0 = $[1];
|
|
81596
|
+
let t1;
|
|
81597
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = ["loading", "initialising"], $[2] = t1) : t1 = $[2];
|
|
81598
|
+
const t2 = t1.includes(state);
|
|
81599
|
+
let t3;
|
|
81600
|
+
return $[3] !== error || $[4] !== t0 || $[5] !== t2 || $[6] !== variants2 ? (t3 = {
|
|
81601
|
+
data: t0,
|
|
81602
|
+
byId: variants2,
|
|
81603
|
+
error,
|
|
81604
|
+
loading: t2
|
|
81605
|
+
}, $[3] = error, $[4] = t0, $[5] = t2, $[6] = variants2, $[7] = t3) : t3 = $[7], t3;
|
|
81606
|
+
}
|
|
81488
81607
|
const CONDITION_KEY_REGEX = /^[a-z][a-z0-9_-]{0,63}$/, RESERVED_KEY_PREFIXES = ["_", "$"];
|
|
81489
81608
|
function getConditionKeyValidationError(key) {
|
|
81490
81609
|
const trimmedKey = key.trim();
|
|
@@ -81532,6 +81651,68 @@ function createPortableTextDescription(text) {
|
|
|
81532
81651
|
style: "normal"
|
|
81533
81652
|
}] : [];
|
|
81534
81653
|
}
|
|
81654
|
+
function sortValues(values2) {
|
|
81655
|
+
return Array.from(values2).filter(Boolean).toSorted((a, b) => a.localeCompare(b));
|
|
81656
|
+
}
|
|
81657
|
+
function buildConditionSuggestionIndex(variants2) {
|
|
81658
|
+
const keys = /* @__PURE__ */ new Set(), valuesByKey = /* @__PURE__ */ new Map();
|
|
81659
|
+
return variants2.forEach((variant) => {
|
|
81660
|
+
Object.entries(variant.conditions).forEach(([rawKey, rawValue]) => {
|
|
81661
|
+
const key = rawKey.trim();
|
|
81662
|
+
if (!key)
|
|
81663
|
+
return;
|
|
81664
|
+
keys.add(key);
|
|
81665
|
+
const value = rawValue?.trim();
|
|
81666
|
+
if (!value)
|
|
81667
|
+
return;
|
|
81668
|
+
let values2 = valuesByKey.get(key);
|
|
81669
|
+
values2 || (values2 = /* @__PURE__ */ new Set(), valuesByKey.set(key, values2)), values2.add(value);
|
|
81670
|
+
});
|
|
81671
|
+
}), {
|
|
81672
|
+
keys: sortValues(keys),
|
|
81673
|
+
valuesByKey: new Map(Array.from(valuesByKey, ([key, values2]) => [key, sortValues(values2)]))
|
|
81674
|
+
};
|
|
81675
|
+
}
|
|
81676
|
+
function getConditionKeyOptions(index, rows, currentRowIndex) {
|
|
81677
|
+
const usedKeys = new Set(rows.filter((_, rowIndex) => rowIndex !== currentRowIndex).map((row) => row.key.trim()).filter(Boolean));
|
|
81678
|
+
return index.keys.filter((key) => !usedKeys.has(key)).map((value) => ({
|
|
81679
|
+
value
|
|
81680
|
+
}));
|
|
81681
|
+
}
|
|
81682
|
+
function getConditionValueOptions(index, conditionKey) {
|
|
81683
|
+
const key = conditionKey.trim();
|
|
81684
|
+
return key ? index.valuesByKey.get(key)?.map((value) => ({
|
|
81685
|
+
value
|
|
81686
|
+
})) ?? [] : [];
|
|
81687
|
+
}
|
|
81688
|
+
function filterConditionOption(query, option) {
|
|
81689
|
+
return option.value.toLowerCase().includes(query.trim().toLowerCase());
|
|
81690
|
+
}
|
|
81691
|
+
function ConditionAutocompleteInput(props2) {
|
|
81692
|
+
const $ = c(16), {
|
|
81693
|
+
ariaLabel,
|
|
81694
|
+
autoFocus,
|
|
81695
|
+
customValidity,
|
|
81696
|
+
invalid,
|
|
81697
|
+
onChange,
|
|
81698
|
+
options,
|
|
81699
|
+
placeholder,
|
|
81700
|
+
testId,
|
|
81701
|
+
value
|
|
81702
|
+
} = props2, id2 = useId(), [focused, setFocused] = useState(!1);
|
|
81703
|
+
let t0;
|
|
81704
|
+
$[0] !== onChange ? (t0 = (nextValue) => {
|
|
81705
|
+
nextValue !== null && onChange(nextValue);
|
|
81706
|
+
}, $[0] = onChange, $[1] = t0) : t0 = $[1];
|
|
81707
|
+
const handleQueryChange = t0, t1 = invalid ? "true" : void 0;
|
|
81708
|
+
let t2;
|
|
81709
|
+
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = () => setFocused(!1), $[2] = t2) : t2 = $[2];
|
|
81710
|
+
let t3;
|
|
81711
|
+
$[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = () => setFocused(!0), $[3] = t3) : t3 = $[3];
|
|
81712
|
+
const t4 = focused ? void 0 : value;
|
|
81713
|
+
let t5;
|
|
81714
|
+
return $[4] !== ariaLabel || $[5] !== autoFocus || $[6] !== customValidity || $[7] !== handleQueryChange || $[8] !== id2 || $[9] !== onChange || $[10] !== options || $[11] !== placeholder || $[12] !== t1 || $[13] !== t4 || $[14] !== testId ? (t5 = /* @__PURE__ */ jsx(Autocomplete, { id: id2, "aria-invalid": t1, "aria-label": ariaLabel, autoFocus, customValidity, "data-testid": testId, filterOption: filterConditionOption, fontSize: 1, onBlur: t2, onChange, onFocus: t3, onQueryChange: handleQueryChange, openButton: !0, options, placeholder, value: t4 }), $[4] = ariaLabel, $[5] = autoFocus, $[6] = customValidity, $[7] = handleQueryChange, $[8] = id2, $[9] = onChange, $[10] = options, $[11] = placeholder, $[12] = t1, $[13] = t4, $[14] = testId, $[15] = t5) : t5 = $[15], t5;
|
|
81715
|
+
}
|
|
81535
81716
|
function getConditionRows(conditions) {
|
|
81536
81717
|
const rows = Object.entries(conditions).map(([key, value]) => ({
|
|
81537
81718
|
id: randomKey$1(12),
|
|
@@ -81585,158 +81766,159 @@ function getPortableTextDescriptionValue(description) {
|
|
|
81585
81766
|
return !Array.isArray(description) || !description.every(isPortableTextBlock) ? "" : toPlainText(description);
|
|
81586
81767
|
}
|
|
81587
81768
|
function VariantForm(props2) {
|
|
81588
|
-
const $ = c(
|
|
81769
|
+
const $ = c(108), {
|
|
81589
81770
|
onChange,
|
|
81590
81771
|
onConditionValidityChange,
|
|
81591
81772
|
showValidation: t0,
|
|
81592
81773
|
value
|
|
81593
81774
|
} = props2, showValidation = t0 === void 0 ? !1 : t0, {
|
|
81594
81775
|
t
|
|
81595
|
-
} = useTranslation(variantsLocaleNamespace),
|
|
81776
|
+
} = useTranslation(variantsLocaleNamespace), {
|
|
81777
|
+
data: variants2
|
|
81778
|
+
} = useAllVariants();
|
|
81596
81779
|
let t1;
|
|
81597
|
-
$[0] !==
|
|
81598
|
-
const
|
|
81780
|
+
$[0] !== variants2 ? (t1 = buildConditionSuggestionIndex(variants2), $[0] = variants2, $[1] = t1) : t1 = $[1];
|
|
81781
|
+
const suggestionIndex = t1, titleId = useId(), descriptionId = useId();
|
|
81599
81782
|
let t2;
|
|
81600
|
-
$[2] !==
|
|
81601
|
-
const
|
|
81783
|
+
$[2] !== value.conditions ? (t2 = () => getConditionRows(value.conditions), $[2] = value.conditions, $[3] = t2) : t2 = $[3];
|
|
81784
|
+
const [conditionRows, setConditionRows] = useState(t2);
|
|
81602
81785
|
let t3;
|
|
81603
|
-
$[4] !==
|
|
81604
|
-
const
|
|
81786
|
+
$[4] !== conditionRows ? (t3 = getConditionRowsValidation(conditionRows), $[4] = conditionRows, $[5] = t3) : t3 = $[5];
|
|
81787
|
+
const conditionsValidation = t3;
|
|
81605
81788
|
let t4;
|
|
81606
|
-
$[6] !==
|
|
81607
|
-
const
|
|
81789
|
+
$[6] !== value ? (t4 = getVariantTitleValue(value), $[6] = value, $[7] = t4) : t4 = $[7];
|
|
81790
|
+
const showTitleError = showValidation && !t4, lastConditionRow = conditionRows[conditionRows.length - 1];
|
|
81608
81791
|
let t5;
|
|
81609
|
-
$[
|
|
81792
|
+
$[8] !== conditionsValidation || $[9] !== lastConditionRow ? (t5 = lastConditionRow && !hasConditionRowsValidationErrors(conditionsValidation), $[8] = conditionsValidation, $[9] = lastConditionRow, $[10] = t5) : t5 = $[10];
|
|
81793
|
+
const canAddCondition = !!t5;
|
|
81794
|
+
let t6;
|
|
81795
|
+
$[11] !== onChange || $[12] !== onConditionValidityChange ? (t6 = (nextRows) => {
|
|
81610
81796
|
const rows = nextRows.length ? nextRows : getConditionRows({});
|
|
81611
81797
|
setConditionRows(rows);
|
|
81612
81798
|
const nextRowsValidation = getConditionRowsValidation(rows), nextRowsInvalid = hasConditionRowsValidationErrors(nextRowsValidation);
|
|
81613
81799
|
onConditionValidityChange?.(nextRowsInvalid), (nextRows.length === 0 || !nextRowsInvalid) && onChange(["conditions"], getConditionsFromRows(nextRows));
|
|
81614
|
-
}, $[
|
|
81615
|
-
const updateConditionRows =
|
|
81616
|
-
let t6;
|
|
81617
|
-
$[12] !== onChange ? (t6 = (event) => {
|
|
81618
|
-
onChange(["metadata", "title"], event.currentTarget.value);
|
|
81619
|
-
}, $[12] = onChange, $[13] = t6) : t6 = $[13];
|
|
81620
|
-
const handleTitleChange = t6;
|
|
81800
|
+
}, $[11] = onChange, $[12] = onConditionValidityChange, $[13] = t6) : t6 = $[13];
|
|
81801
|
+
const updateConditionRows = t6;
|
|
81621
81802
|
let t7;
|
|
81622
|
-
$[14] !== onChange ? (t7 = (
|
|
81623
|
-
onChange(["metadata", "
|
|
81803
|
+
$[14] !== onChange ? (t7 = (event) => {
|
|
81804
|
+
onChange(["metadata", "title"], event.currentTarget.value);
|
|
81624
81805
|
}, $[14] = onChange, $[15] = t7) : t7 = $[15];
|
|
81625
|
-
const
|
|
81806
|
+
const handleTitleChange = t7;
|
|
81626
81807
|
let t8;
|
|
81627
|
-
$[16] !==
|
|
81808
|
+
$[16] !== onChange ? (t8 = (event_0) => {
|
|
81809
|
+
onChange(["metadata", "description"], createPortableTextDescription(event_0.currentTarget.value));
|
|
81810
|
+
}, $[16] = onChange, $[17] = t8) : t8 = $[17];
|
|
81811
|
+
const handleDescriptionChange = t8;
|
|
81812
|
+
let t9;
|
|
81813
|
+
$[18] !== conditionRows || $[19] !== updateConditionRows ? (t9 = (index, field, nextValue) => {
|
|
81628
81814
|
const nextRows_0 = conditionRows.map((row, rowIndex) => rowIndex === index ? {
|
|
81629
81815
|
...row,
|
|
81630
81816
|
[field]: nextValue
|
|
81631
81817
|
} : row);
|
|
81632
81818
|
updateConditionRows(nextRows_0);
|
|
81633
|
-
}, $[
|
|
81634
|
-
const handleConditionChange =
|
|
81635
|
-
let
|
|
81636
|
-
$[
|
|
81819
|
+
}, $[18] = conditionRows, $[19] = updateConditionRows, $[20] = t9) : t9 = $[20];
|
|
81820
|
+
const handleConditionChange = t9;
|
|
81821
|
+
let t10;
|
|
81822
|
+
$[21] !== canAddCondition || $[22] !== conditionRows || $[23] !== updateConditionRows ? (t10 = () => {
|
|
81637
81823
|
canAddCondition && updateConditionRows([...conditionRows, {
|
|
81638
81824
|
id: randomKey$1(12),
|
|
81639
81825
|
key: "",
|
|
81640
81826
|
value: ""
|
|
81641
81827
|
}]);
|
|
81642
|
-
}, $[
|
|
81643
|
-
const handleAddCondition =
|
|
81644
|
-
let
|
|
81645
|
-
$[
|
|
81828
|
+
}, $[21] = canAddCondition, $[22] = conditionRows, $[23] = updateConditionRows, $[24] = t10) : t10 = $[24];
|
|
81829
|
+
const handleAddCondition = t10;
|
|
81830
|
+
let t11;
|
|
81831
|
+
$[25] !== conditionRows || $[26] !== updateConditionRows ? (t11 = (index_0) => {
|
|
81646
81832
|
const nextRows_1 = conditionRows.filter((_, rowIndex_0) => rowIndex_0 !== index_0);
|
|
81647
81833
|
updateConditionRows(nextRows_1);
|
|
81648
|
-
}, $[
|
|
81649
|
-
const handleRemoveCondition =
|
|
81650
|
-
let t11;
|
|
81651
|
-
$[26] !== t ? (t11 = t("dialog.create.variant-title.label"), $[26] = t, $[27] = t11) : t11 = $[27];
|
|
81834
|
+
}, $[25] = conditionRows, $[26] = updateConditionRows, $[27] = t11) : t11 = $[27];
|
|
81835
|
+
const handleRemoveCondition = t11;
|
|
81652
81836
|
let t12;
|
|
81653
|
-
$[28] !==
|
|
81654
|
-
|
|
81655
|
-
|
|
81656
|
-
|
|
81837
|
+
$[28] !== t ? (t12 = t("dialog.create.variant-title.label"), $[28] = t, $[29] = t12) : t12 = $[29];
|
|
81838
|
+
let t13;
|
|
81839
|
+
$[30] !== t12 || $[31] !== titleId ? (t13 = /* @__PURE__ */ jsx(Text$1, { as: "label", htmlFor: titleId, size: 1, weight: "medium", children: t12 }), $[30] = t12, $[31] = titleId, $[32] = t13) : t13 = $[32];
|
|
81840
|
+
const t14 = showTitleError ? "true" : void 0;
|
|
81657
81841
|
let t15;
|
|
81658
|
-
$[34] !== t ? (t15 = t("dialog.create.variant-title.
|
|
81659
|
-
|
|
81660
|
-
|
|
81661
|
-
|
|
81842
|
+
$[33] !== showTitleError || $[34] !== t ? (t15 = showTitleError ? t("dialog.create.variant-title.required") : void 0, $[33] = showTitleError, $[34] = t, $[35] = t15) : t15 = $[35];
|
|
81843
|
+
let t16;
|
|
81844
|
+
$[36] !== t ? (t16 = t("dialog.create.variant-title.placeholder"), $[36] = t, $[37] = t16) : t16 = $[37];
|
|
81845
|
+
const t17 = typeof value.metadata?.title == "string" ? value.metadata.title : "";
|
|
81662
81846
|
let t18;
|
|
81663
|
-
$[
|
|
81847
|
+
$[38] !== handleTitleChange || $[39] !== t14 || $[40] !== t15 || $[41] !== t16 || $[42] !== t17 || $[43] !== titleId ? (t18 = /* @__PURE__ */ jsx(TextInput$1, { autoFocus: !0, "aria-invalid": t14, customValidity: t15, "data-testid": "variant-form-title", fontSize: 2, id: titleId, onChange: handleTitleChange, placeholder: t16, value: t17 }), $[38] = handleTitleChange, $[39] = t14, $[40] = t15, $[41] = t16, $[42] = t17, $[43] = titleId, $[44] = t18) : t18 = $[44];
|
|
81664
81848
|
let t19;
|
|
81665
|
-
$[
|
|
81666
|
-
t12,
|
|
81667
|
-
t17,
|
|
81668
|
-
t18
|
|
81669
|
-
] }), $[46] = t12, $[47] = t17, $[48] = t18, $[49] = t19) : t19 = $[49];
|
|
81849
|
+
$[45] !== showTitleError || $[46] !== t ? (t19 = showTitleError && /* @__PURE__ */ jsx(TextWithTone, { "data-testid": "variant-form-title-error", size: 1, tone: "critical", children: t("dialog.create.variant-title.required") }), $[45] = showTitleError, $[46] = t, $[47] = t19) : t19 = $[47];
|
|
81670
81850
|
let t20;
|
|
81671
|
-
$[
|
|
81851
|
+
$[48] !== t13 || $[49] !== t18 || $[50] !== t19 ? (t20 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
81852
|
+
t13,
|
|
81853
|
+
t18,
|
|
81854
|
+
t19
|
|
81855
|
+
] }), $[48] = t13, $[49] = t18, $[50] = t19, $[51] = t20) : t20 = $[51];
|
|
81672
81856
|
let t21;
|
|
81673
|
-
$[52] !==
|
|
81857
|
+
$[52] !== t ? (t21 = t("dialog.create.description.label"), $[52] = t, $[53] = t21) : t21 = $[53];
|
|
81674
81858
|
let t22;
|
|
81675
|
-
$[55] !==
|
|
81676
|
-
|
|
81677
|
-
|
|
81678
|
-
|
|
81859
|
+
$[54] !== descriptionId || $[55] !== t21 ? (t22 = /* @__PURE__ */ jsx(Text$1, { as: "label", htmlFor: descriptionId, size: 1, weight: "medium", children: t21 }), $[54] = descriptionId, $[55] = t21, $[56] = t22) : t22 = $[56];
|
|
81860
|
+
let t23;
|
|
81861
|
+
$[57] !== t ? (t23 = t("dialog.create.description.placeholder"), $[57] = t, $[58] = t23) : t23 = $[58];
|
|
81862
|
+
const t24 = value.metadata?.description;
|
|
81679
81863
|
let t25;
|
|
81680
|
-
$[59] !==
|
|
81864
|
+
$[59] !== t24 ? (t25 = getPortableTextDescriptionValue(t24), $[59] = t24, $[60] = t25) : t25 = $[60];
|
|
81681
81865
|
let t26;
|
|
81682
|
-
$[
|
|
81683
|
-
t21,
|
|
81684
|
-
t25
|
|
81685
|
-
] }), $[64] = t21, $[65] = t25, $[66] = t26) : t26 = $[66];
|
|
81866
|
+
$[61] !== descriptionId || $[62] !== handleDescriptionChange || $[63] !== t23 || $[64] !== t25 ? (t26 = /* @__PURE__ */ jsx(TextArea, { "data-testid": "variant-form-description", fontSize: 1, id: descriptionId, onChange: handleDescriptionChange, placeholder: t23, rows: 3, value: t25 }), $[61] = descriptionId, $[62] = handleDescriptionChange, $[63] = t23, $[64] = t25, $[65] = t26) : t26 = $[65];
|
|
81686
81867
|
let t27;
|
|
81687
|
-
$[67] !==
|
|
81868
|
+
$[66] !== t22 || $[67] !== t26 ? (t27 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
81869
|
+
t22,
|
|
81870
|
+
t26
|
|
81871
|
+
] }), $[66] = t22, $[67] = t26, $[68] = t27) : t27 = $[68];
|
|
81688
81872
|
let t28;
|
|
81689
|
-
$[69] !==
|
|
81873
|
+
$[69] !== t ? (t28 = t("dialog.create.conditions.title"), $[69] = t, $[70] = t28) : t28 = $[70];
|
|
81690
81874
|
let t29;
|
|
81691
|
-
$[71] !==
|
|
81875
|
+
$[71] !== t28 ? (t29 = /* @__PURE__ */ jsx(Text$1, { size: 1, weight: "medium", children: t28 }), $[71] = t28, $[72] = t29) : t29 = $[72];
|
|
81692
81876
|
let t30;
|
|
81693
|
-
$[73] !==
|
|
81877
|
+
$[73] !== t ? (t30 = t("dialog.create.conditions.description"), $[73] = t, $[74] = t30) : t30 = $[74];
|
|
81694
81878
|
let t31;
|
|
81695
|
-
$[75] !==
|
|
81696
|
-
t28,
|
|
81697
|
-
t30
|
|
81698
|
-
] }), $[75] = t28, $[76] = t30, $[77] = t31) : t31 = $[77];
|
|
81879
|
+
$[75] !== t30 ? (t31 = /* @__PURE__ */ jsx(Text$1, { muted: !0, size: 1, children: t30 }), $[75] = t30, $[76] = t31) : t31 = $[76];
|
|
81699
81880
|
let t32;
|
|
81700
|
-
|
|
81701
|
-
|
|
81702
|
-
|
|
81703
|
-
|
|
81704
|
-
return /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
81705
|
-
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
81706
|
-
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(TextInput$1, { autoFocus: index_1 > 0, "aria-label": t("dialog.create.condition-key.label"), customValidity: validation2.key ? t(validation2.key) : void 0, "aria-invalid": !!validation2.key, onChange: (event_1) => handleConditionChange(index_1, "key", event_1.currentTarget.value), placeholder: t("dialog.create.condition-key.placeholder"), "data-testid": "variant-form-condition-key", value: row_0.key }) }),
|
|
81707
|
-
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(TextInput$1, { "aria-label": t("dialog.create.condition-value.label"), customValidity: valueValidation ? t(valueValidation) : void 0, "aria-invalid": !!valueValidation, onChange: (event_2) => handleConditionChange(index_1, "value", event_2.currentTarget.value), placeholder: t("dialog.create.condition-value.placeholder"), "data-testid": "variant-form-condition-value", value: row_0.value }) }),
|
|
81708
|
-
/* @__PURE__ */ jsx(Button, { disabled: isConditionRowEmpty(row_0) && conditionRows.length === 1, icon: TrashIcon, mode: "bleed", onClick: () => handleRemoveCondition(index_1), tone: "critical", tooltipProps: {
|
|
81709
|
-
content: t("dialog.create.remove-condition")
|
|
81710
|
-
}, type: "button" })
|
|
81711
|
-
] }),
|
|
81712
|
-
conditionValidationError && /* @__PURE__ */ jsx(TextWithTone, { "data-testid": validation2.key ? "variant-form-condition-key-error" : "variant-form-condition-value-error", size: 1, tone: "critical", children: t(conditionValidationError) })
|
|
81713
|
-
] }, row_0.id);
|
|
81714
|
-
}, $[85] = conditionRows.length, $[86] = conditionsValidation, $[87] = handleConditionChange, $[88] = handleRemoveCondition, $[89] = showValidation, $[90] = t, $[91] = t332) : t332 = $[91], t32 = conditionRows.map(t332), $[78] = conditionRows, $[79] = conditionsValidation, $[80] = handleConditionChange, $[81] = handleRemoveCondition, $[82] = showValidation, $[83] = t, $[84] = t32;
|
|
81715
|
-
} else
|
|
81716
|
-
t32 = $[84];
|
|
81881
|
+
$[77] !== t29 || $[78] !== t31 ? (t32 = /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
81882
|
+
t29,
|
|
81883
|
+
t31
|
|
81884
|
+
] }), $[77] = t29, $[78] = t31, $[79] = t32) : t32 = $[79];
|
|
81717
81885
|
let t33;
|
|
81718
|
-
$[
|
|
81719
|
-
|
|
81720
|
-
|
|
81721
|
-
|
|
81886
|
+
$[80] !== conditionRows || $[81] !== conditionsValidation || $[82] !== handleConditionChange || $[83] !== handleRemoveCondition || $[84] !== showValidation || $[85] !== suggestionIndex || $[86] !== t ? (t33 = conditionRows.map((row_0, index_1) => {
|
|
81887
|
+
const validation2 = conditionsValidation.get(index_1) ?? getEmptyConditionRowValidation(), valueValidation = showValidation ? validation2.value : null, conditionValidationError = validation2.key || valueValidation;
|
|
81888
|
+
return /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
81889
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
81890
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(ConditionAutocompleteInput, { autoFocus: index_1 > 0, ariaLabel: t("dialog.create.condition-key.label"), customValidity: validation2.key ? t(validation2.key) : void 0, invalid: !!validation2.key, onChange: (nextValue_0) => handleConditionChange(index_1, "key", nextValue_0), options: getConditionKeyOptions(suggestionIndex, conditionRows, index_1), placeholder: t("dialog.create.condition-key.placeholder"), testId: "variant-form-condition-key", value: row_0.key }) }),
|
|
81891
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(ConditionAutocompleteInput, { ariaLabel: t("dialog.create.condition-value.label"), customValidity: valueValidation ? t(valueValidation) : void 0, invalid: !!valueValidation, onChange: (nextValue_1) => handleConditionChange(index_1, "value", nextValue_1), options: getConditionValueOptions(suggestionIndex, row_0.key), placeholder: t("dialog.create.condition-value.placeholder"), testId: "variant-form-condition-value", value: row_0.value }) }),
|
|
81892
|
+
/* @__PURE__ */ jsx(Button, { disabled: isConditionRowEmpty(row_0) && conditionRows.length === 1, icon: TrashIcon, mode: "bleed", onClick: () => handleRemoveCondition(index_1), tone: "critical", tooltipProps: {
|
|
81893
|
+
content: t("dialog.create.remove-condition")
|
|
81894
|
+
}, type: "button" })
|
|
81895
|
+
] }),
|
|
81896
|
+
conditionValidationError && /* @__PURE__ */ jsx(TextWithTone, { "data-testid": validation2.key ? "variant-form-condition-key-error" : "variant-form-condition-value-error", size: 1, tone: "critical", children: t(conditionValidationError) })
|
|
81897
|
+
] }, row_0.id);
|
|
81898
|
+
}), $[80] = conditionRows, $[81] = conditionsValidation, $[82] = handleConditionChange, $[83] = handleRemoveCondition, $[84] = showValidation, $[85] = suggestionIndex, $[86] = t, $[87] = t33) : t33 = $[87];
|
|
81899
|
+
let t34;
|
|
81900
|
+
$[88] !== t33 ? (t34 = /* @__PURE__ */ jsx(Stack, { space: 2, children: t33 }), $[88] = t33, $[89] = t34) : t34 = $[89];
|
|
81901
|
+
const t35 = !canAddCondition;
|
|
81722
81902
|
let t36;
|
|
81723
|
-
$[
|
|
81724
|
-
content: t("dialog.create.action.add-condition.disabled-hint")
|
|
81725
|
-
}, $[96] = canAddCondition, $[97] = t, $[98] = t36) : t36 = $[98];
|
|
81903
|
+
$[90] !== t ? (t36 = t("dialog.create.action.add-condition"), $[90] = t, $[91] = t36) : t36 = $[91];
|
|
81726
81904
|
let t37;
|
|
81727
|
-
$[
|
|
81905
|
+
$[92] !== canAddCondition || $[93] !== t ? (t37 = canAddCondition ? null : {
|
|
81906
|
+
content: t("dialog.create.action.add-condition.disabled-hint")
|
|
81907
|
+
}, $[92] = canAddCondition, $[93] = t, $[94] = t37) : t37 = $[94];
|
|
81728
81908
|
let t38;
|
|
81729
|
-
$[
|
|
81730
|
-
t31,
|
|
81731
|
-
t33,
|
|
81732
|
-
t37
|
|
81733
|
-
] }), $[104] = t31, $[105] = t33, $[106] = t37, $[107] = t38) : t38 = $[107];
|
|
81909
|
+
$[95] !== handleAddCondition || $[96] !== t35 || $[97] !== t36 || $[98] !== t37 ? (t38 = /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(Button, { disabled: t35, icon: AddIcon, mode: "ghost", onClick: handleAddCondition, text: t36, tooltipProps: t37, type: "button" }) }), $[95] = handleAddCondition, $[96] = t35, $[97] = t36, $[98] = t37, $[99] = t38) : t38 = $[99];
|
|
81734
81910
|
let t39;
|
|
81735
|
-
|
|
81736
|
-
|
|
81737
|
-
|
|
81911
|
+
$[100] !== t32 || $[101] !== t34 || $[102] !== t38 ? (t39 = /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
81912
|
+
t32,
|
|
81913
|
+
t34,
|
|
81738
81914
|
t38
|
|
81739
|
-
] }), $[
|
|
81915
|
+
] }), $[100] = t32, $[101] = t34, $[102] = t38, $[103] = t39) : t39 = $[103];
|
|
81916
|
+
let t40;
|
|
81917
|
+
return $[104] !== t20 || $[105] !== t27 || $[106] !== t39 ? (t40 = /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
|
|
81918
|
+
t20,
|
|
81919
|
+
t27,
|
|
81920
|
+
t39
|
|
81921
|
+
] }), $[104] = t20, $[105] = t27, $[106] = t39, $[107] = t40) : t40 = $[107], t40;
|
|
81740
81922
|
}
|
|
81741
81923
|
function VariantDialog(props2) {
|
|
81742
81924
|
const $ = c(35), {
|
|
@@ -81757,7 +81939,7 @@ function VariantDialog(props2) {
|
|
|
81757
81939
|
const invalid = t1;
|
|
81758
81940
|
let t2;
|
|
81759
81941
|
$[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = (path, nextValue) => {
|
|
81760
|
-
setVariant((currentVariant) => applyPatches$1([at(
|
|
81942
|
+
setVariant((currentVariant) => applyPatches$1([at(path, set$1(nextValue))], currentVariant));
|
|
81761
81943
|
}, $[3] = t2) : t2 = $[3];
|
|
81762
81944
|
const handleVariantChange = t2;
|
|
81763
81945
|
let t3;
|
|
@@ -81834,125 +82016,6 @@ function EditVariantDialog(props2) {
|
|
|
81834
82016
|
let t5;
|
|
81835
82017
|
return $[11] !== handleSubmit || $[12] !== initialValue || $[13] !== onCancel || $[14] !== t2 || $[15] !== t3 || $[16] !== t4 ? (t5 = /* @__PURE__ */ jsx(VariantDialog, { confirmDataTestId: "save-variant-button", confirmText: t2, errorTitle: t3, header: t4, id: "edit-variant-dialog", initialValue, onCancel, onSubmit: handleSubmit, renderCancelButton: !0 }), $[11] = handleSubmit, $[12] = initialValue, $[13] = onCancel, $[14] = t2, $[15] = t3, $[16] = t4, $[17] = t5) : t5 = $[17], t5;
|
|
81836
82018
|
}
|
|
81837
|
-
function createVariantsSet(variants2) {
|
|
81838
|
-
return (variants2 ?? []).reduce((acc, variant) => (acc.set(variant._id, variant), acc), /* @__PURE__ */ new Map());
|
|
81839
|
-
}
|
|
81840
|
-
function variantStoreReducer(state, action) {
|
|
81841
|
-
switch (action.type) {
|
|
81842
|
-
case "LOADING_STATE_CHANGED":
|
|
81843
|
-
return {
|
|
81844
|
-
...state,
|
|
81845
|
-
state: action.payload.error ? "error" : action.payload.loading ? "loading" : "loaded",
|
|
81846
|
-
error: action.payload.error
|
|
81847
|
-
};
|
|
81848
|
-
case "VARIANTS_SET": {
|
|
81849
|
-
const variantsById = createVariantsSet(action.payload);
|
|
81850
|
-
return {
|
|
81851
|
-
...state,
|
|
81852
|
-
variants: variantsById
|
|
81853
|
-
};
|
|
81854
|
-
}
|
|
81855
|
-
case "FETCH_SUCCEEDED": {
|
|
81856
|
-
const variantsById = createVariantsSet(action.payload);
|
|
81857
|
-
return {
|
|
81858
|
-
...state,
|
|
81859
|
-
variants: variantsById,
|
|
81860
|
-
state: "loaded",
|
|
81861
|
-
error: void 0
|
|
81862
|
-
};
|
|
81863
|
-
}
|
|
81864
|
-
case "VARIANT_DELETED": {
|
|
81865
|
-
const {
|
|
81866
|
-
id: id2
|
|
81867
|
-
} = action.payload, restVariants = new Map(state.variants);
|
|
81868
|
-
return restVariants.delete(id2), {
|
|
81869
|
-
...state,
|
|
81870
|
-
variants: restVariants
|
|
81871
|
-
};
|
|
81872
|
-
}
|
|
81873
|
-
default:
|
|
81874
|
-
return state;
|
|
81875
|
-
}
|
|
81876
|
-
}
|
|
81877
|
-
const SORT_FIELD = "_createdAt", SORT_ORDER = "desc", QUERY_SORT_ORDER = `order(${SORT_FIELD} ${SORT_ORDER})`, QUERY_FILTER = `_type=="${VARIANT_DOCUMENT_TYPE}" && _id in path("${VARIANT_DOCUMENTS_PATH}.*")`, QUERY_PROJECTION = `{
|
|
81878
|
-
_id,
|
|
81879
|
-
_type,
|
|
81880
|
-
_rev,
|
|
81881
|
-
_createdAt,
|
|
81882
|
-
_updatedAt,
|
|
81883
|
-
name,
|
|
81884
|
-
conditions,
|
|
81885
|
-
"priority": coalesce(priority, 0),
|
|
81886
|
-
metadata,
|
|
81887
|
-
}`, QUERY = `*[${QUERY_FILTER}] ${QUERY_PROJECTION} | ${QUERY_SORT_ORDER}`, INITIAL_STATE$4 = {
|
|
81888
|
-
variants: /* @__PURE__ */ new Map(),
|
|
81889
|
-
state: "initialising"
|
|
81890
|
-
};
|
|
81891
|
-
function createVariantsStore(context) {
|
|
81892
|
-
const {
|
|
81893
|
-
client
|
|
81894
|
-
} = context, dispatch$ = new Subject();
|
|
81895
|
-
function dispatch(action) {
|
|
81896
|
-
dispatch$.next(action);
|
|
81897
|
-
}
|
|
81898
|
-
const listFetch$ = of({
|
|
81899
|
-
type: "LOADING_STATE_CHANGED",
|
|
81900
|
-
payload: {
|
|
81901
|
-
loading: !0,
|
|
81902
|
-
error: void 0
|
|
81903
|
-
}
|
|
81904
|
-
}).pipe(concatWith(listenQuery(client, QUERY, {}, {
|
|
81905
|
-
tag: "variants.listen"
|
|
81906
|
-
}).pipe(map((variants2) => ({
|
|
81907
|
-
type: "FETCH_SUCCEEDED",
|
|
81908
|
-
payload: variants2
|
|
81909
|
-
})))), catchError$1((error) => of({
|
|
81910
|
-
type: "LOADING_STATE_CHANGED",
|
|
81911
|
-
payload: {
|
|
81912
|
-
loading: !1,
|
|
81913
|
-
error
|
|
81914
|
-
}
|
|
81915
|
-
})));
|
|
81916
|
-
return {
|
|
81917
|
-
state$: merge(listFetch$, dispatch$).pipe(scan$1((state, action) => variantStoreReducer(state, action), INITIAL_STATE$4), startWith(INITIAL_STATE$4), shareReplay$1(1)),
|
|
81918
|
-
dispatch
|
|
81919
|
-
};
|
|
81920
|
-
}
|
|
81921
|
-
function useVariantsStore() {
|
|
81922
|
-
const $ = c(4), resourceCache = useResourceCache(), workspace = useWorkspace(), studioClient = useClient(VARIANTS_STUDIO_CLIENT_OPTIONS);
|
|
81923
|
-
let variantStore;
|
|
81924
|
-
return $[0] !== resourceCache || $[1] !== studioClient || $[2] !== workspace ? (variantStore = resourceCache.get({
|
|
81925
|
-
dependencies: [workspace],
|
|
81926
|
-
namespace: "VariantsStore"
|
|
81927
|
-
}) || createVariantsStore({
|
|
81928
|
-
client: studioClient
|
|
81929
|
-
}), resourceCache.set({
|
|
81930
|
-
dependencies: [workspace],
|
|
81931
|
-
namespace: "VariantsStore",
|
|
81932
|
-
value: variantStore
|
|
81933
|
-
}), $[0] = resourceCache, $[1] = studioClient, $[2] = workspace, $[3] = variantStore) : variantStore = $[3], variantStore;
|
|
81934
|
-
}
|
|
81935
|
-
function useAllVariants() {
|
|
81936
|
-
const $ = c(8), {
|
|
81937
|
-
state$
|
|
81938
|
-
} = useVariantsStore(), {
|
|
81939
|
-
variants: variants2,
|
|
81940
|
-
error,
|
|
81941
|
-
state
|
|
81942
|
-
} = useObservable(state$);
|
|
81943
|
-
let t0;
|
|
81944
|
-
$[0] !== variants2 ? (t0 = Array.from(variants2.values()), $[0] = variants2, $[1] = t0) : t0 = $[1];
|
|
81945
|
-
let t1;
|
|
81946
|
-
$[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = ["loading", "initialising"], $[2] = t1) : t1 = $[2];
|
|
81947
|
-
const t2 = t1.includes(state);
|
|
81948
|
-
let t3;
|
|
81949
|
-
return $[3] !== error || $[4] !== t0 || $[5] !== t2 || $[6] !== variants2 ? (t3 = {
|
|
81950
|
-
data: t0,
|
|
81951
|
-
byId: variants2,
|
|
81952
|
-
error,
|
|
81953
|
-
loading: t2
|
|
81954
|
-
}, $[3] = error, $[4] = t0, $[5] = t2, $[6] = variants2, $[7] = t3) : t3 = $[7], t3;
|
|
81955
|
-
}
|
|
81956
82019
|
function VariantDetailMenuButton(t0) {
|
|
81957
82020
|
const $ = c(21), {
|
|
81958
82021
|
variant
|