@wix/himalaya-cli 0.1173.0 → 0.1175.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/stdlib/wix-sdk/stores-v1/src/extensions.d.ts +13 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/stores-v1/src/products-v3.d.ts +13 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-stores.mjs +10 -3
- package/dist/cli.mjs +66 -23
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/sdk-reference.json +15 -3
- package/package.json +2 -2
- package/templates/beauty-salon/dev/index.ts +63 -41
- package/templates/beauty-salon-owner/dev/index.ts +172 -6
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/branded-lite/dev/index.ts +71 -47
- package/templates/community-club/dev/index.ts +63 -41
- package/templates/community-club-owner/dev/index.ts +257 -8
- package/templates/community-club-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/community-club-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/community-club-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/community-club-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/community-club-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/events-meetups/dev/index.ts +63 -41
- package/templates/events-meetups-owner/dev/index.ts +87 -4
- package/templates/events-meetups-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/gym-fitness/dev/index.ts +63 -41
- package/templates/gym-fitness-owner/dev/index.ts +257 -8
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/nonprofit-cause/dev/index.ts +63 -41
- package/templates/nonprofit-cause-owner/dev/index.ts +87 -4
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/owner-lite/dev/index.ts +512 -17
- package/templates/owner-lite/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/owner-lite/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/owner-lite/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/owner-lite/tier5-src/himi-owner-lite-faq-question-form/index.ts +77 -10
- package/templates/owner-lite/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/owner-lite/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/podcast-creator/dev/index.ts +63 -41
- package/templates/podcast-creator-owner/dev/index.ts +257 -8
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/portfolio-creative/dev/index.ts +63 -41
- package/templates/portfolio-creative-owner/dev/index.ts +172 -6
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/restaurant/dev/index.ts +71 -47
- package/templates/restaurant-owner/dev/index.ts +257 -8
- package/templates/restaurant-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/restaurant-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/retail-store/dev/index.ts +63 -41
- package/templates/retail-store-owner/dev/index.ts +172 -6
- package/templates/retail-store-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/retail-store-owner/tier5-src/_shared/owner-rich-guard.ts +1 -9
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-product-form/index.ts +130 -27
- package/templates/yoga-studio/dev/index.ts +63 -41
- package/templates/yoga-studio-owner/dev/index.ts +87 -4
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-editor-value.ts +71 -5
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event-form/index.ts +117 -51
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post-form/index.ts +17 -42
- package/templates/events-meetups-owner/tier5-src/_shared/owner-rich-guard.ts +0 -35
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-rich-guard.ts +0 -35
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-rich-guard.ts +0 -35
|
@@ -74057,7 +74057,7 @@ const SCREENS = runtimeSetting({
|
|
|
74057
74057
|
"package": "himalaya",
|
|
74058
74058
|
"type": "FormField",
|
|
74059
74059
|
"props": {
|
|
74060
|
-
"id": "
|
|
74060
|
+
"id": "descriptionText",
|
|
74061
74061
|
"label": "Description",
|
|
74062
74062
|
"kind": "text",
|
|
74063
74063
|
"text": {
|
|
@@ -74070,7 +74070,90 @@ const SCREENS = runtimeSetting({
|
|
|
74070
74070
|
}
|
|
74071
74071
|
},
|
|
74072
74072
|
"modifiers": {
|
|
74073
|
-
"hiddenPath": "$service:himiOwnerLiteProductForm.
|
|
74073
|
+
"hiddenPath": "$service:himiOwnerLiteProductForm.descriptionFieldHidden"
|
|
74074
|
+
}
|
|
74075
|
+
},
|
|
74076
|
+
{
|
|
74077
|
+
"id": "product_form.description_slot",
|
|
74078
|
+
"body": {
|
|
74079
|
+
"package": "himalaya",
|
|
74080
|
+
"type": "VStack",
|
|
74081
|
+
"props": {
|
|
74082
|
+
"spacing": 6,
|
|
74083
|
+
"alignment": "leading",
|
|
74084
|
+
"children": [
|
|
74085
|
+
{
|
|
74086
|
+
"id": "",
|
|
74087
|
+
"body": {
|
|
74088
|
+
"package": "himalaya",
|
|
74089
|
+
"type": "Text",
|
|
74090
|
+
"props": {
|
|
74091
|
+
"text": "Description",
|
|
74092
|
+
"style": "bodyEmphasis"
|
|
74093
|
+
}
|
|
74094
|
+
}
|
|
74095
|
+
},
|
|
74096
|
+
{
|
|
74097
|
+
"id": "product_description_editor",
|
|
74098
|
+
"body": {
|
|
74099
|
+
"package": "himalaya",
|
|
74100
|
+
"type": "RichContentEditor",
|
|
74101
|
+
"props": {
|
|
74102
|
+
"name": "description",
|
|
74103
|
+
"documentPath": "$service:himiOwnerLiteProductForm.descriptionJson",
|
|
74104
|
+
"placeholder": "Optional",
|
|
74105
|
+
"uploadService": "himiOwnerLiteProductFormUploads",
|
|
74106
|
+
"onChange": {
|
|
74107
|
+
"actionId": "tier5.himiOwnerLiteProductForm.descriptionChanged"
|
|
74108
|
+
},
|
|
74109
|
+
"minHeight": 200,
|
|
74110
|
+
"fallback": {
|
|
74111
|
+
"id": "product_form.description_unavailable",
|
|
74112
|
+
"body": {
|
|
74113
|
+
"package": "himalaya",
|
|
74114
|
+
"type": "VStack",
|
|
74115
|
+
"props": {
|
|
74116
|
+
"spacing": 4,
|
|
74117
|
+
"alignment": "leading",
|
|
74118
|
+
"children": [
|
|
74119
|
+
{
|
|
74120
|
+
"id": "",
|
|
74121
|
+
"body": {
|
|
74122
|
+
"package": "himalaya",
|
|
74123
|
+
"type": "Text",
|
|
74124
|
+
"props": {
|
|
74125
|
+
"text": "Editor unavailable",
|
|
74126
|
+
"style": "title3"
|
|
74127
|
+
}
|
|
74128
|
+
}
|
|
74129
|
+
},
|
|
74130
|
+
{
|
|
74131
|
+
"id": "",
|
|
74132
|
+
"body": {
|
|
74133
|
+
"package": "himalaya",
|
|
74134
|
+
"type": "Text",
|
|
74135
|
+
"props": {
|
|
74136
|
+
"text": "The description can’t be edited here right now. Name, price and SKU still save, and the description stays as it is.",
|
|
74137
|
+
"style": "footnote",
|
|
74138
|
+
"color": "textSecondary"
|
|
74139
|
+
}
|
|
74140
|
+
}
|
|
74141
|
+
}
|
|
74142
|
+
]
|
|
74143
|
+
}
|
|
74144
|
+
}
|
|
74145
|
+
}
|
|
74146
|
+
}
|
|
74147
|
+
},
|
|
74148
|
+
"modifiers": {
|
|
74149
|
+
"hiddenPath": "$service:himiOwnerLiteProductForm.descriptionPending"
|
|
74150
|
+
}
|
|
74151
|
+
}
|
|
74152
|
+
]
|
|
74153
|
+
}
|
|
74154
|
+
},
|
|
74155
|
+
"modifiers": {
|
|
74156
|
+
"hiddenPath": "$service:himiOwnerLiteProductForm.descriptionEditorHidden"
|
|
74074
74157
|
}
|
|
74075
74158
|
}
|
|
74076
74159
|
],
|
|
@@ -74339,7 +74422,7 @@ const SCREENS = runtimeSetting({
|
|
|
74339
74422
|
"onChange": {
|
|
74340
74423
|
"actionId": "tier5.himiOwnerLitePostForm.bodyChanged"
|
|
74341
74424
|
},
|
|
74342
|
-
"minHeight":
|
|
74425
|
+
"minHeight": 240,
|
|
74343
74426
|
"fallback": {
|
|
74344
74427
|
"id": "post_form.body_unavailable",
|
|
74345
74428
|
"body": {
|
|
@@ -74796,7 +74879,7 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
|
|
|
74796
74879
|
"package": "himalaya",
|
|
74797
74880
|
"type": "FormField",
|
|
74798
74881
|
"props": {
|
|
74799
|
-
"id": "
|
|
74882
|
+
"id": "descriptionText",
|
|
74800
74883
|
"label": "Description",
|
|
74801
74884
|
"kind": "text",
|
|
74802
74885
|
"text": {
|
|
@@ -74809,7 +74892,90 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
|
|
|
74809
74892
|
}
|
|
74810
74893
|
},
|
|
74811
74894
|
"modifiers": {
|
|
74812
|
-
"hiddenPath": "$service:himiOwnerLiteProductForm.
|
|
74895
|
+
"hiddenPath": "$service:himiOwnerLiteProductForm.descriptionFieldHidden"
|
|
74896
|
+
}
|
|
74897
|
+
},
|
|
74898
|
+
{
|
|
74899
|
+
"id": "product_form.description_slot",
|
|
74900
|
+
"body": {
|
|
74901
|
+
"package": "himalaya",
|
|
74902
|
+
"type": "VStack",
|
|
74903
|
+
"props": {
|
|
74904
|
+
"spacing": 6,
|
|
74905
|
+
"alignment": "leading",
|
|
74906
|
+
"children": [
|
|
74907
|
+
{
|
|
74908
|
+
"id": "",
|
|
74909
|
+
"body": {
|
|
74910
|
+
"package": "himalaya",
|
|
74911
|
+
"type": "Text",
|
|
74912
|
+
"props": {
|
|
74913
|
+
"text": "Description",
|
|
74914
|
+
"style": "bodyEmphasis"
|
|
74915
|
+
}
|
|
74916
|
+
}
|
|
74917
|
+
},
|
|
74918
|
+
{
|
|
74919
|
+
"id": "product_description_editor",
|
|
74920
|
+
"body": {
|
|
74921
|
+
"package": "himalaya",
|
|
74922
|
+
"type": "RichContentEditor",
|
|
74923
|
+
"props": {
|
|
74924
|
+
"name": "description",
|
|
74925
|
+
"documentPath": "$service:himiOwnerLiteProductForm.descriptionJson",
|
|
74926
|
+
"placeholder": "Optional",
|
|
74927
|
+
"uploadService": "himiOwnerLiteProductFormUploads",
|
|
74928
|
+
"onChange": {
|
|
74929
|
+
"actionId": "tier5.himiOwnerLiteProductForm.descriptionChanged"
|
|
74930
|
+
},
|
|
74931
|
+
"minHeight": 200,
|
|
74932
|
+
"fallback": {
|
|
74933
|
+
"id": "product_form.description_unavailable",
|
|
74934
|
+
"body": {
|
|
74935
|
+
"package": "himalaya",
|
|
74936
|
+
"type": "VStack",
|
|
74937
|
+
"props": {
|
|
74938
|
+
"spacing": 4,
|
|
74939
|
+
"alignment": "leading",
|
|
74940
|
+
"children": [
|
|
74941
|
+
{
|
|
74942
|
+
"id": "",
|
|
74943
|
+
"body": {
|
|
74944
|
+
"package": "himalaya",
|
|
74945
|
+
"type": "Text",
|
|
74946
|
+
"props": {
|
|
74947
|
+
"text": "Editor unavailable",
|
|
74948
|
+
"style": "title3"
|
|
74949
|
+
}
|
|
74950
|
+
}
|
|
74951
|
+
},
|
|
74952
|
+
{
|
|
74953
|
+
"id": "",
|
|
74954
|
+
"body": {
|
|
74955
|
+
"package": "himalaya",
|
|
74956
|
+
"type": "Text",
|
|
74957
|
+
"props": {
|
|
74958
|
+
"text": "The description can’t be edited here right now. Name, price and SKU still save, and the description stays as it is.",
|
|
74959
|
+
"style": "footnote",
|
|
74960
|
+
"color": "textSecondary"
|
|
74961
|
+
}
|
|
74962
|
+
}
|
|
74963
|
+
}
|
|
74964
|
+
]
|
|
74965
|
+
}
|
|
74966
|
+
}
|
|
74967
|
+
}
|
|
74968
|
+
}
|
|
74969
|
+
},
|
|
74970
|
+
"modifiers": {
|
|
74971
|
+
"hiddenPath": "$service:himiOwnerLiteProductForm.descriptionPending"
|
|
74972
|
+
}
|
|
74973
|
+
}
|
|
74974
|
+
]
|
|
74975
|
+
}
|
|
74976
|
+
},
|
|
74977
|
+
"modifiers": {
|
|
74978
|
+
"hiddenPath": "$service:himiOwnerLiteProductForm.descriptionEditorHidden"
|
|
74813
74979
|
}
|
|
74814
74980
|
}
|
|
74815
74981
|
],
|
|
@@ -75324,7 +75490,7 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
|
|
|
75324
75490
|
"onChange": {
|
|
75325
75491
|
"actionId": "tier5.himiOwnerLitePostForm.bodyChanged"
|
|
75326
75492
|
},
|
|
75327
|
-
"minHeight":
|
|
75493
|
+
"minHeight": 240,
|
|
75328
75494
|
"fallback": {
|
|
75329
75495
|
"id": "post_form.body_unavailable",
|
|
75330
75496
|
"body": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// drops nodes the owner never touched).
|
|
9
9
|
// Inside the platform source this import is a relative path, so node test runs resolve it; an app's
|
|
10
10
|
// copy imports "@himalaya/wix-rich-content".
|
|
11
|
-
import { parseRicosJson, RICH_CONTENT_LIMITS, type RicosDocument } from "@himalaya/wix-rich-content";
|
|
11
|
+
import { parseRicosJson, isPlainRicos, RICH_CONTENT_LIMITS, type RicosDocument } from "@himalaya/wix-rich-content";
|
|
12
12
|
|
|
13
13
|
export type EditorValue =
|
|
14
14
|
| { kind: "absent" } // leave the stored body untouched
|
|
@@ -45,12 +45,78 @@ function overLimits(doc: RicosDocument): boolean {
|
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const TEXT_ONLY = new Set(["PARAGRAPH", "TEXT", "HEADING", "BULLETED_LIST", "ORDERED_LIST", "LIST_ITEM", "BLOCKQUOTE", "CODE_BLOCK"]);
|
|
49
|
+
/** No visible text and no non-text node (an image, a divider, an embed…): an empty body. */
|
|
50
|
+
export function isEmptyDocument(doc: RicosDocument): boolean {
|
|
51
|
+
const empty = (nodes: RicosDocument["nodes"] | undefined): boolean => (nodes ?? []).every((n) =>
|
|
52
|
+
TEXT_ONLY.has(String(n?.type)) && !String(n.textData?.text ?? "").trim() && empty(n.nodes));
|
|
53
|
+
return empty(doc.nodes);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A Ricos JSON string checked as every viewer would: the limits first, then the shape. */
|
|
57
|
+
function checkedDocument(raw: string): EditorValue {
|
|
52
58
|
if (utf8Bytes(raw) > RICH_CONTENT_LIMITS.maxBytes) return { kind: "too_large" };
|
|
53
59
|
const doc = parseRicosJson(raw);
|
|
54
60
|
if (!doc) return { kind: "invalid" };
|
|
55
61
|
return overLimits(doc) ? { kind: "too_large" } : { kind: "doc", doc, json: raw };
|
|
56
62
|
}
|
|
63
|
+
|
|
64
|
+
/** `raw` is `values[name]`; `seededJson` is the string the form published as the editor's seed. */
|
|
65
|
+
export function editorValue(raw: unknown, seededJson: string): EditorValue {
|
|
66
|
+
if (typeof raw !== "string" || raw === "") return { kind: "absent" };
|
|
67
|
+
if (seededJson !== "" && raw === seededJson) return { kind: "unchanged" };
|
|
68
|
+
const checked = checkedDocument(raw);
|
|
69
|
+
// An empty editor over no body (a record that had none) writes nothing, rather than an empty document.
|
|
70
|
+
if (checked.kind === "doc" && seededJson === "" && isEmptyDocument(checked.doc)) return { kind: "unchanged" };
|
|
71
|
+
return checked;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ── The per-field editor machinery every owner form shares (post body, event / product description,
|
|
75
|
+
// FAQ answer). Each form keeps `<key>Json` (the seed), `<key>Pending` and `<key>Dirty` in its state.
|
|
76
|
+
|
|
77
|
+
/** `<key>Pending`: until this run's load lands, the descriptor hides the editor — it seeds ONCE, so a
|
|
78
|
+
* provisional editor the owner typed into would keep that text over the real document.
|
|
79
|
+
* `<key>Dirty`: the editor's on_change fired since the field was loaded or saved. Once ready the bag
|
|
80
|
+
* ALWAYS holds a document — the engine's own re-serialization of the seed, not byte-equal to it — so
|
|
81
|
+
* only this says the owner edited the field. Every arm fires a pending on_change before it releases a
|
|
82
|
+
* Form submit, so an edit made inside the debounce window is reported before the submit reads it. */
|
|
83
|
+
export interface EditorGate { pending: boolean; dirty: boolean }
|
|
84
|
+
|
|
85
|
+
/** What a live submit does with `values[name]`: only an edit the editor reported counts. */
|
|
86
|
+
export function editorSubmitValue(raw: unknown, seededJson: string, gate: EditorGate): EditorValue {
|
|
87
|
+
return gate.pending || !gate.dirty ? { kind: "absent" } : editorValue(raw, seededJson);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A queued write's document. A replay runs in a FRESH worker with no editor, so the string is checked
|
|
91
|
+
* again (shape and limits); "absent" when the item carries none. Never "unchanged": it was an edit. */
|
|
92
|
+
export function queuedDocument(raw: unknown): EditorValue {
|
|
93
|
+
return typeof raw === "string" && raw !== "" ? checkedDocument(raw) : { kind: "absent" };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The editor's on_change: the field is now edited, and a confirmation of an earlier save is stale.
|
|
97
|
+
* No timing window: an arm fires the pending on_change BEFORE it releases a submit, so any on_change
|
|
98
|
+
* that arrives after a save carries an edit that save did not write. */
|
|
99
|
+
export function editorChanged<S extends { status: string; savedMessage: string }>(s: S): Pick<S, "status" | "savedMessage"> {
|
|
100
|
+
return { status: s.status === "saved" ? "idle" : s.status, savedMessage: "" };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The offline cache's verdict on the stored body (`<key>Protected`): rich unless KNOWN plain. From the
|
|
104
|
+
* document when the form knows it; otherwise plain only when the record was loaded as plain. A bundle
|
|
105
|
+
* rolled back past the editor reads this flag to decide whether its plain field may overwrite the body. */
|
|
106
|
+
export function cachedRichVerdict(doc: RicosDocument | null, knownPlain: boolean): "true" | "false" {
|
|
107
|
+
if (doc) return isPlainRicos(doc) ? "false" : "true";
|
|
108
|
+
return knownPlain ? "false" : "true";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Cold boot: the runtime lays this service's last persisted snapshot over its declared state, so the
|
|
112
|
+
* editor's first seed would be the document as it was when the screen last ran — and a Save after
|
|
113
|
+
* typing would write it over whatever the record holds now. Blank the hydrated seed and reset the gate
|
|
114
|
+
* before anything renders, in place (no action has run yet). `extra` resets further UI state. */
|
|
115
|
+
export function resetHydratedEditor(svc: unknown, keys: { json: string; pending: string; dirty: string }, pendingAtBoot: boolean, extra: Record<string, unknown> = {}): void {
|
|
116
|
+
const booted = (svc as { getState?: () => Record<string, unknown> | undefined }).getState?.();
|
|
117
|
+
if (!booted || typeof booted !== "object") return;
|
|
118
|
+
if (booted[keys.json]) booted[keys.json] = "";
|
|
119
|
+
booted[keys.pending] = pendingAtBoot;
|
|
120
|
+
booted[keys.dirty] = false;
|
|
121
|
+
Object.assign(booted, extra);
|
|
122
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// this file adds the read-only previews the forms show for a locked body, and the FAQ's legacy DraftJS answer.
|
|
3
3
|
// Inside the platform source this import is a relative path, so node test runs resolve it; an app's copy
|
|
4
4
|
// imports "@himalaya/wix-rich-content".
|
|
5
|
-
import { htmlIsTrivial
|
|
5
|
+
import { htmlIsTrivial } from "@himalaya/wix-rich-content";
|
|
6
6
|
|
|
7
7
|
export { htmlIsTrivial };
|
|
8
8
|
|
|
@@ -16,14 +16,6 @@ export function htmlPreviewText(html: string | null | undefined): string {
|
|
|
16
16
|
.split("\n").map((l) => l.replace(/\s+/g, " ").trim()).filter(Boolean).join("\n");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/** True when a plain text field can round-trip this Ricos document: no document styling, and
|
|
20
|
-
* only paragraphs of undecorated text whose paragraph data is the wire default (Events v3 sends
|
|
21
|
-
* `{ textStyle: { textAlignment: "AUTO" }, indentation: 0 }` on every paragraph). Anything else —
|
|
22
|
-
* a heading, list, link, bold run, media node, alignment or indent — is rich, and so is a missing
|
|
23
|
-
* document (callers decide what an absent body means). */
|
|
24
|
-
export const ricosIsPlain = (doc: { nodes?: unknown; documentStyle?: unknown } | null | undefined): boolean =>
|
|
25
|
-
!!doc && isPlainRicos(doc);
|
|
26
|
-
|
|
27
19
|
/** Preview text for a legacy DraftJS document: its `blocks[].text` joined by a blank line, or ""
|
|
28
20
|
* when the payload is not DraftJS JSON (never a throw). */
|
|
29
21
|
export function draftjsText(raw: string | null | undefined): string {
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
// screen (himiOwnerLitePost.publish). Bound by buildForm ($service:himiOwnerLitePostForm.*).
|
|
5
5
|
|
|
6
6
|
import { postBodyText, plainPostBody, postCoverUrl } from "../_shared/owner-post-content.js";
|
|
7
|
-
import {
|
|
8
|
-
import { parseRicosJson } from "@himalaya/wix-rich-content";
|
|
7
|
+
import { editorSubmitValue, queuedDocument, editorChanged, resetHydratedEditor } from "../_shared/owner-editor-value.js";
|
|
9
8
|
import { ricosUploadService } from "@himalaya/wix-rich-content-editor";
|
|
10
9
|
import { wixCall } from "@himalaya/wix-site-media";
|
|
11
10
|
import { wixMediaUrl, WIX_DETAIL_IMAGE } from "../_shared/himi-store.js";
|
|
@@ -43,15 +42,10 @@ interface PostFormState {
|
|
|
43
42
|
bodyJson: string;
|
|
44
43
|
/** The "Post details" sheet (excerpt + cover) is open. */
|
|
45
44
|
detailsOpen: boolean;
|
|
46
|
-
/** The editor
|
|
47
|
-
*
|
|
48
|
-
* byte-equal to it — so only this says the owner actually edited the body. */
|
|
45
|
+
/** The editor gate (`EditorGate` in _shared/owner-editor-value.ts): the editor's on_change fired since
|
|
46
|
+
* the body was loaded or saved, and (edit mode) the editor is hidden until this run's load lands. */
|
|
49
47
|
bodyDirty: boolean;
|
|
50
|
-
/** Edit mode, until `load` lands: the descriptor hides the editor, because a provisional editor
|
|
51
|
-
* the owner typed into keeps that text when the real document arrives (the seed latch). */
|
|
52
48
|
bodyPending: boolean;
|
|
53
|
-
/** When a save last wrote the body (ms), so its own trailing on_change does not undo "Post updated.". */
|
|
54
|
-
bodySavedAt: number;
|
|
55
49
|
coverUrl: string;
|
|
56
50
|
originalCoverUrl: string;
|
|
57
51
|
coverPreview: string;
|
|
@@ -104,9 +98,7 @@ function boolString(value: unknown, fallback: string): string {
|
|
|
104
98
|
return fallback;
|
|
105
99
|
}
|
|
106
100
|
/** What every load that publishes a document resets: the editor may show it, nothing is edited yet. */
|
|
107
|
-
const BODY_LOADED = { bodyPending: false, bodyDirty: false,
|
|
108
|
-
/** How long after a body save its own debounced on_change may still arrive (the arm waits 500 ms). */
|
|
109
|
-
const TRAILING_CHANGE_MS = 1500;
|
|
101
|
+
const BODY_LOADED = { bodyPending: false, bodyDirty: false, detailsOpen: false } as const;
|
|
110
102
|
const valueOf = (arg: unknown): string =>
|
|
111
103
|
String(typeof arg === "string" ? arg : (arg as { value?: unknown; text?: unknown } | undefined)?.value ?? (arg as { text?: unknown } | undefined)?.text ?? "");
|
|
112
104
|
const docJson = (doc: unknown): string => (doc ? JSON.stringify(doc) : "");
|
|
@@ -128,7 +120,6 @@ function shape(s: Partial<PostFormState>): PostFormState {
|
|
|
128
120
|
detailsOpen: s.detailsOpen ?? false,
|
|
129
121
|
bodyDirty: s.bodyDirty ?? false,
|
|
130
122
|
bodyPending: s.bodyPending ?? false,
|
|
131
|
-
bodySavedAt: s.bodySavedAt ?? 0,
|
|
132
123
|
coverUrl: s.coverUrl ?? "",
|
|
133
124
|
originalCoverUrl: s.originalCoverUrl ?? "",
|
|
134
125
|
coverPreview: wixMediaUrl(s.coverUrl ?? "", WIX_DETAIL_IMAGE),
|
|
@@ -244,13 +235,8 @@ const svc = defineService<PostFormState, {
|
|
|
244
235
|
setExcerpt: (s, arg) => shape({ ...s, excerpt: valueOf(arg), error: "" }),
|
|
245
236
|
detailsOpen: (s) => shape({ ...s, detailsOpen: true }),
|
|
246
237
|
detailsClose: (s) => shape({ ...s, detailsOpen: false }),
|
|
247
|
-
// The editor's
|
|
248
|
-
|
|
249
|
-
// this is the trailing on_change of the very edit that save wrote.
|
|
250
|
-
bodyChanged: (s) => {
|
|
251
|
-
const trailing = s.status === "saved" && s.bodySavedAt > 0 && Date.now() - s.bodySavedAt < TRAILING_CHANGE_MS;
|
|
252
|
-
return shape({ ...s, bodyDirty: true, ...(trailing ? {} : { savedMessage: "", status: s.status === "saved" ? "idle" : s.status }) });
|
|
253
|
-
},
|
|
238
|
+
// The editor's `on_change` carries `args.dirty` only; the document stays in the form bag.
|
|
239
|
+
bodyChanged: (s) => shape({ ...s, bodyDirty: true, ...editorChanged(s) }),
|
|
254
240
|
submit: async (s, values) => {
|
|
255
241
|
if (isOwnerPreviewDemo() || s.demoNote) return demoRefusal(s);
|
|
256
242
|
const v = values ?? {};
|
|
@@ -277,14 +263,15 @@ const svc = defineService<PostFormState, {
|
|
|
277
263
|
let bodyRaw = "";
|
|
278
264
|
let bodyTooLarge = false;
|
|
279
265
|
if (replay) {
|
|
280
|
-
const queued =
|
|
281
|
-
|
|
266
|
+
const queued = queuedDocument(v.richContentJson);
|
|
267
|
+
// A queued body that no longer reads (or is past the limits) writes NOTHING, and says so.
|
|
268
|
+
if (queued.kind === "invalid" || queued.kind === "too_large") return shape({ ...s, status: "error", error: copyParam("ownerPostForm.queuedBodyError", "The post body saved offline could not be read, so nothing was written. Edit it again."), savedMessage: "" });
|
|
269
|
+
if (queued.kind === "doc") { richContent = queued.doc as unknown as WixRichContent; bodyRaw = queued.json; }
|
|
282
270
|
else if (v.preserveBody === "false") { richContent = plainPostBody(String(v.body ?? "")); bodyRaw = docJson(richContent); }
|
|
283
271
|
} else {
|
|
284
|
-
// Only an edit the editor reported counts: before load lands the editor is hidden
|
|
285
|
-
//
|
|
286
|
-
|
|
287
|
-
const ev = s.bodyPending || !s.bodyDirty ? { kind: "absent" as const } : editorValue(v.body, s.bodyJson);
|
|
272
|
+
// Only an edit the editor reported counts (EditorGate): before load lands the editor is hidden,
|
|
273
|
+
// and an untouched bag holds the engine's re-serialization of the seed.
|
|
274
|
+
const ev = editorSubmitValue(v.body, s.bodyJson, { pending: s.bodyPending, dirty: s.bodyDirty });
|
|
288
275
|
if (ev.kind === "invalid") return shape({ ...s, status: "error", error: copyParam("ownerPostForm.bodyInvalid", "Couldn’t read the post body from the editor. Nothing was saved; try again."), savedMessage: "" });
|
|
289
276
|
if (ev.kind === "doc") { richContent = ev.doc as unknown as WixRichContent; bodyRaw = ev.json; }
|
|
290
277
|
// A body past the rich-content limits is not written (every viewer would show its
|
|
@@ -308,7 +295,7 @@ const svc = defineService<PostFormState, {
|
|
|
308
295
|
const savedState = (id: string, savedMessage: string) => shape({
|
|
309
296
|
...s, mode: "edit", id, heading: copyParam("ownerPostForm.headingEdit", "Edit post"),
|
|
310
297
|
title, excerpt, body: postBodyText(kept), richContent: kept, bodyJson: bodyEdited ? bodyRaw : s.bodyJson,
|
|
311
|
-
bodyDirty: bodyEdited ? false : s.bodyDirty,
|
|
298
|
+
bodyDirty: bodyEdited ? false : s.bodyDirty,
|
|
312
299
|
coverUrl, originalCoverUrl: coverUrl, isFeatured: isFeatured ? "true" : "false",
|
|
313
300
|
status: "saved", savedMessage, savedId: id,
|
|
314
301
|
error: bodyTooLarge ? copyParam("ownerPostForm.bodyTooLarge", "The post body is too long to save, so it was left as it was. Your other changes were saved.") : "",
|
|
@@ -366,20 +353,8 @@ const svc = defineService<PostFormState, {
|
|
|
366
353
|
},
|
|
367
354
|
});
|
|
368
355
|
|
|
369
|
-
// [rico] #3371 — adopter contract
|
|
370
|
-
// document
|
|
371
|
-
|
|
372
|
-
// typing would write it over whatever the post holds now. Blank the hydrated seed before anything
|
|
373
|
-
// renders: the editor stays provisional (writes nothing) until `load` publishes the fresh document.
|
|
374
|
-
// In place, at boot, because no action has run yet; the state object is the runtime's own merge.
|
|
375
|
-
{
|
|
376
|
-
const booted = (svc as { getState?: () => Partial<PostFormState> | undefined }).getState?.();
|
|
377
|
-
if (booted && typeof booted === "object") {
|
|
378
|
-
if (booted.bodyJson) booted.bodyJson = "";
|
|
379
|
-
// Nor does it carry this run's UI over: the editor waits for this run's load, the sheet is shut.
|
|
380
|
-
booted.bodyPending = startMode === "edit";
|
|
381
|
-
booted.detailsOpen = false;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
356
|
+
// [rico] #3371 — adopter contract: the editor seeds once, so a cold boot must not seed it with the last
|
|
357
|
+
// run's document. Nor does it carry this run's UI over: the details sheet is shut.
|
|
358
|
+
resetHydratedEditor(svc, { json: "bodyJson", pending: "bodyPending", dirty: "bodyDirty" }, startMode === "edit", { detailsOpen: false });
|
|
384
359
|
|
|
385
360
|
export { svc };
|