blixify-ui-web 1.2.116 → 1.2.118

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,34 @@
1
+ /**
2
+ * Mermaid diagrams for fenced ```mermaid code blocks.
3
+ *
4
+ * INFO: mermaid is never imported here. This library compiles to CommonJS, so
5
+ * an `import("mermaid")` would become a plain require and pull the whole
6
+ * renderer into every app that uses a markdown field. The host passes a loader
7
+ * instead — `lib.mermaid: () => import("mermaid")` — and its bundler splits the
8
+ * chunk so it is only fetched by a page that actually holds a diagram. A host
9
+ * that passes nothing gets the source shown as an ordinary code block.
10
+ */
11
+ export type MermaidLoader = () => Promise<any>;
12
+ export interface MermaidResult {
13
+ svg?: string;
14
+ error?: string;
15
+ }
16
+ export declare const MERMAID_LANGUAGE = "mermaid";
17
+ export declare const MERMAID_STARTER = "flowchart LR\n A[Start] --> B[Next step]";
18
+ /**
19
+ * Renders one diagram's source to an svg string.
20
+ *
21
+ * INFO: never throws — a typo in a diagram is an everyday edit, and it must
22
+ * show a readable message in place of the diagram rather than break the page
23
+ * or the editor around it.
24
+ */
25
+ export declare const handleRenderMermaid: (loader: MermaidLoader, source: string) => Promise<MermaidResult>;
26
+ /**
27
+ * Replaces every rendered ```mermaid block inside a container with its diagram.
28
+ *
29
+ * INFO: used by the static renderer, which sets raw html — so this runs over the
30
+ * DOM after mount. The error is written as text, never as html, because it can
31
+ * echo the diagram source back.
32
+ */
33
+ export declare const handleRenderMermaidBlocks: (container: HTMLElement | null, loader?: MermaidLoader) => Promise<void>;
34
+ //# sourceMappingURL=mermaid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../../../src/components/input/markdown/mermaid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,eAAO,MAAM,eAAe,8CAA8C,CAAC;AAiC3E;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,WACtB,aAAa,UACb,MAAM,KACb,OAAO,CAAC,aAAa,CAgBvB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,cACzB,WAAW,GAAG,IAAI,WACpB,aAAa,kBA+BvB,CAAC"}
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ /**
3
+ * Mermaid diagrams for fenced ```mermaid code blocks.
4
+ *
5
+ * INFO: mermaid is never imported here. This library compiles to CommonJS, so
6
+ * an `import("mermaid")` would become a plain require and pull the whole
7
+ * renderer into every app that uses a markdown field. The host passes a loader
8
+ * instead — `lib.mermaid: () => import("mermaid")` — and its bundler splits the
9
+ * chunk so it is only fetched by a page that actually holds a diagram. A host
10
+ * that passes nothing gets the source shown as an ordinary code block.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.handleRenderMermaidBlocks = exports.handleRenderMermaid = exports.MERMAID_STARTER = exports.MERMAID_LANGUAGE = void 0;
50
+ exports.MERMAID_LANGUAGE = "mermaid";
51
+ exports.MERMAID_STARTER = "flowchart LR\n A[Start] --> B[Next step]";
52
+ // INFO: one initialisation per loaded module. initialize is global mermaid
53
+ // state, so repeating it per diagram would be wasted work at best.
54
+ var initialised = new WeakSet();
55
+ var renderCount = 0;
56
+ var handleResolveMermaid = function (loader) { return __awaiter(void 0, void 0, void 0, function () {
57
+ var loaded, mermaid;
58
+ var _a;
59
+ return __generator(this, function (_b) {
60
+ switch (_b.label) {
61
+ case 0: return [4 /*yield*/, loader()];
62
+ case 1:
63
+ loaded = _b.sent();
64
+ mermaid = (_a = loaded === null || loaded === void 0 ? void 0 : loaded.default) !== null && _a !== void 0 ? _a : loaded;
65
+ if (!(mermaid === null || mermaid === void 0 ? void 0 : mermaid.render))
66
+ throw new Error("Mermaid could not be loaded");
67
+ if (!initialised.has(mermaid)) {
68
+ mermaid.initialize({
69
+ startOnLoad: false,
70
+ // INFO: documents can be published to anyone with a link. "strict" keeps
71
+ // mermaid sanitising labels and refusing click handlers, so a diagram's
72
+ // source cannot put script into the reader's page.
73
+ securityLevel: "strict",
74
+ // INFO: html labels stay on so inline formatting (<b>, <i>, <sup>) draws
75
+ // instead of showing as literal tags. Strict still keeps sanitised tags
76
+ // there, and an <img> would be a remote image any author can make every
77
+ // reader of a public page fetch, so it is removed outright.
78
+ dompurifyConfig: { FORBID_TAGS: ["img"] },
79
+ // INFO: on a syntax error mermaid otherwise appends its own "Syntax error
80
+ // in text" graphic to document.body — outside the block, and left behind
81
+ // at the bottom of the page after the message here has replaced it
82
+ suppressErrorRendering: true,
83
+ });
84
+ initialised.add(mermaid);
85
+ }
86
+ return [2 /*return*/, mermaid];
87
+ }
88
+ });
89
+ }); };
90
+ /**
91
+ * Renders one diagram's source to an svg string.
92
+ *
93
+ * INFO: never throws — a typo in a diagram is an everyday edit, and it must
94
+ * show a readable message in place of the diagram rather than break the page
95
+ * or the editor around it.
96
+ */
97
+ var handleRenderMermaid = function (loader, source) { return __awaiter(void 0, void 0, void 0, function () {
98
+ var trimmed, mermaid, svg, err_1, message;
99
+ var _a, _b;
100
+ return __generator(this, function (_c) {
101
+ switch (_c.label) {
102
+ case 0:
103
+ trimmed = (source !== null && source !== void 0 ? source : "").trim();
104
+ if (!trimmed)
105
+ return [2 /*return*/, { error: "This diagram is empty." }];
106
+ _c.label = 1;
107
+ case 1:
108
+ _c.trys.push([1, 4, , 5]);
109
+ return [4 /*yield*/, handleResolveMermaid(loader)];
110
+ case 2:
111
+ mermaid = _c.sent();
112
+ renderCount += 1;
113
+ return [4 /*yield*/, mermaid.render("mermaid-diagram-".concat(renderCount), trimmed)];
114
+ case 3:
115
+ svg = (_c.sent()).svg;
116
+ return [2 /*return*/, { svg: svg }];
117
+ case 4:
118
+ err_1 = _c.sent();
119
+ message = String((_b = (_a = err_1 === null || err_1 === void 0 ? void 0 : err_1.message) !== null && _a !== void 0 ? _a : err_1) !== null && _b !== void 0 ? _b : "").split("\n")[0];
120
+ return [2 /*return*/, {
121
+ error: message
122
+ ? "This diagram could not be drawn: ".concat(message)
123
+ : "This diagram could not be drawn.",
124
+ }];
125
+ case 5: return [2 /*return*/];
126
+ }
127
+ });
128
+ }); };
129
+ exports.handleRenderMermaid = handleRenderMermaid;
130
+ /**
131
+ * Replaces every rendered ```mermaid block inside a container with its diagram.
132
+ *
133
+ * INFO: used by the static renderer, which sets raw html — so this runs over the
134
+ * DOM after mount. The error is written as text, never as html, because it can
135
+ * echo the diagram source back.
136
+ */
137
+ var handleRenderMermaidBlocks = function (container, loader) { return __awaiter(void 0, void 0, void 0, function () {
138
+ var blocks, _i, blocks_1, eachCode, pre, result, figure;
139
+ var _a, _b;
140
+ return __generator(this, function (_c) {
141
+ switch (_c.label) {
142
+ case 0:
143
+ if (!container || !loader)
144
+ return [2 /*return*/];
145
+ blocks = Array.from(container.querySelectorAll("pre > code.language-".concat(exports.MERMAID_LANGUAGE)));
146
+ _i = 0, blocks_1 = blocks;
147
+ _c.label = 1;
148
+ case 1:
149
+ if (!(_i < blocks_1.length)) return [3 /*break*/, 4];
150
+ eachCode = blocks_1[_i];
151
+ pre = eachCode.parentElement;
152
+ // INFO: a failed block stays in the DOM, so it is marked to keep a second
153
+ // pass over the same html from stacking another error above it
154
+ if (!pre || !pre.isConnected || pre.hasAttribute("data-mermaid-failed"))
155
+ return [3 /*break*/, 3];
156
+ return [4 /*yield*/, (0, exports.handleRenderMermaid)(loader, (_a = eachCode.textContent) !== null && _a !== void 0 ? _a : "")];
157
+ case 2:
158
+ result = _c.sent();
159
+ // INFO: the html may have been replaced while the diagram was rendering
160
+ if (!pre.isConnected)
161
+ return [3 /*break*/, 3];
162
+ figure = document.createElement("div");
163
+ figure.setAttribute("data-mermaid", "");
164
+ if (result.svg) {
165
+ figure.className = "not-prose my-3 overflow-x-auto";
166
+ figure.innerHTML = result.svg;
167
+ pre.replaceWith(figure);
168
+ return [3 /*break*/, 3];
169
+ }
170
+ // INFO: a failed diagram keeps its source on screen under the message, so
171
+ // the reader still gets the content the diagram was meant to show
172
+ figure.className =
173
+ "not-prose my-3 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700";
174
+ figure.textContent = (_b = result.error) !== null && _b !== void 0 ? _b : "This diagram could not be drawn.";
175
+ pre.setAttribute("data-mermaid-failed", "");
176
+ pre.before(figure);
177
+ _c.label = 3;
178
+ case 3:
179
+ _i++;
180
+ return [3 /*break*/, 1];
181
+ case 4: return [2 /*return*/];
182
+ }
183
+ });
184
+ }); };
185
+ exports.handleRenderMermaidBlocks = handleRenderMermaidBlocks;
186
+ //# sourceMappingURL=mermaid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../../../src/components/input/markdown/mermaid.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASU,QAAA,gBAAgB,GAAG,SAAS,CAAC;AAE7B,QAAA,eAAe,GAAG,2CAA2C,CAAC;AAE3E,2EAA2E;AAC3E,mEAAmE;AACnE,IAAM,WAAW,GAAG,IAAI,OAAO,EAAU,CAAC;AAC1C,IAAI,WAAW,GAAG,CAAC,CAAC;AAEpB,IAAM,oBAAoB,GAAG,UAAO,MAAqB;;;;;oBACxC,qBAAM,MAAM,EAAE,EAAA;;gBAAvB,MAAM,GAAG,SAAc;gBACvB,OAAO,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE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BACpD,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;oBAC9B,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;oBACxB,wBAAS;gBACX,CAAC;gBACD,0EAA0E;gBAC1E,kEAAkE;gBAClE,MAAM,CAAC,SAAS;oBACd,0FAA0F,CAAC;gBAC7F,MAAM,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,KAAK,mCAAI,kCAAkC,CAAC;gBACxE,GAAG,CAAC,YAAY,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;gBAC5C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;;gBAvBE,IAAM,CAAA;;;;;KAyB9B,CAAC;AAjCW,QAAA,yBAAyB,6BAiCpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-ui-web",
3
- "version": "1.2.116",
3
+ "version": "1.2.118",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -93,6 +93,7 @@
93
93
  "commit-message-validator": "^1.0.2",
94
94
  "copyfiles": "^2.4.1",
95
95
  "husky": "^8.0.2",
96
+ "mermaid": "^11.17.2",
96
97
  "papaparse": "^5.4.0",
97
98
  "postcss": "^8.4.18",
98
99
  "prop-types": "^15.8.1",
@@ -125,6 +126,7 @@
125
126
  "@tailwindcss/forms": "^0.5.3",
126
127
  "@tailwindcss/typography": "^0.5.13",
127
128
  "@tiptap/core": "^3.22.5",
129
+ "@tiptap/extension-code-block": "^3.22.5",
128
130
  "@tiptap/extension-image": "^3.22.5",
129
131
  "@tiptap/extension-list": "^3.22.5",
130
132
  "@tiptap/extension-subscript": "^3.22.5",