@timbenniks/contentstack-platform-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.cjs +607 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +108 -0
- package/dist/auth/index.d.ts +108 -0
- package/dist/auth/index.mjs +25 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/brandkit/index.cjs +525 -0
- package/dist/brandkit/index.cjs.map +1 -0
- package/dist/brandkit/index.d.cts +95 -0
- package/dist/brandkit/index.d.ts +95 -0
- package/dist/brandkit/index.mjs +11 -0
- package/dist/brandkit/index.mjs.map +1 -0
- package/dist/chunk-3C6J2BDB.mjs +84 -0
- package/dist/chunk-3C6J2BDB.mjs.map +1 -0
- package/dist/chunk-3KE63N3I.mjs +64 -0
- package/dist/chunk-3KE63N3I.mjs.map +1 -0
- package/dist/chunk-4CJ4IVPJ.mjs +212 -0
- package/dist/chunk-4CJ4IVPJ.mjs.map +1 -0
- package/dist/chunk-4JFUI7MJ.mjs +368 -0
- package/dist/chunk-4JFUI7MJ.mjs.map +1 -0
- package/dist/chunk-7VFGD32I.mjs +26 -0
- package/dist/chunk-7VFGD32I.mjs.map +1 -0
- package/dist/chunk-ARPJDW3A.mjs +44 -0
- package/dist/chunk-ARPJDW3A.mjs.map +1 -0
- package/dist/chunk-AVJHCFRK.mjs +52 -0
- package/dist/chunk-AVJHCFRK.mjs.map +1 -0
- package/dist/chunk-BK2IBTQS.mjs +131 -0
- package/dist/chunk-BK2IBTQS.mjs.map +1 -0
- package/dist/chunk-BUZ6CQHE.mjs +75 -0
- package/dist/chunk-BUZ6CQHE.mjs.map +1 -0
- package/dist/chunk-CKMAOWBQ.mjs +379 -0
- package/dist/chunk-CKMAOWBQ.mjs.map +1 -0
- package/dist/chunk-DJQLN4TR.mjs +1 -0
- package/dist/chunk-DJQLN4TR.mjs.map +1 -0
- package/dist/chunk-DMERADWM.mjs +67 -0
- package/dist/chunk-DMERADWM.mjs.map +1 -0
- package/dist/chunk-EREPKWTW.mjs +926 -0
- package/dist/chunk-EREPKWTW.mjs.map +1 -0
- package/dist/chunk-FQP4PB5X.mjs +88 -0
- package/dist/chunk-FQP4PB5X.mjs.map +1 -0
- package/dist/chunk-GNPQJBFX.mjs +144 -0
- package/dist/chunk-GNPQJBFX.mjs.map +1 -0
- package/dist/chunk-GOSB24M6.mjs +87 -0
- package/dist/chunk-GOSB24M6.mjs.map +1 -0
- package/dist/chunk-JL2E3EOT.mjs +255 -0
- package/dist/chunk-JL2E3EOT.mjs.map +1 -0
- package/dist/chunk-JYGZBKTH.mjs +222 -0
- package/dist/chunk-JYGZBKTH.mjs.map +1 -0
- package/dist/chunk-JZE2W7VW.mjs +52 -0
- package/dist/chunk-JZE2W7VW.mjs.map +1 -0
- package/dist/chunk-K76DKSHJ.mjs +18 -0
- package/dist/chunk-K76DKSHJ.mjs.map +1 -0
- package/dist/chunk-KLVIROVU.mjs +232 -0
- package/dist/chunk-KLVIROVU.mjs.map +1 -0
- package/dist/chunk-LPVVA5J3.mjs +18 -0
- package/dist/chunk-LPVVA5J3.mjs.map +1 -0
- package/dist/chunk-NKLOZ5VI.mjs +112 -0
- package/dist/chunk-NKLOZ5VI.mjs.map +1 -0
- package/dist/chunk-QGA4WBDC.mjs +7 -0
- package/dist/chunk-QGA4WBDC.mjs.map +1 -0
- package/dist/chunk-QW7TVYOA.mjs +56 -0
- package/dist/chunk-QW7TVYOA.mjs.map +1 -0
- package/dist/chunk-SU5QEKYW.mjs +83 -0
- package/dist/chunk-SU5QEKYW.mjs.map +1 -0
- package/dist/chunk-T5A2E2RI.mjs +654 -0
- package/dist/chunk-T5A2E2RI.mjs.map +1 -0
- package/dist/chunk-T5OIJQK7.mjs +116 -0
- package/dist/chunk-T5OIJQK7.mjs.map +1 -0
- package/dist/chunk-VW7DD6HV.mjs +253 -0
- package/dist/chunk-VW7DD6HV.mjs.map +1 -0
- package/dist/chunk-XH7NLHGW.mjs +133 -0
- package/dist/chunk-XH7NLHGW.mjs.map +1 -0
- package/dist/client-DJ5haQGd.d.cts +22 -0
- package/dist/client-DwVGVSQz.d.ts +22 -0
- package/dist/cma/index.cjs +1349 -0
- package/dist/cma/index.cjs.map +1 -0
- package/dist/cma/index.d.cts +22 -0
- package/dist/cma/index.d.ts +22 -0
- package/dist/cma/index.mjs +70 -0
- package/dist/cma/index.mjs.map +1 -0
- package/dist/errors-CAw-IRCP.d.cts +65 -0
- package/dist/errors-CAw-IRCP.d.ts +65 -0
- package/dist/generative-ai/index.cjs +401 -0
- package/dist/generative-ai/index.cjs.map +1 -0
- package/dist/generative-ai/index.d.cts +31 -0
- package/dist/generative-ai/index.d.ts +31 -0
- package/dist/generative-ai/index.mjs +10 -0
- package/dist/generative-ai/index.mjs.map +1 -0
- package/dist/images/index.cjs +185 -0
- package/dist/images/index.cjs.map +1 -0
- package/dist/images/index.d.cts +27 -0
- package/dist/images/index.d.ts +27 -0
- package/dist/images/index.mjs +8 -0
- package/dist/images/index.mjs.map +1 -0
- package/dist/index.cjs +2909 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.mjs +153 -0
- package/dist/index.mjs.map +1 -0
- package/dist/knowledge-vault/index.cjs +413 -0
- package/dist/knowledge-vault/index.cjs.map +1 -0
- package/dist/knowledge-vault/index.d.cts +49 -0
- package/dist/knowledge-vault/index.d.ts +49 -0
- package/dist/knowledge-vault/index.mjs +10 -0
- package/dist/knowledge-vault/index.mjs.map +1 -0
- package/dist/launch/index.cjs +624 -0
- package/dist/launch/index.cjs.map +1 -0
- package/dist/launch/index.d.cts +169 -0
- package/dist/launch/index.d.ts +169 -0
- package/dist/launch/index.mjs +11 -0
- package/dist/launch/index.mjs.map +1 -0
- package/dist/react/auth/index.cjs +113 -0
- package/dist/react/auth/index.cjs.map +1 -0
- package/dist/react/auth/index.d.cts +33 -0
- package/dist/react/auth/index.d.ts +33 -0
- package/dist/react/auth/index.mjs +13 -0
- package/dist/react/auth/index.mjs.map +1 -0
- package/dist/react/content/index.cjs +113 -0
- package/dist/react/content/index.cjs.map +1 -0
- package/dist/react/content/index.d.cts +25 -0
- package/dist/react/content/index.d.ts +25 -0
- package/dist/react/content/index.mjs +7 -0
- package/dist/react/content/index.mjs.map +1 -0
- package/dist/react/hooks/index.cjs +2097 -0
- package/dist/react/hooks/index.cjs.map +1 -0
- package/dist/react/hooks/index.d.cts +77 -0
- package/dist/react/hooks/index.d.ts +77 -0
- package/dist/react/hooks/index.mjs +46 -0
- package/dist/react/hooks/index.mjs.map +1 -0
- package/dist/react/index.cjs +2307 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +16 -0
- package/dist/react/index.d.ts +16 -0
- package/dist/react/index.mjs +67 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react/provider/index.cjs +83 -0
- package/dist/react/provider/index.cjs.map +1 -0
- package/dist/react/provider/index.d.cts +30 -0
- package/dist/react/provider/index.d.ts +30 -0
- package/dist/react/provider/index.mjs +11 -0
- package/dist/react/provider/index.mjs.map +1 -0
- package/dist/regions/index.cjs +171 -0
- package/dist/regions/index.cjs.map +1 -0
- package/dist/regions/index.d.cts +55 -0
- package/dist/regions/index.d.ts +55 -0
- package/dist/regions/index.mjs +13 -0
- package/dist/regions/index.mjs.map +1 -0
- package/dist/request-builders-BxeolQIw.d.ts +735 -0
- package/dist/request-builders-C2IG1LUo.d.cts +735 -0
- package/dist/rte/index.cjs +683 -0
- package/dist/rte/index.cjs.map +1 -0
- package/dist/rte/index.d.cts +33 -0
- package/dist/rte/index.d.ts +33 -0
- package/dist/rte/index.mjs +17 -0
- package/dist/rte/index.mjs.map +1 -0
- package/dist/server/index.cjs +917 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +6 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.mjs +45 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/middleware/index.cjs +614 -0
- package/dist/server/middleware/index.cjs.map +1 -0
- package/dist/server/middleware/index.d.cts +77 -0
- package/dist/server/middleware/index.d.ts +77 -0
- package/dist/server/middleware/index.mjs +27 -0
- package/dist/server/middleware/index.mjs.map +1 -0
- package/dist/server/proxy/index.cjs +329 -0
- package/dist/server/proxy/index.cjs.map +1 -0
- package/dist/server/proxy/index.d.cts +143 -0
- package/dist/server/proxy/index.d.ts +143 -0
- package/dist/server/proxy/index.mjs +29 -0
- package/dist/server/proxy/index.mjs.map +1 -0
- package/dist/server/webhooks/index.cjs +131 -0
- package/dist/server/webhooks/index.cjs.map +1 -0
- package/dist/server/webhooks/index.d.cts +230 -0
- package/dist/server/webhooks/index.d.ts +230 -0
- package/dist/server/webhooks/index.mjs +23 -0
- package/dist/server/webhooks/index.mjs.map +1 -0
- package/dist/types-6D9VR7pT.d.cts +26 -0
- package/dist/types-AelT0rFJ.d.cts +21 -0
- package/dist/types-AelT0rFJ.d.ts +21 -0
- package/dist/types-Bu5yCgmw.d.ts +26 -0
- package/dist/types-DgixK-ll.d.cts +23 -0
- package/dist/types-DgixK-ll.d.ts +23 -0
- package/dist/types-DrMwdlH9.d.cts +245 -0
- package/dist/types-DrMwdlH9.d.ts +245 -0
- package/dist/ui/css/index.cjs +31 -0
- package/dist/ui/css/index.cjs.map +1 -0
- package/dist/ui/css/index.d.cts +15 -0
- package/dist/ui/css/index.d.ts +15 -0
- package/dist/ui/css/index.mjs +7 -0
- package/dist/ui/css/index.mjs.map +1 -0
- package/dist/ui/index.cjs +368 -0
- package/dist/ui/index.cjs.map +1 -0
- package/dist/ui/index.d.cts +4 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.mjs +33 -0
- package/dist/ui/index.mjs.map +1 -0
- package/dist/ui/theme/index.cjs +105 -0
- package/dist/ui/theme/index.cjs.map +1 -0
- package/dist/ui/theme/index.d.cts +33 -0
- package/dist/ui/theme/index.d.ts +33 -0
- package/dist/ui/theme/index.mjs +15 -0
- package/dist/ui/theme/index.mjs.map +1 -0
- package/dist/ui/tokens/index.cjs +286 -0
- package/dist/ui/tokens/index.cjs.map +1 -0
- package/dist/ui/tokens/index.d.cts +54 -0
- package/dist/ui/tokens/index.d.ts +54 -0
- package/dist/ui/tokens/index.mjs +17 -0
- package/dist/ui/tokens/index.mjs.map +1 -0
- package/dist/ui/tokens.css +408 -0
- package/dist/vue/auth/index.cjs +141 -0
- package/dist/vue/auth/index.cjs.map +1 -0
- package/dist/vue/auth/index.d.cts +78 -0
- package/dist/vue/auth/index.d.ts +78 -0
- package/dist/vue/auth/index.mjs +13 -0
- package/dist/vue/auth/index.mjs.map +1 -0
- package/dist/vue/composables/index.cjs +2108 -0
- package/dist/vue/composables/index.cjs.map +1 -0
- package/dist/vue/composables/index.d.cts +78 -0
- package/dist/vue/composables/index.d.ts +78 -0
- package/dist/vue/composables/index.mjs +46 -0
- package/dist/vue/composables/index.mjs.map +1 -0
- package/dist/vue/content/index.cjs +142 -0
- package/dist/vue/content/index.cjs.map +1 -0
- package/dist/vue/content/index.d.cts +47 -0
- package/dist/vue/content/index.d.ts +47 -0
- package/dist/vue/content/index.mjs +7 -0
- package/dist/vue/content/index.mjs.map +1 -0
- package/dist/vue/index.cjs +2389 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.cts +16 -0
- package/dist/vue/index.d.ts +16 -0
- package/dist/vue/index.mjs +69 -0
- package/dist/vue/index.mjs.map +1 -0
- package/dist/vue/provider/index.cjs +97 -0
- package/dist/vue/provider/index.cjs.map +1 -0
- package/dist/vue/provider/index.d.cts +90 -0
- package/dist/vue/provider/index.d.ts +90 -0
- package/dist/vue/provider/index.mjs +13 -0
- package/dist/vue/provider/index.mjs.map +1 -0
- package/package.json +195 -0
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/rte/index.ts
|
|
21
|
+
var rte_exports = {};
|
|
22
|
+
__export(rte_exports, {
|
|
23
|
+
fromHTML: () => fromHTML,
|
|
24
|
+
toHTML: () => toHTML,
|
|
25
|
+
toMarkdown: () => toMarkdown,
|
|
26
|
+
toPlainText: () => toPlainText,
|
|
27
|
+
transform: () => transform,
|
|
28
|
+
validate: () => validate
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(rte_exports);
|
|
31
|
+
|
|
32
|
+
// src/rte/to-html.ts
|
|
33
|
+
var import_json_rte_serializer = require("@contentstack/json-rte-serializer");
|
|
34
|
+
|
|
35
|
+
// src/rte/utils.ts
|
|
36
|
+
var KNOWN_RTE_TYPES = /* @__PURE__ */ new Set([
|
|
37
|
+
"doc",
|
|
38
|
+
"p",
|
|
39
|
+
"h1",
|
|
40
|
+
"h2",
|
|
41
|
+
"h3",
|
|
42
|
+
"h4",
|
|
43
|
+
"h5",
|
|
44
|
+
"h6",
|
|
45
|
+
"ul",
|
|
46
|
+
"ol",
|
|
47
|
+
"li",
|
|
48
|
+
"blockquote",
|
|
49
|
+
"code",
|
|
50
|
+
"img",
|
|
51
|
+
"a",
|
|
52
|
+
"table",
|
|
53
|
+
"tr",
|
|
54
|
+
"td",
|
|
55
|
+
"th",
|
|
56
|
+
"hr",
|
|
57
|
+
"reference"
|
|
58
|
+
]);
|
|
59
|
+
function isRecord(value) {
|
|
60
|
+
return typeof value === "object" && value !== null;
|
|
61
|
+
}
|
|
62
|
+
function isTextNode(value) {
|
|
63
|
+
return isRecord(value) && typeof value.text === "string" && typeof value.type !== "string";
|
|
64
|
+
}
|
|
65
|
+
function isElementNode(value) {
|
|
66
|
+
return isRecord(value) && typeof value.type === "string" && typeof value.uid === "string";
|
|
67
|
+
}
|
|
68
|
+
function decodeHTML(value) {
|
|
69
|
+
return value.replace(/ /g, " ").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
70
|
+
}
|
|
71
|
+
function createUid() {
|
|
72
|
+
const uuid = globalThis.crypto?.randomUUID;
|
|
73
|
+
if (typeof uuid === "function") {
|
|
74
|
+
return uuid.call(globalThis.crypto);
|
|
75
|
+
}
|
|
76
|
+
return `rte-${Math.random().toString(36).slice(2, 10)}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/rte/serializer.ts
|
|
80
|
+
var DEFAULT_TABLE_COLUMN_WIDTH = 250;
|
|
81
|
+
function normalizeForSerializer(doc) {
|
|
82
|
+
const normalized = normalizeNode(doc);
|
|
83
|
+
if (!isTextNode(normalized) && normalized.type === "doc") {
|
|
84
|
+
return normalized;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...doc,
|
|
88
|
+
children: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function normalizeNode(node) {
|
|
92
|
+
if (isTextNode(node)) {
|
|
93
|
+
return { ...node };
|
|
94
|
+
}
|
|
95
|
+
const children = node.children?.map((child) => normalizeNode(child));
|
|
96
|
+
const attrs = isRecord(node.attrs) ? { ...node.attrs } : {};
|
|
97
|
+
if (node.type === "a" && typeof attrs.url !== "string" && typeof attrs.href === "string") {
|
|
98
|
+
attrs.url = attrs.href;
|
|
99
|
+
}
|
|
100
|
+
if (node.type === "img" && typeof attrs.url !== "string" && typeof attrs.src === "string") {
|
|
101
|
+
attrs.url = attrs.src;
|
|
102
|
+
}
|
|
103
|
+
if (node.type === "table") {
|
|
104
|
+
const tableRows = (children ?? []).filter(
|
|
105
|
+
(row) => !isTextNode(row) && row.type === "tr"
|
|
106
|
+
);
|
|
107
|
+
const inferredCols = tableRows.reduce((max, row) => {
|
|
108
|
+
const columnCount = (row.children ?? []).filter(
|
|
109
|
+
(cell) => !isTextNode(cell) && (cell.type === "td" || cell.type === "th")
|
|
110
|
+
).length;
|
|
111
|
+
return Math.max(max, columnCount);
|
|
112
|
+
}, 0);
|
|
113
|
+
const normalizedCols = typeof attrs.cols === "number" && attrs.cols > 0 ? attrs.cols : inferredCols;
|
|
114
|
+
const normalizedRows = typeof attrs.rows === "number" && attrs.rows > 0 ? attrs.rows : tableRows.length;
|
|
115
|
+
const normalizedWidths = Array.isArray(attrs.colWidths) && attrs.colWidths.length > 0 && attrs.colWidths.every((width) => typeof width === "number") ? attrs.colWidths : Array.from({ length: Math.max(normalizedCols, 1) }, () => DEFAULT_TABLE_COLUMN_WIDTH);
|
|
116
|
+
return {
|
|
117
|
+
...node,
|
|
118
|
+
attrs: {
|
|
119
|
+
...attrs,
|
|
120
|
+
rows: normalizedRows,
|
|
121
|
+
cols: Math.max(normalizedCols, 1),
|
|
122
|
+
colWidths: normalizedWidths
|
|
123
|
+
},
|
|
124
|
+
...children ? { children } : {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
...node,
|
|
129
|
+
attrs,
|
|
130
|
+
...children ? { children } : {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/rte/to-html.ts
|
|
135
|
+
function toHTML(doc, options = {}) {
|
|
136
|
+
return (0, import_json_rte_serializer.jsonToHtml)(
|
|
137
|
+
normalizeForSerializer(doc),
|
|
138
|
+
buildSerializerOptions(options)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function buildSerializerOptions(options) {
|
|
142
|
+
const { renderEntry, renderAsset, serializerOptions } = options;
|
|
143
|
+
if (!renderEntry && !renderAsset) {
|
|
144
|
+
return serializerOptions;
|
|
145
|
+
}
|
|
146
|
+
const customElementTypes = {
|
|
147
|
+
...serializerOptions?.customElementTypes ?? {}
|
|
148
|
+
};
|
|
149
|
+
const existingReferenceRenderer = customElementTypes.reference;
|
|
150
|
+
customElementTypes.reference = (attrs, child, jsonBlock, extraProps) => {
|
|
151
|
+
const block = asRTENode(jsonBlock);
|
|
152
|
+
const referenceAttrs = isRecord(block.attrs) ? block.attrs : {};
|
|
153
|
+
if (referenceAttrs.type === "entry" && renderEntry) {
|
|
154
|
+
return renderEntry(referenceAttrs, block);
|
|
155
|
+
}
|
|
156
|
+
if (referenceAttrs.type === "asset" && renderAsset) {
|
|
157
|
+
return renderAsset(referenceAttrs, block);
|
|
158
|
+
}
|
|
159
|
+
return typeof existingReferenceRenderer === "function" ? existingReferenceRenderer(attrs, child, jsonBlock, extraProps) : "";
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
...serializerOptions,
|
|
163
|
+
customElementTypes
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function asRTENode(value) {
|
|
167
|
+
if (isRecord(value) && typeof value.type === "string" && typeof value.uid === "string") {
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
type: "reference",
|
|
172
|
+
uid: "reference"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/rte/to-markdown.ts
|
|
177
|
+
var import_json_rte_serializer2 = require("@contentstack/json-rte-serializer");
|
|
178
|
+
function toMarkdown(doc, options = {}) {
|
|
179
|
+
const mappedDoc = options.renderEntry || options.renderAsset ? mapReferenceNodes(doc, options) : doc;
|
|
180
|
+
const markdown = (0, import_json_rte_serializer2.jsonToMarkdown)(normalizeForSerializer(mappedDoc)).trim();
|
|
181
|
+
return normalizeMarkdownOutput(markdown);
|
|
182
|
+
}
|
|
183
|
+
function mapReferenceNodes(doc, options) {
|
|
184
|
+
const mapped = mapNode(doc, options);
|
|
185
|
+
if (isTextNode(mapped)) {
|
|
186
|
+
return {
|
|
187
|
+
...doc,
|
|
188
|
+
children: []
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
...doc,
|
|
193
|
+
...mapped,
|
|
194
|
+
type: "doc",
|
|
195
|
+
uid: mapped.uid ?? doc.uid
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function mapNode(node, options) {
|
|
199
|
+
if (isTextNode(node)) {
|
|
200
|
+
return { ...node };
|
|
201
|
+
}
|
|
202
|
+
if (node.type === "reference") {
|
|
203
|
+
const attrs = node.attrs ?? {};
|
|
204
|
+
if (attrs.type === "entry" && options.renderEntry) {
|
|
205
|
+
return { text: options.renderEntry(attrs, node) };
|
|
206
|
+
}
|
|
207
|
+
if (attrs.type === "asset" && options.renderAsset) {
|
|
208
|
+
return { text: options.renderAsset(attrs, node) };
|
|
209
|
+
}
|
|
210
|
+
return { text: "" };
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
...node,
|
|
214
|
+
...node.children ? { children: node.children.map((child) => mapNode(child, options)) } : {}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function normalizeMarkdownOutput(markdown) {
|
|
218
|
+
return markdown.replace(/!\[([^\]]*)\]\s*\n\s*\(([^)\n]+)\)/g, "");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/rte/to-plaintext.ts
|
|
222
|
+
var DOUBLE_BREAK_TYPES = /* @__PURE__ */ new Set([
|
|
223
|
+
"p",
|
|
224
|
+
"h1",
|
|
225
|
+
"h2",
|
|
226
|
+
"h3",
|
|
227
|
+
"h4",
|
|
228
|
+
"h5",
|
|
229
|
+
"h6",
|
|
230
|
+
"blockquote",
|
|
231
|
+
"code",
|
|
232
|
+
"ul",
|
|
233
|
+
"ol",
|
|
234
|
+
"table"
|
|
235
|
+
]);
|
|
236
|
+
var SINGLE_BREAK_TYPES = /* @__PURE__ */ new Set(["li", "tr", "td", "th"]);
|
|
237
|
+
function toPlainText(doc) {
|
|
238
|
+
return renderNode(doc).replace(/\n{3,}/g, "\n\n").trim();
|
|
239
|
+
}
|
|
240
|
+
function renderNode(node) {
|
|
241
|
+
if (isTextNode(node)) {
|
|
242
|
+
return node.text;
|
|
243
|
+
}
|
|
244
|
+
const children = (node.children ?? []).map((child) => renderNode(child)).join("");
|
|
245
|
+
if (node.type === "doc") {
|
|
246
|
+
return children;
|
|
247
|
+
}
|
|
248
|
+
if (node.type === "img") {
|
|
249
|
+
const alt = node.attrs?.alt;
|
|
250
|
+
if (typeof alt === "string" && alt.trim()) {
|
|
251
|
+
return `${alt}
|
|
252
|
+
|
|
253
|
+
`;
|
|
254
|
+
}
|
|
255
|
+
return "\n";
|
|
256
|
+
}
|
|
257
|
+
if (node.type === "a") {
|
|
258
|
+
const href = node.attrs?.href;
|
|
259
|
+
const text = children || (typeof href === "string" ? href : "");
|
|
260
|
+
return text;
|
|
261
|
+
}
|
|
262
|
+
if (node.type === "hr") {
|
|
263
|
+
return "\n";
|
|
264
|
+
}
|
|
265
|
+
if (node.type === "reference") {
|
|
266
|
+
return "";
|
|
267
|
+
}
|
|
268
|
+
if (DOUBLE_BREAK_TYPES.has(node.type)) {
|
|
269
|
+
return `${children}
|
|
270
|
+
|
|
271
|
+
`;
|
|
272
|
+
}
|
|
273
|
+
if (SINGLE_BREAK_TYPES.has(node.type)) {
|
|
274
|
+
return `${children}
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
return children;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/rte/from-html.ts
|
|
281
|
+
var import_json_rte_serializer3 = require("@contentstack/json-rte-serializer");
|
|
282
|
+
var VOID_TAGS = /* @__PURE__ */ new Set(["img", "hr", "br", "meta", "link", "input"]);
|
|
283
|
+
function fromHTML(html, options = {}) {
|
|
284
|
+
const parsed = parseWithSerializer(html, options);
|
|
285
|
+
if (parsed) {
|
|
286
|
+
return parsed;
|
|
287
|
+
}
|
|
288
|
+
return parseWithFallback(html);
|
|
289
|
+
}
|
|
290
|
+
function parseWithSerializer(html, options) {
|
|
291
|
+
try {
|
|
292
|
+
const parsed = (0, import_json_rte_serializer3.htmlToJson)(html, options.serializerOptions);
|
|
293
|
+
return normalizeDoc(parsed);
|
|
294
|
+
} catch {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function normalizeDoc(value) {
|
|
299
|
+
if (isRecord(value) && value.type === "doc" && Array.isArray(value.children)) {
|
|
300
|
+
return {
|
|
301
|
+
...value,
|
|
302
|
+
type: "doc",
|
|
303
|
+
uid: typeof value.uid === "string" && value.uid.length > 0 ? value.uid : createUid(),
|
|
304
|
+
children: value.children
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
function parseWithFallback(html) {
|
|
310
|
+
const root = parseHTML(html);
|
|
311
|
+
const children = convertNodes(root.children);
|
|
312
|
+
return {
|
|
313
|
+
type: "doc",
|
|
314
|
+
uid: createUid(),
|
|
315
|
+
children
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function parseHTML(html) {
|
|
319
|
+
const root = {
|
|
320
|
+
kind: "element",
|
|
321
|
+
tag: "root",
|
|
322
|
+
attrs: {},
|
|
323
|
+
children: []
|
|
324
|
+
};
|
|
325
|
+
const stack = [root];
|
|
326
|
+
const tokenPattern = /<!--[\s\S]*?-->|<\/?[^>]+>|[^<]+/g;
|
|
327
|
+
const tokens = html.match(tokenPattern) ?? [];
|
|
328
|
+
for (const token of tokens) {
|
|
329
|
+
if (!token) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (token.startsWith("<!--")) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (!token.startsWith("<")) {
|
|
336
|
+
const text = decodeHTML(token);
|
|
337
|
+
if (text.length === 0) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
const parent2 = stack[stack.length - 1];
|
|
341
|
+
if (!parent2) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
parent2.children.push({
|
|
345
|
+
kind: "text",
|
|
346
|
+
value: text
|
|
347
|
+
});
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (token.startsWith("</")) {
|
|
351
|
+
const closingTag = token.slice(2, -1).trim().toLowerCase();
|
|
352
|
+
while (stack.length > 1) {
|
|
353
|
+
const current = stack.pop();
|
|
354
|
+
if (current?.tag === closingTag) {
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const parsed = parseOpeningTag(token);
|
|
361
|
+
if (!parsed) {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const parent = stack[stack.length - 1];
|
|
365
|
+
if (!parent) {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
parent.children.push(parsed.element);
|
|
369
|
+
const isVoid = parsed.selfClosing || VOID_TAGS.has(parsed.element.tag);
|
|
370
|
+
if (!isVoid) {
|
|
371
|
+
stack.push(parsed.element);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return root;
|
|
375
|
+
}
|
|
376
|
+
function parseOpeningTag(token) {
|
|
377
|
+
const isSelfClosing = token.endsWith("/>");
|
|
378
|
+
const content = token.slice(1, token.length - (isSelfClosing ? 2 : 1)).trim();
|
|
379
|
+
if (!content) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
const tagMatch = content.match(/^([a-zA-Z0-9-]+)/);
|
|
383
|
+
if (!tagMatch?.[1]) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
const tag = tagMatch[1].toLowerCase();
|
|
387
|
+
const attrs = parseAttributes(content.slice(tag.length).trim());
|
|
388
|
+
return {
|
|
389
|
+
element: {
|
|
390
|
+
kind: "element",
|
|
391
|
+
tag,
|
|
392
|
+
attrs,
|
|
393
|
+
children: []
|
|
394
|
+
},
|
|
395
|
+
selfClosing: isSelfClosing
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function parseAttributes(input) {
|
|
399
|
+
const attrs = {};
|
|
400
|
+
const attrPattern = /([:@a-zA-Z0-9_-]+)(?:\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
|
|
401
|
+
let match = attrPattern.exec(input);
|
|
402
|
+
while (match) {
|
|
403
|
+
const key = match[1];
|
|
404
|
+
if (key) {
|
|
405
|
+
const value = decodeHTML(match[3] ?? match[4] ?? match[5] ?? "");
|
|
406
|
+
attrs[key] = value;
|
|
407
|
+
}
|
|
408
|
+
match = attrPattern.exec(input);
|
|
409
|
+
}
|
|
410
|
+
return attrs;
|
|
411
|
+
}
|
|
412
|
+
function convertNodes(nodes, marks = {}) {
|
|
413
|
+
const output = [];
|
|
414
|
+
for (const node of nodes) {
|
|
415
|
+
if (node.kind === "text") {
|
|
416
|
+
const cleaned = normalizeText(node.value);
|
|
417
|
+
if (!cleaned) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
output.push({
|
|
421
|
+
text: cleaned,
|
|
422
|
+
...marks.bold ? { bold: true } : {},
|
|
423
|
+
...marks.italic ? { italic: true } : {},
|
|
424
|
+
...marks.underline ? { underline: true } : {},
|
|
425
|
+
...marks.strikethrough ? { strikethrough: true } : {},
|
|
426
|
+
...marks.code ? { code: true } : {},
|
|
427
|
+
...marks.superscript ? { superscript: true } : {},
|
|
428
|
+
...marks.subscript ? { subscript: true } : {}
|
|
429
|
+
});
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
output.push(...convertElement(node, marks));
|
|
433
|
+
}
|
|
434
|
+
return output;
|
|
435
|
+
}
|
|
436
|
+
function convertElement(element, marks) {
|
|
437
|
+
switch (element.tag) {
|
|
438
|
+
case "strong":
|
|
439
|
+
case "b":
|
|
440
|
+
return convertNodes(element.children, { ...marks, bold: true });
|
|
441
|
+
case "em":
|
|
442
|
+
case "i":
|
|
443
|
+
return convertNodes(element.children, { ...marks, italic: true });
|
|
444
|
+
case "u":
|
|
445
|
+
return convertNodes(element.children, { ...marks, underline: true });
|
|
446
|
+
case "s":
|
|
447
|
+
case "strike":
|
|
448
|
+
case "del":
|
|
449
|
+
return convertNodes(element.children, { ...marks, strikethrough: true });
|
|
450
|
+
case "sup":
|
|
451
|
+
return convertNodes(element.children, { ...marks, superscript: true });
|
|
452
|
+
case "sub":
|
|
453
|
+
return convertNodes(element.children, { ...marks, subscript: true });
|
|
454
|
+
case "code":
|
|
455
|
+
return convertNodes(element.children, { ...marks, code: true });
|
|
456
|
+
case "br":
|
|
457
|
+
return [{ text: "\n" }];
|
|
458
|
+
case "img":
|
|
459
|
+
return [
|
|
460
|
+
{
|
|
461
|
+
type: "img",
|
|
462
|
+
uid: createUid(),
|
|
463
|
+
attrs: {
|
|
464
|
+
src: element.attrs.src ?? "",
|
|
465
|
+
alt: element.attrs.alt ?? ""
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
];
|
|
469
|
+
case "hr":
|
|
470
|
+
return [
|
|
471
|
+
{
|
|
472
|
+
type: "hr",
|
|
473
|
+
uid: createUid()
|
|
474
|
+
}
|
|
475
|
+
];
|
|
476
|
+
case "a":
|
|
477
|
+
return [
|
|
478
|
+
{
|
|
479
|
+
type: "a",
|
|
480
|
+
uid: createUid(),
|
|
481
|
+
attrs: {
|
|
482
|
+
href: element.attrs.href ?? "",
|
|
483
|
+
...element.attrs.target ? { target: element.attrs.target } : {}
|
|
484
|
+
},
|
|
485
|
+
children: convertNodes(element.children)
|
|
486
|
+
}
|
|
487
|
+
];
|
|
488
|
+
case "reference":
|
|
489
|
+
return [
|
|
490
|
+
{
|
|
491
|
+
type: "reference",
|
|
492
|
+
uid: createUid(),
|
|
493
|
+
attrs: {
|
|
494
|
+
...element.attrs
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
];
|
|
498
|
+
case "pre": {
|
|
499
|
+
const codeText = extractTextContent(element);
|
|
500
|
+
return [
|
|
501
|
+
{
|
|
502
|
+
type: "code",
|
|
503
|
+
uid: createUid(),
|
|
504
|
+
children: codeText ? [{ text: codeText }] : []
|
|
505
|
+
}
|
|
506
|
+
];
|
|
507
|
+
}
|
|
508
|
+
case "p":
|
|
509
|
+
case "h1":
|
|
510
|
+
case "h2":
|
|
511
|
+
case "h3":
|
|
512
|
+
case "h4":
|
|
513
|
+
case "h5":
|
|
514
|
+
case "h6":
|
|
515
|
+
case "ul":
|
|
516
|
+
case "ol":
|
|
517
|
+
case "li":
|
|
518
|
+
case "blockquote":
|
|
519
|
+
case "table":
|
|
520
|
+
case "tr":
|
|
521
|
+
case "td":
|
|
522
|
+
case "th":
|
|
523
|
+
return [
|
|
524
|
+
{
|
|
525
|
+
type: element.tag,
|
|
526
|
+
uid: createUid(),
|
|
527
|
+
children: convertNodes(element.children)
|
|
528
|
+
}
|
|
529
|
+
];
|
|
530
|
+
default:
|
|
531
|
+
return convertNodes(element.children, marks);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function extractTextContent(node) {
|
|
535
|
+
if (node.kind === "text") {
|
|
536
|
+
return decodeHTML(node.value);
|
|
537
|
+
}
|
|
538
|
+
return node.children.map((child) => extractTextContent(child)).join("");
|
|
539
|
+
}
|
|
540
|
+
function normalizeText(value) {
|
|
541
|
+
const collapsed = value.replace(/\s+/g, " ");
|
|
542
|
+
if (collapsed.trim().length === 0) {
|
|
543
|
+
return " ";
|
|
544
|
+
}
|
|
545
|
+
return collapsed;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// src/rte/transform.ts
|
|
549
|
+
function transform(doc, visitors) {
|
|
550
|
+
const transformed = visitNode(doc, visitors);
|
|
551
|
+
if (!transformed || isTextNode(transformed) || transformed.type !== "doc") {
|
|
552
|
+
return {
|
|
553
|
+
...doc,
|
|
554
|
+
children: []
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
return transformed;
|
|
558
|
+
}
|
|
559
|
+
function visitNode(node, visitors) {
|
|
560
|
+
if (isTextNode(node)) {
|
|
561
|
+
return { ...node };
|
|
562
|
+
}
|
|
563
|
+
const nextChildren = (node.children ?? []).map((child) => visitNode(child, visitors)).filter((child) => Boolean(child));
|
|
564
|
+
const withChildren = {
|
|
565
|
+
...node,
|
|
566
|
+
...node.children ? { children: nextChildren } : {}
|
|
567
|
+
};
|
|
568
|
+
const visitor = visitors[withChildren.type];
|
|
569
|
+
if (!visitor) {
|
|
570
|
+
return withChildren;
|
|
571
|
+
}
|
|
572
|
+
return visitor(withChildren);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/rte/validate.ts
|
|
576
|
+
function validate(doc) {
|
|
577
|
+
const errors = [];
|
|
578
|
+
if (!isElementNode(doc)) {
|
|
579
|
+
errors.push("Document must be an object node with type and uid");
|
|
580
|
+
return { valid: false, errors };
|
|
581
|
+
}
|
|
582
|
+
if (doc.type !== "doc") {
|
|
583
|
+
errors.push('Document root node must have type "doc"');
|
|
584
|
+
}
|
|
585
|
+
if (!Array.isArray(doc.children)) {
|
|
586
|
+
errors.push('Document root node must include a "children" array');
|
|
587
|
+
} else {
|
|
588
|
+
validateChildren(doc.children, "doc.children", errors);
|
|
589
|
+
}
|
|
590
|
+
return { valid: errors.length === 0, errors };
|
|
591
|
+
}
|
|
592
|
+
function validateChildren(children, path, errors) {
|
|
593
|
+
children.forEach((child, index) => {
|
|
594
|
+
validateNode(child, `${path}[${index}]`, errors);
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
function validateNode(node, path, errors) {
|
|
598
|
+
if (isTextNode(node)) {
|
|
599
|
+
if (typeof node.text !== "string") {
|
|
600
|
+
errors.push(`${path} must have a string text value`);
|
|
601
|
+
}
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (!isElementNode(node)) {
|
|
605
|
+
errors.push(`${path} must be a valid element node or text node`);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
validateElementNode(node, path, errors);
|
|
609
|
+
}
|
|
610
|
+
function validateElementNode(node, path, errors) {
|
|
611
|
+
if (!KNOWN_RTE_TYPES.has(node.type)) {
|
|
612
|
+
errors.push(`${path}.type "${node.type}" is not a supported RTE node type`);
|
|
613
|
+
}
|
|
614
|
+
if (typeof node.uid !== "string" || node.uid.trim().length === 0) {
|
|
615
|
+
errors.push(`${path}.uid must be a non-empty string`);
|
|
616
|
+
}
|
|
617
|
+
if (node.children !== void 0) {
|
|
618
|
+
if (!Array.isArray(node.children)) {
|
|
619
|
+
errors.push(`${path}.children must be an array when provided`);
|
|
620
|
+
} else {
|
|
621
|
+
validateChildren(node.children, `${path}.children`, errors);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
switch (node.type) {
|
|
625
|
+
case "img":
|
|
626
|
+
validateImgNode(node, path, errors);
|
|
627
|
+
break;
|
|
628
|
+
case "a":
|
|
629
|
+
validateAnchorNode(node, path, errors);
|
|
630
|
+
break;
|
|
631
|
+
case "reference":
|
|
632
|
+
validateReferenceNode(node, path, errors);
|
|
633
|
+
break;
|
|
634
|
+
case "hr":
|
|
635
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
636
|
+
errors.push(`${path}.children must be empty for hr nodes`);
|
|
637
|
+
}
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function validateImgNode(node, path, errors) {
|
|
642
|
+
if (!isRecord(node.attrs) || typeof node.attrs.src !== "string" || node.attrs.src.length === 0) {
|
|
643
|
+
errors.push(`${path}.attrs.src must be a non-empty string for img nodes`);
|
|
644
|
+
}
|
|
645
|
+
if (isRecord(node.attrs) && node.attrs.alt !== void 0 && typeof node.attrs.alt !== "string") {
|
|
646
|
+
errors.push(`${path}.attrs.alt must be a string when provided`);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function validateAnchorNode(node, path, errors) {
|
|
650
|
+
if (!isRecord(node.attrs) || typeof node.attrs.href !== "string" || node.attrs.href.length === 0) {
|
|
651
|
+
errors.push(`${path}.attrs.href must be a non-empty string for a nodes`);
|
|
652
|
+
}
|
|
653
|
+
if (isRecord(node.attrs) && node.attrs.target !== void 0 && typeof node.attrs.target !== "string") {
|
|
654
|
+
errors.push(`${path}.attrs.target must be a string when provided`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function validateReferenceNode(node, path, errors) {
|
|
658
|
+
if (!isRecord(node.attrs)) {
|
|
659
|
+
errors.push(`${path}.attrs must be present for reference nodes`);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const refType = node.attrs.type;
|
|
663
|
+
if (refType !== "entry" && refType !== "asset") {
|
|
664
|
+
errors.push(`${path}.attrs.type must be "entry" or "asset" for reference nodes`);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (refType === "entry" && typeof node.attrs["entry-uid"] !== "string") {
|
|
668
|
+
errors.push(`${path}.attrs["entry-uid"] must be provided for entry references`);
|
|
669
|
+
}
|
|
670
|
+
if (refType === "asset" && typeof node.attrs["asset-uid"] !== "string") {
|
|
671
|
+
errors.push(`${path}.attrs["asset-uid"] must be provided for asset references`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
675
|
+
0 && (module.exports = {
|
|
676
|
+
fromHTML,
|
|
677
|
+
toHTML,
|
|
678
|
+
toMarkdown,
|
|
679
|
+
toPlainText,
|
|
680
|
+
transform,
|
|
681
|
+
validate
|
|
682
|
+
});
|
|
683
|
+
//# sourceMappingURL=index.cjs.map
|