@examplary/ui 1.55.0 → 1.58.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/components/ai/ai-icon.js +2 -25
- package/dist/components/ai/ai-prompt-suggestion.js +3 -26
- package/dist/components/brand/tick-icon.js +2 -25
- package/dist/components/chat/chat-input.js +8 -31
- package/dist/components/chat/chat-typing-indicator.js +2 -2
- package/dist/components/chat/chat-view.js +6 -34
- package/dist/components/loading/ai-spinner.js +2 -13
- package/dist/components/loading/tick-loader.js +39 -104
- package/dist/components/print/answer-box.js +2 -25
- package/dist/components/question-types/fetch-component.js +65 -106
- package/dist/components/question-types/format-question-type.d.ts +41 -41
- package/dist/components/question-types/format-question-type.js +36 -37
- package/dist/components/rich-text/minimal-rich-text-field.d.ts +2 -2
- package/dist/components/rich-text/minimal-rich-text-field.js +47 -85
- package/dist/components/rich-text/rich-text-display.js +15 -33
- package/dist/components/rich-text/rich-text-field.js +2 -25
- package/dist/components/rich-text/rich-text-toolbar.d.ts +3 -2
- package/dist/components/rich-text/rich-text-toolbar.js +5 -6
- package/dist/components/rich-text/tiptap/collaboration-caret.js +24 -34
- package/dist/components/rich-text/tiptap/comments/comment-bubble.d.ts +1 -1
- package/dist/components/rich-text/tiptap/comments/comment-bubble.js +36 -41
- package/dist/components/rich-text/tiptap/content-reference.js +6 -7
- package/dist/components/rich-text/tiptap/crop-page-clipping-modal.d.ts +3 -3
- package/dist/components/rich-text/tiptap/crop-page-clipping-modal.js +20 -25
- package/dist/components/rich-text/tiptap/extensions.d.ts +2 -2
- package/dist/components/rich-text/tiptap/extensions.js +6 -16
- package/dist/components/rich-text/tiptap/file-attachment.js +9 -11
- package/dist/components/rich-text/tiptap/file-handler.d.ts +2 -2
- package/dist/components/rich-text/tiptap/file-handler.js +110 -185
- package/dist/components/rich-text/tiptap/image.js +18 -23
- package/dist/components/rich-text/tiptap/mathematics-component.js +25 -30
- package/dist/components/rich-text/tiptap/mathematics.js +56 -82
- package/dist/components/rich-text/tiptap/page-clipping.js +3 -4
- package/dist/components/rich-text/tiptap/png-scanner.js +63 -108
- package/dist/components/rich-text/tiptap/rich-text-formatting-menu.d.ts +1 -1
- package/dist/components/rich-text/tiptap/rich-text-formatting-menu.js +31 -46
- package/dist/components/ui/alert.d.ts +3 -3
- package/dist/components/ui/alert.js +7 -32
- package/dist/components/ui/avatar.js +18 -14
- package/dist/components/ui/badge.d.ts +3 -3
- package/dist/components/ui/badge.js +4 -27
- package/dist/components/ui/button.d.ts +4 -4
- package/dist/components/ui/button.js +4 -27
- package/dist/components/ui/card.js +6 -46
- package/dist/components/ui/checkbox.js +1 -26
- package/dist/components/ui/color-picker.js +11 -22
- package/dist/components/ui/command-palette.d.ts +2 -2
- package/dist/components/ui/command-palette.js +38 -72
- package/dist/components/ui/command.js +18 -49
- package/dist/components/ui/comments.js +37 -107
- package/dist/components/ui/context-menu.js +30 -67
- package/dist/components/ui/dialog.js +15 -61
- package/dist/components/ui/dropdown.js +17 -64
- package/dist/components/ui/floating-menu.js +2 -25
- package/dist/components/ui/floating-resizable.d.ts +5 -0
- package/dist/components/ui/floating-resizable.js +24 -0
- package/dist/components/ui/help-icon.js +1 -2
- package/dist/components/ui/icon-picker.js +50 -130
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/input.js +2 -25
- package/dist/components/ui/label.d.ts +1 -1
- package/dist/components/ui/label.js +2 -27
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/popover.js +4 -32
- package/dist/components/ui/progress-bar.js +2 -3
- package/dist/components/ui/radio-group.js +4 -28
- package/dist/components/ui/resizable.d.ts +6 -9
- package/dist/components/ui/resizable.js +13 -60
- package/dist/components/ui/select.js +12 -55
- package/dist/components/ui/separator.js +1 -26
- package/dist/components/ui/sheet.d.ts +3 -3
- package/dist/components/ui/sheet.js +11 -51
- package/dist/components/ui/skeleton.js +2 -25
- package/dist/components/ui/slider.js +7 -32
- package/dist/components/ui/sortable.d.ts +1 -1
- package/dist/components/ui/sortable.js +131 -155
- package/dist/components/ui/switch.d.ts +3 -3
- package/dist/components/ui/switch.js +3 -28
- package/dist/components/ui/table.js +8 -54
- package/dist/components/ui/tabs.js +8 -34
- package/dist/components/ui/text-selection-menu.d.ts +1 -1
- package/dist/components/ui/text-selection-menu.js +19 -25
- package/dist/components/ui/textarea.js +7 -30
- package/dist/components/ui/tooltip.js +4 -29
- package/dist/components/web-components/content-reference.js +81 -106
- package/dist/components/web-components/file-attachment.js +9 -30
- package/dist/components/web-components/index.js +1 -1
- package/dist/components/web-components/inline-comment-reply.js +3 -24
- package/dist/components/web-components/inline-comment.js +3 -24
- package/dist/components/web-components/inline-math.js +14 -36
- package/dist/components/web-components/page-clipping.js +13 -34
- package/dist/lib/compose-refs.js +10 -18
- package/dist/lib/use-spin-loop.js +19 -69
- package/dist/src/global.css +2 -2
- package/dist/utils.js +1 -5
- package/package.json +7 -6
- package/src/global.css +6 -1
- package/dist/components/rich-text/tiptap/comments/comment-reply.d.ts +0 -21
- package/dist/components/rich-text/tiptap/comments/comment-reply.js +0 -230
- package/dist/components/rich-text/tiptap/comments/comment.d.ts +0 -22
- package/dist/components/rich-text/tiptap/comments/comment.js +0 -199
- package/dist/components/rich-text/tiptap/comments/helpers.d.ts +0 -19
- package/dist/components/rich-text/tiptap/comments/helpers.js +0 -95
- package/dist/components/rich-text/tiptap/comments/types.d.ts +0 -29
- package/dist/components/rich-text/tiptap/comments/types.js +0 -1
|
@@ -1,45 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
import * as _React from "react";
|
|
39
3
|
import * as _ReactDom from "react-dom";
|
|
40
4
|
import * as _jsxRuntime from "react/jsx-runtime";
|
|
41
5
|
import * as ExamplaryUI from "../../index";
|
|
42
|
-
|
|
6
|
+
const componentCache = new Map();
|
|
43
7
|
/**
|
|
44
8
|
* Little helper to evaluate the JS code in the context of the module.
|
|
45
9
|
*
|
|
@@ -52,84 +16,79 @@ var componentCache = new Map();
|
|
|
52
16
|
* However, if the code being evaluated here were to be modified by an attacker
|
|
53
17
|
* after review, but before being loaded by users, then this could be a security risk.
|
|
54
18
|
*/
|
|
55
|
-
|
|
56
|
-
return new Function(
|
|
19
|
+
const evalInScope = (js, contextAsScope) => {
|
|
20
|
+
return new Function(`
|
|
21
|
+
with (this) {
|
|
22
|
+
${js}
|
|
23
|
+
|
|
24
|
+
if (module.exports.default) {
|
|
25
|
+
module.exports.default._context = this;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`).call(contextAsScope);
|
|
57
29
|
};
|
|
58
|
-
export
|
|
59
|
-
if (document.querySelector(
|
|
30
|
+
export const loadComponentStyles = (url) => {
|
|
31
|
+
if (document.querySelector(`link[href="${url}"]`)) {
|
|
60
32
|
return; // Styles already loaded
|
|
61
33
|
}
|
|
62
|
-
|
|
34
|
+
const link = document.createElement("link");
|
|
63
35
|
link.rel = "stylesheet";
|
|
64
36
|
link.href = url;
|
|
65
37
|
link.dataset.source = "component-loader";
|
|
66
38
|
document.head.appendChild(link);
|
|
67
39
|
};
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var require_1 = function (name) {
|
|
76
|
-
if (name === "react")
|
|
77
|
-
// @ts-expect-error default
|
|
78
|
-
return _React.default || _React;
|
|
79
|
-
if (name === "react-dom")
|
|
80
|
-
// @ts-expect-error default
|
|
81
|
-
return _ReactDom.default || _ReactDom;
|
|
82
|
-
if (name === "react/jsx-runtime")
|
|
83
|
-
// @ts-expect-error default
|
|
84
|
-
return _jsxRuntime.default || _jsxRuntime;
|
|
85
|
-
if (name === "@examplary/ui")
|
|
86
|
-
// @ts-expect-error default
|
|
87
|
-
return ExamplaryUI.default || ExamplaryUI;
|
|
88
|
-
throw new Error("Module not found: ".concat(name));
|
|
89
|
-
};
|
|
90
|
-
evalInScope(js, {
|
|
91
|
-
module: module_1,
|
|
92
|
-
exports: module_1.exports,
|
|
40
|
+
export const evalComponent = async (js) => {
|
|
41
|
+
let _componentResult;
|
|
42
|
+
(() => {
|
|
43
|
+
try {
|
|
44
|
+
const module = { exports: { default: null } };
|
|
45
|
+
const require = (name) => {
|
|
46
|
+
if (name === "react")
|
|
93
47
|
// @ts-expect-error default
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
48
|
+
return _React.default || _React;
|
|
49
|
+
if (name === "react-dom")
|
|
50
|
+
// @ts-expect-error default
|
|
51
|
+
return _ReactDom.default || _ReactDom;
|
|
52
|
+
if (name === "react/jsx-runtime")
|
|
53
|
+
// @ts-expect-error default
|
|
54
|
+
return _jsxRuntime.default || _jsxRuntime;
|
|
55
|
+
if (name === "@examplary/ui")
|
|
56
|
+
// @ts-expect-error default
|
|
57
|
+
return ExamplaryUI.default || ExamplaryUI;
|
|
58
|
+
throw new Error(`Module not found: ${name}`);
|
|
59
|
+
};
|
|
60
|
+
evalInScope(js, {
|
|
61
|
+
module,
|
|
62
|
+
exports: module.exports,
|
|
63
|
+
// @ts-expect-error default
|
|
64
|
+
React: _React.default || _React,
|
|
65
|
+
require,
|
|
66
|
+
__dirname: "/web/task",
|
|
67
|
+
__filename: "dynamic-module.js",
|
|
68
|
+
});
|
|
69
|
+
_componentResult = module.exports?.default;
|
|
70
|
+
if (!_componentResult) {
|
|
71
|
+
throw new Error("No default export found in the module");
|
|
107
72
|
}
|
|
108
|
-
})();
|
|
109
|
-
return [2 /*return*/, _componentResult];
|
|
110
|
-
});
|
|
111
|
-
}); };
|
|
112
|
-
export var fetchComponent = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
-
var js, res;
|
|
114
|
-
return __generator(this, function (_a) {
|
|
115
|
-
switch (_a.label) {
|
|
116
|
-
case 0:
|
|
117
|
-
if (componentCache.has(url)) {
|
|
118
|
-
return [2 /*return*/, componentCache.get(url)];
|
|
119
|
-
}
|
|
120
|
-
return [4 /*yield*/, fetch(url).then(function (res) {
|
|
121
|
-
if (!res.ok) {
|
|
122
|
-
throw new Error("Failed to fetch component from ".concat(url, ": ").concat(res.status, " ").concat(res.statusText));
|
|
123
|
-
}
|
|
124
|
-
return res.text();
|
|
125
|
-
})];
|
|
126
|
-
case 1:
|
|
127
|
-
js = _a.sent();
|
|
128
|
-
return [4 /*yield*/, evalComponent(js)];
|
|
129
|
-
case 2:
|
|
130
|
-
res = _a.sent();
|
|
131
|
-
componentCache.set(url, res);
|
|
132
|
-
return [2 /*return*/, res];
|
|
133
73
|
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error(e);
|
|
76
|
+
throw new Error(`Failed to evaluate component: ${e.message}`);
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
return _componentResult;
|
|
80
|
+
};
|
|
81
|
+
export const fetchComponent = async (url) => {
|
|
82
|
+
if (componentCache.has(url)) {
|
|
83
|
+
return componentCache.get(url);
|
|
84
|
+
}
|
|
85
|
+
const js = await fetch(url).then((res) => {
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
throw new Error(`Failed to fetch component from ${url}: ${res.status} ${res.statusText}`);
|
|
88
|
+
}
|
|
89
|
+
return res.text();
|
|
134
90
|
});
|
|
135
|
-
|
|
91
|
+
const res = await evalComponent(js);
|
|
92
|
+
componentCache.set(url, res);
|
|
93
|
+
return res;
|
|
94
|
+
};
|
|
@@ -14,63 +14,63 @@ export declare const formatQuestionType: (type: QuestionType, i18n: any) => {
|
|
|
14
14
|
options: {
|
|
15
15
|
label: any;
|
|
16
16
|
value: string;
|
|
17
|
-
}[];
|
|
17
|
+
}[] | undefined;
|
|
18
18
|
id: string;
|
|
19
19
|
type: "string" | "number" | "boolean" | "tags" | "enum" | "custom" | "string-array" | "scoring-criteria" | "question-type";
|
|
20
|
-
description?: string;
|
|
21
|
-
index?: number;
|
|
22
|
-
hidden?: boolean;
|
|
20
|
+
description?: string | undefined;
|
|
21
|
+
index?: number | undefined;
|
|
22
|
+
hidden?: boolean | undefined;
|
|
23
23
|
default?: any;
|
|
24
|
-
required?: boolean;
|
|
25
|
-
step?: number;
|
|
26
|
-
min?: number;
|
|
27
|
-
max?: number;
|
|
28
|
-
}[];
|
|
24
|
+
required?: boolean | undefined;
|
|
25
|
+
step?: number | undefined;
|
|
26
|
+
min?: number | undefined;
|
|
27
|
+
max?: number | undefined;
|
|
28
|
+
}[] | undefined;
|
|
29
29
|
id: string;
|
|
30
|
-
$schema?: string;
|
|
31
|
-
icon?: string;
|
|
32
|
-
shortcut?: string;
|
|
30
|
+
$schema?: string | undefined;
|
|
31
|
+
icon?: string | undefined;
|
|
32
|
+
shortcut?: string | undefined;
|
|
33
33
|
generation?: {
|
|
34
34
|
enabled: boolean;
|
|
35
|
-
instructions?: string | string[];
|
|
36
|
-
};
|
|
35
|
+
instructions?: string | string[] | undefined;
|
|
36
|
+
} | undefined;
|
|
37
37
|
grading?: {
|
|
38
38
|
enabled: boolean;
|
|
39
|
-
instructions?: string | string[];
|
|
40
|
-
};
|
|
39
|
+
instructions?: string | string[] | undefined;
|
|
40
|
+
} | undefined;
|
|
41
41
|
scanning?: {
|
|
42
|
-
instructions?: string | string[];
|
|
43
|
-
};
|
|
44
|
-
timeEstimateMinutes?: number;
|
|
45
|
-
isAi?: boolean;
|
|
46
|
-
backgroundColor?: string;
|
|
47
|
-
enforcePosition?: "end" | "start";
|
|
48
|
-
hideSettings?: boolean;
|
|
49
|
-
isPreviewRefreshable?: boolean;
|
|
50
|
-
hasSimpleScoring?: boolean;
|
|
42
|
+
instructions?: string | string[] | undefined;
|
|
43
|
+
} | undefined;
|
|
44
|
+
timeEstimateMinutes?: number | undefined;
|
|
45
|
+
isAi?: boolean | undefined;
|
|
46
|
+
backgroundColor?: string | undefined;
|
|
47
|
+
enforcePosition?: "end" | "start" | undefined;
|
|
48
|
+
hideSettings?: boolean | undefined;
|
|
49
|
+
isPreviewRefreshable?: boolean | undefined;
|
|
50
|
+
hasSimpleScoring?: boolean | undefined;
|
|
51
51
|
components?: {
|
|
52
|
-
assessment?: string;
|
|
53
|
-
print?: string;
|
|
54
|
-
"settings-area"?: string;
|
|
55
|
-
results?: string;
|
|
56
|
-
};
|
|
57
|
-
public?: boolean;
|
|
58
|
-
translations?: Record<string, string | Record<string, string
|
|
52
|
+
assessment?: string | undefined;
|
|
53
|
+
print?: string | undefined;
|
|
54
|
+
"settings-area"?: string | undefined;
|
|
55
|
+
results?: string | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
public?: boolean | undefined;
|
|
58
|
+
translations?: Record<string, string | Record<string, string>> | undefined;
|
|
59
59
|
capabilities?: {
|
|
60
60
|
[x: string]: unknown;
|
|
61
|
-
"answer-scanning"?: boolean;
|
|
62
|
-
};
|
|
61
|
+
"answer-scanning"?: boolean | undefined;
|
|
62
|
+
} | undefined;
|
|
63
63
|
export?: {
|
|
64
64
|
qti3?: {
|
|
65
65
|
interaction: {
|
|
66
66
|
type: "AssociateInteraction" | "ChoiceInteraction" | "DrawingInteraction" | "EndAttemptInteraction" | "ExtendedTextInteraction" | "GapMatchInteraction" | "GraphicAssociateInteraction" | "GraphicGapMatchInteraction" | "GraphicOrderInteraction" | "HotspotInteraction" | "HottextInteraction" | "InlineChoiceInteraction" | "MatchInteraction" | "MediaInteraction" | "OrderInteraction" | "PortableCustomInteraction" | "PositionObjectInteraction" | "SelectPointInteraction" | "SliderInteraction" | "TextEntryInteraction" | "UploadInteraction";
|
|
67
|
-
options?: Record<string, string | number | boolean | any[] | Record<string, never
|
|
67
|
+
options?: Record<string, string | number | boolean | any[] | Record<string, never>> | undefined;
|
|
68
68
|
};
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
metadata?: Record<string, string | number | boolean
|
|
72
|
-
stylesheet?: string;
|
|
73
|
-
index?: number;
|
|
74
|
-
isDefault?: boolean;
|
|
69
|
+
} | undefined;
|
|
70
|
+
} | undefined;
|
|
71
|
+
metadata?: Record<string, string | number | boolean | null> | undefined;
|
|
72
|
+
stylesheet?: string | undefined;
|
|
73
|
+
index?: number | undefined;
|
|
74
|
+
isDefault?: boolean | undefined;
|
|
75
75
|
};
|
|
76
76
|
export type FormattedQuestionType = ReturnType<typeof formatQuestionType>;
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
export var formatQuestionType = function (type, i18n) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
var locale = i18n.language;
|
|
15
|
-
var translationNs = "question_type_".concat(type.id);
|
|
16
|
-
var scopedT = i18n.getFixedT(locale, translationNs);
|
|
1
|
+
export const formatQuestionType = (type, i18n) => {
|
|
2
|
+
const locale = i18n.language;
|
|
3
|
+
const translationNs = `question_type_${type.id}`;
|
|
4
|
+
const scopedT = i18n.getFixedT(locale, translationNs);
|
|
17
5
|
// Load the translations for the question type
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const resources = {};
|
|
7
|
+
const extractTranslations = (key, obj) => {
|
|
20
8
|
if (!obj)
|
|
21
9
|
return;
|
|
22
10
|
if (typeof obj === "string") {
|
|
@@ -25,8 +13,7 @@ export var formatQuestionType = function (type, i18n) {
|
|
|
25
13
|
resources[locale][key] = obj;
|
|
26
14
|
}
|
|
27
15
|
else if (typeof obj === "object") {
|
|
28
|
-
Object.entries(obj).forEach(
|
|
29
|
-
var lang = _a[0], value = _a[1];
|
|
16
|
+
Object.entries(obj).forEach(([lang, value]) => {
|
|
30
17
|
if (!resources[lang])
|
|
31
18
|
resources[lang] = {};
|
|
32
19
|
resources[lang][key] = value;
|
|
@@ -39,25 +26,37 @@ export var formatQuestionType = function (type, i18n) {
|
|
|
39
26
|
extractTranslations("titlePlaceholder", type.titlePlaceholder);
|
|
40
27
|
extractTranslations("descriptionPlaceholder", type.descriptionPlaceholder);
|
|
41
28
|
extractTranslations("untitledPlaceholder", type.untitledPlaceholder);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
extractTranslations(
|
|
45
|
-
extractTranslations(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
extractTranslations("settings.".concat(setting.id, ".options.").concat(option.value), option.label);
|
|
29
|
+
type.settings?.forEach((setting) => {
|
|
30
|
+
extractTranslations(`settings.${setting.id}.name`, setting.name);
|
|
31
|
+
extractTranslations(`settings.${setting.id}.helpText`, setting.helpText);
|
|
32
|
+
extractTranslations(`settings.${setting.id}.placeholder`, setting.placeholder);
|
|
33
|
+
setting.options?.forEach((option) => {
|
|
34
|
+
extractTranslations(`settings.${setting.id}.options.${option.value}`, option.label);
|
|
49
35
|
});
|
|
50
36
|
});
|
|
51
|
-
Object.entries(
|
|
52
|
-
|
|
53
|
-
return extractTranslations(key, value);
|
|
54
|
-
});
|
|
55
|
-
for (var lang in resources) {
|
|
37
|
+
Object.entries(type?.translations || {}).forEach(([key, value]) => extractTranslations(key, value));
|
|
38
|
+
for (const lang in resources) {
|
|
56
39
|
i18n.addResources(lang, translationNs, resources[lang]);
|
|
57
40
|
}
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
return {
|
|
42
|
+
...type,
|
|
43
|
+
translationNs,
|
|
44
|
+
name: type.name && scopedT("name"),
|
|
45
|
+
description: type.description && scopedT("description"),
|
|
46
|
+
enforceTitle: type.enforceTitle && scopedT("enforceTitle"),
|
|
47
|
+
titlePlaceholder: type.titlePlaceholder && scopedT("titlePlaceholder"),
|
|
48
|
+
descriptionPlaceholder: type.descriptionPlaceholder && scopedT("descriptionPlaceholder"),
|
|
49
|
+
untitledPlaceholder: type.untitledPlaceholder && scopedT("untitledPlaceholder"),
|
|
50
|
+
settings: type.settings?.map((setting) => ({
|
|
51
|
+
...setting,
|
|
52
|
+
name: setting.name && scopedT(`settings.${setting.id}.name`),
|
|
53
|
+
helpText: setting.helpText && scopedT(`settings.${setting.id}.helpText`),
|
|
54
|
+
placeholder: setting.placeholder && scopedT(`settings.${setting.id}.placeholder`),
|
|
55
|
+
options: setting.options?.map((option) => ({
|
|
56
|
+
...option,
|
|
57
|
+
label: option.label &&
|
|
58
|
+
scopedT(`settings.${setting.id}.options.${option.value}`),
|
|
59
|
+
})),
|
|
60
|
+
})),
|
|
61
|
+
};
|
|
63
62
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Editor, EditorContentProps } from "@tiptap/react";
|
|
2
|
+
import { CommentAuthor } from "tiptap-inline-comments";
|
|
2
3
|
import { XmlFragment } from "yjs";
|
|
3
|
-
|
|
4
|
-
export declare const getEditorById: (id: string) => Editor;
|
|
4
|
+
export declare const getEditorById: (id: string) => Editor | undefined;
|
|
5
5
|
export type MinimalRichTextFieldProps = {
|
|
6
6
|
className?: string;
|
|
7
7
|
value?: string;
|
|
@@ -1,35 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
-
if (ar || !(i in from)) {
|
|
27
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
-
ar[i] = from[i];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
-
};
|
|
33
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
34
3
|
import { useEffect, useMemo, useState } from "react";
|
|
35
4
|
import Collaboration from "@tiptap/extension-collaboration";
|
|
@@ -37,42 +6,40 @@ import Document from "@tiptap/extension-document";
|
|
|
37
6
|
import Placeholder from "@tiptap/extension-placeholder";
|
|
38
7
|
import { UndoRedo } from "@tiptap/extensions";
|
|
39
8
|
import { EditorContent, useEditor, } from "@tiptap/react";
|
|
9
|
+
import { InlineComments } from "tiptap-inline-comments";
|
|
40
10
|
import { CollaborationCaret } from "./tiptap/collaboration-caret";
|
|
41
11
|
import { cn } from "../../utils";
|
|
42
12
|
import { registerWebComponents } from "../web-components";
|
|
43
|
-
import { Comment } from "./tiptap/comments/comment";
|
|
44
13
|
import { CommentBubble } from "./tiptap/comments/comment-bubble";
|
|
45
|
-
import { CommentReply } from "./tiptap/comments/comment-reply";
|
|
46
14
|
import { defaultRichTextExtensions } from "./tiptap/extensions";
|
|
47
15
|
import { fileHandler } from "./tiptap/file-handler";
|
|
48
16
|
import Image from "./tiptap/image";
|
|
49
17
|
import { RichTextFormattingMenu } from "./tiptap/rich-text-formatting-menu";
|
|
50
18
|
registerWebComponents();
|
|
51
|
-
|
|
52
|
-
export
|
|
19
|
+
const textEditors = new Map();
|
|
20
|
+
export const getEditorById = (id) => {
|
|
53
21
|
return textEditors.get(id);
|
|
54
22
|
};
|
|
55
|
-
|
|
56
|
-
addCommands
|
|
23
|
+
const CustomCollaboration = Collaboration.extend({
|
|
24
|
+
addCommands() {
|
|
57
25
|
return {
|
|
58
|
-
undo:
|
|
26
|
+
undo: () => () => {
|
|
59
27
|
return false;
|
|
60
|
-
}
|
|
61
|
-
redo:
|
|
28
|
+
},
|
|
29
|
+
redo: () => () => {
|
|
62
30
|
return false;
|
|
63
|
-
}
|
|
31
|
+
},
|
|
64
32
|
};
|
|
65
33
|
},
|
|
66
|
-
addKeyboardShortcuts
|
|
34
|
+
addKeyboardShortcuts() {
|
|
67
35
|
return {};
|
|
68
36
|
},
|
|
69
37
|
});
|
|
70
|
-
|
|
71
|
-
var _a;
|
|
38
|
+
const isEmpty = (value) => {
|
|
72
39
|
if (!value) {
|
|
73
40
|
return true;
|
|
74
41
|
}
|
|
75
|
-
if (!
|
|
42
|
+
if (!value.trim?.()) {
|
|
76
43
|
return true;
|
|
77
44
|
}
|
|
78
45
|
if (value.trim() === "<p></p>" || value.trim() === "<p><br></p>") {
|
|
@@ -83,63 +50,58 @@ var isEmpty = function (value) {
|
|
|
83
50
|
}
|
|
84
51
|
return false;
|
|
85
52
|
};
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}, [singleLine, placeholder, uploadFile, fragment, awareness, commentAuthor]);
|
|
109
|
-
var editor = useEditor({
|
|
110
|
-
onUpdate: function (_a) {
|
|
111
|
-
var editor = _a.editor;
|
|
53
|
+
export const MinimalRichTextField = ({ className = "", value = "", defaultValue, placeholder = "", onChange, onBlur, slotBefore, style, singleLine = false, autoFocus = false, showFormattingMenu = false, commentAuthor, uploadFile = undefined, fragment, awareness, id, ...props }) => {
|
|
54
|
+
const [content, setContent] = useState(value);
|
|
55
|
+
const extensions = useMemo(() => [
|
|
56
|
+
...defaultRichTextExtensions,
|
|
57
|
+
singleLine
|
|
58
|
+
? Document.extend({
|
|
59
|
+
content: "block",
|
|
60
|
+
})
|
|
61
|
+
: Document,
|
|
62
|
+
Image,
|
|
63
|
+
!fragment && UndoRedo,
|
|
64
|
+
fragment &&
|
|
65
|
+
CustomCollaboration.configure({
|
|
66
|
+
fragment,
|
|
67
|
+
}),
|
|
68
|
+
awareness && CollaborationCaret.configure({ awareness }),
|
|
69
|
+
placeholder && Placeholder.configure({ placeholder }),
|
|
70
|
+
uploadFile && fileHandler(uploadFile),
|
|
71
|
+
commentAuthor && InlineComments.configure({ createdBy: commentAuthor }),
|
|
72
|
+
].filter(Boolean), [singleLine, placeholder, uploadFile, fragment, awareness, commentAuthor]);
|
|
73
|
+
const editor = useEditor({
|
|
74
|
+
onUpdate: ({ editor }) => {
|
|
112
75
|
if (onChange || !fragment) {
|
|
113
|
-
|
|
76
|
+
let html = editor.getHTML();
|
|
114
77
|
html = isEmpty(html) ? "" : html;
|
|
115
78
|
setContent(html);
|
|
116
|
-
onChange
|
|
79
|
+
onChange?.(html);
|
|
117
80
|
}
|
|
118
81
|
},
|
|
119
|
-
onBlur:
|
|
120
|
-
var editor = _a.editor;
|
|
82
|
+
onBlur: ({ editor }) => {
|
|
121
83
|
if (onBlur) {
|
|
122
|
-
|
|
84
|
+
let html = editor.getHTML();
|
|
123
85
|
html = isEmpty(html) ? "" : html;
|
|
124
86
|
onBlur(html);
|
|
125
87
|
}
|
|
126
88
|
},
|
|
127
89
|
autofocus: autoFocus,
|
|
128
90
|
content: fragment ? undefined : content,
|
|
129
|
-
extensions
|
|
91
|
+
extensions,
|
|
130
92
|
editorProps: {
|
|
131
93
|
attributes: {
|
|
132
|
-
class: cn(
|
|
94
|
+
class: cn(`max-w-none`, className),
|
|
133
95
|
style: style,
|
|
134
96
|
},
|
|
135
97
|
},
|
|
136
98
|
});
|
|
137
|
-
useEffect(
|
|
99
|
+
useEffect(() => {
|
|
138
100
|
if (fragment)
|
|
139
101
|
return;
|
|
140
102
|
if (value !== content && defaultValue === undefined) {
|
|
141
103
|
setContent(value);
|
|
142
|
-
editor
|
|
104
|
+
editor?.commands.setContent(value, {
|
|
143
105
|
emitUpdate: false,
|
|
144
106
|
parseOptions: {
|
|
145
107
|
preserveWhitespace: "full",
|
|
@@ -147,12 +109,12 @@ export var MinimalRichTextField = function (_a) {
|
|
|
147
109
|
});
|
|
148
110
|
}
|
|
149
111
|
}, [value, content, editor, fragment]);
|
|
150
|
-
useEffect(
|
|
112
|
+
useEffect(() => {
|
|
151
113
|
if (fragment)
|
|
152
114
|
return;
|
|
153
115
|
if (defaultValue !== undefined) {
|
|
154
116
|
setContent(defaultValue);
|
|
155
|
-
editor
|
|
117
|
+
editor?.commands.setContent(defaultValue, {
|
|
156
118
|
emitUpdate: false,
|
|
157
119
|
parseOptions: {
|
|
158
120
|
preserveWhitespace: "full",
|
|
@@ -160,15 +122,15 @@ export var MinimalRichTextField = function (_a) {
|
|
|
160
122
|
});
|
|
161
123
|
}
|
|
162
124
|
}, [defaultValue, fragment]);
|
|
163
|
-
useEffect(
|
|
125
|
+
useEffect(() => {
|
|
164
126
|
if (!editor || !id)
|
|
165
127
|
return;
|
|
166
128
|
textEditors.set(id, editor);
|
|
167
|
-
return
|
|
129
|
+
return () => {
|
|
168
130
|
if (textEditors.get(id) === editor) {
|
|
169
131
|
textEditors.delete(id);
|
|
170
132
|
}
|
|
171
133
|
};
|
|
172
134
|
}, [editor, id]);
|
|
173
|
-
return (_jsxs(_Fragment, { children: [slotBefore ? slotBefore(editor) : null, showFormattingMenu && (_jsx(RichTextFormattingMenu, { allowComments: !!commentAuthor, editor: editor })), !!commentAuthor && (_jsx(CommentBubble, { editor: editor, commentAuthor: commentAuthor })), _jsx(EditorContent,
|
|
135
|
+
return (_jsxs(_Fragment, { children: [slotBefore ? slotBefore(editor) : null, showFormattingMenu && (_jsx(RichTextFormattingMenu, { allowComments: !!commentAuthor, editor: editor })), !!commentAuthor && (_jsx(CommentBubble, { editor: editor, commentAuthor: commentAuthor })), _jsx(EditorContent, { editor: editor, ...props })] }));
|
|
174
136
|
};
|