@wix/himalaya-cli 0.1870.0 → 0.1872.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.
Files changed (497) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +3 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/portfolio/src/index.d.ts +19 -0
  3. package/dist/cli.mjs +90 -39
  4. package/fixtures/wix-canned.json +8 -0
  5. package/guides/android-ux.md +3 -2
  6. package/guides/designing-himi-screens.md +10 -4
  7. package/guides/ios-ux.md +3 -2
  8. package/guides/release-notes.md +18 -0
  9. package/guides/sdk-reference.json +8 -1
  10. package/package.json +2 -2
  11. package/template-icons/professional-services.png +0 -0
  12. package/templates/bare-fashion/config.ts +37 -2
  13. package/templates/bare-fashion/dev/index.ts +4006 -48
  14. package/templates/bare-fashion/himalaya.content.json +15 -0
  15. package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +6 -1
  16. package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
  17. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  18. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  19. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  20. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  21. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  22. package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  23. package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +6 -1
  24. package/templates/beauty-salon/tier5-src/_shared/himi-events.ts +27 -0
  25. package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +6 -1
  26. package/templates/beauty-salon-owner/tier5-src/_shared/himi-events.ts +27 -0
  27. package/templates/branded-lite/dev/index.ts +22 -1
  28. package/templates/branded-lite/l10n/ar.json +10 -0
  29. package/templates/branded-lite/l10n/cs.json +10 -0
  30. package/templates/branded-lite/l10n/da.json +10 -0
  31. package/templates/branded-lite/l10n/de.json +10 -0
  32. package/templates/branded-lite/l10n/el.json +10 -0
  33. package/templates/branded-lite/l10n/es.json +10 -0
  34. package/templates/branded-lite/l10n/fi.json +10 -0
  35. package/templates/branded-lite/l10n/fr.json +10 -0
  36. package/templates/branded-lite/l10n/he.json +8 -0
  37. package/templates/branded-lite/l10n/hu.json +10 -0
  38. package/templates/branded-lite/l10n/id.json +10 -0
  39. package/templates/branded-lite/l10n/it.json +10 -0
  40. package/templates/branded-lite/l10n/ja.json +10 -0
  41. package/templates/branded-lite/l10n/ko.json +10 -0
  42. package/templates/branded-lite/l10n/lt.json +10 -0
  43. package/templates/branded-lite/l10n/nl.json +10 -0
  44. package/templates/branded-lite/l10n/no.json +10 -0
  45. package/templates/branded-lite/l10n/pl.json +10 -0
  46. package/templates/branded-lite/l10n/pt.json +10 -0
  47. package/templates/branded-lite/l10n/ru.json +10 -0
  48. package/templates/branded-lite/l10n/sv.json +10 -0
  49. package/templates/branded-lite/l10n/th.json +10 -0
  50. package/templates/branded-lite/l10n/tr.json +10 -0
  51. package/templates/branded-lite/l10n/uk.json +10 -0
  52. package/templates/branded-lite/l10n/vi.json +10 -0
  53. package/templates/branded-lite/l10n/zh.json +10 -0
  54. package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +6 -1
  55. package/templates/branded-lite/tier5-src/_shared/himi-events.ts +27 -0
  56. package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
  57. package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
  58. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  59. package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  60. package/templates/branded-lite/tier5-src/himi-events-detail/index.ts +3 -1
  61. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +38 -8
  62. package/templates/branded-lite/tier5-src/himi-events-my-events/index.ts +4 -2
  63. package/templates/brandy/tier5-src/_shared/collection-contract.ts +6 -1
  64. package/templates/community-club/dev/index.ts +20 -0
  65. package/templates/community-club/l10n/ar.json +10 -0
  66. package/templates/community-club/l10n/cs.json +10 -0
  67. package/templates/community-club/l10n/da.json +10 -0
  68. package/templates/community-club/l10n/de.json +10 -0
  69. package/templates/community-club/l10n/el.json +10 -0
  70. package/templates/community-club/l10n/es.json +10 -0
  71. package/templates/community-club/l10n/fi.json +10 -0
  72. package/templates/community-club/l10n/fr.json +10 -0
  73. package/templates/community-club/l10n/he.json +8 -0
  74. package/templates/community-club/l10n/hu.json +10 -0
  75. package/templates/community-club/l10n/id.json +10 -0
  76. package/templates/community-club/l10n/it.json +10 -0
  77. package/templates/community-club/l10n/ja.json +10 -0
  78. package/templates/community-club/l10n/ko.json +10 -0
  79. package/templates/community-club/l10n/lt.json +10 -0
  80. package/templates/community-club/l10n/nl.json +10 -0
  81. package/templates/community-club/l10n/no.json +10 -0
  82. package/templates/community-club/l10n/pl.json +10 -0
  83. package/templates/community-club/l10n/pt.json +10 -0
  84. package/templates/community-club/l10n/ru.json +10 -0
  85. package/templates/community-club/l10n/sv.json +10 -0
  86. package/templates/community-club/l10n/th.json +10 -0
  87. package/templates/community-club/l10n/tr.json +10 -0
  88. package/templates/community-club/l10n/uk.json +10 -0
  89. package/templates/community-club/l10n/vi.json +10 -0
  90. package/templates/community-club/l10n/zh.json +10 -0
  91. package/templates/community-club/tier5-src/_shared/collection-contract.ts +6 -1
  92. package/templates/community-club/tier5-src/_shared/himi-events.ts +27 -0
  93. package/templates/community-club/tier5-src/himi-events-detail/index.ts +3 -1
  94. package/templates/community-club/tier5-src/himi-events-list/index.ts +38 -8
  95. package/templates/community-club/tier5-src/himi-events-my-events/index.ts +4 -2
  96. package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +6 -1
  97. package/templates/community-club-owner/tier5-src/_shared/himi-events.ts +27 -0
  98. package/templates/conference/config.ts +43 -1
  99. package/templates/conference/dev/index.ts +4147 -0
  100. package/templates/conference/himalaya.content.json +18 -0
  101. package/templates/conference/tier5-src/_shared/collection-contract.ts +6 -1
  102. package/templates/conference/tier5-src/_shared/himi-events.ts +27 -0
  103. package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  104. package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  105. package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  106. package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  107. package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  108. package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  109. package/templates/conference/tier5-src/himi-events-detail/index.ts +3 -1
  110. package/templates/conference/tier5-src/himi-events-list/index.ts +38 -8
  111. package/templates/conference/tier5-src/himi-events-my-events/index.ts +4 -2
  112. package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  113. package/templates/events-meetups/dev/index.ts +20 -0
  114. package/templates/events-meetups/l10n/ar.json +10 -0
  115. package/templates/events-meetups/l10n/cs.json +10 -0
  116. package/templates/events-meetups/l10n/da.json +10 -0
  117. package/templates/events-meetups/l10n/de.json +10 -0
  118. package/templates/events-meetups/l10n/el.json +10 -0
  119. package/templates/events-meetups/l10n/es.json +10 -0
  120. package/templates/events-meetups/l10n/fi.json +10 -0
  121. package/templates/events-meetups/l10n/fr.json +10 -0
  122. package/templates/events-meetups/l10n/he.json +8 -0
  123. package/templates/events-meetups/l10n/hu.json +10 -0
  124. package/templates/events-meetups/l10n/id.json +10 -0
  125. package/templates/events-meetups/l10n/it.json +10 -0
  126. package/templates/events-meetups/l10n/ja.json +10 -0
  127. package/templates/events-meetups/l10n/ko.json +10 -0
  128. package/templates/events-meetups/l10n/lt.json +10 -0
  129. package/templates/events-meetups/l10n/nl.json +10 -0
  130. package/templates/events-meetups/l10n/no.json +10 -0
  131. package/templates/events-meetups/l10n/pl.json +10 -0
  132. package/templates/events-meetups/l10n/pt.json +10 -0
  133. package/templates/events-meetups/l10n/ru.json +10 -0
  134. package/templates/events-meetups/l10n/sv.json +10 -0
  135. package/templates/events-meetups/l10n/th.json +10 -0
  136. package/templates/events-meetups/l10n/tr.json +10 -0
  137. package/templates/events-meetups/l10n/uk.json +10 -0
  138. package/templates/events-meetups/l10n/vi.json +10 -0
  139. package/templates/events-meetups/l10n/zh.json +10 -0
  140. package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +6 -1
  141. package/templates/events-meetups/tier5-src/_shared/himi-events.ts +27 -0
  142. package/templates/events-meetups/tier5-src/himi-events-detail/index.ts +3 -1
  143. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +38 -8
  144. package/templates/events-meetups/tier5-src/himi-events-my-events/index.ts +4 -2
  145. package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +6 -1
  146. package/templates/events-meetups-owner/tier5-src/_shared/himi-events.ts +27 -0
  147. package/templates/fitness-gym/tier5-src/_shared/collection-contract.ts +6 -1
  148. package/templates/gym-fitness/dev/index.ts +20 -0
  149. package/templates/gym-fitness/l10n/ar.json +10 -0
  150. package/templates/gym-fitness/l10n/cs.json +10 -0
  151. package/templates/gym-fitness/l10n/da.json +10 -0
  152. package/templates/gym-fitness/l10n/de.json +10 -0
  153. package/templates/gym-fitness/l10n/el.json +10 -0
  154. package/templates/gym-fitness/l10n/es.json +10 -0
  155. package/templates/gym-fitness/l10n/fi.json +10 -0
  156. package/templates/gym-fitness/l10n/fr.json +10 -0
  157. package/templates/gym-fitness/l10n/he.json +8 -0
  158. package/templates/gym-fitness/l10n/hu.json +10 -0
  159. package/templates/gym-fitness/l10n/id.json +10 -0
  160. package/templates/gym-fitness/l10n/it.json +10 -0
  161. package/templates/gym-fitness/l10n/ja.json +10 -0
  162. package/templates/gym-fitness/l10n/ko.json +10 -0
  163. package/templates/gym-fitness/l10n/lt.json +10 -0
  164. package/templates/gym-fitness/l10n/nl.json +10 -0
  165. package/templates/gym-fitness/l10n/no.json +10 -0
  166. package/templates/gym-fitness/l10n/pl.json +10 -0
  167. package/templates/gym-fitness/l10n/pt.json +10 -0
  168. package/templates/gym-fitness/l10n/ru.json +10 -0
  169. package/templates/gym-fitness/l10n/sv.json +10 -0
  170. package/templates/gym-fitness/l10n/th.json +10 -0
  171. package/templates/gym-fitness/l10n/tr.json +10 -0
  172. package/templates/gym-fitness/l10n/uk.json +10 -0
  173. package/templates/gym-fitness/l10n/vi.json +10 -0
  174. package/templates/gym-fitness/l10n/zh.json +10 -0
  175. package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +6 -1
  176. package/templates/gym-fitness/tier5-src/_shared/himi-events.ts +27 -0
  177. package/templates/gym-fitness/tier5-src/himi-events-detail/index.ts +3 -1
  178. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +38 -8
  179. package/templates/gym-fitness/tier5-src/himi-events-my-events/index.ts +4 -2
  180. package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +6 -1
  181. package/templates/gym-fitness-owner/tier5-src/_shared/himi-events.ts +27 -0
  182. package/templates/medical-services/config.ts +42 -0
  183. package/templates/medical-services/dev/index.ts +4136 -0
  184. package/templates/medical-services/himalaya.content.json +18 -0
  185. package/templates/medical-services/tier5-src/_shared/collection-contract.ts +6 -1
  186. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  187. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  188. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  189. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  190. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  191. package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  192. package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  193. package/templates/nonprofit-cause/dev/index.ts +20 -0
  194. package/templates/nonprofit-cause/l10n/ar.json +10 -0
  195. package/templates/nonprofit-cause/l10n/cs.json +10 -0
  196. package/templates/nonprofit-cause/l10n/da.json +10 -0
  197. package/templates/nonprofit-cause/l10n/de.json +10 -0
  198. package/templates/nonprofit-cause/l10n/el.json +10 -0
  199. package/templates/nonprofit-cause/l10n/es.json +10 -0
  200. package/templates/nonprofit-cause/l10n/fi.json +10 -0
  201. package/templates/nonprofit-cause/l10n/fr.json +10 -0
  202. package/templates/nonprofit-cause/l10n/he.json +8 -0
  203. package/templates/nonprofit-cause/l10n/hu.json +10 -0
  204. package/templates/nonprofit-cause/l10n/id.json +10 -0
  205. package/templates/nonprofit-cause/l10n/it.json +10 -0
  206. package/templates/nonprofit-cause/l10n/ja.json +10 -0
  207. package/templates/nonprofit-cause/l10n/ko.json +10 -0
  208. package/templates/nonprofit-cause/l10n/lt.json +10 -0
  209. package/templates/nonprofit-cause/l10n/nl.json +10 -0
  210. package/templates/nonprofit-cause/l10n/no.json +10 -0
  211. package/templates/nonprofit-cause/l10n/pl.json +10 -0
  212. package/templates/nonprofit-cause/l10n/pt.json +10 -0
  213. package/templates/nonprofit-cause/l10n/ru.json +10 -0
  214. package/templates/nonprofit-cause/l10n/sv.json +10 -0
  215. package/templates/nonprofit-cause/l10n/th.json +10 -0
  216. package/templates/nonprofit-cause/l10n/tr.json +10 -0
  217. package/templates/nonprofit-cause/l10n/uk.json +10 -0
  218. package/templates/nonprofit-cause/l10n/vi.json +10 -0
  219. package/templates/nonprofit-cause/l10n/zh.json +10 -0
  220. package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +6 -1
  221. package/templates/nonprofit-cause/tier5-src/_shared/himi-events.ts +27 -0
  222. package/templates/nonprofit-cause/tier5-src/himi-events-detail/index.ts +3 -1
  223. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +38 -8
  224. package/templates/nonprofit-cause/tier5-src/himi-events-my-events/index.ts +4 -2
  225. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +6 -1
  226. package/templates/nonprofit-cause-owner/tier5-src/_shared/himi-events.ts +27 -0
  227. package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +6 -1
  228. package/templates/owner-lite/tier5-src/_shared/himi-events.ts +27 -0
  229. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-contract.ts +6 -1
  230. package/templates/podcast-creator/dev/index.ts +20 -0
  231. package/templates/podcast-creator/l10n/ar.json +10 -0
  232. package/templates/podcast-creator/l10n/cs.json +10 -0
  233. package/templates/podcast-creator/l10n/da.json +10 -0
  234. package/templates/podcast-creator/l10n/de.json +10 -0
  235. package/templates/podcast-creator/l10n/el.json +10 -0
  236. package/templates/podcast-creator/l10n/es.json +10 -0
  237. package/templates/podcast-creator/l10n/fi.json +10 -0
  238. package/templates/podcast-creator/l10n/fr.json +10 -0
  239. package/templates/podcast-creator/l10n/he.json +8 -0
  240. package/templates/podcast-creator/l10n/hu.json +10 -0
  241. package/templates/podcast-creator/l10n/id.json +10 -0
  242. package/templates/podcast-creator/l10n/it.json +10 -0
  243. package/templates/podcast-creator/l10n/ja.json +10 -0
  244. package/templates/podcast-creator/l10n/ko.json +10 -0
  245. package/templates/podcast-creator/l10n/lt.json +10 -0
  246. package/templates/podcast-creator/l10n/nl.json +10 -0
  247. package/templates/podcast-creator/l10n/no.json +10 -0
  248. package/templates/podcast-creator/l10n/pl.json +10 -0
  249. package/templates/podcast-creator/l10n/pt.json +10 -0
  250. package/templates/podcast-creator/l10n/ru.json +10 -0
  251. package/templates/podcast-creator/l10n/sv.json +10 -0
  252. package/templates/podcast-creator/l10n/th.json +10 -0
  253. package/templates/podcast-creator/l10n/tr.json +10 -0
  254. package/templates/podcast-creator/l10n/uk.json +10 -0
  255. package/templates/podcast-creator/l10n/vi.json +10 -0
  256. package/templates/podcast-creator/l10n/zh.json +10 -0
  257. package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +6 -1
  258. package/templates/podcast-creator/tier5-src/_shared/himi-events.ts +27 -0
  259. package/templates/podcast-creator/tier5-src/himi-events-detail/index.ts +3 -1
  260. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +38 -8
  261. package/templates/podcast-creator/tier5-src/himi-events-my-events/index.ts +4 -2
  262. package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +6 -1
  263. package/templates/podcast-creator-owner/tier5-src/_shared/himi-events.ts +27 -0
  264. package/templates/portfolio-creative/dev/index.ts +22 -1
  265. package/templates/portfolio-creative/l10n/ar.json +10 -0
  266. package/templates/portfolio-creative/l10n/cs.json +10 -0
  267. package/templates/portfolio-creative/l10n/da.json +10 -0
  268. package/templates/portfolio-creative/l10n/de.json +10 -0
  269. package/templates/portfolio-creative/l10n/el.json +10 -0
  270. package/templates/portfolio-creative/l10n/es.json +10 -0
  271. package/templates/portfolio-creative/l10n/fi.json +10 -0
  272. package/templates/portfolio-creative/l10n/fr.json +10 -0
  273. package/templates/portfolio-creative/l10n/he.json +8 -0
  274. package/templates/portfolio-creative/l10n/hu.json +10 -0
  275. package/templates/portfolio-creative/l10n/id.json +10 -0
  276. package/templates/portfolio-creative/l10n/it.json +10 -0
  277. package/templates/portfolio-creative/l10n/ja.json +10 -0
  278. package/templates/portfolio-creative/l10n/ko.json +10 -0
  279. package/templates/portfolio-creative/l10n/lt.json +10 -0
  280. package/templates/portfolio-creative/l10n/nl.json +10 -0
  281. package/templates/portfolio-creative/l10n/no.json +10 -0
  282. package/templates/portfolio-creative/l10n/pl.json +10 -0
  283. package/templates/portfolio-creative/l10n/pt.json +10 -0
  284. package/templates/portfolio-creative/l10n/ru.json +10 -0
  285. package/templates/portfolio-creative/l10n/sv.json +10 -0
  286. package/templates/portfolio-creative/l10n/th.json +10 -0
  287. package/templates/portfolio-creative/l10n/tr.json +10 -0
  288. package/templates/portfolio-creative/l10n/uk.json +10 -0
  289. package/templates/portfolio-creative/l10n/vi.json +10 -0
  290. package/templates/portfolio-creative/l10n/zh.json +10 -0
  291. package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +6 -1
  292. package/templates/portfolio-creative/tier5-src/_shared/himi-events.ts +27 -0
  293. package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
  294. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
  295. package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
  296. package/templates/portfolio-creative/tier5-src/himi-events-detail/index.ts +3 -1
  297. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +38 -8
  298. package/templates/portfolio-creative/tier5-src/himi-events-my-events/index.ts +4 -2
  299. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +6 -1
  300. package/templates/portfolio-creative-owner/tier5-src/_shared/himi-events.ts +27 -0
  301. package/templates/professional-services/README.md +55 -0
  302. package/templates/professional-services/config.ts +436 -0
  303. package/templates/professional-services/dev/index.ts +44772 -0
  304. package/templates/professional-services/himalaya.content.json +100 -0
  305. package/templates/professional-services/himalaya.template.json +16 -0
  306. package/templates/professional-services/icon.png +0 -0
  307. package/templates/professional-services/platforms.json +1 -0
  308. package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
  309. package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
  310. package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
  311. package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  312. package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
  313. package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
  314. package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
  315. package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
  316. package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
  317. package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
  318. package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
  319. package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
  320. package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
  321. package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
  322. package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
  323. package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
  324. package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
  325. package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
  326. package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
  327. package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
  328. package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
  329. package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
  330. package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
  331. package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
  332. package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
  333. package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
  334. package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
  335. package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
  336. package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
  337. package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
  338. package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
  339. package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
  340. package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
  341. package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
  342. package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
  343. package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
  344. package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
  345. package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
  346. package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
  347. package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
  348. package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
  349. package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
  350. package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
  351. package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
  352. package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
  353. package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
  354. package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
  355. package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
  356. package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
  357. package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
  358. package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
  359. package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
  360. package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
  361. package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
  362. package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
  363. package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
  364. package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
  365. package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
  366. package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
  367. package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
  368. package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
  369. package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
  370. package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
  371. package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
  372. package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
  373. package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
  374. package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
  375. package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
  376. package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
  377. package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
  378. package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
  379. package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
  380. package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
  381. package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
  382. package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
  383. package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
  384. package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
  385. package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
  386. package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
  387. package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
  388. package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
  389. package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
  390. package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
  391. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
  392. package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
  393. package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
  394. package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
  395. package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
  396. package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
  397. package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
  398. package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
  399. package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
  400. package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
  401. package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
  402. package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
  403. package/templates/professional-services/tokens.json +456 -0
  404. package/templates/restaurant/dev/index.ts +20 -0
  405. package/templates/restaurant/l10n/ar.json +10 -0
  406. package/templates/restaurant/l10n/cs.json +10 -0
  407. package/templates/restaurant/l10n/da.json +10 -0
  408. package/templates/restaurant/l10n/de.json +10 -0
  409. package/templates/restaurant/l10n/el.json +10 -0
  410. package/templates/restaurant/l10n/es.json +10 -0
  411. package/templates/restaurant/l10n/fi.json +10 -0
  412. package/templates/restaurant/l10n/fr.json +10 -0
  413. package/templates/restaurant/l10n/he.json +8 -0
  414. package/templates/restaurant/l10n/hu.json +10 -0
  415. package/templates/restaurant/l10n/id.json +10 -0
  416. package/templates/restaurant/l10n/it.json +10 -0
  417. package/templates/restaurant/l10n/ja.json +10 -0
  418. package/templates/restaurant/l10n/ko.json +10 -0
  419. package/templates/restaurant/l10n/lt.json +10 -0
  420. package/templates/restaurant/l10n/nl.json +10 -0
  421. package/templates/restaurant/l10n/no.json +10 -0
  422. package/templates/restaurant/l10n/pl.json +10 -0
  423. package/templates/restaurant/l10n/pt.json +10 -0
  424. package/templates/restaurant/l10n/ru.json +10 -0
  425. package/templates/restaurant/l10n/sv.json +10 -0
  426. package/templates/restaurant/l10n/th.json +10 -0
  427. package/templates/restaurant/l10n/tr.json +10 -0
  428. package/templates/restaurant/l10n/uk.json +10 -0
  429. package/templates/restaurant/l10n/vi.json +10 -0
  430. package/templates/restaurant/l10n/zh.json +10 -0
  431. package/templates/restaurant/tier5-src/_shared/collection-contract.ts +6 -1
  432. package/templates/restaurant/tier5-src/_shared/himi-events.ts +27 -0
  433. package/templates/restaurant/tier5-src/himi-events-detail/index.ts +3 -1
  434. package/templates/restaurant/tier5-src/himi-events-list/index.ts +38 -8
  435. package/templates/restaurant/tier5-src/himi-events-my-events/index.ts +4 -2
  436. package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +6 -1
  437. package/templates/restaurant-owner/tier5-src/_shared/himi-events.ts +27 -0
  438. package/templates/retail-store/tier5-src/_shared/collection-contract.ts +6 -1
  439. package/templates/retail-store/tier5-src/_shared/himi-events.ts +27 -0
  440. package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +6 -1
  441. package/templates/retail-store-owner/tier5-src/_shared/himi-events.ts +27 -0
  442. package/templates/salon-spa/config.ts +42 -0
  443. package/templates/salon-spa/dev/index.ts +4136 -0
  444. package/templates/salon-spa/himalaya.content.json +18 -0
  445. package/templates/salon-spa/tier5-src/_shared/collection-contract.ts +6 -1
  446. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  447. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  448. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  449. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  450. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  451. package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  452. package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  453. package/templates/wholesale-store/config.ts +43 -1
  454. package/templates/wholesale-store/dev/index.ts +4136 -0
  455. package/templates/wholesale-store/himalaya.content.json +18 -0
  456. package/templates/wholesale-store/tier5-src/_shared/collection-contract.ts +6 -1
  457. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
  458. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
  459. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
  460. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
  461. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
  462. package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
  463. package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  464. package/templates/yoga-studio/dev/index.ts +20 -0
  465. package/templates/yoga-studio/l10n/ar.json +10 -0
  466. package/templates/yoga-studio/l10n/cs.json +10 -0
  467. package/templates/yoga-studio/l10n/da.json +10 -0
  468. package/templates/yoga-studio/l10n/de.json +10 -0
  469. package/templates/yoga-studio/l10n/el.json +10 -0
  470. package/templates/yoga-studio/l10n/es.json +10 -0
  471. package/templates/yoga-studio/l10n/fi.json +10 -0
  472. package/templates/yoga-studio/l10n/fr.json +10 -0
  473. package/templates/yoga-studio/l10n/he.json +8 -0
  474. package/templates/yoga-studio/l10n/hu.json +10 -0
  475. package/templates/yoga-studio/l10n/id.json +10 -0
  476. package/templates/yoga-studio/l10n/it.json +10 -0
  477. package/templates/yoga-studio/l10n/ja.json +10 -0
  478. package/templates/yoga-studio/l10n/ko.json +10 -0
  479. package/templates/yoga-studio/l10n/lt.json +10 -0
  480. package/templates/yoga-studio/l10n/nl.json +10 -0
  481. package/templates/yoga-studio/l10n/no.json +10 -0
  482. package/templates/yoga-studio/l10n/pl.json +10 -0
  483. package/templates/yoga-studio/l10n/pt.json +10 -0
  484. package/templates/yoga-studio/l10n/ru.json +10 -0
  485. package/templates/yoga-studio/l10n/sv.json +10 -0
  486. package/templates/yoga-studio/l10n/th.json +10 -0
  487. package/templates/yoga-studio/l10n/tr.json +10 -0
  488. package/templates/yoga-studio/l10n/uk.json +10 -0
  489. package/templates/yoga-studio/l10n/vi.json +10 -0
  490. package/templates/yoga-studio/l10n/zh.json +10 -0
  491. package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +6 -1
  492. package/templates/yoga-studio/tier5-src/_shared/himi-events.ts +27 -0
  493. package/templates/yoga-studio/tier5-src/himi-events-detail/index.ts +3 -1
  494. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +38 -8
  495. package/templates/yoga-studio/tier5-src/himi-events-my-events/index.ts +4 -2
  496. package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +6 -1
  497. package/templates/yoga-studio-owner/tier5-src/_shared/himi-events.ts +27 -0
