@wix/himalaya-cli 0.1947.0 → 0.1949.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/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/files/src/index.d.ts +23 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/admob-ids.d.ts +4 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/index.d.ts +1 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/social-feed/src/index.d.ts +13 -4
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/video/src/display.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +8 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/files.mjs +4 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +3 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-video.mjs +4 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{da958a2a47eef7082c7892c1cc755a58bbeefcb4b617b47fde87f1ce567b3e64.bin → a8cfd0e17359578587e8937e88dedd40b46d533f08b4d2fdac4c47d5bae6f385.bin} +1 -1
- package/dist/browser-plane/sw.js +9 -9
- package/dist/cli.mjs +1906 -800
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/app-icon.md +7 -3
- package/guides/getting-started.md +6 -1
- package/guides/himi-skill.md +6 -1
- package/guides/himi-test.md +30 -1
- package/guides/one-app-section-mappings.md +1 -1
- package/guides/one-app-to-himi-app.md +23 -16
- package/guides/sdk-reference.json +28 -7
- package/guides/skill.md +1 -1
- package/package.json +2 -2
- package/templates/beauty-salon-owner/config.ts +7 -0
- package/templates/beauty-salon-owner/dev/index.ts +567 -0
- package/templates/beauty-salon-owner/himalaya.content.json +3 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/branded-lite/l10n/ar.json +21 -0
- package/templates/branded-lite/l10n/cs.json +21 -0
- package/templates/branded-lite/l10n/da.json +21 -0
- package/templates/branded-lite/l10n/de.json +21 -0
- package/templates/branded-lite/l10n/el.json +21 -0
- package/templates/branded-lite/l10n/en.json +5 -0
- package/templates/branded-lite/l10n/es.json +21 -0
- package/templates/branded-lite/l10n/fi.json +21 -0
- package/templates/branded-lite/l10n/fr.json +21 -0
- package/templates/branded-lite/l10n/he.json +21 -0
- package/templates/branded-lite/l10n/hu.json +21 -0
- package/templates/branded-lite/l10n/id.json +21 -0
- package/templates/branded-lite/l10n/it.json +21 -0
- package/templates/branded-lite/l10n/ja.json +21 -0
- package/templates/branded-lite/l10n/ko.json +21 -0
- package/templates/branded-lite/l10n/lt.json +21 -0
- package/templates/branded-lite/l10n/nl.json +21 -0
- package/templates/branded-lite/l10n/no.json +21 -0
- package/templates/branded-lite/l10n/pl.json +21 -0
- package/templates/branded-lite/l10n/pt.json +21 -0
- package/templates/branded-lite/l10n/ru.json +21 -0
- package/templates/branded-lite/l10n/sv.json +21 -0
- package/templates/branded-lite/l10n/th.json +21 -0
- package/templates/branded-lite/l10n/tr.json +21 -0
- package/templates/branded-lite/l10n/uk.json +21 -0
- package/templates/branded-lite/l10n/vi.json +21 -0
- package/templates/branded-lite/l10n/zh.json +21 -0
- package/templates/branded-lite/recipes/form-section.json +958 -0
- package/templates/branded-lite/recipes/group-feed.json +221 -3
- package/templates/branded-lite/recipes/groups-newsfeed.json +160 -2
- package/templates/branded-lite/recipes/video-library.json +475 -0
- package/templates/branded-lite/tier5-src/_shared/event-agenda.ts +15 -15
- package/templates/branded-lite/tier5-src/_shared/event-schedule-section.ts +8 -8
- package/templates/branded-lite/tier5-src/_shared/form-section.ts +640 -0
- package/templates/branded-lite/tier5-src/_shared/group-feed-section.ts +119 -7
- package/templates/branded-lite/tier5-src/_shared/groups-newsfeed-section.ts +17 -9
- package/templates/branded-lite/tier5-src/_shared/videos-section.ts +134 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-form/index.ts +4 -588
- package/templates/branded-lite/tier5-src/himi-branded-lite-video/index.ts +4 -2
- package/templates/branded-lite/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/community-club/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/community-club-owner/config.ts +7 -0
- package/templates/community-club-owner/dev/index.ts +567 -0
- package/templates/community-club-owner/himalaya.content.json +3 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/conference/tier5-src/_shared/event-agenda.ts +15 -15
- package/templates/conference/tier5-src/himi-conference-agenda/index.ts +3 -5
- package/templates/conference/tier5-src/himi-conference-home/index.ts +5 -6
- package/templates/conference/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/events-meetups/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/events-meetups-owner/config.ts +7 -0
- package/templates/events-meetups-owner/dev/index.ts +567 -0
- package/templates/events-meetups-owner/himalaya.content.json +3 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/gym-fitness/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/gym-fitness-owner/config.ts +7 -0
- package/templates/gym-fitness-owner/dev/index.ts +567 -0
- package/templates/gym-fitness-owner/himalaya.content.json +3 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/nonprofit-cause/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/nonprofit-cause-owner/config.ts +7 -0
- package/templates/nonprofit-cause-owner/dev/index.ts +567 -0
- package/templates/nonprofit-cause-owner/himalaya.content.json +3 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/owner-lite/config.ts +7 -0
- package/templates/owner-lite/dev/index.ts +567 -0
- package/templates/owner-lite/himalaya.content.json +3 -0
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-video/index.ts +4 -2
- package/templates/podcast-creator/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/podcast-creator-owner/config.ts +7 -0
- package/templates/podcast-creator-owner/dev/index.ts +567 -0
- package/templates/podcast-creator-owner/himalaya.content.json +3 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/portfolio-creative/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/portfolio-creative-owner/config.ts +7 -0
- package/templates/portfolio-creative-owner/dev/index.ts +567 -0
- package/templates/portfolio-creative-owner/himalaya.content.json +3 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/professional-services/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/restaurant/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/restaurant-owner/config.ts +7 -0
- package/templates/restaurant-owner/dev/index.ts +567 -0
- package/templates/restaurant-owner/himalaya.content.json +3 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/retail-store-owner/config.ts +7 -0
- package/templates/retail-store-owner/dev/index.ts +567 -0
- package/templates/retail-store-owner/himalaya.content.json +3 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/yoga-studio/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/yoga-studio-owner/config.ts +7 -0
- package/templates/yoga-studio-owner/dev/index.ts +567 -0
- package/templates/yoga-studio-owner/himalaya.content.json +3 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
|
@@ -1,592 +1,8 @@
|
|
|
1
1
|
// himi-branded-lite-form — the Branded Lite Form screen: one Wix Form a visitor fills
|
|
2
|
-
// out and sends.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// (_shared/branded-form.ts parses the schema). A signed-in member gets email, names and
|
|
6
|
-
// phone filled in from their member record, matched by each field's contact mapping.
|
|
7
|
-
// V4 send = local checks → validateFormSubmission → createSubmission (offline outbox).
|
|
8
|
-
// Legacy send uses the v2 form key/value contract, online only. Server errors land in each field's own
|
|
9
|
-
// slot; a failed send keeps every value and says so by the button.
|
|
10
|
-
//
|
|
11
|
-
// A form with a field the app cannot fill, or a conditional rule, shows a notice that
|
|
12
|
-
// opens the website instead (a hidden required field would fail the whole send). A form
|
|
13
|
-
// whose deadline passed shows a closed notice. Replaces wix-spaces-form-detail for this
|
|
14
|
-
// app only: the Spaces clone fixture still uses that worker.
|
|
15
|
-
import { classifyLoadError, defineService, navigate } from "@himalaya/state";
|
|
16
|
-
import { alert } from "@himalaya/ui";
|
|
17
|
-
import { dispatch } from "@himalaya/dispatch";
|
|
18
|
-
import { get as dbGet, remove as dbRemove, upsert as dbUpsert } from "@himalaya/local-db";
|
|
19
|
-
import { open as openUrl } from "@himalaya/open-url";
|
|
20
|
-
import { createSubmission, getForm, getLegacyFormByShortId, submitLegacyForm, validateFormSubmission } from "@himalaya/wix-forms";
|
|
21
|
-
import { getMyMember } from "@himalaya/wix-members";
|
|
22
|
-
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
23
|
-
import { detailInputId, presence, presenceAfterError, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
24
|
-
import { memberAccess } from "../_shared/member-access.js";
|
|
25
|
-
import {
|
|
26
|
-
EMPTY_VALUE, isoDate, localProblems, parseForm, parseLegacyForm, serverProblems, submissionValues,
|
|
27
|
-
type FieldValue, type FormFieldModel, type FormModel,
|
|
28
|
-
} from "../_shared/branded-form.js";
|
|
2
|
+
// out and sends. The service is `_shared/form-section.ts`, so a migrated page can lay
|
|
3
|
+
// the same form out inline (registerFormSection with a formId).
|
|
4
|
+
import { registerFormSection } from "../_shared/form-section.js";
|
|
29
5
|
|
|
30
|
-
|
|
31
|
-
interface FieldRow {
|
|
32
|
-
id: string; target: string;
|
|
33
|
-
label: string; hideLabel: boolean; help: string; hideHelp: boolean; placeholder: string;
|
|
34
|
-
checkLabel: string; displayText: string;
|
|
35
|
-
value: string; checked: boolean;
|
|
36
|
-
/** The stored date as unix seconds (local noon), or "" — the inline date picker's literal
|
|
37
|
-
* `valuePath` seed. Unix, not `YYYY-MM-DD`: no renderer parses a bare date. */
|
|
38
|
-
dateUnix: string;
|
|
39
|
-
/** The field's error, drawn on the line under it (every kind: a TextField's `errorPath` takes
|
|
40
|
-
* only a `$service:` binding, so a row's error cannot use the field's own slot). */
|
|
41
|
-
error: string; noError: boolean;
|
|
42
|
-
options: OptionRow[];
|
|
43
|
-
// hiddenWhen hides on TRUE: one "not" flag per field kind.
|
|
44
|
-
notText: boolean; notArea: boolean; notEmail: boolean; notPhone: boolean; notNumber: boolean; notUrl: boolean;
|
|
45
|
-
notDate: boolean; notCheck: boolean; notChoice: boolean; notMulti: boolean; notDisplay: boolean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface S extends PresenceFlags {
|
|
49
|
-
status: "loading" | "ready";
|
|
50
|
-
title: string;
|
|
51
|
-
rows: FieldRow[];
|
|
52
|
-
pageCaption: string; noPageCaption: boolean;
|
|
53
|
-
primaryLabel: string; backLabel: string;
|
|
54
|
-
/** The footer variant (hiddenWhen hides on TRUE): a one-page form; the first, a middle and
|
|
55
|
-
* the last page of a form with several. */
|
|
56
|
-
hideFooterSingle: boolean; hideFooterFirst: boolean; hideFooterMiddle: boolean; hideFooterLast: boolean;
|
|
57
|
-
/** "Clear form" shows once the visitor has entered an answer. */
|
|
58
|
-
hideClear: boolean;
|
|
59
|
-
sending: boolean;
|
|
60
|
-
sendError: string; noSendError: boolean;
|
|
61
|
-
/** The fields and the footer: hidden unless the form is there, fillable, open and not sent. */
|
|
62
|
-
hideForm: boolean;
|
|
63
|
-
hideUnsupported: boolean; hideClosed: boolean;
|
|
64
|
-
/** No site URL (hosted mode): the notice keeps its sentence and drops the link. */
|
|
65
|
-
hideOpenWebsite: boolean;
|
|
66
|
-
hideDone: boolean; doneTitle: string; doneBody: string;
|
|
67
|
-
hideOfflineError: boolean; hideServerError: boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const BASE: S = {
|
|
71
|
-
status: "loading", title: "", rows: [], pageCaption: "", noPageCaption: true,
|
|
72
|
-
primaryLabel: "", backLabel: "", hideFooterSingle: true, hideFooterFirst: true, hideFooterMiddle: true, hideFooterLast: true,
|
|
73
|
-
hideClear: true, sending: false, sendError: "", noSendError: true,
|
|
74
|
-
hideForm: true, hideUnsupported: true, hideClosed: true, hideOpenWebsite: true, hideDone: true, doneTitle: "", doneBody: "",
|
|
75
|
-
hideOfflineError: true, hideServerError: true,
|
|
76
|
-
...presence("loading"),
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// The worker is the source of truth for what the visitor typed: a keystroke updates this
|
|
80
|
-
// map and returns the state unchanged, so typing never re-renders the field list.
|
|
81
|
-
let form: FormModel | undefined;
|
|
82
|
-
let loadedInputId = "";
|
|
83
|
-
let isLegacy = false;
|
|
84
|
-
let values: Record<string, FieldValue> = {};
|
|
85
|
-
let page = 0;
|
|
86
|
-
let problems: Record<string, string> = {};
|
|
87
|
-
let siteUrl = "";
|
|
88
|
-
|
|
89
|
-
const valueOf = (target: string): FieldValue => values[target] ?? EMPTY_VALUE;
|
|
90
|
-
const pageFields = (): FormFieldModel[] => (form?.pages[page] ?? []).map((id) => form!.fields[id]).filter(Boolean);
|
|
91
|
-
const allFields = (): FormFieldModel[] => (form ? form.pages.flat().map((id) => form!.fields[id]).filter(Boolean) : []);
|
|
92
|
-
const lastPage = (): boolean => !form || page >= form.pages.length - 1;
|
|
93
|
-
|
|
94
|
-
function problemText(f: FormFieldModel, type: string): string {
|
|
95
|
-
switch (type) {
|
|
96
|
-
case "required":
|
|
97
|
-
return f.kind === "checkbox" ? copyParam("form.errorCheck", "Check this box to continue.")
|
|
98
|
-
: f.kind === "choice" || f.kind === "multi" ? copyParam("form.errorChoose", "Choose an option.")
|
|
99
|
-
: copyParam("form.errorRequired", "Enter a value.");
|
|
100
|
-
case "email": return copyParam("form.errorEmail", "Enter a valid email.");
|
|
101
|
-
case "number": return copyParam("form.errorNumber", "Enter a number.");
|
|
102
|
-
case "url": return copyParam("form.errorUrl", "Enter a valid link.");
|
|
103
|
-
case "phone": return copyParam("form.errorPhone", "Enter a valid phone number.");
|
|
104
|
-
case "REQUIRED_VALUE_ERROR": return problemText(f, "required");
|
|
105
|
-
case "FORMAT_ERROR":
|
|
106
|
-
return f.kind === "email" ? problemText(f, "email") : f.kind === "phone" ? copyParam("form.errorPhone", "Enter a valid phone number.")
|
|
107
|
-
: f.kind === "url" ? problemText(f, "url") : copyParam("form.errorInvalid", "Check this value.");
|
|
108
|
-
default: return copyParam("form.errorInvalid", "Check this value.");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function row(f: FormFieldModel): FieldRow {
|
|
113
|
-
const v = valueOf(f.target);
|
|
114
|
-
const error = problems[f.target] ? problemText(f, problems[f.target]) : "";
|
|
115
|
-
const marked = f.label ? `${f.label}${f.required ? " *" : ""}` : "";
|
|
116
|
-
// A checkbox's label sits beside its box, and a text block is its own text: neither has
|
|
117
|
-
// a label line above it.
|
|
118
|
-
const label = f.kind === "checkbox" || f.kind === "display" ? "" : marked;
|
|
119
|
-
// After "Clear form" the rows take new ids: a native field keeps what was typed when only its
|
|
120
|
-
// literal value changes, so an emptied row must mount as a new field to show empty.
|
|
121
|
-
const id = generation ? `${f.id}_r${generation}` : f.id;
|
|
122
|
-
return {
|
|
123
|
-
id, target: f.target,
|
|
124
|
-
label, hideLabel: !label, help: f.help, hideHelp: !f.help,
|
|
125
|
-
checkLabel: f.kind === "checkbox" ? marked : "", displayText: f.kind === "display" ? f.label : "",
|
|
126
|
-
placeholder: f.placeholder,
|
|
127
|
-
value: v.text, checked: v.checked, dateUnix: f.kind === "date" ? unixOfIsoDate(v.text) : "",
|
|
128
|
-
error, noError: !error,
|
|
129
|
-
options: f.options.map((o, i) => ({ id: `${id}_${i}`, target: f.target, value: o.value, label: o.label, selected: v.selected.includes(o.value) })),
|
|
130
|
-
notText: f.kind !== "text", notArea: f.kind !== "area", notEmail: f.kind !== "email", notPhone: f.kind !== "phone",
|
|
131
|
-
notNumber: f.kind !== "number", notUrl: f.kind !== "url", notDate: f.kind !== "date", notCheck: f.kind !== "checkbox",
|
|
132
|
-
notChoice: f.kind !== "choice", notMulti: f.kind !== "multi", notDisplay: f.kind !== "display",
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** The visible state for the current form, page, values and problems. */
|
|
137
|
-
function view(s: S, patch: Partial<S> = {}): S {
|
|
138
|
-
if (!form) return { ...s, ...patch };
|
|
139
|
-
const pages = form.pages.length;
|
|
140
|
-
const fillable = !form.unsupported && !form.closed;
|
|
141
|
-
return {
|
|
142
|
-
...s,
|
|
143
|
-
status: "ready",
|
|
144
|
-
title: form.title || copyParam("form.untitled", "Untitled form"),
|
|
145
|
-
rows: fillable ? pageFields().map(row) : [],
|
|
146
|
-
pageCaption: pages > 1 ? copyTemplate("form.pageCaption", "Page {page} of {total}", { page: String(page + 1), total: String(pages) }) : "",
|
|
147
|
-
noPageCaption: !fillable || pages < 2,
|
|
148
|
-
primaryLabel: lastPage() ? (form.submitText || copyParam("form.submitCta", "Submit")) : (form.nextText || copyParam("form.nextCta", "Next")),
|
|
149
|
-
backLabel: form.backText || copyParam("form.previousCta", "Back"),
|
|
150
|
-
hideFooterSingle: !fillable || pages > 1,
|
|
151
|
-
hideFooterFirst: !fillable || pages < 2 || page !== 0,
|
|
152
|
-
hideFooterMiddle: !fillable || pages < 2 || page === 0 || lastPage(),
|
|
153
|
-
hideFooterLast: !fillable || pages < 2 || !lastPage(),
|
|
154
|
-
hideClear: !fillable || !hasAnswers(),
|
|
155
|
-
hideForm: !fillable,
|
|
156
|
-
hideUnsupported: !form.unsupported,
|
|
157
|
-
hideOpenWebsite: !siteUrl,
|
|
158
|
-
hideClosed: form.unsupported || !form.closed,
|
|
159
|
-
hideDone: true,
|
|
160
|
-
hideOfflineError: true, hideServerError: true,
|
|
161
|
-
...presence("found"),
|
|
162
|
-
...patch,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** A signed-in member's own details by contact field, or `{}` for a visitor or a member read
|
|
167
|
-
* that fails. Fetched beside the form (not after it), so a member does not wait twice. */
|
|
168
|
-
async function memberDetails(): Promise<Record<string, string | undefined>> {
|
|
169
|
-
const access = await memberAccess().catch(() => ({ email: "", scope: "" }));
|
|
170
|
-
if (!access.email) return {};
|
|
171
|
-
let contact: { firstName?: string; lastName?: string; phones?: string[] } = {};
|
|
172
|
-
let loginEmail = access.email;
|
|
173
|
-
try {
|
|
174
|
-
const r = await getMyMember({ fieldsets: ["FULL"] }) as { member?: { loginEmail?: string; contact?: typeof contact } };
|
|
175
|
-
contact = r.member?.contact ?? {};
|
|
176
|
-
loginEmail = (r.member?.loginEmail || access.email).trim();
|
|
177
|
-
} catch { /* the email from the session is still the member's own */ }
|
|
178
|
-
return { EMAIL: loginEmail, FIRST_NAME: contact.firstName, LAST_NAME: contact.lastName, PHONE: contact.phones?.[0] };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** The member's details, written into the empty fields they map to. */
|
|
182
|
-
function prefill(byField: Record<string, string | undefined>): void {
|
|
183
|
-
for (const f of allFields()) {
|
|
184
|
-
const known = byField[f.contactField]?.trim();
|
|
185
|
-
// A field in the draft keeps the visitor's own answer, an emptied one included.
|
|
186
|
-
if (!known || f.target in values) continue;
|
|
187
|
-
values[f.target] = { ...valueOf(f.target), text: known };
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function setValue(target: string, next: Partial<FieldValue>): void {
|
|
192
|
-
values[target] = { ...valueOf(target), ...next };
|
|
193
|
-
touched = true;
|
|
194
|
-
saveDraft();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** How many times "Clear form" ran on this form (row ids carry it, see row()). */
|
|
198
|
-
let generation = 0;
|
|
199
|
-
|
|
200
|
-
/** The visitor has started filling this form (a change, or a draft from an earlier visit):
|
|
201
|
-
* member details prefilled on open do not count. */
|
|
202
|
-
let touched = false;
|
|
203
|
-
|
|
204
|
-
/** Has the visitor entered an answer that "Clear form" would remove? */
|
|
205
|
-
function hasAnswers(): boolean {
|
|
206
|
-
return touched && Object.values(values).some((v) => v.text.trim() !== "" || v.checked || v.selected.length > 0);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ---- Drafts ---------------------------------------------------------------------------------
|
|
210
|
-
// What the user typed survives leaving the form: every change rewrites this form's draft (the
|
|
211
|
-
// latest answers, a cleared field included), it is read back when the form opens again, and a sent
|
|
212
|
-
// or cleared form removes it. One draft per form id, so forms never share answers.
|
|
213
|
-
// Where it is kept depends on who is filling it in. A signed-in member's goes to the device
|
|
214
|
-
// database, whose partition is that member's own, in an entity encrypted at rest (config.ts
|
|
215
|
-
// dataSchema): it survives a restart. A visitor's stays in this worker's memory only: every
|
|
216
|
-
// visitor on a device or browser shares one database partition, so a written draft would show one
|
|
217
|
-
// visitor's names, emails and phone numbers to the next. It survives closing and reopening the form.
|
|
218
|
-
const DRAFTS = "form_drafts";
|
|
219
|
-
const memoryDrafts = new Map<string, Record<string, FieldValue>>();
|
|
220
|
-
/** The loaded form belongs to a signed-in member (see Drafts). */
|
|
221
|
-
let persistDrafts = false;
|
|
222
|
-
/** Whose drafts `memoryDrafts` holds: the member's email, or "" for a visitor. The worker outlives
|
|
223
|
-
* the form modal, so a sign-in, a sign-out or another member clears them before any is read. */
|
|
224
|
-
let draftOwner: string | undefined;
|
|
225
|
-
|
|
226
|
-
function claimDrafts(owner: string): void {
|
|
227
|
-
if (owner === draftOwner) return;
|
|
228
|
-
memoryDrafts.clear();
|
|
229
|
-
draftOwner = owner;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function saveDraft(): void {
|
|
233
|
-
if (!loadedInputId) return;
|
|
234
|
-
memoryDrafts.set(loadedInputId, { ...values });
|
|
235
|
-
if (!persistDrafts) return;
|
|
236
|
-
void dbUpsert(DRAFTS, { id: loadedInputId, values: JSON.stringify(values) }).catch(() => { /* a lost draft is not an error */ });
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function dropDraft(id: string): void {
|
|
240
|
-
if (!id) return;
|
|
241
|
-
memoryDrafts.delete(id);
|
|
242
|
-
if (persistDrafts) void dbRemove(DRAFTS, id).catch(() => { /* nothing to drop */ });
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function readDraft(id: string, persistent: boolean): Promise<Record<string, FieldValue>> {
|
|
246
|
-
const kept = memoryDrafts.get(id);
|
|
247
|
-
if (kept) return { ...kept };
|
|
248
|
-
if (!persistent) return {};
|
|
249
|
-
// A draft is a convenience on top of the form, which has already loaded: a draft that cannot be
|
|
250
|
-
// read means no saved answers, so the form opens empty (the catch falls through to that).
|
|
251
|
-
try {
|
|
252
|
-
const row = await dbGet(DRAFTS, id);
|
|
253
|
-
const raw = typeof row?.values === "string" ? JSON.parse(row.values) as unknown : null;
|
|
254
|
-
if (!raw || typeof raw !== "object") return {};
|
|
255
|
-
const out: Record<string, FieldValue> = {};
|
|
256
|
-
for (const [target, v] of Object.entries(raw as Record<string, Partial<FieldValue>>)) {
|
|
257
|
-
out[target] = {
|
|
258
|
-
text: typeof v?.text === "string" ? v.text : "",
|
|
259
|
-
checked: v?.checked === true,
|
|
260
|
-
selected: Array.isArray(v?.selected) ? v.selected.filter((x): x is string => typeof x === "string") : [],
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
return out;
|
|
264
|
-
} catch { /* an unreadable draft is no draft */ }
|
|
265
|
-
return {};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function argOf(arg: unknown): Record<string, unknown> {
|
|
269
|
-
return arg && typeof arg === "object" ? arg as Record<string, unknown> : {};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function messageFor(err: unknown): Partial<S> {
|
|
273
|
-
const offline = (err as { code?: unknown })?.code === "offline_write_blocked" || classifyLoadError(err) === "offline";
|
|
274
|
-
return {
|
|
275
|
-
sending: false,
|
|
276
|
-
sendError: offline ? copyParam("form.offlineError", "Connect to the internet, then try again.") : copyParam("form.sendError", "Couldn't send the form. Try again."),
|
|
277
|
-
noSendError: false,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/** Keeps the problems that name a field the screen shows and moves to the first page with one;
|
|
282
|
-
* false when none does. A server error for a target the app does not render (a hidden field, an
|
|
283
|
-
* unknown path) cannot be shown in a field, so the caller says so by the button instead. */
|
|
284
|
-
function applyProblems(found: Record<string, string>): boolean {
|
|
285
|
-
const shown = new Set(allFields().map((f) => f.target));
|
|
286
|
-
problems = Object.fromEntries(Object.entries(found).filter(([target]) => shown.has(target)));
|
|
287
|
-
const targets = Object.keys(problems);
|
|
288
|
-
if (!targets.length || !form) return false;
|
|
289
|
-
const pageWithProblem = form.pages.findIndex((ids) => ids.some((id) => targets.includes(form!.fields[id]?.target ?? "")));
|
|
290
|
-
if (pageWithProblem >= 0) page = pageWithProblem;
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/** `YYYY-MM-DD` → unix seconds at local noon (a time zone shift cannot move the day), or "". */
|
|
295
|
-
function unixOfIsoDate(iso: string): string {
|
|
296
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
|
|
297
|
-
return m ? String(Math.floor(new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]), 12).getTime() / 1000)) : "";
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** The footer line when Next or Submit is blocked: it names the first field to fix, which may be
|
|
301
|
-
* below the fold (each field also shows its own error under it). */
|
|
302
|
-
function blocked(): Partial<S> {
|
|
303
|
-
showsBlocked = true;
|
|
304
|
-
return blockedLine();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** The footer line naming the first field still to fix, or none once every field is fixed. */
|
|
308
|
-
function blockedLine(): Partial<S> {
|
|
309
|
-
const first = allFields().find((f) => problems[f.target]);
|
|
310
|
-
if (!first) { showsBlocked = false; return { noSendError: true, sendError: "" }; }
|
|
311
|
-
const field = first.label || first.help;
|
|
312
|
-
return {
|
|
313
|
-
noSendError: false,
|
|
314
|
-
sendError: field
|
|
315
|
-
? copyTemplate("form.fixField", "Check “{field}” and try again.", { field })
|
|
316
|
-
: copyParam("form.fixFields", "Check the highlighted answers and try again."),
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/** The footer shows a blocked-Next line (not a send failure), which follows the fixes. */
|
|
321
|
-
let showsBlocked = false;
|
|
322
|
-
|
|
323
|
-
/** No footer line (a page change, a clear, a send starting). */
|
|
324
|
-
function noLine(): Partial<S> {
|
|
325
|
-
showsBlocked = false;
|
|
326
|
-
return { noSendError: true, sendError: "" };
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/** A field's answer changed: a flagged field is checked again, so its error goes only once the
|
|
330
|
-
* value is valid, and a blocked-Next line names the next field still to fix. */
|
|
331
|
-
function fixed(s: S, target: string): S {
|
|
332
|
-
if (problems[target]) {
|
|
333
|
-
const field = allFields().find((f) => f.target === target);
|
|
334
|
-
const still = field ? localProblems([field], values)[target] : undefined;
|
|
335
|
-
if (still) problems[target] = still; else delete problems[target];
|
|
336
|
-
}
|
|
337
|
-
return view(s, showsBlocked ? blockedLine() : {});
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/** The forms list opens a form as a modal and says so (`modal: "1"`); a deep link does not. */
|
|
341
|
-
function openedAsModal(): boolean {
|
|
342
|
-
return (globalThis as { himalaya?: { input?: { modal?: unknown } } }).himalaya?.input?.modal === "1";
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/** After a send: close the modal form, and confirm in a dialog over the screen behind it. The
|
|
346
|
-
* dialog is the app's own (`ui.alert`), so it outlives the form; Back only closes it.
|
|
347
|
-
* The close is a host action, not a returned `_nav`: this runs after `finishSend`, which the
|
|
348
|
-
* worker calls itself, and the host reads `_nav` only from an action it dispatched.
|
|
349
|
-
* A binary without the `ui` handler refuses the alert at once, before it answers the next host
|
|
350
|
-
* call, so the form then stays open on its done state rather than closing with no confirmation. */
|
|
351
|
-
async function confirmAndClose(title: string, message: string, success: boolean): Promise<void> {
|
|
352
|
-
let refused = false, closed = false;
|
|
353
|
-
// Back on the dialog: the sheet is gone by then, so the done state goes too, and the form opened
|
|
354
|
-
// again from the list shows its loading state rather than the last "Thank you".
|
|
355
|
-
void alert({ title, message, confirmLabel: copyParam("form.doneBackCta", "Back"), ...(success ? { icon: "success" as const } : {}) })
|
|
356
|
-
.then(() => { if (closed) void svc.forgetDone(); })
|
|
357
|
-
.catch(() => { refused = true; });
|
|
358
|
-
if (!openedAsModal()) return;
|
|
359
|
-
await dbGet(DRAFTS, loadedInputId || "_").catch(() => null);
|
|
360
|
-
if (!refused) {
|
|
361
|
-
closed = true;
|
|
362
|
-
void dispatch("himi.open", { presentation: "dismiss" }).catch(() => { closed = false; /* the done state stays */ });
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/** A send in flight is numbered; a later load or send makes an earlier answer stale. */
|
|
367
|
-
let sendVersion = 0;
|
|
368
|
-
|
|
369
|
-
type SendRequest = Parameters<typeof createSubmission>[0];
|
|
370
|
-
|
|
371
|
-
/** V4 checks first, then its queueable send. Legacy forms use their separate v2 write:
|
|
372
|
-
* no v4 validation or offline queue is implied by resolving a short ID. */
|
|
373
|
-
async function send(version: number, request: SendRequest, legacy: boolean): Promise<void> {
|
|
374
|
-
// The form this send is for: its kept answers go once it is sent, even when another form has
|
|
375
|
-
// loaded since (its finishSend is then stale and does nothing).
|
|
376
|
-
const draftId = loadedInputId;
|
|
377
|
-
let outcome: Record<string, unknown>;
|
|
378
|
-
try {
|
|
379
|
-
if (legacy) {
|
|
380
|
-
const sent = await submitLegacyForm({ formId: request.submission.formId,
|
|
381
|
-
fields: Object.entries(request.submission.submissions).map(([key, value]) => ({ key, value: value as string | number | boolean | string[] })) });
|
|
382
|
-
if (!sent.submissionId) throw new Error("The form did not confirm a submission.");
|
|
383
|
-
outcome = { outcome: "sent" };
|
|
384
|
-
} else {
|
|
385
|
-
const check = await validateFormSubmission(request).catch(() => undefined);
|
|
386
|
-
const found = check && check.valid === false ? serverProblems(check) : {};
|
|
387
|
-
if (Object.keys(found).length) outcome = { outcome: "problems", problems: found };
|
|
388
|
-
else {
|
|
389
|
-
const sent = await createSubmission(request, { offline: "queue" });
|
|
390
|
-
outcome = { outcome: sent.status === "queued" ? "queued" : "sent" };
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
} catch (err) {
|
|
394
|
-
const found = serverProblems(err);
|
|
395
|
-
outcome = Object.keys(found).length
|
|
396
|
-
? { outcome: "problems", problems: found }
|
|
397
|
-
: { outcome: "failed", error: { code: (err as { code?: unknown })?.code, message: String((err as Error)?.message ?? err) } };
|
|
398
|
-
}
|
|
399
|
-
if (outcome.outcome === "sent" || outcome.outcome === "queued") dropDraft(draftId);
|
|
400
|
-
await svc.finishSend({ version, ...outcome });
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/** The form was sent (or queued): its done state outlives a repeat onAppear load. */
|
|
404
|
-
let completed = false;
|
|
405
|
-
let inflight: Promise<S> | undefined;
|
|
406
|
-
let inflightId = "";
|
|
407
|
-
|
|
408
|
-
async function loadForm(id: string): Promise<S> {
|
|
409
|
-
form = undefined; loadedInputId = ""; values = {}; page = 0; problems = {}; completed = false; touched = false; generation = 0;
|
|
410
|
-
const version = ++sendVersion;
|
|
411
|
-
const legacy = /^\d+$/.test(id);
|
|
412
|
-
if (!id) return { ...BASE, status: "ready", ...presence("missing") };
|
|
413
|
-
const member = memberDetails();
|
|
414
|
-
// A member's details (an email) say whether the draft may live in the device database.
|
|
415
|
-
const draft = member.then((m) => { claimDrafts(m.EMAIL ?? ""); return readDraft(id, Boolean(m.EMAIL)); });
|
|
416
|
-
try {
|
|
417
|
-
const res = legacy ? await getLegacyFormByShortId(id) : await getForm(id);
|
|
418
|
-
if (version !== sendVersion) return svc.getState();
|
|
419
|
-
const parsed = legacy ? parseLegacyForm(res) : parseForm(res);
|
|
420
|
-
if (!parsed.id || (res as { form?: { enabled?: boolean } }).form?.enabled === false) return { ...BASE, status: "ready", ...presence("missing") };
|
|
421
|
-
const memberInfo = await member;
|
|
422
|
-
if (version !== sendVersion) return svc.getState();
|
|
423
|
-
const saved = await draft;
|
|
424
|
-
if (version !== sendVersion) return svc.getState();
|
|
425
|
-
form = parsed;
|
|
426
|
-
loadedInputId = id;
|
|
427
|
-
isLegacy = legacy;
|
|
428
|
-
persistDrafts = Boolean(memberInfo.EMAIL);
|
|
429
|
-
// The visitor's own latest answers first; member details fill only what is still empty.
|
|
430
|
-
const known = new Set(allFields().map((f) => f.target));
|
|
431
|
-
values = Object.fromEntries(Object.entries(saved).filter(([target]) => known.has(target)));
|
|
432
|
-
touched = Object.keys(values).length > 0;
|
|
433
|
-
prefill(memberInfo);
|
|
434
|
-
return view({ ...BASE });
|
|
435
|
-
} catch (err) {
|
|
436
|
-
if (version !== sendVersion) return svc.getState();
|
|
437
|
-
const p = presenceAfterError(err);
|
|
438
|
-
if (p.notFound) return { ...BASE, status: "ready", ...p };
|
|
439
|
-
const offline = classifyLoadError(err) === "offline";
|
|
440
|
-
return { ...BASE, status: "ready", ...p, hideLoadError: true, hideOfflineError: !offline, hideServerError: offline };
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const svc = defineService<S, {
|
|
445
|
-
load: (s: S, arg?: unknown) => Promise<S>;
|
|
446
|
-
setText: (s: S, arg?: unknown) => S;
|
|
447
|
-
toggleCheck: (s: S, arg?: unknown) => S;
|
|
448
|
-
choose: (s: S, arg?: unknown) => S;
|
|
449
|
-
toggleOption: (s: S, arg?: unknown) => S;
|
|
450
|
-
setDate: (s: S, arg?: unknown) => S;
|
|
451
|
-
clearForm: (s: S) => S;
|
|
452
|
-
close: (s: S) => S;
|
|
453
|
-
next: (s: S) => S;
|
|
454
|
-
finishSend: (s: S, arg?: unknown) => S;
|
|
455
|
-
forgetDone: (s: S) => S;
|
|
456
|
-
back: (s: S) => S;
|
|
457
|
-
openWebsite: (s: S) => Promise<S>;
|
|
458
|
-
}>("himiBrandedForm", {
|
|
459
|
-
state: BASE,
|
|
460
|
-
actions: {
|
|
461
|
-
load: async (s, arg) => {
|
|
462
|
-
stashCopy(arg);
|
|
463
|
-
const a = argOf(arg);
|
|
464
|
-
if (typeof a.siteUrl === "string") siteUrl = a.siteUrl.trim();
|
|
465
|
-
const id = detailInputId();
|
|
466
|
-
// The boot load and the descriptor's onAppear both ask for the same form, and onAppear fires
|
|
467
|
-
// again when the screen comes back (a sheet or the in-app browser closes). The same form id
|
|
468
|
-
// keeps what the visitor typed and the page they are on; only a new id, or a retry after a
|
|
469
|
-
// failure (no form held), starts over.
|
|
470
|
-
// A form already sent keeps its thank-you state: re-opening the editable form would invite
|
|
471
|
-
// a second submission.
|
|
472
|
-
// A form opened again as a modal after its send starts over (the list reuses this worker);
|
|
473
|
-
// only a deep-linked form keeps its done state on a repeat onAppear.
|
|
474
|
-
if (form && id && loadedInputId === id && !(completed && openedAsModal())) return completed ? s : view(s);
|
|
475
|
-
if (inflight && inflightId === id) return inflight;
|
|
476
|
-
inflightId = id;
|
|
477
|
-
const pending = loadForm(id);
|
|
478
|
-
inflight = pending;
|
|
479
|
-
try { return await pending; } finally { if (inflight === pending) inflight = undefined; }
|
|
480
|
-
},
|
|
481
|
-
// Keystrokes: the value lives in the worker (and its draft); the state changes only to clear
|
|
482
|
-
// an error or to show / hide "Clear form", so typing does not re-render the field list.
|
|
483
|
-
setText: (s, arg) => {
|
|
484
|
-
const a = argOf(arg);
|
|
485
|
-
const target = String(a.target ?? "");
|
|
486
|
-
const text = typeof a.value === "string" ? a.value : typeof a.text === "string" ? a.text : "";
|
|
487
|
-
if (!target) return s;
|
|
488
|
-
const hadAnswers = hasAnswers();
|
|
489
|
-
setValue(target, { text });
|
|
490
|
-
if (!problems[target] && hadAnswers === hasAnswers()) return s;
|
|
491
|
-
return fixed(s, target);
|
|
492
|
-
},
|
|
493
|
-
toggleCheck: (s, arg) => {
|
|
494
|
-
const a = argOf(arg);
|
|
495
|
-
const target = String(a.target ?? "");
|
|
496
|
-
if (!target) return s;
|
|
497
|
-
setValue(target, { checked: typeof a.value === "boolean" ? a.value : !valueOf(target).checked });
|
|
498
|
-
return fixed(s, target);
|
|
499
|
-
},
|
|
500
|
-
choose: (s, arg) => {
|
|
501
|
-
const a = argOf(arg);
|
|
502
|
-
const target = String(a.target ?? ""), value = String(a.option ?? "");
|
|
503
|
-
if (!target || !value) return s;
|
|
504
|
-
setValue(target, { selected: [value] });
|
|
505
|
-
return fixed(s, target);
|
|
506
|
-
},
|
|
507
|
-
toggleOption: (s, arg) => {
|
|
508
|
-
const a = argOf(arg);
|
|
509
|
-
const target = String(a.target ?? ""), value = String(a.option ?? "");
|
|
510
|
-
if (!target || !value) return s;
|
|
511
|
-
const sel = valueOf(target).selected;
|
|
512
|
-
setValue(target, { selected: sel.includes(value) ? sel.filter((x) => x !== value) : [...sel, value] });
|
|
513
|
-
return fixed(s, target);
|
|
514
|
-
},
|
|
515
|
-
// The platform date picker sits in the field itself and reports the picked day (unix seconds).
|
|
516
|
-
// Dismissing it without a choice reports nothing, so the stored date stays as it was. A cleared
|
|
517
|
-
// input (web) reports an empty value, which clears the answer.
|
|
518
|
-
setDate: (s, arg) => {
|
|
519
|
-
const a = argOf(arg);
|
|
520
|
-
const target = String(a.target ?? "");
|
|
521
|
-
if (!target || s.sending) return s;
|
|
522
|
-
if (a.value === "" || a.value === null) {
|
|
523
|
-
setValue(target, { text: "" });
|
|
524
|
-
return fixed(s, target);
|
|
525
|
-
}
|
|
526
|
-
const v = Number(a.value);
|
|
527
|
-
if (!Number.isFinite(v) || v <= 0) return s;
|
|
528
|
-
setValue(target, { text: isoDate(v) });
|
|
529
|
-
return fixed(s, target);
|
|
530
|
-
},
|
|
531
|
-
// Every answer of this form, on every page, and its draft: reopening shows an empty form.
|
|
532
|
-
clearForm: (s) => {
|
|
533
|
-
if (!form || s.sending) return s;
|
|
534
|
-
values = {};
|
|
535
|
-
problems = {};
|
|
536
|
-
touched = false;
|
|
537
|
-
generation += 1;
|
|
538
|
-
dropDraft(loadedInputId);
|
|
539
|
-
return view(s, noLine());
|
|
540
|
-
},
|
|
541
|
-
// The closed-form notice's link: back to the list the modal opened from.
|
|
542
|
-
close: (s) => navigate(s, { presentation: openedAsModal() ? "dismiss" : "back" }),
|
|
543
|
-
back: (s) => {
|
|
544
|
-
if (page === 0 || s.sending) return s;
|
|
545
|
-
page -= 1;
|
|
546
|
-
return view(s, noLine());
|
|
547
|
-
},
|
|
548
|
-
// "Next" on an earlier page, "Submit" on the last one.
|
|
549
|
-
next: (s) => {
|
|
550
|
-
if (!form || form.unsupported || form.closed || s.sending) return s;
|
|
551
|
-
const local = localProblems(pageFields(), values);
|
|
552
|
-
if (applyProblems(local)) return view(s, blocked());
|
|
553
|
-
if (!lastPage()) { page += 1; problems = {}; return view(s, noLine()); }
|
|
554
|
-
const all = allFields();
|
|
555
|
-
const allLocal = localProblems(all, values);
|
|
556
|
-
if (applyProblems(allLocal)) return view(s, blocked());
|
|
557
|
-
const version = ++sendVersion;
|
|
558
|
-
void send(version, { submission: { formId: form.id, submissions: submissionValues(all, values) } }, isLegacy);
|
|
559
|
-
return { ...s, sending: true, ...noLine() };
|
|
560
|
-
},
|
|
561
|
-
finishSend: (s, arg) => {
|
|
562
|
-
const r = argOf(arg) as { version?: unknown; outcome?: unknown; problems?: unknown; error?: unknown };
|
|
563
|
-
if (r.version !== sendVersion || !form) return s;
|
|
564
|
-
if (r.outcome === "problems") {
|
|
565
|
-
if (applyProblems(r.problems as Record<string, string>)) return view(s, { sending: false, ...blocked() });
|
|
566
|
-
return view(s, { sending: false, noSendError: false, sendError: copyParam("form.checkError", "Some answers can't be sent. Check the form and try again.") });
|
|
567
|
-
}
|
|
568
|
-
if (r.outcome === "failed") return view(s, messageFor(r.error));
|
|
569
|
-
const queued = r.outcome === "queued";
|
|
570
|
-
completed = true;
|
|
571
|
-
dropDraft(loadedInputId);
|
|
572
|
-
const doneTitle = queued ? copyParam("form.queuedTitle", "Form saved") : copyParam("form.sentTitle", "Thank you");
|
|
573
|
-
const doneBody = queued ? copyParam("form.queuedBody", "We'll send your form when you're back online.")
|
|
574
|
-
: copyParam("form.sentBody", "Your answer was submitted successfully.");
|
|
575
|
-
void confirmAndClose(doneTitle, doneBody, !queued);
|
|
576
|
-
// The done state is what shows when the form cannot close (a deep link, not a modal) or the
|
|
577
|
-
// app has no dialog: never the editable form again.
|
|
578
|
-
return view(s, {
|
|
579
|
-
sending: false, hideForm: true, hideFooterSingle: true, hideFooterFirst: true, hideFooterMiddle: true,
|
|
580
|
-
hideFooterLast: true, hideClear: true, hideDone: false, rows: [], noPageCaption: true, doneTitle, doneBody,
|
|
581
|
-
});
|
|
582
|
-
},
|
|
583
|
-
// The modal form closed after its send (see confirmAndClose).
|
|
584
|
-
forgetDone: (s) => (completed && openedAsModal() ? { ...BASE } : s),
|
|
585
|
-
openWebsite: async (s) => {
|
|
586
|
-
if (siteUrl) { try { await openUrl(siteUrl, "in_app_browser"); } catch { /* the handoff is best-effort */ } }
|
|
587
|
-
return s;
|
|
588
|
-
},
|
|
589
|
-
},
|
|
590
|
-
});
|
|
6
|
+
const svc = registerFormSection("himiBrandedForm");
|
|
591
7
|
svc.load();
|
|
592
8
|
export { svc };
|
|
@@ -11,7 +11,7 @@ import { iapPriceCopy, iapPurchaseCopy, resetUnhydratedKeysOnOlderRuntime } from
|
|
|
11
11
|
import { LOADING, loaded, loadFailed, needsSignIn, type LoadFlags } from "../_shared/branded-load-state.js";
|
|
12
12
|
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
13
13
|
import {
|
|
14
|
-
canWatchVideo, getVideo, getVideoStreamUrl, isHostedVideo, isVideoProcessing, listChannelVideos, videoCard, youtubeVideoId,
|
|
14
|
+
canWatchVideo, getVideo, getVideoStreamUrl, isHostedVideo, isPlayableVideo, isVideoProcessing, listChannelVideos, videoCard, youtubeVideoId,
|
|
15
15
|
} from "@himalaya/wix-video";
|
|
16
16
|
import type { MediaItem } from "@himalaya/core";
|
|
17
17
|
|
|
@@ -213,7 +213,9 @@ async function run(): Promise<undefined> {
|
|
|
213
213
|
}
|
|
214
214
|
else {
|
|
215
215
|
let item: MediaItem | undefined;
|
|
216
|
-
|
|
216
|
+
// The same rule the page sections use to pick a clip this screen can play (isPlayableVideo).
|
|
217
|
+
if (!isPlayableVideo(video)) item = undefined;
|
|
218
|
+
else if (video.source === "YOUTUBE") {
|
|
217
219
|
const providerId = youtubeVideoId(video);
|
|
218
220
|
if (providerId) item = { id, kind: "video", provider: "youtube", providerId, title: next.title };
|
|
219
221
|
} else if (isHostedVideo(video)) {
|
|
@@ -475,7 +475,7 @@ function calendarFallbackUrl(s: S, end: number): string {
|
|
|
475
475
|
|
|
476
476
|
/** The Events v3 fieldsets the detail reads (see `WixEventFieldset`). DETAILS carries mainImage and
|
|
477
477
|
* shortDescription: REGISTRATION fills eventType, which skips the query enrichment that used to supply them. */
|
|
478
|
-
export const EVENT_DETAIL_FIELDSETS: WixEventFieldset[] = ["DETAILS", "TEXTS", "REGISTRATION", "URLS", "FORM"
|
|
478
|
+
export const EVENT_DETAIL_FIELDSETS: WixEventFieldset[] = ["DETAILS", "TEXTS", "REGISTRATION", "URLS", "FORM"];
|
|
479
479
|
|
|
480
480
|
function detailCopy(key: string, fallback: string): string { return copyParam(key, fallback); }
|
|
481
481
|
|
|
@@ -1065,25 +1065,26 @@ const svc: ReturnType<typeof defineService<S, DetailActions>> = defineService<S,
|
|
|
1065
1065
|
const dates = detailDate(e);
|
|
1066
1066
|
const place = detailPlace(e);
|
|
1067
1067
|
const registration = registrationUi(e, Date.now());
|
|
1068
|
-
const rawEvent = e as unknown as { shortDescription?: string;
|
|
1068
|
+
const rawEvent = e as unknown as { shortDescription?: string; dateAndTimeSettings?: { recurrenceStatus?: string; recurringEvents?: { categoryId?: string } }; registration?: { allowedGuestTypes?: string; tickets?: { lowestPrice?: EventDetailMoney; highestPrice?: EventDetailMoney } } };
|
|
1069
1069
|
const lowest = detailMoney(rawEvent.registration?.tickets?.lowestPrice);
|
|
1070
1070
|
const highest = detailMoney(rawEvent.registration?.tickets?.highestPrice);
|
|
1071
1071
|
const price = kind === "tickets" && lowest ? (highest && highest !== lowest ? detailCopy("event.priceFrom", "From {price}").replace("{price}", lowest) : lowest) : "";
|
|
1072
1072
|
const memberProbeNeeded = kind === "rsvp" || rawEvent.registration?.allowedGuestTypes === "MEMBER";
|
|
1073
1073
|
const isMember = memberProbeNeeded ? await signedInMember() : false;
|
|
1074
1074
|
const [scheduleResponse, policyResponse, rsvpResponse] = await Promise.all([
|
|
1075
|
-
// `limit` is required: without it Wix answers the agenda's `total` with an EMPTY `items`.
|
|
1076
|
-
|
|
1075
|
+
// `limit` is required: without it Wix answers the agenda's `total` with an EMPTY `items`. Read whatever the
|
|
1076
|
+
// event's agenda switch says: it is the website's agenda page, and Wix still answers a visitor with it off.
|
|
1077
|
+
bestEffort("GET", `/events/v1/schedule?eventId=${encodeURIComponent(id)}&limit=100`),
|
|
1077
1078
|
bestEffort("POST", "/events-policies/v2/policies/query", { query: { filter: { eventId: { $eq: id } }, paging: { limit: 100 } } }),
|
|
1078
1079
|
kind === "rsvp" && isMember ? bestEffort("GET", `/events/v2/rsvps/current?eventId=${encodeURIComponent(id)}`) : undefined,
|
|
1079
1080
|
]);
|
|
1080
1081
|
let optionalReadFailed = [scheduleResponse, policyResponse, rsvpResponse].some((response) => response?.ok === false);
|
|
1081
1082
|
const scheduleRaw = (scheduleResponse?.ok ? scheduleResponse.value : undefined) as { agenda?: Array<Record<string, unknown>>; schedule?: Array<Record<string, unknown>>; items?: Array<Record<string, unknown>>; agendaItems?: Array<Record<string, unknown>> } | undefined;
|
|
1082
|
-
// A hidden or
|
|
1083
|
+
// A hidden, canceled or draft session is not on the agenda, and an item id is listed once (an owner's
|
|
1083
1084
|
// read carries a draft and its published copy); sessions in start order.
|
|
1084
1085
|
const seenItems = new Set<string>();
|
|
1085
1086
|
const scheduleSource = (scheduleRaw?.agenda ?? scheduleRaw?.agendaItems ?? scheduleRaw?.schedule ?? scheduleRaw?.items ?? [])
|
|
1086
|
-
.filter((item) => item.hidden !== true && String(item.status ?? "").toUpperCase() !== "CANCELED")
|
|
1087
|
+
.filter((item) => item.hidden !== true && item.draft !== true && String(item.status ?? "").toUpperCase() !== "CANCELED")
|
|
1087
1088
|
.filter((item) => { const key = String(item.id ?? ""); if (!key) return true; if (seenItems.has(key)) return false; seenItems.add(key); return true; })
|
|
1088
1089
|
.map((item) => ({ item, at: Date.parse(String((item.timeSlot as { start?: string } | undefined)?.start ?? item.startTime ?? item.startDate ?? "")) }))
|
|
1089
1090
|
.sort((a, b) => (Number.isNaN(a.at) ? Infinity : a.at) - (Number.isNaN(b.at) ? Infinity : b.at))
|