hububb-saas-shared 1.2.51 → 1.2.52

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.
@@ -0,0 +1,12 @@
1
+ export declare function isGuideBodyHtml(body: string): boolean;
2
+ export declare function escapeGuideHtml(text: string): string;
3
+ /** Converts legacy plain-text guide bodies to simple HTML paragraphs. */
4
+ export declare function plainTextToGuideHtml(body: string): string;
5
+ /** Normalizes stored guide body for HTML rendering (guest + mobile display). */
6
+ export declare function normalizeGuideBodyForDisplay(body: string | null | undefined): string;
7
+ /** Prepares stored guide body for rich-text editors. */
8
+ export declare function guideBodyToEditorHtml(body: string | null | undefined): string;
9
+ export declare function stripGuideBodyPreview(body: string | null | undefined): string;
10
+ export declare function isGuideBodyEmpty(body: string | null | undefined): boolean;
11
+ /** Tags allowed when sanitizing guide HTML for display. */
12
+ export declare const GUIDE_BODY_ALLOWED_TAGS: readonly ["p", "br", "strong", "b", "em", "i", "ul", "ol", "li", "h2", "h3", "h4", "a", "blockquote"];
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GUIDE_BODY_ALLOWED_TAGS = void 0;
4
+ exports.isGuideBodyHtml = isGuideBodyHtml;
5
+ exports.escapeGuideHtml = escapeGuideHtml;
6
+ exports.plainTextToGuideHtml = plainTextToGuideHtml;
7
+ exports.normalizeGuideBodyForDisplay = normalizeGuideBodyForDisplay;
8
+ exports.guideBodyToEditorHtml = guideBodyToEditorHtml;
9
+ exports.stripGuideBodyPreview = stripGuideBodyPreview;
10
+ exports.isGuideBodyEmpty = isGuideBodyEmpty;
11
+ const HTML_TAG_PATTERN = /<\s*[a-z][^>]*>/i;
12
+ const EMPTY_HTML_PATTERNS = [/^<p>\s*<\/p>$/i, /^<p><br\s*\/?><\/p>$/i, /^<p>\s*<br\s*\/?>\s*<\/p>$/i];
13
+ function isGuideBodyHtml(body) {
14
+ return HTML_TAG_PATTERN.test(body);
15
+ }
16
+ function escapeGuideHtml(text) {
17
+ return text
18
+ .replace(/&/g, '&amp;')
19
+ .replace(/</g, '&lt;')
20
+ .replace(/>/g, '&gt;')
21
+ .replace(/"/g, '&quot;')
22
+ .replace(/'/g, '&#39;');
23
+ }
24
+ /** Converts legacy plain-text guide bodies to simple HTML paragraphs. */
25
+ function plainTextToGuideHtml(body) {
26
+ const blocks = body
27
+ .split(/\n{2,}/)
28
+ .map((paragraph) => paragraph.trim())
29
+ .filter(Boolean);
30
+ if (blocks.length === 0)
31
+ return '';
32
+ return blocks
33
+ .map((paragraph) => `<p>${escapeGuideHtml(paragraph).replace(/\n/g, '<br />')}</p>`)
34
+ .join('');
35
+ }
36
+ /** Normalizes stored guide body for HTML rendering (guest + mobile display). */
37
+ function normalizeGuideBodyForDisplay(body) {
38
+ if (!(body === null || body === void 0 ? void 0 : body.trim()))
39
+ return '';
40
+ if (isGuideBodyHtml(body))
41
+ return body;
42
+ return plainTextToGuideHtml(body);
43
+ }
44
+ /** Prepares stored guide body for rich-text editors. */
45
+ function guideBodyToEditorHtml(body) {
46
+ return normalizeGuideBodyForDisplay(body);
47
+ }
48
+ function stripGuideBodyPreview(body) {
49
+ if (!(body === null || body === void 0 ? void 0 : body.trim()))
50
+ return '';
51
+ const source = isGuideBodyHtml(body)
52
+ ? body.replace(/<[^>]+>/g, ' ').replace(/&nbsp;/gi, ' ')
53
+ : body;
54
+ return source.replace(/\s+/g, ' ').trim();
55
+ }
56
+ function isGuideBodyEmpty(body) {
57
+ if (!(body === null || body === void 0 ? void 0 : body.trim()))
58
+ return true;
59
+ const normalized = normalizeGuideBodyForDisplay(body).trim();
60
+ if (!normalized)
61
+ return true;
62
+ return EMPTY_HTML_PATTERNS.some((pattern) => pattern.test(normalized));
63
+ }
64
+ /** Tags allowed when sanitizing guide HTML for display. */
65
+ exports.GUIDE_BODY_ALLOWED_TAGS = [
66
+ 'p',
67
+ 'br',
68
+ 'strong',
69
+ 'b',
70
+ 'em',
71
+ 'i',
72
+ 'ul',
73
+ 'ol',
74
+ 'li',
75
+ 'h2',
76
+ 'h3',
77
+ 'h4',
78
+ 'a',
79
+ 'blockquote',
80
+ ];
@@ -1,4 +1,5 @@
1
1
  export { GUIDE_ICON_KEYS, GUIDE_ICON_LABELS, GUIDE_ICON_PHOSPHOR_NAMES, type GuideIconKey } from './icons';
2
+ export { GUIDE_BODY_ALLOWED_TAGS, escapeGuideHtml, guideBodyToEditorHtml, isGuideBodyEmpty, isGuideBodyHtml, normalizeGuideBodyForDisplay, plainTextToGuideHtml, stripGuideBodyPreview, } from './body';
2
3
  export declare const propertyGuideSchema: import("zod").ZodObject<{
3
4
  id: import("zod").ZodNumber;
4
5
  propertyId: import("zod").ZodNumber;
@@ -1,12 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyGuideSchema = exports.GUIDE_ICON_PHOSPHOR_NAMES = exports.GUIDE_ICON_LABELS = exports.GUIDE_ICON_KEYS = void 0;
3
+ exports.propertyGuideSchema = exports.stripGuideBodyPreview = exports.plainTextToGuideHtml = exports.normalizeGuideBodyForDisplay = exports.isGuideBodyHtml = exports.isGuideBodyEmpty = exports.guideBodyToEditorHtml = exports.escapeGuideHtml = exports.GUIDE_BODY_ALLOWED_TAGS = exports.GUIDE_ICON_PHOSPHOR_NAMES = exports.GUIDE_ICON_LABELS = exports.GUIDE_ICON_KEYS = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const icons_1 = require("./icons");
6
6
  var icons_2 = require("./icons");
7
7
  Object.defineProperty(exports, "GUIDE_ICON_KEYS", { enumerable: true, get: function () { return icons_2.GUIDE_ICON_KEYS; } });
8
8
  Object.defineProperty(exports, "GUIDE_ICON_LABELS", { enumerable: true, get: function () { return icons_2.GUIDE_ICON_LABELS; } });
9
9
  Object.defineProperty(exports, "GUIDE_ICON_PHOSPHOR_NAMES", { enumerable: true, get: function () { return icons_2.GUIDE_ICON_PHOSPHOR_NAMES; } });
10
+ var body_1 = require("./body");
11
+ Object.defineProperty(exports, "GUIDE_BODY_ALLOWED_TAGS", { enumerable: true, get: function () { return body_1.GUIDE_BODY_ALLOWED_TAGS; } });
12
+ Object.defineProperty(exports, "escapeGuideHtml", { enumerable: true, get: function () { return body_1.escapeGuideHtml; } });
13
+ Object.defineProperty(exports, "guideBodyToEditorHtml", { enumerable: true, get: function () { return body_1.guideBodyToEditorHtml; } });
14
+ Object.defineProperty(exports, "isGuideBodyEmpty", { enumerable: true, get: function () { return body_1.isGuideBodyEmpty; } });
15
+ Object.defineProperty(exports, "isGuideBodyHtml", { enumerable: true, get: function () { return body_1.isGuideBodyHtml; } });
16
+ Object.defineProperty(exports, "normalizeGuideBodyForDisplay", { enumerable: true, get: function () { return body_1.normalizeGuideBodyForDisplay; } });
17
+ Object.defineProperty(exports, "plainTextToGuideHtml", { enumerable: true, get: function () { return body_1.plainTextToGuideHtml; } });
18
+ Object.defineProperty(exports, "stripGuideBodyPreview", { enumerable: true, get: function () { return body_1.stripGuideBodyPreview; } });
10
19
  exports.propertyGuideSchema = (0, zod_1.object)({
11
20
  id: (0, zod_1.number)().int(),
12
21
  propertyId: (0, zod_1.number)().int(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "commonjs",
3
3
  "name": "hububb-saas-shared",
4
- "version": "1.2.51",
4
+ "version": "1.2.52",
5
5
  "description": "This is a shared package for the hububb saas project",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.js",