@@ -0,0 +1,1239 @@
1
+ // Tier-5 bundle: Himi Blog post detail - reader content plus member actions.
2
+ import { defineService, navigate } from "@himalaya/state";
3
+ import { snackbar } from "@himalaya/ui";
4
+ import { share as shareSheet } from "@himalaya/share";
5
+ import { getPost, likePost, unlikePost, queryPosts, queryCategories, queryTags, type WixPost, type WixPostWithContent, type WixQueryPostsRequest } from "@himalaya/wix-blog";
6
+ import { likedBlogComments, listBlogCommentPage, postBlogComment, setBlogCommentLike, type WixBlogCommentRow } from "@himalaya/wix-comments";
7
+ import { getMyMember } from "@himalaya/wix-members";
8
+ import { dismiss as dismissKeyboard } from "@himalaya/keyboard";
9
+ import { get, type DbEntity } from "@himalaya/local-db";
10
+ import { isSavedId, toggleSavedId } from "../_shared/himi-blog-saved";
11
+ import { hideId, isHiddenId, unhideId } from "../_shared/himi-blog-hidden";
12
+ import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
13
+ import { formatDateMedium } from "../_shared/engine-intl.js";
14
+ import { relativeTime } from "../_shared/relative-time.js";
15
+ import { openRichLink } from "../_shared/rich-content-link.js";
16
+ import { richBody, ROW_IMAGE_WIDTH } from "../_shared/rich-body.js";
17
+ import { readAccess, assertReadAccess, readAccessDenied, readSignInFlags, NO_READ_SIGN_IN, type ReadAccess } from "../_shared/member-read.js";
18
+ import { authorFields, BLOG_HERO_IMAGE, BLOG_THUMB_IMAGE, commentsLabelFor, type BlogAuthor, countsOf, coverOf, dateLineOf, dateOf, legacyRowFixes, LIST_FIELDSETS, cachedCover, NO_AUTHOR, likesLabelFor, profilePhoto, resolveAuthors, viewsLabelFor, type AuthorFields, type BlogPostShape } from "../_shared/himi-blog-post-row.js";
19
+
20
+ // Offline-first (data-offline): the post body is a public read-through — when the
21
+ // live fetch fails (offline) fall back to the last-synced row the feed cached under
22
+ // the `blog_posts` entity, so a previously-seen post still opens. The saved-id KV is
23
+ // untouched (it stays himalaya.storage). DEGRADES GRACEFULLY: the local-db read is
24
+ // wrapped so an app without the `local_database` grant behaves exactly as before.
25
+ const ENTITY = "blog_posts";
26
+ async function readCachedPost(id: string): Promise<DbEntity | null> {
27
+ try { return await get(ENTITY, id); } catch { /* capability not granted → online-only */ return null; }
28
+ }
29
+
30
+ /** How many "Recent posts" rows the end of the post shows. */
31
+ const RECENT_COUNT = 3;
32
+ /** How many comments the post's comments box shows (the newest); the sheet shows them all. */
33
+ const LATEST_COMMENTS = 3;
34
+ /** Top-level comments per page the comments sheet reads. */
35
+ const COMMENTS_PAGE = 20;
36
+
37
+ interface CommentRow {
38
+ id: string;
39
+ /** A reply's parent comment id ("" on a top-level comment). Replies are one level deep. */
40
+ parentId: string;
41
+ isReply: boolean;
42
+ notReply: boolean;
43
+ /** The author's member id ("" for a visitor): the row's name and photo come from it. */
44
+ authorMemberId: string;
45
+ authorName: string;
46
+ /** The author's first letter, for the round initial when there is no photo. */
47
+ authorInitial: string;
48
+ authorPhoto: string;
49
+ hasAuthorPhoto: boolean;
50
+ noAuthorPhoto: boolean;
51
+ /** The comment's plain text: the row RichContent's fallback. */
52
+ text: string;
53
+ /** The box's two-line preview: the text with no empty lines between its paragraphs. */
54
+ preview: string;
55
+ /** When it was written, relative ("2 hours ago") for the last week. */
56
+ meta: string;
57
+ createdDate: string;
58
+ /** [rico] #3372 — the comment's Ricos document as ONE string for the row's RichContent; "" when it has none
59
+ * or the encoder rejected it. */
60
+ bodyJson: string;
61
+ /** bodyJson !== "" — gates the row's plain text, because RichContent draws nothing for "". */
62
+ hasBodyJson: boolean;
63
+ /** Likes: the count, the reader's own like, and `noLikes` when the site sent no reaction summary
64
+ * (it takes no reactions there, so Like is not offered). */
65
+ likeCount: number;
66
+ likes: string;
67
+ liked: boolean;
68
+ notLiked: boolean;
69
+ noLikes: boolean;
70
+ /** No Reply on this site (its comments carry no reply count). */
71
+ noReply: boolean;
72
+ /** The ⋮ menu's Report is not offered: the reader's own comment, or one they reported. */
73
+ noReport: boolean;
74
+ /** The comment the reader just sent, tinted until the sheet closes or they send another. */
75
+ highlight: boolean;
76
+ /** The row's background token: `accentSurface` while highlighted, "" otherwise. */
77
+ rowBackground: string;
78
+ }
79
+
80
+ interface TagRow { id: string; label: string }
81
+
82
+ /** One "Recent posts" row: the photo (or none), the title and the date. */
83
+ interface RecentRow {
84
+ id: string;
85
+ title: string;
86
+ date: string;
87
+ cover: string;
88
+ hasCover: boolean;
89
+ noCover: boolean;
90
+ detailScreenId: string;
91
+ }
92
+
93
+ interface S extends AuthorFields {
94
+ signInRequired: boolean; noSignIn: boolean; signInScreenId: string;
95
+ status: "loading" | "ready" | "error";
96
+ id: string;
97
+ commentResourceId: string;
98
+ title: string;
99
+ /** "Jul 30, 2026 · 4 min read". */
100
+ subtitle: string;
101
+ /** "Updated Aug 2, 2026" when the post changed on a later day than it was published; "" otherwise. */
102
+ updatedLine: string;
103
+ /** The post's first category's name ("" when it has none). */
104
+ categoryLabel: string;
105
+ hasCategory: boolean;
106
+ noCategory: boolean;
107
+ tags: TagRow[];
108
+ /** The tags read failed: the post shows no tags rather than claiming it has none. */
109
+ tagsUnavailable: boolean;
110
+ hasTags: boolean;
111
+ noTags: boolean;
112
+ /** Counts, as strings for the counts row; null / "" when the read carried no counts (never zeros).
113
+ * `likeCount` is the number the Like toggle shows. */
114
+ likeCount: number | null;
115
+ hasCounts: boolean;
116
+ noCounts: boolean;
117
+ likes: string;
118
+ views: string;
119
+ commentCount: string;
120
+ /** The spoken counts ("1 like", "3 views", "2 comments"). */
121
+ likesLabel: string;
122
+ viewsLabel: string;
123
+ commentsLabel: string;
124
+ /** [rico] #3370 — the body as ONE Ricos document JSON string for RichContent: the encoder has
125
+ * sized its media and dropped disallowed links. "" when the post has none, or the encoder rejected it. */
126
+ bodyJson: string;
127
+ /** bodyJson !== "" — gates the plain text, because RichContent draws nothing for "". */
128
+ hasBodyJson: boolean;
129
+ /** Plain text of the body: RichContent's `fallback`, and what shows when there is no document. */
130
+ bodyText: string;
131
+ /** Share payload — the post's public URL when the payload carries one. */
132
+ shareUrl: string;
133
+ /** Blog v3 `preview`: the body is the free part of a paid post. The screen ends it with a notice. */
134
+ isPaid: boolean;
135
+ notPaid: boolean;
136
+ /** The paid notice's website link shows only when there is a URL to open. */
137
+ noShareUrl: boolean;
138
+ cover: string;
139
+ hasCover: boolean;
140
+ noCover: boolean;
141
+ initial: string;
142
+ liked: boolean;
143
+ notLiked: boolean;
144
+ saved: boolean;
145
+ notSaved: boolean;
146
+ /** This device's reader hid the post: the feed, Home and Saved leave it out, and this screen offers Undo. */
147
+ hidden: boolean;
148
+ notHidden: boolean;
149
+ /** The ⋯ sheet (Report, Hide) is open. */
150
+ moreSheetOpen: boolean;
151
+ /** The reason sheet (offensive / misleading / other) is open. */
152
+ hideSheetOpen: boolean;
153
+ /** The reader reported the post this visit; the report row then goes and the tap stops sending. */
154
+ reported: boolean;
155
+ notReported: boolean;
156
+ commentText: string;
157
+ /** Every loaded comment, newest first, each one's replies under it (oldest reply first). */
158
+ comments: CommentRow[];
159
+ /** The newest LATEST_COMMENTS top-level comments: the post's comments box. */
160
+ latestComments: CommentRow[];
161
+ hasComments: boolean;
162
+ noComments: boolean;
163
+ /** "Show all (N)" — the box's link to the comments sheet. */
164
+ showAllLabel: string;
165
+ /** The comments sheet ("Show all", a tap on the box's input or on Reply) is open. */
166
+ commentsSheetOpen: boolean;
167
+ /** The cursor of the next page of comments ("" when they are all loaded). */
168
+ commentsCursor: string;
169
+ hasMoreComments: boolean;
170
+ noMoreComments: boolean;
171
+ /** A nonce: a new value focuses the sheet's comment field (and opens the keyboard). */
172
+ composerFocus: string;
173
+ /** The comment a reply goes to ("" = a new comment), and "Replying to <name>". */
174
+ replyToId: string;
175
+ replyingLine: string;
176
+ isReplying: boolean;
177
+ notReplying: boolean;
178
+ /** The field has text to send. */
179
+ canSend: boolean;
180
+ cannotSend: boolean;
181
+ /** Why the last send failed, under the field ("" = none). The text stays to send again. */
182
+ sendError: string;
183
+ noSendError: boolean;
184
+ /** The reader is a signed-in member (a visitor signs in before a comment, a like or a reply). */
185
+ isMember: boolean;
186
+ /** The member's own id, name, photo and initial: the comment inputs' avatar and their new comments. */
187
+ memberId: string;
188
+ memberName: string;
189
+ memberPhoto: string;
190
+ memberInitial: string;
191
+ hasMemberPhoto: boolean;
192
+ noMemberPhoto: boolean;
193
+ commentsTitle: string;
194
+ /** "Comments (N)" in the sheet. */
195
+ sheetTitle: string;
196
+ commentsUnavailable: boolean;
197
+ commentsAvailable: boolean;
198
+ /** The owner turned comments off for this post (Blog v3 `commentingEnabled: false`). */
199
+ commentsOff: boolean;
200
+ commentsOn: boolean;
201
+ commentStatusText: string;
202
+ noCommentStatus: boolean;
203
+ /** The comments loaded, there are none, and the post takes comments: the box's empty state. */
204
+ commentsEmpty: boolean;
205
+ notCommentsEmpty: boolean;
206
+ recent: RecentRow[];
207
+ /** A "Recent posts" read failed; the section shows what the other reads found. */
208
+ recentUnavailable: boolean;
209
+ hasRecent: boolean;
210
+ noRecent: boolean;
211
+ emptyText: string;
212
+ errorText: string;
213
+ hasPost: boolean;
214
+ noPost: boolean;
215
+ isLoading: boolean;
216
+ notLoading: boolean;
217
+ errored: boolean;
218
+ notErrored: boolean;
219
+ blogScreenId: string;
220
+ }
221
+
222
+ type PostWithExtras = WixPostWithContent & BlogPostShape & {
223
+ richContent?: unknown;
224
+ contentText?: string;
225
+ plainContent?: string;
226
+ url?: { base?: string; path?: string } | string;
227
+ tagIds?: string[];
228
+ relatedPostIds?: string[];
229
+ commentingEnabled?: boolean;
230
+ preview?: boolean;
231
+ memberInteraction?: { liked?: boolean };
232
+ };
233
+
234
+ /** The post's public URL when the payload carries one ("" otherwise). */
235
+ function postShareUrl(post: PostWithExtras): string {
236
+ if (typeof post.url === "string" && /^https?:\/\//i.test(post.url)) return post.url;
237
+ if (post.url && typeof post.url === "object" && typeof post.url.base === "string" && post.url.base) {
238
+ const path = typeof post.url.path === "string" ? post.url.path : "";
239
+ return `${post.url.base.replace(/\/$/, "")}${path && !path.startsWith("/") ? "/" : ""}${path}`;
240
+ }
241
+ return "";
242
+ }
243
+
244
+ function inputId(): string {
245
+ const input = (globalThis as { himalaya?: { input?: { id?: string; screenId?: string } } }).himalaya?.input;
246
+ if (typeof input?.id === "string" && input.id) return input.id;
247
+ // WS-C — `himalaya.input.id` is the PRIMARY contract: hosts thread the row's
248
+ // `id` nav param (himi.open { screenId: "himi_blog_post", id }) into worker
249
+ // input. The slice below is #570 back-compat for pre-params releases with
250
+ // baked `himi_blog_post_<id>` screenIds — do not author against this.
251
+ // Historical rationale (why input.id was ever absent): a baked
252
+ // `himi_blog_post_<id>` screenId is ALSO prefixed by the shorter param-less
253
+ // `himi_blog` linkable, so the screenId→params match resolved to the linkable
254
+ // and dropped the id. Canonical ids + first-class params dissolve that
255
+ // collision — the canonical `himi_blog_post` never carries a baked suffix.
256
+ const screenId = typeof input?.screenId === "string" ? input.screenId : "";
257
+ const prefix = "himi_blog_post_";
258
+ return screenId.startsWith(prefix) ? screenId.slice(prefix.length) : "";
259
+ }
260
+
261
+ function strOf(arg: unknown): string {
262
+ if (typeof arg === "string") return arg;
263
+ const a = arg as { value?: string; text?: string } | undefined;
264
+ return a?.value ?? a?.text ?? "";
265
+ }
266
+
267
+ /** "Updated <date>" when the last publish is on a later day than the first ("" otherwise). */
268
+ function updatedLineOf(post: PostWithExtras): string {
269
+ if (!post.firstPublishedDate || !post.lastPublishedDate) return "";
270
+ const first = new Date(post.firstPublishedDate), last = new Date(post.lastPublishedDate);
271
+ if (Number.isNaN(first.getTime()) || Number.isNaN(last.getTime())) return "";
272
+ if (formatDateMedium(last) === formatDateMedium(first) || last.getTime() < first.getTime()) return "";
273
+ return copyTemplate("blogPost.updatedLine", "Updated {date}", { date: formatDateMedium(last) });
274
+ }
275
+
276
+ function bodyText(post: PostWithExtras): string {
277
+ return post.plainContent || post.contentText || post.excerpt || copyParam("blogPost.bodyFallback", "This post has no readable body yet.");
278
+ }
279
+
280
+ /** The reader's own profile, for the comment inputs' avatar and the comments they send. */
281
+ interface Me { id: string; name: string; photo: string }
282
+ const NO_ME: Me = { id: "", name: "", photo: "" };
283
+
284
+ function toCommentRow(row: WixBlogCommentRow, authors: Map<string, BlogAuthor>, liked: ReadonlySet<string>, now = Date.now()): CommentRow {
285
+ // The plain text is the document's own (runs joined as written, not space-separated) when it has one.
286
+ // `forum.commentCta` is the app's one "Comment": the pack forwards that single key to this screen (see the prefixes).
287
+ const { bodyJson, bodyText } = richBody(row.richContent, row.text || copyParam("forum.commentCta", "Comment"), ROW_IMAGE_WIDTH);
288
+ const memberId = row.authorMemberId ?? "";
289
+ // The Comments API names an author by id only: the public profile names them. "Member" only for an
290
+ // author with no public profile (a visitor, a private profile).
291
+ const author = authors.get(memberId);
292
+ const authorName = author?.name || row.authorName || copyParam("blogPost.memberFallback", "Member");
293
+ const photo = author?.photo ?? "";
294
+ const likeCount = Math.max(0, row.reactionTotal ?? 0);
295
+ const isLiked = liked.has(row.id);
296
+ const parentId = row.parentCommentId ?? "";
297
+ return {
298
+ id: row.id,
299
+ parentId,
300
+ isReply: !!parentId,
301
+ notReply: !parentId,
302
+ authorMemberId: memberId,
303
+ authorName,
304
+ authorInitial: (authorName[0] || "#").toUpperCase(),
305
+ authorPhoto: photo,
306
+ hasAuthorPhoto: !!photo,
307
+ noAuthorPhoto: !photo,
308
+ text: bodyText,
309
+ preview: bodyText.split(/\n\s*\n+/).join("\n").trim(),
310
+ meta: relativeTime(row.createdDate, skewedNow(row.createdDate, now)),
311
+ createdDate: row.createdDate,
312
+ bodyJson,
313
+ hasBodyJson: bodyJson !== "",
314
+ likeCount,
315
+ likes: String(likeCount),
316
+ liked: isLiked,
317
+ notLiked: !isLiked,
318
+ noLikes: row.reactionTotal === undefined,
319
+ noReply: row.replyCount === undefined && !parentId,
320
+ noReport: reportedComments.has(row.id),
321
+ highlight: false,
322
+ rowBackground: "",
323
+ };
324
+ }
325
+
326
+ const HIGHLIGHT = "accentSurface";
327
+ const unhighlighted = (row: CommentRow): CommentRow => row.highlight ? { ...row, highlight: false, rowBackground: "" } : row;
328
+
329
+ /** The site's clock can run a few seconds ahead of the device: a comment just sent then reads as
330
+ * in the future, which `relativeTime` shows as a date. Up to CLOCK_SKEW_MS ahead counts as now. */
331
+ const CLOCK_SKEW_MS = 5 * 60_000;
332
+ function skewedNow(iso: string, now: number): number {
333
+ const at = Date.parse(iso);
334
+ return Number.isFinite(at) && at > now && at - now <= CLOCK_SKEW_MS ? at : now;
335
+ }
336
+
337
+ /** Comments this reader reported in this session: Report is not offered on them again. No site
338
+ * API takes a member's report on a comment, so, as for the post, the tap is the signal. */
339
+ const reportedComments = new Set<string>();
340
+
341
+ /** Report is not offered on the reader's own comments. */
342
+ const withOwnComments = (rows: CommentRow[], memberId: string): CommentRow[] =>
343
+ memberId ? rows.map((row) => row.authorMemberId === memberId && !row.noReport ? { ...row, noReport: true } : row) : rows;
344
+
345
+ /** A row with a new like state and count. */
346
+ function withLike(row: CommentRow, liked: boolean): CommentRow {
347
+ const likeCount = Math.max(0, row.likeCount + (liked === row.liked ? 0 : liked ? 1 : -1));
348
+ return { ...row, liked, notLiked: !liked, likeCount, likes: String(likeCount) };
349
+ }
350
+
351
+ /** Add a sent comment: a new one at the top, a reply after its parent's last reply. */
352
+ function insertComment(rows: CommentRow[], created: CommentRow): CommentRow[] {
353
+ const plain = rows.map(unhighlighted);
354
+ if (!created.parentId) return [created, ...plain];
355
+ let at = plain.findIndex((row) => row.id === created.parentId);
356
+ if (at < 0) return [created, ...plain];
357
+ while (plain[at + 1]?.parentId === created.parentId) at++;
358
+ return [...plain.slice(0, at + 1), created, ...plain.slice(at + 1)];
359
+ }
360
+
361
+ const commentsTitleFor = (count: number): string =>
362
+ count > 0 ? copyTemplate("blogPost.commentsTitleCount", "Comments ({count})", { count }) : copyParam("blogPost.commentsTitle", "Comments");
363
+
364
+ function toRecentRow(post: WixPost): RecentRow {
365
+ const cover = coverOf(post as PostWithExtras, BLOG_THUMB_IMAGE);
366
+ return { id: post.id, title: post.title || copyParam("blogCommon.untitled", "Untitled post"), date: dateOf(post as PostWithExtras), cover, hasCover: !!cover, noCover: !cover, detailScreenId: "himi_blog_post" };
367
+ }
368
+
369
+ /** Up to three other posts: the owner's related posts, then the newest in the same category,
370
+ * then the newest overall. Never the current post or one this device hid. A failed read
371
+ * leaves that step out: the section shows what the earlier steps found, or nothing. */
372
+ /** How many candidates each "Recent posts" read asks for: enough that the current post and a few
373
+ * hidden ones can be left out and three still remain. */
374
+ const RECENT_CANDIDATES = 10;
375
+
376
+ async function loadRecent(post: PostWithExtras): Promise<{ posts: WixPost[]; failed: boolean }> {
377
+ const picked: WixPost[] = [];
378
+ // A failed read is recorded: the section then shows what the other reads found.
379
+ let failed = false;
380
+ const seen = new Set<string>([post.id]);
381
+ const add = (posts: WixPost[] | undefined) => {
382
+ for (const candidate of posts ?? []) {
383
+ if (picked.length >= RECENT_COUNT) return;
384
+ if (!candidate?.id || seen.has(candidate.id) || isHiddenId(candidate.id)) continue;
385
+ seen.add(candidate.id);
386
+ picked.push(candidate);
387
+ }
388
+ };
389
+ const query = async (filter: Record<string, unknown> | undefined): Promise<WixPost[] | undefined> => {
390
+ const base = { ...(filter ? { filter } : {}), paging: { limit: RECENT_CANDIDATES } };
391
+ // Newest first; a source that refuses the sort is asked again without it, as the feed does.
392
+ try {
393
+ return (await queryPosts({ query: { ...base, sort: [{ fieldName: "firstPublishedDate", order: "DESC" }] }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest)).posts;
394
+ } catch { /* asked again below */ }
395
+ try {
396
+ return (await queryPosts({ query: base, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest)).posts;
397
+ } catch { failed = true; }
398
+ return undefined;
399
+ };
400
+ const related = (post.relatedPostIds ?? []).filter((id) => typeof id === "string" && id);
401
+ if (related.length) add(await query({ id: { $in: related } }));
402
+ const category = post.categoryIds?.[0];
403
+ if (picked.length < RECENT_COUNT && category) add(await query({ categoryIds: { $hasSome: [category] } }));
404
+ if (picked.length < RECENT_COUNT) add(await query(undefined));
405
+ return { posts: picked, failed };
406
+ }
407
+
408
+ async function loadCategoryLabel(post: PostWithExtras): Promise<string> {
409
+ const ids = post.categoryIds ?? [];
410
+ if (!ids.length) return "";
411
+ try {
412
+ const result = await queryCategories({ paging: { limit: 100 } });
413
+ const labels = new Map((result.categories ?? []).map((category) => [category.id, (category.label || category.title || "").trim()]));
414
+ for (const id of ids) { const label = labels.get(id); if (label) return label; }
415
+ } catch { /* no label: the category line collapses */ }
416
+ return "";
417
+ }
418
+
419
+ async function loadTags(post: PostWithExtras): Promise<{ rows: TagRow[]; failed: boolean }> {
420
+ const ids = (post.tagIds ?? []).filter((id) => typeof id === "string" && id);
421
+ if (!ids.length) return { rows: [], failed: false };
422
+ let byId = new Map<string, string>();
423
+ let failed = false;
424
+ try {
425
+ const result = await queryTags({ filter: { id: { $in: ids } }, paging: { limit: 100 } });
426
+ byId = new Map((result.tags ?? []).map((tag) => [tag.id, (tag.label ?? "").trim()]));
427
+ } catch { failed = true; }
428
+ // The post's own order; a tag the site did not return is left out.
429
+ return { rows: ids.map((id) => ({ id, label: byId.get(id) ?? "" })).filter((tag) => tag.label), failed };
430
+ }
431
+
432
+ /** The comment flags the box, the sheet and the composer bind. */
433
+ function commentFlags(s: S): Partial<S> {
434
+ const comments = withOwnComments(s.comments, s.memberId);
435
+ // The site's count when it is ahead (a page not loaded yet), the loaded list when the metric lags.
436
+ const total = Math.max(Number(s.commentCount) || 0, s.comments.length);
437
+ const empty = s.status === "ready" && !s.commentsUnavailable && !s.commentsOff && s.comments.length === 0;
438
+ return {
439
+ comments,
440
+ latestComments: comments.filter((row) => !row.parentId).slice(0, LATEST_COMMENTS),
441
+ hasComments: s.comments.length > 0,
442
+ noComments: s.comments.length === 0,
443
+ showAllLabel: copyTemplate("blogPost.showAllComments", "Show all ({count})", { count: total }),
444
+ sheetTitle: commentsTitleFor(total),
445
+ commentsEmpty: empty,
446
+ notCommentsEmpty: !empty,
447
+ hasMoreComments: !!s.commentsCursor,
448
+ noMoreComments: !s.commentsCursor,
449
+ isReplying: !!s.replyToId,
450
+ notReplying: !s.replyToId,
451
+ canSend: !!s.commentText.trim(),
452
+ cannotSend: !s.commentText.trim(),
453
+ noSendError: !s.sendError,
454
+ hasMemberPhoto: !!s.memberPhoto,
455
+ noMemberPhoto: !s.memberPhoto,
456
+ };
457
+ }
458
+
459
+ function derive(s: S): S {
460
+ const isLoading = s.status === "loading";
461
+ const errored = s.status === "error";
462
+ const hasPost = Boolean(s.id && s.title && !errored);
463
+ return {
464
+ ...s,
465
+ isLoading,
466
+ notLoading: !isLoading,
467
+ errored,
468
+ notErrored: !errored,
469
+ hasPost,
470
+ noPost: !hasPost,
471
+ hasCover: Boolean(s.cover),
472
+ noCover: !s.cover,
473
+ hasBodyJson: s.bodyJson !== "",
474
+ hasCategory: !!s.categoryLabel,
475
+ noCategory: !s.categoryLabel,
476
+ hasTags: s.tags.length > 0,
477
+ noTags: s.tags.length === 0,
478
+ likes: s.likeCount === null ? "" : String(Math.max(0, s.likeCount)),
479
+ likesLabel: s.likeCount === null ? "" : likesLabelFor(Math.max(0, s.likeCount)),
480
+ viewsLabel: s.views === "" ? "" : viewsLabelFor(Number(s.views) || 0),
481
+ commentsLabel: s.commentCount === "" ? "" : commentsLabelFor(Number(s.commentCount) || 0),
482
+ hasCounts: s.likeCount !== null,
483
+ noCounts: s.likeCount === null,
484
+ noShareUrl: !s.shareUrl,
485
+ noCommentStatus: !s.commentStatusText,
486
+ notPaid: !s.isPaid,
487
+ notLiked: !s.liked,
488
+ notSaved: !s.saved,
489
+ notHidden: !s.hidden,
490
+ notReported: !s.reported,
491
+ commentsAvailable: !s.commentsUnavailable,
492
+ commentsOn: !s.commentsOff,
493
+ ...commentFlags(s),
494
+ hasRecent: s.recent.length > 0,
495
+ noRecent: s.recent.length === 0,
496
+ };
497
+ }
498
+
499
+ /** A message after an action, as the app's snackbar (a toast above the tab bar that closes on its
500
+ * own); after Hide its button is Undo, which runs `unhide`. The state is returned as it is: the
501
+ * screen shows the change itself. A host with no snackbar presenter shows nothing. */
502
+ function say(s: S, message: string, undo = false): S {
503
+ if (message) {
504
+ // Undo names the post it hid: the reader may have opened another post (Recent posts) by then.
505
+ const action = undo ? { action: { label: copyParam("blogCommon.undoCta", "Undo"), actionId: "tier5.himiBlogPost.unhide", args: { id: s.id } } } : {};
506
+ void snackbar({ message, ...action }).catch(() => undefined);
507
+ }
508
+ return derive(s);
509
+ }
510
+
511
+ /** A like or comment the site refused (401/403: a visitor, or a member without the right) opens the
512
+ * app's sign-in, as the post's own Sign in button does, instead of telling the reader to sign in. */
513
+ const signIn = (s: S): S => navigate(derive(s), { screenId: s.signInScreenId, args: { mode: "signin" } });
514
+
515
+ /** The post a like or unlike call is on its way for ("" = none). */
516
+ let likeInFlight = "";
517
+
518
+ /** The state as it is now (set once the service exists). An action that awaits the network builds its
519
+ * result on this, not on the state it was tapped in: a Save, Hide or message that landed meanwhile stays. */
520
+ let committed: () => S | undefined = () => undefined;
521
+ /** After an await: the current state, or null when the reader opened another post meanwhile. A
522
+ * runtime that reports no state gets the state the action was tapped in. */
523
+ function samePost(s: S): S | null {
524
+ const now = committed();
525
+ if (!now) return s;
526
+ return now.id === s.id ? now : null;
527
+ }
528
+
529
+ /** The counts after a like (`step` 1) or an unlike (-1). The site answers with METRICS read before
530
+ * the change (seen on the demo site: a post with one like answered a like with 1 and the unlike
531
+ * with 2), so the like count moves by one from what the screen showed, or from the answer when the
532
+ * screen had none; an answer that already moved past that is taken as it is. Views and comments
533
+ * come with it, so a post read without counts never shows a likes number beside two empty chips. */
534
+ function countsAfter(now: S, after: { likes: number; comments: number; views: number } | null, step: 1 | -1): Partial<S> {
535
+ if (!after) return {};
536
+ const base = now.likeCount ?? after.likes;
537
+ const likeCount = step > 0 ? Math.max(after.likes, base + 1) : Math.max(0, Math.min(after.likes, base - 1));
538
+ return { likeCount, views: String(after.views), commentCount: String(Math.max(after.comments, now.comments.length, Number(now.commentCount) || 0)) };
539
+ }
540
+
541
+ const baseState: S = derive({
542
+ ...NO_READ_SIGN_IN, signInScreenId: "himi_account",
543
+ ...NO_AUTHOR,
544
+ status: "loading",
545
+ id: "",
546
+ commentResourceId: "",
547
+ title: "",
548
+ subtitle: "",
549
+ updatedLine: "",
550
+ categoryLabel: "",
551
+ hasCategory: false,
552
+ noCategory: true,
553
+ tags: [],
554
+ tagsUnavailable: false,
555
+ hasTags: false,
556
+ noTags: true,
557
+ likeCount: null,
558
+ hasCounts: false,
559
+ noCounts: true,
560
+ likes: "0",
561
+ views: "",
562
+ commentCount: "",
563
+ likesLabel: "",
564
+ viewsLabel: "",
565
+ commentsLabel: "",
566
+ bodyJson: "",
567
+ hasBodyJson: false,
568
+ bodyText: "",
569
+ shareUrl: "",
570
+ isPaid: false,
571
+ notPaid: true,
572
+ noShareUrl: true,
573
+ cover: "",
574
+ hasCover: false,
575
+ noCover: true,
576
+ initial: "",
577
+ liked: false,
578
+ notLiked: true,
579
+ saved: false,
580
+ notSaved: true,
581
+ hidden: false,
582
+ notHidden: true,
583
+ moreSheetOpen: false,
584
+ hideSheetOpen: false,
585
+ reported: false,
586
+ notReported: true,
587
+ commentText: "",
588
+ comments: [],
589
+ latestComments: [],
590
+ hasComments: false,
591
+ noComments: true,
592
+ showAllLabel: "",
593
+ commentsSheetOpen: false,
594
+ commentsCursor: "",
595
+ hasMoreComments: false,
596
+ noMoreComments: true,
597
+ composerFocus: "",
598
+ replyToId: "",
599
+ replyingLine: "",
600
+ isReplying: false,
601
+ notReplying: true,
602
+ canSend: false,
603
+ cannotSend: true,
604
+ sendError: "",
605
+ noSendError: true,
606
+ isMember: false,
607
+ memberId: "",
608
+ memberName: "",
609
+ memberPhoto: "",
610
+ memberInitial: "",
611
+ hasMemberPhoto: false,
612
+ noMemberPhoto: true,
613
+ commentsTitle: "Comments",
614
+ sheetTitle: "Comments",
615
+ commentsUnavailable: false,
616
+ commentsAvailable: true,
617
+ commentsOff: false,
618
+ commentsOn: true,
619
+ commentStatusText: "",
620
+ noCommentStatus: true,
621
+ commentsEmpty: false,
622
+ notCommentsEmpty: true,
623
+ recent: [],
624
+ recentUnavailable: false,
625
+ hasRecent: false,
626
+ noRecent: true,
627
+ emptyText: "",
628
+ errorText: "",
629
+ hasPost: false,
630
+ noPost: true,
631
+ isLoading: true,
632
+ notLoading: false,
633
+ errored: false,
634
+ notErrored: true,
635
+ blogScreenId: "himi_blog",
636
+ });
637
+
638
+ // Offline fallback: render the detail from the last-synced cached row (feed-populated)
639
+ // when the live post fetch fails. Returns the existing error state when nothing is cached.
640
+ async function cachedPostState(s: S, id: string): Promise<S> {
641
+ const cached = await readCachedPost(id);
642
+ if (!cached) {
643
+ return derive({ ...s, status: "error", id, errorText: copyParam("blogPost.errorText", "This post could not load.") });
644
+ }
645
+ const title = String(cached.title ?? "") || "Untitled post";
646
+ const fixed = { ...cached, ...legacyRowFixes(cached) };
647
+ const author = cached.hasAuthor === true
648
+ ? authorFields({ name: String(cached.authorName ?? ""), photo: String(cached.authorPhoto ?? ""), initial: String(cached.authorInitial ?? "") })
649
+ : NO_AUTHOR;
650
+ return derive({
651
+ ...s,
652
+ ...author,
653
+ status: "ready",
654
+ id,
655
+ commentResourceId: "",
656
+ title,
657
+ subtitle: String(cached.meta ?? ""),
658
+ categoryLabel: String(fixed.category ?? ""),
659
+ // A row cached by an older build has no counts: unknown, not zero.
660
+ likeCount: cached.hasCounts === true ? Number(cached.likes) || 0 : null,
661
+ views: cached.hasCounts === true ? String(cached.views ?? "") : "",
662
+ commentCount: cached.hasCounts === true ? String(cached.comments ?? "") : "",
663
+ // The feed caches no Ricos body, so the offline copy is plain text (the descriptor's gated text shows it).
664
+ bodyJson: "",
665
+ // `||`, not `??`: the feed caches an empty excerpt as "", which is no body either.
666
+ bodyText: String(cached.body || fixed.excerpt || copyParam("blogPost.bodyFallback", "This post has no readable body yet.")),
667
+ cover: cachedCover(cached, BLOG_HERO_IMAGE),
668
+ initial: String(cached.initial ?? "") || (title[0] || "#").toUpperCase(),
669
+ liked: false,
670
+ saved: isSavedId(id),
671
+ hidden: isHiddenId(id),
672
+ comments: [],
673
+ commentsCursor: "",
674
+ commentsUnavailable: true,
675
+ commentStatusText: copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now."),
676
+ errorText: "",
677
+ emptyText: "",
678
+ });
679
+ }
680
+
681
+ /** The network half of a post load: the post and its comments, author, category, tags and recent
682
+ * posts, unmapped (the copy pack that names them arrives with the screen's onAppear load). */
683
+ interface CommentFetch {
684
+ rows: WixBlogCommentRow[];
685
+ nextCursor: string;
686
+ unavailable: boolean;
687
+ /** The comment authors' public names and photos, read in ONE members query for the page. */
688
+ authors: Map<string, BlogAuthor>;
689
+ /** The comments on the page the reader liked (empty for a visitor). */
690
+ liked: Set<string>;
691
+ }
692
+
693
+ /** A page of the post's comments with their authors and the reader's likes. A failed authors or
694
+ * likes read leaves those out ("Member", no like); a failed page is "comments unavailable". */
695
+ async function fetchComments(resourceId: string, member: boolean, cursor = ""): Promise<CommentFetch> {
696
+ if (!resourceId) return { rows: [], nextCursor: "", unavailable: true, authors: new Map(), liked: new Set() };
697
+ let page: { comments: WixBlogCommentRow[]; nextCursor: string };
698
+ try { page = await listBlogCommentPage(resourceId, { limit: COMMENTS_PAGE, ...(cursor ? { cursor } : {}) }); }
699
+ catch { return { rows: [], nextCursor: "", unavailable: true, authors: new Map(), liked: new Set() }; }
700
+ const [authors, liked] = await Promise.all([
701
+ resolveAuthors(page.comments.map((row) => row.authorMemberId)).catch(() => new Map<string, BlogAuthor>()),
702
+ member && page.comments.length ? likedBlogComments(resourceId, page.comments.map((row) => row.id)).catch(() => new Set<string>()) : Promise.resolve(new Set<string>()),
703
+ ]);
704
+ return { rows: page.comments, nextCursor: page.nextCursor, unavailable: false, authors, liked };
705
+ }
706
+
707
+ /** The signed-in member's name (public nickname, else contact name) and photo ("" for a visitor, or when the read fails). */
708
+ async function fetchMe(member: boolean): Promise<Me> {
709
+ if (!member) return NO_ME;
710
+ try {
711
+ // FULL: the member's own record, so a member with no public nickname shows their contact name on
712
+ // the comment they just sent (as the account screen does), never "Member".
713
+ const found = (await getMyMember({ fieldsets: ["FULL"] }))?.member;
714
+ const name = (found?.profile?.nickname ?? "").trim()
715
+ || [found?.contact?.firstName, found?.contact?.lastName].map((part) => (part ?? "").trim()).filter(Boolean).join(" ");
716
+ return { id: found?.id ?? "", name, photo: profilePhoto(found?.profile?.photo) };
717
+ } catch { return NO_ME; }
718
+ }
719
+
720
+ interface PostFetch {
721
+ post: PostWithExtras;
722
+ comments: CommentFetch;
723
+ me: Me;
724
+ authors: Map<string, BlogAuthor>;
725
+ categoryLabel: string;
726
+ tags: { rows: TagRow[]; failed: boolean };
727
+ recent: { posts: WixPost[]; failed: boolean };
728
+ }
729
+
730
+ async function fetchPost(id: string, access: ReadAccess): Promise<PostFetch> {
731
+ const response = await getPost(id, { fieldsets: ["RICH_CONTENT", "CONTENT_TEXT", "INTERNAL_ID", "METRICS", "URL"] }, { preserveAccessErrors: true });
732
+ // The reader may have changed (sign-in, another site) while the post was read: its dependent
733
+ // reads (Comments above all) must not start under the new reader.
734
+ await assertReadAccess(access);
735
+ const post = response.post as PostWithExtras;
736
+ // Native Blog v3 Comments scopes by internalId, not the navigation UUID.
737
+ // A missing projection cannot establish that the post has no comments.
738
+ const commentResourceId = post.internalId?.trim() ?? "";
739
+ const member = !!access.member.email;
740
+ const [comments, me, authors, categoryLabel, tags, recent] = await Promise.all([
741
+ fetchComments(commentResourceId, member),
742
+ fetchMe(member),
743
+ resolveAuthors([post.memberId]),
744
+ loadCategoryLabel(post),
745
+ loadTags(post),
746
+ loadRecent(post),
747
+ ]);
748
+ return { post, comments, me, authors, categoryLabel, tags, recent };
749
+ }
750
+
751
+ // The worker loads at boot AND again on the screen's onAppear (which carries the copy pack). The
752
+ // second load reuses the first one's reads, in flight or finished in the last FETCH_REUSE_MS, for
753
+ // the same post and the same reader; a Retry always reads again.
754
+ const FETCH_REUSE_MS = 10_000;
755
+ let lastFetch: { key: string; at: number; promise: Promise<PostFetch> } | null = null;
756
+ function sharedFetch(id: string, access: ReadAccess, fresh: boolean): Promise<PostFetch> {
757
+ const key = `${JSON.stringify(access)}|${id}`;
758
+ if (!fresh && lastFetch?.key === key && Date.now() - lastFetch.at < FETCH_REUSE_MS) return lastFetch.promise;
759
+ const promise = fetchPost(id, access);
760
+ const entry = { key, at: Date.now(), promise };
761
+ lastFetch = entry;
762
+ // A failed read is never handed to the next load.
763
+ promise.catch(() => { if (lastFetch === entry) lastFetch = null; });
764
+ return promise;
765
+ }
766
+
767
+ /** After the reader changes the post (a like, a comment), the next load reads it again: the
768
+ * reused answer predates the change. */
769
+ function forgetFetch(): void { lastFetch = null; }
770
+
771
+ /** How long a sign-in may take and still reopen the comments sheet. */
772
+ const RESUME_COMPOSER_MS = 5 * 60_000;
773
+ /** The post a visitor tapped the comment input on (or Reply) before signing in, and when. In the
774
+ * device KV, not only in memory: on Android a sign-in changes the reader and the host starts a new
775
+ * worker for the post, which would forget an in-memory mark. */
776
+ const RESUME_COMPOSER_KEY = "himi-blog:resume-composer:v1";
777
+ type StorageLike = { getItem: (key: string) => string | null; setItem: (key: string, value: string) => void };
778
+ const kv = (): StorageLike | undefined => {
779
+ const host = globalThis as { himalaya?: { storage?: StorageLike }; localStorage?: StorageLike };
780
+ return host.himalaya?.storage ?? host.localStorage;
781
+ };
782
+ /** `replyTo` / `replyName`: the comment a visitor's Reply was for, so the reply survives sign-in.
783
+ * `text`: what the visitor had typed when Send took them to sign-in (Android starts a new worker). */
784
+ interface ComposerMark { id: string; at: number; replyTo?: string; replyName?: string; text?: string }
785
+ let composerMark: ComposerMark | null = null;
786
+ function readComposerMark(): ComposerMark | null {
787
+ try {
788
+ const raw = kv()?.getItem(RESUME_COMPOSER_KEY);
789
+ const mark = raw ? JSON.parse(raw) as { id?: unknown; at?: unknown; replyTo?: unknown; replyName?: unknown; text?: unknown } : null;
790
+ if (mark && typeof mark.id === "string" && typeof mark.at === "number") {
791
+ return {
792
+ id: mark.id, at: mark.at,
793
+ ...(typeof mark.replyTo === "string" && mark.replyTo ? { replyTo: mark.replyTo, replyName: typeof mark.replyName === "string" ? mark.replyName : "" } : {}),
794
+ ...(typeof mark.text === "string" && mark.text ? { text: mark.text } : {}),
795
+ };
796
+ }
797
+ } catch { /* unreadable: the in-memory mark below */ }
798
+ // Nothing stored (spent, or a store that keeps no writes): this worker's own mark, if any.
799
+ return composerMark;
800
+ }
801
+ function writeComposerMark(mark: ComposerMark | null): void {
802
+ composerMark = mark;
803
+ try { kv()?.setItem(RESUME_COMPOSER_KEY, mark ? JSON.stringify(mark) : ""); } catch { /* the in-memory mark stays */ }
804
+ }
805
+ /** Mark the composer as it is now (the reply it is for and the typed text), so it comes back after sign-in. */
806
+ function markComposer(s: S): void {
807
+ const target = s.replyToId ? s.comments.find((row) => row.id === s.replyToId) : undefined;
808
+ writeComposerMark({
809
+ id: s.id, at: Date.now(),
810
+ ...(target ? { replyTo: s.replyToId, replyName: target.authorName } : {}),
811
+ ...(s.commentText.trim() ? { text: s.commentText } : {}),
812
+ });
813
+ }
814
+ /** A new focus token for the comment field (see TextFieldProps.focus_path). */
815
+ let focusCount = 0;
816
+ const nonce = (): string => `${Date.now()}-${++focusCount}`;
817
+
818
+ function meFields(me: Me): Pick<S, "memberId" | "memberName" | "memberPhoto" | "memberInitial"> {
819
+ return { memberId: me.id, memberName: me.name, memberPhoto: me.photo, memberInitial: (me.name[0] || "").toUpperCase() };
820
+ }
821
+
822
+ /** The member's own fields as an author: their new comment shows their name and photo at once. */
823
+ function meAsAuthors(s: S, memberId: string | undefined): Map<string, BlogAuthor> {
824
+ return memberId && s.memberName
825
+ ? new Map([[memberId, { name: s.memberName, photo: s.memberPhoto, initial: s.memberInitial }]])
826
+ : new Map();
827
+ }
828
+
829
+ /** The comment `id` names in an action's args ("" when none). */
830
+ const argId = (arg: unknown): string => {
831
+ const id = (arg as { id?: unknown } | undefined)?.id;
832
+ return typeof id === "string" ? id : "";
833
+ };
834
+
835
+ /** Show a comment's like state now (set once the service exists). */
836
+ let showCommentLike: (id: string, liked: boolean) => unknown = () => undefined;
837
+ /** Comment likes on their way, by comment id: a second tap waits for the first. */
838
+ const commentLikesInFlight = new Set<string>();
839
+ /** The like state the reader's last tap asked for while a call on that comment was on its way. */
840
+ const commentLikesWanted = new Map<string, boolean>();
841
+ /** The post a comment is being sent on ("" = none): a second Send waits for the first. */
842
+ let sendInFlight = "";
843
+ /** The page of comments being read ("" = none). */
844
+ let moreCommentsInFlight = "";
845
+
846
+ let loadVersion = 0;
847
+ async function loadPostState(s: S, fresh = false): Promise<S | undefined> {
848
+ const version = ++loadVersion;
849
+ await svc.prepare();
850
+ const clean = { ...baseState, signInScreenId: s.signInScreenId };
851
+ const id = inputId();
852
+ if (!id) {
853
+ return derive({ ...clean, status: "ready", emptyText: copyParam("blogPost.notFoundText", "Post not found.") });
854
+ }
855
+ try {
856
+ const access = await readAccess();
857
+ const { post, comments: commentResult, me, authors, categoryLabel, tags, recent } = await sharedFetch(id, access, fresh);
858
+ await assertReadAccess(access);
859
+ if (version !== loadVersion) return undefined;
860
+ const commentResourceId = post.internalId?.trim() ?? "";
861
+ const commentsOff = post.commentingEnabled === false;
862
+ const cover = coverOf(post, BLOG_HERO_IMAGE);
863
+ const title = post.title || copyParam("blogCommon.untitled", "Untitled post");
864
+ const counts = countsOf(post);
865
+ const now = Date.now();
866
+ const commentRows = commentResult.rows.map((row) => toCommentRow(row, commentResult.authors, commentResult.liked, now));
867
+ const isMember = !!access.member.email;
868
+ // A visitor who tapped the comment input signed in and came back: the sheet opens with the keyboard.
869
+ // The mark stays until it is used: a reload can run before the host knows about the sign-in
870
+ // (seen on Android), and that one must not spend it. Another post or an old mark drops it.
871
+ const mark = readComposerMark();
872
+ const pending = mark?.id === id && Date.now() - mark.at < RESUME_COMPOSER_MS;
873
+ if (mark && !pending) writeComposerMark(null);
874
+ const resume = pending && isMember && !commentsOff;
875
+ if (resume) writeComposerMark(null);
876
+ // A load never closes a sheet already open on this post, or empties its composer: the worker
877
+ // loads at boot and again on the screen's onAppear, and the boot load may be the one that
878
+ // reopened it.
879
+ const sheetOpen = s.commentsSheetOpen && s.id === id;
880
+ return derive({
881
+ ...clean,
882
+ ...meFields(me),
883
+ isMember,
884
+ commentsSheetOpen: resume || sheetOpen,
885
+ ...(sheetOpen ? { commentText: s.commentText, replyToId: s.replyToId, replyingLine: s.replyingLine } : {}),
886
+ // A visitor who started from Reply comes back replying to the same comment, with what they typed.
887
+ ...(resume && mark?.replyTo && commentRows.some((row) => row.id === mark.replyTo)
888
+ ? { replyToId: mark.replyTo, replyingLine: copyTemplate("blogPost.replyingTo", "Replying to {name}", { name: mark.replyName ?? "" }) }
889
+ : {}),
890
+ ...(resume && mark?.text && !(sheetOpen && s.commentText) ? { commentText: mark.text } : {}),
891
+ composerFocus: resume ? nonce() : sheetOpen ? s.composerFocus : "",
892
+ ...authorFields(authors.get(post.memberId ?? "")),
893
+ status: "ready",
894
+ id,
895
+ commentResourceId,
896
+ title,
897
+ subtitle: dateLineOf(post),
898
+ updatedLine: updatedLineOf(post),
899
+ categoryLabel,
900
+ tags: tags.rows,
901
+ tagsUnavailable: tags.failed,
902
+ likeCount: counts ? counts.likes : null,
903
+ views: counts ? String(counts.views) : "",
904
+ // The loaded list is the better count when the site's metric lags (or is missing).
905
+ commentCount: counts ? String(Math.max(counts.comments, commentRows.length)) : commentResult.unavailable ? "" : String(commentRows.length),
906
+ // No Ricos body, or one the encoder rejects: bodyJson "" and the gated plain text shows bodyText.
907
+ ...richBody(post.richContent, bodyText(post)),
908
+ shareUrl: postShareUrl(post),
909
+ isPaid: post.preview === true,
910
+ cover,
911
+ initial: (title[0] || "#").toUpperCase(),
912
+ liked: Boolean(post.memberInteraction?.liked),
913
+ saved: isSavedId(id),
914
+ hidden: isHiddenId(id),
915
+ comments: commentRows,
916
+ commentsCursor: commentResult.nextCursor,
917
+ commentsTitle: copyParam("blogPost.commentsTitle", "Comments"),
918
+ commentsUnavailable: commentResult.unavailable,
919
+ commentsOff,
920
+ // "No comments yet" is the box's own empty state (commentsEmpty), not a status line.
921
+ commentStatusText: commentsOff
922
+ ? copyParam("blogPost.commentsOff", "Comments are turned off for this post.")
923
+ : commentResult.unavailable
924
+ ? copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now.")
925
+ : "",
926
+ recent: recent.posts.map(toRecentRow),
927
+ recentUnavailable: recent.failed,
928
+ errorText: "",
929
+ emptyText: "",
930
+ });
931
+ } catch (error) {
932
+ const flags = await readSignInFlags(error);
933
+ const failed = derive({ ...clean, ...flags, status: "error", id, errorText: copyParam("blogPost.errorText", "This post could not load.") });
934
+ if (version !== loadVersion) return undefined;
935
+ if (readAccessDenied(error)) return failed;
936
+ const access = await readAccess();
937
+ const cached = await cachedPostState(clean, id);
938
+ try { await assertReadAccess(access); }
939
+ catch { return version === loadVersion ? failed : undefined; }
940
+ return version === loadVersion ? cached : undefined;
941
+ }
942
+ }
943
+
944
+ /** Like or unlike one comment: the heart and the count change at once, and go back when the site
945
+ * refuses. A visitor signs in first. */
946
+ async function toggleCommentLike(s: S, id: string, like: boolean): Promise<S | undefined> {
947
+ const row = s.comments.find((comment) => comment.id === id);
948
+ if (!row || row.noLikes || row.liked === like) return undefined;
949
+ if (!s.isMember) return signIn(s);
950
+ // The change shows at once (through the internal action, while the call is on its way); the
951
+ // answer only undoes it on a refusal.
952
+ void showCommentLike(id, like);
953
+ // A tap while a call is on its way is kept: the call that follows sends the reader's last choice.
954
+ if (commentLikesInFlight.has(id)) { commentLikesWanted.set(id, like); return undefined; }
955
+ commentLikesInFlight.add(id);
956
+ const swap = (state: S, value: boolean): S => derive({ ...state, comments: state.comments.map((comment) => comment.id === id ? withLike(comment, value) : comment) });
957
+ let sent = like;
958
+ try {
959
+ for (;;) {
960
+ await setBlogCommentLike(id, sent);
961
+ // The next load reads the comments again: a reused fetch predates this like.
962
+ forgetFetch();
963
+ const wanted = commentLikesWanted.get(id);
964
+ commentLikesWanted.delete(id);
965
+ if (wanted === undefined || wanted === sent) break;
966
+ sent = wanted;
967
+ }
968
+ const now = samePost(s);
969
+ return now ? swap(now, sent) : undefined;
970
+ } catch (error) {
971
+ commentLikesWanted.delete(id);
972
+ const now = samePost(s);
973
+ if (!now) return undefined;
974
+ const back = swap(now, !sent);
975
+ return readAccessDenied(error) ? signIn(back) : say(back, copyParam("blogPost.likeFailed", "Could not update like."));
976
+ } finally {
977
+ commentLikesInFlight.delete(id);
978
+ }
979
+ }
980
+
981
+ const svc = defineService<S, {
982
+ prepare: (s: S) => S;
983
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
984
+ retry: (s: S) => Promise<S | undefined>;
985
+ like: (s: S) => Promise<S | undefined>;
986
+ unlike: (s: S) => Promise<S | undefined>;
987
+ toggleSave: (s: S) => S;
988
+ openMore: (s: S) => S;
989
+ closeMore: (s: S) => S;
990
+ /** Report the post: no site API takes a member's report, so the reader is thanked and the tap is the signal. */
991
+ report: (s: S) => S;
992
+ openHide: (s: S) => S;
993
+ closeHide: (s: S) => S;
994
+ /** Hide the post on this device. The sheet's three reasons (offensive, misleading, other) are asked for as the One
995
+ * App asks them, but the list keeps only the id and the site is told nothing, so the worker does not read the reason. */
996
+ hide: (s: S) => S;
997
+ /** `{ id }`: the snackbar's Undo names the post it hid; ⋯ → Show post leaves it out (this post). */
998
+ unhide: (s: S, arg?: unknown) => S;
999
+ /** Resolves after the share sheet closes; success keeps the state as it is THEN (undefined), so a
1000
+ * message that closed meanwhile does not come back. */
1001
+ share: (s: S) => Promise<S | undefined>;
1002
+ /** The paid-post notice's link: the post on the site, where a subscriber can read all of it. */
1003
+ openOnWebsite: (s: S) => Promise<S | undefined>;
1004
+ setComment: (s: S, arg?: unknown) => S;
1005
+ /** Send the comment (or the reply) in the sheet's field. */
1006
+ submitComment: (s: S) => Promise<S | undefined>;
1007
+ /** "Show all": the comments sheet, without the keyboard. */
1008
+ openComments: (s: S) => S;
1009
+ /** The box's "Leave a comment…": the sheet with the field focused. A visitor signs in first. */
1010
+ openComposer: (s: S) => S;
1011
+ closeComments: (s: S) => S;
1012
+ /** `{ id }`: reply to that comment (a reply to a reply goes to its parent). Opens the sheet when
1013
+ * it is not open, and focuses the field. A visitor signs in first. */
1014
+ replyTo: (s: S, arg?: unknown) => S;
1015
+ cancelReply: (s: S) => S;
1016
+ /** `{ id }`: like or unlike that comment. A visitor signs in first. */
1017
+ likeComment: (s: S, arg?: unknown) => Promise<S | undefined>;
1018
+ unlikeComment: (s: S, arg?: unknown) => Promise<S | undefined>;
1019
+ /** The sheet's list reached its end: the next page of comments. */
1020
+ loadMoreComments: (s: S) => Promise<S | undefined>;
1021
+ /** Internal: `{ id, liked }` — a comment's like as the reader sees it while the call is on its way. */
1022
+ _commentLike: (s: S, arg?: unknown) => S;
1023
+ /** `{ id }`: the ⋮ menu's Report on a comment. The reader is thanked and Report goes from that comment. */
1024
+ reportComment: (s: S, arg?: unknown) => S;
1025
+ /** [rico] #3370 — RichContent's on_link: `{ url }` of the tapped link. */
1026
+ openLink: (s: S, arg?: unknown) => Promise<S | undefined>;
1027
+ }>("himiBlogPost", {
1028
+ state: baseState,
1029
+ actions: {
1030
+ prepare: (s) => ({ ...s, ...baseState }),
1031
+ load: (s, arg) => {
1032
+ stashCopy(arg);
1033
+ const target = (arg as { signInScreenId?: unknown })?.signInScreenId;
1034
+ return loadPostState({ ...s, signInScreenId: target === "himi_sign_in" ? target : s.signInScreenId });
1035
+ },
1036
+ retry: (s) => loadPostState({ ...s, status: "loading", errorText: "" }, true),
1037
+ like: async (s) => {
1038
+ if (!s.id) return say(s, copyParam("blogPost.noPostMessage", "No post selected."));
1039
+ // A second tap while the first is on its way is ignored: each answer moves the count by one.
1040
+ if (likeInFlight === s.id) return undefined;
1041
+ likeInFlight = s.id;
1042
+ try {
1043
+ // The count after the like (see countsAfter); with no counts in the answer it is left as it
1044
+ // was (the member may have liked before: "liked" is not readable here).
1045
+ const after = countsOf(((await likePost(s.id))?.post ?? {}) as BlogPostShape);
1046
+ forgetFetch();
1047
+ const now = samePost(s);
1048
+ // No message: the filled heart and the count show the change.
1049
+ return now ? derive({ ...now, liked: true, ...countsAfter(now, after, 1) }) : undefined;
1050
+ } catch (error) {
1051
+ const now = samePost(s);
1052
+ if (!now) return undefined;
1053
+ return readAccessDenied(error) ? signIn(now) : say(now, copyParam("blogPost.likeFailed", "Could not update like."));
1054
+ } finally {
1055
+ likeInFlight = "";
1056
+ }
1057
+ },
1058
+ unlike: async (s) => {
1059
+ if (!s.id) return s;
1060
+ if (likeInFlight === s.id) return undefined;
1061
+ likeInFlight = s.id;
1062
+ try {
1063
+ const after = countsOf(((await unlikePost(s.id))?.post ?? {}) as BlogPostShape);
1064
+ forgetFetch();
1065
+ const now = samePost(s);
1066
+ return now ? derive({ ...now, liked: false, ...countsAfter(now, after, -1) }) : undefined;
1067
+ } catch (error) {
1068
+ const now = samePost(s);
1069
+ if (!now) return undefined;
1070
+ return readAccessDenied(error) ? signIn(now) : say(now, copyParam("blogPost.likeFailed", "Could not update like."));
1071
+ } finally {
1072
+ likeInFlight = "";
1073
+ }
1074
+ },
1075
+ toggleSave: (s) => {
1076
+ if (!s.id) return s;
1077
+ const saved = toggleSavedId(s.id);
1078
+ return say({ ...s, saved }, saved ? copyParam("blogPost.savedMessage", "Saved for later") : copyParam("blogPost.unsavedMessage", "Removed from saved"));
1079
+ },
1080
+ openMore: (s) => s.id ? derive({ ...s, moreSheetOpen: true, hideSheetOpen: false }) : s,
1081
+ closeMore: (s) => derive({ ...s, moreSheetOpen: false }),
1082
+ report: (s) => {
1083
+ if (!s.id || s.reported) return derive({ ...s, moreSheetOpen: false });
1084
+ return say({ ...s, reported: true, moreSheetOpen: false }, copyParam("blogPost.reportedMessage", "Post reported"));
1085
+ },
1086
+ // The reason sheet replaces the ⋯ sheet: two sheets never show at once.
1087
+ openHide: (s) => s.id ? derive({ ...s, moreSheetOpen: false, hideSheetOpen: true }) : s,
1088
+ closeHide: (s) => derive({ ...s, hideSheetOpen: false }),
1089
+ hide: (s) => {
1090
+ if (!s.id) return s;
1091
+ hideId(s.id);
1092
+ return say({ ...s, hidden: true, hideSheetOpen: false, moreSheetOpen: false }, copyParam("blogPost.hiddenMessage", "Post hidden. It will not show in your feeds."), true);
1093
+ },
1094
+ unhide: (s, arg) => {
1095
+ const named = (arg as { id?: unknown } | undefined)?.id;
1096
+ const id = typeof named === "string" && named ? named : s.id;
1097
+ if (!id) return s;
1098
+ unhideId(id);
1099
+ // Another post on screen keeps its own state; the message still says the hidden one is back.
1100
+ const next = id === s.id ? { ...s, hidden: false, moreSheetOpen: false } : s;
1101
+ return say(next, copyParam("blogPost.unhiddenMessage", "Post is visible again"));
1102
+ },
1103
+ share: async (s) => {
1104
+ if (!s.title) return s;
1105
+ try {
1106
+ await shareSheet({ subject: s.title, text: s.title, ...(s.shareUrl ? { url: s.shareUrl } : {}) });
1107
+ return undefined;
1108
+ } catch {
1109
+ return say(s, copyParam("blogPost.shareUnavailable", "Sharing is not available on this device."));
1110
+ }
1111
+ },
1112
+ openOnWebsite: async (s) => {
1113
+ // Opened: keep the state as it is now (the browser may have been open for a while).
1114
+ return (await openRichLink({ url: s.shareUrl })) ? undefined : say(s, copyParam("blogPost.linkOpenFailed", "This link could not be opened."));
1115
+ },
1116
+ setComment: (s, arg) => derive({ ...s, commentText: strOf(arg), sendError: "" }),
1117
+ submitComment: async (s) => {
1118
+ const text = s.commentText.trim();
1119
+ if (s.commentsOff || sendInFlight === s.id) return s;
1120
+ if (!text) return derive({ ...s, sendError: copyParam("blogPost.commentValidation", "Write a comment first.") });
1121
+ if (!s.commentResourceId) return derive({ ...s, sendError: copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now.") });
1122
+ const parentId = s.replyToId;
1123
+ sendInFlight = s.id;
1124
+ try {
1125
+ const created = await postBlogComment(s.commentResourceId, text, parentId || undefined);
1126
+ forgetFetch();
1127
+ const now = samePost(s);
1128
+ if (!now) return undefined;
1129
+ // The reader's own name and photo at once, never "Member" first.
1130
+ const authorId = created.authorMemberId || now.memberId;
1131
+ const row = { ...toCommentRow({ ...created, ...(authorId ? { authorMemberId: authorId } : {}) }, meAsAuthors(now, authorId), new Set()), highlight: true, rowBackground: HIGHLIGHT };
1132
+ // An unknown count (no METRICS, no comment list) stays unknown: one more of an unknown number is not 1.
1133
+ const total = now.commentCount === "" ? null : Math.max(Number(now.commentCount) || 0, now.comments.length) + 1;
1134
+ // The keyboard closes; the sheet stays open on the new comment.
1135
+ void dismissKeyboard().catch(() => undefined);
1136
+ return derive({
1137
+ ...now,
1138
+ // Text typed while the comment was sending stays in the box.
1139
+ commentText: now.commentText.trim() === text ? "" : now.commentText,
1140
+ // Only the reply that was sent is done: a Reply started while it was on its way stays.
1141
+ ...(now.replyToId === parentId ? { replyToId: "", replyingLine: "" } : {}),
1142
+ sendError: "",
1143
+ comments: insertComment(now.comments, row),
1144
+ commentCount: total === null ? "" : String(total),
1145
+ commentsUnavailable: false,
1146
+ commentStatusText: "",
1147
+ });
1148
+ } catch (error) {
1149
+ // A refusal opens sign-in, and the sheet comes back after it with the same reply and text; any
1150
+ // other failure says so under the field and keeps the text to send again.
1151
+ const now = samePost(s);
1152
+ if (!now) return undefined;
1153
+ if (readAccessDenied(error)) { markComposer(now); return signIn(now); }
1154
+ return derive({ ...now, sendError: copyParam("blogPost.commentSendFailed", "Your comment was not sent. Try again.") });
1155
+ } finally {
1156
+ sendInFlight = "";
1157
+ }
1158
+ },
1159
+ // No focus token: a field that mounts with a non-empty one takes focus, and "Show all" opens no keyboard.
1160
+ openComments: (s) => s.hasPost ? derive({ ...s, commentsSheetOpen: true, moreSheetOpen: false, hideSheetOpen: false, composerFocus: "" }) : s,
1161
+ openComposer: (s) => {
1162
+ if (!s.hasPost || s.commentsOff) return s;
1163
+ if (!s.isMember) { writeComposerMark({ id: s.id, at: Date.now() }); return signIn(s); }
1164
+ return derive({ ...s, commentsSheetOpen: true, moreSheetOpen: false, hideSheetOpen: false, composerFocus: nonce() });
1165
+ },
1166
+ closeComments: (s) => derive({
1167
+ ...s,
1168
+ commentsSheetOpen: false,
1169
+ composerFocus: "",
1170
+ replyToId: "",
1171
+ replyingLine: "",
1172
+ sendError: "",
1173
+ comments: s.comments.map(unhighlighted),
1174
+ }),
1175
+ replyTo: (s, arg) => {
1176
+ const target = s.comments.find((row) => row.id === argId(arg));
1177
+ if (!target || s.commentsOff) return s;
1178
+ if (!s.isMember) {
1179
+ writeComposerMark({ id: s.id, at: Date.now(), replyTo: target.parentId || target.id, replyName: target.authorName });
1180
+ return signIn(s);
1181
+ }
1182
+ // One level, as the Wix Comments threads are: a reply to a reply goes to the same parent.
1183
+ return derive({
1184
+ ...s,
1185
+ commentsSheetOpen: true,
1186
+ replyToId: target.parentId || target.id,
1187
+ replyingLine: copyTemplate("blogPost.replyingTo", "Replying to {name}", { name: target.authorName }),
1188
+ composerFocus: nonce(),
1189
+ });
1190
+ },
1191
+ cancelReply: (s) => derive({ ...s, replyToId: "", replyingLine: "" }),
1192
+ likeComment: (s, arg) => toggleCommentLike(s, argId(arg), true),
1193
+ unlikeComment: (s, arg) => toggleCommentLike(s, argId(arg), false),
1194
+ reportComment: (s, arg) => {
1195
+ const id = argId(arg);
1196
+ const row = s.comments.find((comment) => comment.id === id);
1197
+ if (!row || row.noReport) return s;
1198
+ reportedComments.add(id);
1199
+ return say({ ...s, comments: s.comments.map((comment) => comment.id === id ? { ...comment, noReport: true } : comment) },
1200
+ copyParam("blogPost.commentReportedMessage", "Comment reported"));
1201
+ },
1202
+ _commentLike: (s, arg) => {
1203
+ const { id, liked } = (arg ?? {}) as { id?: unknown; liked?: unknown };
1204
+ if (typeof id !== "string" || typeof liked !== "boolean") return s;
1205
+ return derive({ ...s, comments: s.comments.map((comment) => comment.id === id ? withLike(comment, liked) : comment) });
1206
+ },
1207
+ loadMoreComments: async (s) => {
1208
+ const cursor = s.commentsCursor;
1209
+ if (!cursor || moreCommentsInFlight === cursor) return undefined;
1210
+ moreCommentsInFlight = cursor;
1211
+ try {
1212
+ const page = await fetchComments(s.commentResourceId, s.isMember, cursor);
1213
+ const now = samePost(s);
1214
+ if (!now || now.commentsCursor !== cursor) return undefined;
1215
+ // A failed page keeps what is loaded and its cursor: the next scroll to the end asks again.
1216
+ if (page.unavailable) return undefined;
1217
+ const known = new Set(now.comments.map((row) => row.id));
1218
+ const stamp = Date.now();
1219
+ const added = page.rows.filter((row) => !known.has(row.id)).map((row) => toCommentRow(row, page.authors, page.liked, stamp));
1220
+ return derive({ ...now, comments: [...now.comments, ...added], commentsCursor: page.nextCursor });
1221
+ } finally {
1222
+ moreCommentsInFlight = "";
1223
+ }
1224
+ },
1225
+ // Only http(s), mailto and tel links reach open_url; a refused link, or one nothing opened, says so, and
1226
+ // a link that opens clears that message rather than leaving an earlier failure on screen.
1227
+ openLink: async (s, arg) => {
1228
+ const opened = await openRichLink(arg);
1229
+ const now = samePost(s);
1230
+ return now ? say(now, opened ? "" : copyParam("blogPost.linkOpenFailed", "This link could not be opened.")) : undefined;
1231
+ },
1232
+ },
1233
+ });
1234
+
1235
+ committed = () => (svc as { getState?: () => S }).getState?.();
1236
+ showCommentLike = (id, liked) => svc._commentLike({ id, liked });
1237
+ svc.prepare();
1238
+ svc.load();
1239
+ export { svc };