@wix/himalaya-cli 0.1693.0 → 0.1694.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1 -1
- package/package.json +2 -2
- package/templates/beauty-salon/l10n/en.json +3 -5
- package/templates/branded-lite/dev/index.ts +955 -13
- package/templates/branded-lite/l10n/en.json +49 -9
- package/templates/branded-lite/l10n/he.json +40 -0
- package/templates/branded-lite/tier5-src/_shared/himi-cms.ts +2 -1
- package/templates/branded-lite/tier5-src/himi-branded-lite-cms-collection/index.ts +175 -12
- package/templates/community-club/dev/index.ts +471 -0
- package/templates/community-club/l10n/en.json +49 -9
- package/templates/community-club/l10n/he.json +40 -0
- package/templates/community-club/tier5-src/_shared/himi-cms.ts +2 -1
- package/templates/community-club/tier5-src/himi-branded-lite-cms-collection/index.ts +175 -12
- package/templates/events-meetups/l10n/en.json +5 -9
- package/templates/gym-fitness/l10n/en.json +4 -7
- package/templates/nonprofit-cause/l10n/en.json +5 -9
- package/templates/podcast-creator/l10n/en.json +5 -9
- package/templates/portfolio-creative/l10n/en.json +5 -9
- package/templates/restaurant/l10n/en.json +5 -9
- package/templates/retail-store/l10n/en.json +3 -5
- package/templates/yoga-studio/l10n/en.json +5 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$source": "en",
|
|
3
|
-
"$generated": "2026-11-
|
|
3
|
+
"$generated": "2026-11-12T18:53:33.063Z",
|
|
4
4
|
"messages": {
|
|
5
5
|
"h_00234c88e324": {
|
|
6
6
|
"source": "This site's galleries couldn't be loaded.",
|
|
@@ -323,6 +323,11 @@
|
|
|
323
323
|
"key": "faq.emptyBody",
|
|
324
324
|
"keyOrigin": "string-table"
|
|
325
325
|
},
|
|
326
|
+
"h_13105f46e202": {
|
|
327
|
+
"source": "Z to A",
|
|
328
|
+
"translation": "",
|
|
329
|
+
"key": "cmsCollection.sortZa"
|
|
330
|
+
},
|
|
326
331
|
"h_13c95a1bb260": {
|
|
327
332
|
"source": "Login info",
|
|
328
333
|
"kind": "Text.text",
|
|
@@ -1040,6 +1045,11 @@
|
|
|
1040
1045
|
"key": "cart.checkoutCta",
|
|
1041
1046
|
"keyOrigin": "string-table"
|
|
1042
1047
|
},
|
|
1048
|
+
"h_3ae085e5fa14": {
|
|
1049
|
+
"source": "A to Z",
|
|
1050
|
+
"translation": "",
|
|
1051
|
+
"key": "cmsCollection.sortAz"
|
|
1052
|
+
},
|
|
1043
1053
|
"h_3ccb9d38d15d": {
|
|
1044
1054
|
"source": "Update profile URL",
|
|
1045
1055
|
"kind": "Button.title",
|
|
@@ -1675,8 +1685,7 @@
|
|
|
1675
1685
|
"source": "Clear search",
|
|
1676
1686
|
"kind": "Button.title",
|
|
1677
1687
|
"translation": "",
|
|
1678
|
-
"key": "collections.clearCta"
|
|
1679
|
-
"keyOrigin": "string-table"
|
|
1688
|
+
"key": "collections.clearCta"
|
|
1680
1689
|
},
|
|
1681
1690
|
"h_6733d4f14f4d": {
|
|
1682
1691
|
"source": "Type your message…",
|
|
@@ -1744,8 +1753,12 @@
|
|
|
1744
1753
|
"source": "All",
|
|
1745
1754
|
"kind": "atom.label",
|
|
1746
1755
|
"translation": "",
|
|
1747
|
-
"key": "collection.all"
|
|
1748
|
-
|
|
1756
|
+
"key": "collection.all"
|
|
1757
|
+
},
|
|
1758
|
+
"h_6a99c65c33fe": {
|
|
1759
|
+
"source": "Oldest first",
|
|
1760
|
+
"translation": "",
|
|
1761
|
+
"key": "cmsCollection.sortOldest"
|
|
1749
1762
|
},
|
|
1750
1763
|
"h_6ad6d0d72459": {
|
|
1751
1764
|
"source": "Updates and conversations from the community.",
|
|
@@ -2081,6 +2094,11 @@
|
|
|
2081
2094
|
"key": "explore.blogBody",
|
|
2082
2095
|
"keyOrigin": "string-table"
|
|
2083
2096
|
},
|
|
2097
|
+
"h_7f54ed3fbf32": {
|
|
2098
|
+
"source": "No results for “{query}”",
|
|
2099
|
+
"translation": "",
|
|
2100
|
+
"key": "cmsCollection.noMatchQuery"
|
|
2101
|
+
},
|
|
2084
2102
|
"h_7fef20e1cfed": {
|
|
2085
2103
|
"source": "Blog posts",
|
|
2086
2104
|
"kind": "Text.text",
|
|
@@ -2137,6 +2155,13 @@
|
|
|
2137
2155
|
"key": "invoiceDetail.backCta",
|
|
2138
2156
|
"keyOrigin": "string-table"
|
|
2139
2157
|
},
|
|
2158
|
+
"h_83bc238044da": {
|
|
2159
|
+
"source": "Search content",
|
|
2160
|
+
"kind": "TextField.placeholder",
|
|
2161
|
+
"translation": "",
|
|
2162
|
+
"key": "cmsCollection.searchPlaceholder",
|
|
2163
|
+
"keyOrigin": "string-table"
|
|
2164
|
+
},
|
|
2140
2165
|
"h_83d6f7788309": {
|
|
2141
2166
|
"source": "Hide post",
|
|
2142
2167
|
"kind": "Text.text",
|
|
@@ -2745,8 +2770,7 @@
|
|
|
2745
2770
|
"source": "No matching items",
|
|
2746
2771
|
"kind": "Text.text",
|
|
2747
2772
|
"translation": "",
|
|
2748
|
-
"key": "collection.empty"
|
|
2749
|
-
"keyOrigin": "string-table"
|
|
2773
|
+
"key": "collection.empty"
|
|
2750
2774
|
},
|
|
2751
2775
|
"h_a14a8c9cb59d": {
|
|
2752
2776
|
"source": "Groups are temporarily unavailable.",
|
|
@@ -2817,6 +2841,11 @@
|
|
|
2817
2841
|
"key": "programs.loadingText",
|
|
2818
2842
|
"keyOrigin": "string-table"
|
|
2819
2843
|
},
|
|
2844
|
+
"h_a3c686e711e4": {
|
|
2845
|
+
"source": "Category",
|
|
2846
|
+
"translation": "",
|
|
2847
|
+
"key": "cmsCollection.categoryChip"
|
|
2848
|
+
},
|
|
2820
2849
|
"h_a43dc58df006": {
|
|
2821
2850
|
"source": "Offers & Wallet",
|
|
2822
2851
|
"kind": "atom.label",
|
|
@@ -2975,8 +3004,7 @@
|
|
|
2975
3004
|
"source": "Sort",
|
|
2976
3005
|
"kind": "Text.text",
|
|
2977
3006
|
"translation": "",
|
|
2978
|
-
"key": "collection.sortShown"
|
|
2979
|
-
"keyOrigin": "string-table"
|
|
3007
|
+
"key": "collection.sortShown"
|
|
2980
3008
|
},
|
|
2981
3009
|
"h_ae1ef0143294": {
|
|
2982
3010
|
"source": "Dark",
|
|
@@ -3838,6 +3866,13 @@
|
|
|
3838
3866
|
"key": "account.signOutCta",
|
|
3839
3867
|
"keyOrigin": "string-table"
|
|
3840
3868
|
},
|
|
3869
|
+
"h_ddc04e083593": {
|
|
3870
|
+
"source": "Try another search or category.",
|
|
3871
|
+
"kind": "EmptyState.subtitle",
|
|
3872
|
+
"translation": "",
|
|
3873
|
+
"key": "cmsCollection.noMatchSubtitle",
|
|
3874
|
+
"keyOrigin": "string-table"
|
|
3875
|
+
},
|
|
3841
3876
|
"h_decd7ca80010": {
|
|
3842
3877
|
"source": "Latest",
|
|
3843
3878
|
"kind": "Button.title",
|
|
@@ -4349,6 +4384,11 @@
|
|
|
4349
4384
|
"key": "subscriptionDetail.cancelFailed",
|
|
4350
4385
|
"keyOrigin": "string-table"
|
|
4351
4386
|
},
|
|
4387
|
+
"h_f5ec7772ca9b": {
|
|
4388
|
+
"source": "Newest first",
|
|
4389
|
+
"translation": "",
|
|
4390
|
+
"key": "cmsCollection.sortNewest"
|
|
4391
|
+
},
|
|
4352
4392
|
"h_f642d5314521": {
|
|
4353
4393
|
"source": "+1 555 0100",
|
|
4354
4394
|
"kind": "atom.placeholder",
|
|
@@ -1391,6 +1391,11 @@
|
|
|
1391
1391
|
"key": "invoiceDetail.backCta",
|
|
1392
1392
|
"translation": "חזרה לחשבוניות"
|
|
1393
1393
|
},
|
|
1394
|
+
"h_83bc238044da": {
|
|
1395
|
+
"source": "Search content",
|
|
1396
|
+
"translation": "חיפוש תוכן",
|
|
1397
|
+
"key": "cmsCollection.searchPlaceholder"
|
|
1398
|
+
},
|
|
1394
1399
|
"h_844f869acdc9": {
|
|
1395
1400
|
"source": "These are example badges — this community has none yet.",
|
|
1396
1401
|
"key": "badges.sampleBody",
|
|
@@ -3360,6 +3365,41 @@
|
|
|
3360
3365
|
"key": "cmsCollection.pageError",
|
|
3361
3366
|
"translation": "לא ניתן לטעון עוד."
|
|
3362
3367
|
},
|
|
3368
|
+
"h_f5ec7772ca9b": {
|
|
3369
|
+
"source": "Newest first",
|
|
3370
|
+
"key": "cmsCollection.sortNewest",
|
|
3371
|
+
"translation": "החדשים ביותר תחילה"
|
|
3372
|
+
},
|
|
3373
|
+
"h_6a99c65c33fe": {
|
|
3374
|
+
"source": "Oldest first",
|
|
3375
|
+
"key": "cmsCollection.sortOldest",
|
|
3376
|
+
"translation": "הישנים ביותר תחילה"
|
|
3377
|
+
},
|
|
3378
|
+
"h_3ae085e5fa14": {
|
|
3379
|
+
"source": "A to Z",
|
|
3380
|
+
"key": "cmsCollection.sortAz",
|
|
3381
|
+
"translation": "מא׳ עד ת׳"
|
|
3382
|
+
},
|
|
3383
|
+
"h_13105f46e202": {
|
|
3384
|
+
"source": "Z to A",
|
|
3385
|
+
"key": "cmsCollection.sortZa",
|
|
3386
|
+
"translation": "מת׳ עד א׳"
|
|
3387
|
+
},
|
|
3388
|
+
"h_7f54ed3fbf32": {
|
|
3389
|
+
"source": "No results for “{query}”",
|
|
3390
|
+
"key": "cmsCollection.noMatchQuery",
|
|
3391
|
+
"translation": "אין תוצאות עבור “{query}”"
|
|
3392
|
+
},
|
|
3393
|
+
"h_ddc04e083593": {
|
|
3394
|
+
"source": "Try another search or category.",
|
|
3395
|
+
"key": "cmsCollection.noMatchSubtitle",
|
|
3396
|
+
"translation": "נסו חיפוש או קטגוריה אחרים."
|
|
3397
|
+
},
|
|
3398
|
+
"h_a3c686e711e4": {
|
|
3399
|
+
"source": "Category",
|
|
3400
|
+
"key": "cmsCollection.categoryChip",
|
|
3401
|
+
"translation": "קטגוריה"
|
|
3402
|
+
},
|
|
3363
3403
|
"h_03e89418ffdf": {
|
|
3364
3404
|
"source": "Your Home",
|
|
3365
3405
|
"translation": "הבית שלך"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
queryDataItems as queryWixDataItems,
|
|
3
3
|
countDataItems,
|
|
4
|
+
queryDistinctValues,
|
|
4
5
|
insertDataItem,
|
|
5
6
|
updateDataItem,
|
|
6
7
|
removeDataItem,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
} from "@himalaya/wix-data";
|
|
11
12
|
|
|
12
13
|
export type { WixDataItem, WixQueryDataItemsResponse };
|
|
13
|
-
export { countDataItems, insertDataItem, updateDataItem, removeDataItem };
|
|
14
|
+
export { countDataItems, queryDistinctValues, insertDataItem, updateDataItem, removeDataItem };
|
|
14
15
|
|
|
15
16
|
export interface CmsFieldDefinition {
|
|
16
17
|
key: string;
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
collectionArg,
|
|
4
4
|
collectionDefinitions,
|
|
5
5
|
countDataItems,
|
|
6
|
+
queryDistinctValues,
|
|
6
7
|
queryDataItems,
|
|
7
8
|
type CmsCollectionDefinition,
|
|
8
9
|
type CmsFieldDefinition,
|
|
@@ -101,6 +102,40 @@ const PAGE_SIZE = 20;
|
|
|
101
102
|
const META_FIELD_MAX_CHARS = 24;
|
|
102
103
|
/** The newest-first default: Wix's own created date, present on every collection. */
|
|
103
104
|
const DEFAULT_SORT = [{ fieldName: "_createdDate", order: "DESC" as const }];
|
|
105
|
+
const SORT_IDS = ["newest", "oldest", "az", "za"] as const;
|
|
106
|
+
type SortId = typeof SORT_IDS[number];
|
|
107
|
+
interface Criteria { query: string; sort: string; category: string; categoryField: string }
|
|
108
|
+
let categoryCatalog: { collectionId: string; field: string; name: string; values: string[]; done: boolean; retryable?: boolean } | undefined;
|
|
109
|
+
let discoveryGeneration = 0;
|
|
110
|
+
|
|
111
|
+
function criteria(state: Criteria): Criteria { return { query: state.query, sort: state.sort, category: state.category, categoryField: state.categoryField }; }
|
|
112
|
+
function criteriaKey(state: Criteria): string { return JSON.stringify([state.query.trim(), state.sort, state.category, state.categoryField]); }
|
|
113
|
+
function defaultView(state: Criteria): boolean { return !state.query.trim() && !state.category && state.sort === "newest"; }
|
|
114
|
+
// Wix contains accepts string/reference values, not dates, numbers or objects.
|
|
115
|
+
// These CMS field types store scalar strings; media values are their URLs/ids.
|
|
116
|
+
const SEARCHABLE_DISPLAY_TYPES = new Set(["TEXT", "RICH_TEXT", "URL", "EMAIL", "IMAGE", "DOCUMENT", "VIDEO", "AUDIO", "TIME", "REFERENCE", "PAGE_LINK"]);
|
|
117
|
+
function supportsSearch(collection: CmsCollectionDefinition): boolean {
|
|
118
|
+
return collection.fields.some(field => field.key === collection.displayField && SEARCHABLE_DISPLAY_TYPES.has(field.type));
|
|
119
|
+
}
|
|
120
|
+
function queryFilter(state: Criteria, collection: CmsCollectionDefinition): Record<string, unknown> | undefined {
|
|
121
|
+
const filter: Record<string, unknown> = {};
|
|
122
|
+
if (state.query.trim() && supportsSearch(collection)) filter[collection.displayField] = { $contains: state.query.trim() };
|
|
123
|
+
if (state.category && state.categoryField) filter[state.categoryField] = state.category;
|
|
124
|
+
return Object.keys(filter).length ? filter : undefined;
|
|
125
|
+
}
|
|
126
|
+
function querySort(state: Criteria, collection: CmsCollectionDefinition) {
|
|
127
|
+
return state.sort === "oldest" ? [{ fieldName: "_createdDate", order: "ASC" as const }]
|
|
128
|
+
: state.sort === "az" || state.sort === "za" ? [{ fieldName: collection.displayField, order: state.sort === "az" ? "ASC" as const : "DESC" as const }]
|
|
129
|
+
: DEFAULT_SORT;
|
|
130
|
+
}
|
|
131
|
+
function sortLabel(id: string): string {
|
|
132
|
+
const labels: Record<string, [string, string]> = {
|
|
133
|
+
newest: ["cmsCollection.sortNewest", "Newest first"], oldest: ["cmsCollection.sortOldest", "Oldest first"],
|
|
134
|
+
az: ["cmsCollection.sortAz", "A to Z"], za: ["cmsCollection.sortZa", "Z to A"],
|
|
135
|
+
};
|
|
136
|
+
const [key, fallback] = labels[id] ?? labels.newest;
|
|
137
|
+
return copyParam(key, fallback);
|
|
138
|
+
}
|
|
104
139
|
|
|
105
140
|
interface ItemRow {
|
|
106
141
|
id: string;
|
|
@@ -160,13 +195,36 @@ interface Facts {
|
|
|
160
195
|
refreshFailed: boolean;
|
|
161
196
|
refreshing: boolean;
|
|
162
197
|
errorKind: ErrorKind;
|
|
163
|
-
//
|
|
198
|
+
// Server query criteria. A new view never inherits another view’s rows or caption.
|
|
199
|
+
searchable: boolean;
|
|
164
200
|
query: string;
|
|
165
201
|
sort: string;
|
|
166
202
|
category: string;
|
|
203
|
+
categoryField: string;
|
|
204
|
+
sortOpen: boolean;
|
|
205
|
+
categoryOpen: boolean;
|
|
167
206
|
}
|
|
168
207
|
|
|
169
208
|
interface State extends Facts {
|
|
209
|
+
hideSearch: boolean;
|
|
210
|
+
sortLabel: string;
|
|
211
|
+
sortSelected: boolean;
|
|
212
|
+
noSortSelected: boolean;
|
|
213
|
+
noCategorySelected: boolean;
|
|
214
|
+
hideSortSheet: boolean;
|
|
215
|
+
hideCategorySheet: boolean;
|
|
216
|
+
sortOptions: Array<{ id: string; label: string; notSelected: boolean }>;
|
|
217
|
+
sortChips: Array<{ id: string; label: string }>;
|
|
218
|
+
categoryChips: Array<{ id: string; label: string }>;
|
|
219
|
+
categoryLabel: string;
|
|
220
|
+
categoryName: string;
|
|
221
|
+
categorySelected: boolean;
|
|
222
|
+
categoryOptions: Array<{ id: string; value: string; label: string; notSelected: boolean }>;
|
|
223
|
+
hideCategory: boolean;
|
|
224
|
+
hideCategorySkeleton: boolean;
|
|
225
|
+
noMatchTitle: string;
|
|
226
|
+
showNoMatch: boolean;
|
|
227
|
+
hideNoMatch: boolean;
|
|
170
228
|
/** Shared collection projection; its preferences have their own scoped store. */
|
|
171
229
|
collection?: unknown;
|
|
172
230
|
noCount: boolean;
|
|
@@ -200,10 +258,13 @@ function derive(f: Facts): State {
|
|
|
200
258
|
const countText = typeof f.countTotal === "number" ? countLine(f.countTotal) : f.countText;
|
|
201
259
|
const hasRows = f.rows.length > 0;
|
|
202
260
|
const failed = f.status === "error";
|
|
261
|
+
const narrowed = !!(f.query.trim() || f.category);
|
|
262
|
+
const catalog = categoryCatalog?.collectionId === f.collectionId ? categoryCatalog : undefined;
|
|
203
263
|
const show = {
|
|
204
264
|
showLoading: f.status === "loading",
|
|
205
265
|
showRows: f.status === "ready" && hasRows,
|
|
206
|
-
showEmpty: f.status === "ready" && !hasRows,
|
|
266
|
+
showEmpty: f.status === "ready" && !hasRows && !narrowed,
|
|
267
|
+
showNoMatch: f.status === "ready" && !hasRows && narrowed,
|
|
207
268
|
showRetryableError: failed && (f.errorKind === "offline" || f.errorKind === "server"),
|
|
208
269
|
showSignInError: failed && f.errorKind === "signIn",
|
|
209
270
|
showPermissionError: failed && f.errorKind === "permission",
|
|
@@ -212,11 +273,29 @@ function derive(f: Facts): State {
|
|
|
212
273
|
};
|
|
213
274
|
return {
|
|
214
275
|
...f,
|
|
276
|
+
hideSearch: !f.searchable,
|
|
277
|
+
sortLabel: f.sort === "newest" ? copyParam("cmsCollection.sortChip", "Sort") : sortLabel(f.sort),
|
|
278
|
+
sortSelected: f.sort !== "newest",
|
|
279
|
+
noSortSelected: f.sort === "newest",
|
|
280
|
+
noCategorySelected: !f.category,
|
|
281
|
+
hideSortSheet: !f.sortOpen,
|
|
282
|
+
hideCategorySheet: !f.categoryOpen,
|
|
283
|
+
sortOptions: SORT_IDS.map(id => ({ id, label: sortLabel(id), notSelected: id !== f.sort })),
|
|
284
|
+
sortChips: [{ id: "sort", label: sortLabel(f.sort) }],
|
|
285
|
+
categoryChips: [{ id: "category", label: f.category || catalog?.name || copyParam("cmsCollection.categoryChip", "Category") }],
|
|
286
|
+
categoryName: catalog?.name || copyParam("cmsCollection.categoryChip", "Category"),
|
|
287
|
+
categoryLabel: f.category || catalog?.name || copyParam("cmsCollection.categoryChip", "Category"),
|
|
288
|
+
categorySelected: !!f.category,
|
|
289
|
+
categoryOptions: [{ id: "category-all", value: "", label: copyParam("cmsCollection.allCategories", "All"), notSelected: !!f.category }, ...(catalog?.values ?? []).map(value => ({ id: `category:${value}`, value, label: value, notSelected: value !== f.category }))],
|
|
290
|
+
hideCategory: !catalog?.field,
|
|
291
|
+
hideCategorySkeleton: !f.collectionId || failed || !!catalog?.done,
|
|
292
|
+
noMatchTitle: f.query.trim() ? copyTemplate("cmsCollection.noMatchQuery", "No results for “{query}”", { query: f.query.trim() }) : copyParam("cmsCollection.noMatchTitle", "No matching items"),
|
|
215
293
|
countText,
|
|
216
294
|
...show,
|
|
217
295
|
hideLoading: !show.showLoading,
|
|
218
296
|
hideRows: !show.showRows,
|
|
219
297
|
hideEmpty: !show.showEmpty,
|
|
298
|
+
hideNoMatch: !show.showNoMatch,
|
|
220
299
|
hideRetryableError: !show.showRetryableError,
|
|
221
300
|
hideSignInError: !show.showSignInError,
|
|
222
301
|
hidePermissionError: !show.showPermissionError,
|
|
@@ -249,9 +328,13 @@ function facts(collection: CmsCollectionDefinition | undefined, over: Partial<Fa
|
|
|
249
328
|
refreshFailed: false,
|
|
250
329
|
refreshing: false,
|
|
251
330
|
errorKind: "",
|
|
331
|
+
searchable: collection ? supportsSearch(collection) : false,
|
|
252
332
|
query: "",
|
|
253
333
|
sort: "newest",
|
|
254
334
|
category: "",
|
|
335
|
+
categoryField: "",
|
|
336
|
+
sortOpen: false,
|
|
337
|
+
categoryOpen: false,
|
|
255
338
|
...over,
|
|
256
339
|
};
|
|
257
340
|
}
|
|
@@ -451,17 +534,72 @@ function countLine(total: number): string {
|
|
|
451
534
|
}
|
|
452
535
|
|
|
453
536
|
let current: CmsCollectionDefinition | undefined;
|
|
454
|
-
let firstPageFlight: { collectionId: string; promise: Promise<State> } | undefined;
|
|
537
|
+
let firstPageFlight: { collectionId: string; criteriaKey: string; promise: Promise<State> } | undefined;
|
|
455
538
|
const WARM_FRESH_MS = 30_000;
|
|
456
539
|
let loadingMoreFlight: { cursor: string; generation: number } | undefined;
|
|
457
540
|
let firstPageGeneration = 0;
|
|
458
541
|
/** The latest state, so a read in flight can repaint (the load-more spinner) before its action returns. */
|
|
459
542
|
let published: State | undefined;
|
|
460
543
|
|
|
544
|
+
/** Nine values suffice to reject a high-cardinality field. Never infer categories
|
|
545
|
+
* from page one, nor accept a truncated response as the entire distinct set. */
|
|
546
|
+
function discoverCategories(collection: CmsCollectionDefinition, retry = false): void {
|
|
547
|
+
if (categoryCatalog?.collectionId === collection.id && !(retry && categoryCatalog.done && categoryCatalog.retryable)) return;
|
|
548
|
+
const revision = ++discoveryGeneration;
|
|
549
|
+
categoryCatalog = { collectionId: collection.id, field: "", name: "", values: [], done: false };
|
|
550
|
+
void (async () => {
|
|
551
|
+
const fields = collection.fields.filter(field => field.key !== collection.displayField && field.type === "TEXT" && !field.key.startsWith("_"));
|
|
552
|
+
let match = { field: "", name: "", values: [] as string[] };
|
|
553
|
+
let failed = false;
|
|
554
|
+
for (const field of fields) {
|
|
555
|
+
if (revision !== discoveryGeneration) return;
|
|
556
|
+
try {
|
|
557
|
+
const response = await queryDistinctValues(collection.id, field.key, { paging: { limit: 9 } });
|
|
558
|
+
if (revision !== discoveryGeneration) return;
|
|
559
|
+
const raw = response.distinctValues ?? [];
|
|
560
|
+
const values = [...new Set(raw.filter((value): value is string => typeof value === "string" && !!value.trim()))];
|
|
561
|
+
if (response.pagingMetadata?.hasNext || response.pagingMetadata?.cursors?.next || raw.length >= 9 || raw.some(value => typeof value !== "string" && value != null)) continue;
|
|
562
|
+
if (values.length >= 2 && values.length <= 8) { match = { field: field.key, name: field.displayName, values }; break; }
|
|
563
|
+
} catch { failed = true; /* Optional discovery must never fail the collection read. */ }
|
|
564
|
+
}
|
|
565
|
+
if (revision !== discoveryGeneration) return;
|
|
566
|
+
categoryCatalog = { collectionId: collection.id, ...match, done: true, retryable: failed && !match.field };
|
|
567
|
+
if (published?.collectionId === collection.id) {
|
|
568
|
+
published = derive(published);
|
|
569
|
+
void svc.publish();
|
|
570
|
+
}
|
|
571
|
+
})();
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** Criteria changes retire rows, cursors and captions synchronously, before any
|
|
575
|
+
* storage read can revive an unrelated view. Presentation-only actions
|
|
576
|
+
* keep the latest projection rather than an action's queued snapshot. */
|
|
577
|
+
function changeCriteria(state: State, update: Partial<Criteria>): State | Promise<State> {
|
|
578
|
+
if (!current || state.collectionId !== current.id) return published ?? state;
|
|
579
|
+
const active = published ?? state;
|
|
580
|
+
const next = { ...criteria(active), ...update };
|
|
581
|
+
if (!active.searchable) next.query = "";
|
|
582
|
+
if (criteriaKey(next) === criteriaKey(active)) {
|
|
583
|
+
published = derive({ ...active, ...next, sortOpen: false, categoryOpen: false });
|
|
584
|
+
// Native fields flush onChange before onSubmit. Joining the same read lets
|
|
585
|
+
// the newer decorator action commit its result; returning a loading snapshot
|
|
586
|
+
// would supersede the original reducer and strand the host on its skeleton.
|
|
587
|
+
return firstPageFlight?.collectionId === current.id && firstPageFlight.criteriaKey === criteriaKey(next)
|
|
588
|
+
? firstPageFlight.promise : published;
|
|
589
|
+
}
|
|
590
|
+
++firstPageGeneration;
|
|
591
|
+
firstPageFlight = undefined;
|
|
592
|
+
published = derive(facts(current, { ...next, cacheAccessFence: active.cacheAccessFence }));
|
|
593
|
+
void svc.publish();
|
|
594
|
+
return loadFirstPage(published, { collection: JSON.stringify(current), force: "1" });
|
|
595
|
+
}
|
|
596
|
+
|
|
461
597
|
async function denyAccess(collection: CmsCollectionDefinition, errorKind: ErrorKind): Promise<State> {
|
|
462
598
|
// Access denial supersedes both in-memory rows and their offline snapshot.
|
|
463
599
|
// Retire pending pages/counts before awaiting native storage acknowledgements.
|
|
464
600
|
++firstPageGeneration;
|
|
601
|
+
++discoveryGeneration;
|
|
602
|
+
categoryCatalog = undefined;
|
|
465
603
|
const fence = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
466
604
|
// Dispatch the durable fence before publishing denial, independently of an old
|
|
467
605
|
// snapshot acknowledgement. Other workers never trust a snapshot with an older fence.
|
|
@@ -470,7 +608,7 @@ async function denyAccess(collection: CmsCollectionDefinition, errorKind: ErrorK
|
|
|
470
608
|
// acknowledgement: that older callback must not erase a newer authorized worker.
|
|
471
609
|
const cleared = upsert(ENTITY, { id: pageCacheKey(collection.id), cachePageKind: "cms-first-page", cachePageVersion: 1, cacheAccessFence: fence, rowsJson: "[]" }).catch(() => {});
|
|
472
610
|
cacheWriteTail = Promise.all([cacheWriteTail, fenced, cleared]).then(() => {});
|
|
473
|
-
const denied = derive(facts(collection, { status: "error", errorKind, countPending: false, cacheAccessFence: fence }));
|
|
611
|
+
const denied = derive(facts(collection, { ...(published ? criteria(published) : {}), status: "error", errorKind, countPending: false, cacheAccessFence: fence }));
|
|
474
612
|
published = denied;
|
|
475
613
|
void svc.publish();
|
|
476
614
|
await cacheWriteTail;
|
|
@@ -483,7 +621,8 @@ const boot = resolveCollection(undefined);
|
|
|
483
621
|
function loadFirstPage(state: State, arg?: unknown): Promise<State> {
|
|
484
622
|
stashCopy(arg);
|
|
485
623
|
const collection = resolveCollection(arg);
|
|
486
|
-
|
|
624
|
+
const active = published && published.collectionId === collection?.id ? published : state;
|
|
625
|
+
if (argValue(arg, "force") !== "1" && collection && firstPageFlight?.collectionId === collection.id && firstPageFlight.criteriaKey === criteriaKey(active)) {
|
|
487
626
|
if (published?.collectionId === collection.id) {
|
|
488
627
|
published = localizeState(published);
|
|
489
628
|
void svc.publish();
|
|
@@ -491,7 +630,7 @@ function loadFirstPage(state: State, arg?: unknown): Promise<State> {
|
|
|
491
630
|
return firstPageFlight.promise;
|
|
492
631
|
}
|
|
493
632
|
const promise = readFirstPage(state, arg).then(localizeState);
|
|
494
|
-
const flight = { collectionId: collection?.id ?? "", promise };
|
|
633
|
+
const flight = { collectionId: collection?.id ?? "", criteriaKey: criteriaKey(active), promise };
|
|
495
634
|
firstPageFlight = flight;
|
|
496
635
|
void promise.finally(() => { if (firstPageFlight === flight) firstPageFlight = undefined; });
|
|
497
636
|
return promise;
|
|
@@ -511,6 +650,7 @@ async function readFirstPage(state: State, arg?: unknown): Promise<State> {
|
|
|
511
650
|
// A cold-restored ready state skips the first read but still needs its paging definition.
|
|
512
651
|
current = collection;
|
|
513
652
|
const force = argValue(arg, "force") === "1";
|
|
653
|
+
discoverCategories(collection, force);
|
|
514
654
|
const fresh = !force && state.collectionId === collection.id && state.status === "ready" && Date.now() - state.lastSuccessAt < WARM_FRESH_MS;
|
|
515
655
|
// A forced/stale refresh retires old pages before the asynchronous fence read.
|
|
516
656
|
const refreshGeneration = fresh ? undefined : ++firstPageGeneration;
|
|
@@ -532,15 +672,17 @@ async function readFirstPage(state: State, arg?: unknown): Promise<State> {
|
|
|
532
672
|
// A different collection owns a different cursor and row actions. Retire the
|
|
533
673
|
// previous presentation before even the asynchronous local-cache read.
|
|
534
674
|
if (state.collectionId !== collection.id || revoked) {
|
|
535
|
-
published = derive(facts(collection));
|
|
675
|
+
state = published = derive(facts(collection, state.collectionId === collection.id ? criteria(state) : {}));
|
|
536
676
|
void svc.publish();
|
|
537
677
|
}
|
|
538
678
|
const keptRows = state.collectionId === collection.id && state.status === "ready" ? state.rows : [];
|
|
539
679
|
// Last-synced items for THIS collection (offline-safe; empty on first-ever run).
|
|
540
|
-
const cache = keptRows.length ? { rows: [], accessFence: state.cacheAccessFence ?? "" }
|
|
680
|
+
const cache = keptRows.length ? { rows: [], accessFence: state.cacheAccessFence ?? "" }
|
|
681
|
+
: defaultView(state) ? await readCached(collection.id, collection)
|
|
682
|
+
: { rows: [], accessFence: (await readAccessFence(collection.id)) ?? null };
|
|
541
683
|
const cached = cache.rows;
|
|
542
684
|
if (generation !== firstPageGeneration) return published ?? state;
|
|
543
|
-
const base = facts(collection, { cacheAccessFence: cache.accessFence ?? "" });
|
|
685
|
+
const base = facts(collection, { ...criteria(state), cacheAccessFence: cache.accessFence ?? "" });
|
|
544
686
|
// A cold cache is usable while a slow request is still pending; warm rows stay exactly as shown.
|
|
545
687
|
const retained = keptRows.length ? derive({ ...state, refreshing: true, loadingMore: false }) : cached.length ? derive({ ...base, status: "ready", rows: cached, refreshing: true }) : undefined;
|
|
546
688
|
if (retained) {
|
|
@@ -551,7 +693,8 @@ async function readFirstPage(state: State, arg?: unknown): Promise<State> {
|
|
|
551
693
|
let countPending = true;
|
|
552
694
|
let countTotal: number | null = null;
|
|
553
695
|
let rowsPublished = !!retained;
|
|
554
|
-
|
|
696
|
+
const filter = queryFilter(base, collection);
|
|
697
|
+
void countDataItems(collection.id, filter)
|
|
555
698
|
.then((result) => (typeof result.totalCount === "number" && Number.isFinite(result.totalCount) && result.totalCount >= 0 ? result.totalCount : null))
|
|
556
699
|
.catch(() => null)
|
|
557
700
|
.then((total) => {
|
|
@@ -570,11 +713,11 @@ async function readFirstPage(state: State, arg?: unknown): Promise<State> {
|
|
|
570
713
|
}
|
|
571
714
|
});
|
|
572
715
|
try {
|
|
573
|
-
const response = await queryDataItems(collection.id, PAGE_SIZE, { sort:
|
|
716
|
+
const response = await queryDataItems(collection.id, PAGE_SIZE, { filter, sort: querySort(base, collection) });
|
|
574
717
|
if (generation !== firstPageGeneration) return published ?? state;
|
|
575
718
|
const items = response.dataItems ?? response.items ?? [];
|
|
576
719
|
let rows = items.map((item, index) => itemRow(item, collection, index));
|
|
577
|
-
await writeCached(collection.id, rows, generation, cache.accessFence);
|
|
720
|
+
if (defaultView(base)) await writeCached(collection.id, rows, generation, cache.accessFence);
|
|
578
721
|
if (generation !== firstPageGeneration) return published ?? state;
|
|
579
722
|
// Read interaction state after storage too: a tap may happen while a local write awaits.
|
|
580
723
|
const previous = published?.collectionId === collection.id ? published : state.collectionId === collection.id ? state : undefined;
|
|
@@ -611,6 +754,13 @@ const svc = defineService<State, {
|
|
|
611
754
|
loadMore: (state: State, arg?: unknown) => Promise<State>;
|
|
612
755
|
toggleRow: (state: State, arg?: unknown) => State;
|
|
613
756
|
publish: (state: State) => State;
|
|
757
|
+
search: (state: State, arg?: unknown) => State | Promise<State>;
|
|
758
|
+
setSort: (state: State, arg?: unknown) => State | Promise<State>;
|
|
759
|
+
setCategory: (state: State, arg?: unknown) => State | Promise<State>;
|
|
760
|
+
clearFilters: (state: State) => State | Promise<State>;
|
|
761
|
+
openSort: (state: State) => State;
|
|
762
|
+
openCategory: (state: State) => State;
|
|
763
|
+
closePanels: (state: State) => State;
|
|
614
764
|
/** [rico] #3372 — a row RichContent's on_link: `{ url }` of the tapped link. */
|
|
615
765
|
openLink: (state: State, arg?: unknown) => Promise<State>;
|
|
616
766
|
}>("himiBrandedCmsCollection", {
|
|
@@ -619,6 +769,19 @@ const svc = defineService<State, {
|
|
|
619
769
|
notPersisted: cacheOwnedKeys,
|
|
620
770
|
actions: {
|
|
621
771
|
load: loadFirstPage,
|
|
772
|
+
search: (state, arg) => changeCriteria(state, { query: argValue(arg, "value").slice(0, 256) }),
|
|
773
|
+
setSort: (state, arg) => {
|
|
774
|
+
const sort = argValue(arg, "id");
|
|
775
|
+
return SORT_IDS.includes(sort as SortId) ? changeCriteria(state, { sort }) : published ?? state;
|
|
776
|
+
},
|
|
777
|
+
setCategory: (state, arg) => {
|
|
778
|
+
const category = argValue(arg, "id");
|
|
779
|
+
return !category || categoryCatalog?.values.includes(category) ? changeCriteria(state, { category, categoryField: category ? categoryCatalog?.field ?? "" : "" }) : published ?? state;
|
|
780
|
+
},
|
|
781
|
+
clearFilters: (state) => changeCriteria(state, { query: "", category: "", categoryField: "" }),
|
|
782
|
+
openSort: (state) => published = derive({ ...(published ?? state), sortOpen: true, categoryOpen: false }),
|
|
783
|
+
openCategory: (state) => published = derive({ ...(published ?? state), sortOpen: false, categoryOpen: !((published ?? state).hideCategory) }),
|
|
784
|
+
closePanels: (state) => published = derive({ ...(published ?? state), sortOpen: false, categoryOpen: false }),
|
|
622
785
|
// The error node's, the banner's and the sign-in return's "Try again": the same first load, forced.
|
|
623
786
|
retry: (state, arg) => loadFirstPage(state, { ...(typeof arg === "object" && arg ? arg as Record<string, unknown> : {}), force: "1" }),
|
|
624
787
|
loadMore: async (state) => {
|