drf-react-by-schema 0.28.22 → 0.28.24

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 (40) hide show
  1. package/dist/@types/index.d.ts +8 -0
  2. package/dist/@types/index.d.ts.map +1 -1
  3. package/dist/api.d.ts +1 -1
  4. package/dist/api.d.ts.map +1 -1
  5. package/dist/api.js +4 -1
  6. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
  7. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +17 -2
  8. package/dist/components/GenericModelList.d.ts.map +1 -1
  9. package/dist/components/GenericModelList.js +6 -2
  10. package/dist/components/GenericRelatedModelList.d.ts.map +1 -1
  11. package/dist/components/GenericRelatedModelList.js +7 -1
  12. package/dist/components/HtmlContent.d.ts +13 -0
  13. package/dist/components/HtmlContent.d.ts.map +1 -0
  14. package/dist/components/HtmlContent.js +148 -0
  15. package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -1
  16. package/dist/components/details/DetailFieldBySchema.js +7 -0
  17. package/dist/components/forms/FieldBySchema.d.ts.map +1 -1
  18. package/dist/components/forms/FieldBySchema.js +5 -0
  19. package/dist/components/forms/inputs/HtmlFieldBySchema.d.ts +9 -0
  20. package/dist/components/forms/inputs/HtmlFieldBySchema.d.ts.map +1 -0
  21. package/dist/components/forms/inputs/HtmlFieldBySchema.js +55 -0
  22. package/dist/components/forms/inputs/RichTextEditorInput.d.ts +24 -0
  23. package/dist/components/forms/inputs/RichTextEditorInput.d.ts.map +1 -0
  24. package/dist/components/forms/inputs/RichTextEditorInput.js +252 -0
  25. package/dist/context/DRFReactBySchemaContext.d.ts +3 -1
  26. package/dist/context/DRFReactBySchemaContext.d.ts.map +1 -1
  27. package/dist/context/DRFReactBySchemaContext.js +10 -1
  28. package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
  29. package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -1
  30. package/dist/context/DRFReactBySchemaProvider.js +3 -2
  31. package/dist/index.d.ts +4 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +6 -1
  34. package/dist/styles/texts.d.ts +25 -0
  35. package/dist/styles/texts.d.ts.map +1 -1
  36. package/dist/styles/texts.js +25 -0
  37. package/dist/utils/utils.d.ts +12 -0
  38. package/dist/utils/utils.d.ts.map +1 -1
  39. package/dist/utils/utils.js +69 -0
  40. package/package.json +13 -1
@@ -67,6 +67,8 @@ exports.buildConditionalVisibleBySchema = buildConditionalVisibleBySchema;
67
67
  exports.showConditionalVisibleField = showConditionalVisibleField;
68
68
  exports.showConditionalVisibleFieldObj = showConditionalVisibleFieldObj;
69
69
  exports.getMapLibraries = getMapLibraries;
70
+ exports.getRichTextLibraries = getRichTextLibraries;
71
+ exports.getHtmlSanitizer = getHtmlSanitizer;
70
72
  exports.geometryValueToString = geometryValueToString;
71
73
  exports.parseGeoJSON = parseGeoJSON;
72
74
  const dayjs_1 = __importDefault(require("dayjs"));
@@ -992,6 +994,73 @@ function getMapLibraries() {
992
994
  }
993
995
  return null;
994
996
  }
997
+ // --- Optional rich-text (Tiptap) support ------------------------------------
998
+ // Fields flagged as ``model_html`` by the backend hold HTML. Editing them uses
999
+ // Tiptap when the consuming app has it installed; otherwise the form falls back
1000
+ // to the multiline text field.
1001
+ let richTextLibraries;
1002
+ /**
1003
+ * Detect whether the consuming app has installed `@tiptap/react` +
1004
+ * `@tiptap/starter-kit`. Returns the pieces the editor needs, or null so
1005
+ * callers can fall back to plain text editing.
1006
+ */
1007
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1008
+ function getRichTextLibraries() {
1009
+ var _a;
1010
+ if (richTextLibraries !== undefined) {
1011
+ return richTextLibraries;
1012
+ }
1013
+ try {
1014
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
1015
+ const react = require('@tiptap/react');
1016
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
1017
+ const starterKit = require('@tiptap/starter-kit');
1018
+ const editor = react.useEditor;
1019
+ const starterKitExtension = (_a = starterKit.default) !== null && _a !== void 0 ? _a : starterKit.StarterKit;
1020
+ if (typeof editor === 'function' &&
1021
+ typeof react.EditorContent !== 'undefined' &&
1022
+ typeof starterKitExtension !== 'undefined') {
1023
+ richTextLibraries = {
1024
+ useEditor: react.useEditor,
1025
+ useEditorState: react.useEditorState,
1026
+ EditorContent: react.EditorContent,
1027
+ StarterKit: starterKitExtension,
1028
+ };
1029
+ }
1030
+ else {
1031
+ richTextLibraries = null;
1032
+ }
1033
+ }
1034
+ catch (_b) {
1035
+ // @tiptap/react / @tiptap/starter-kit not installed -> plain text fallback
1036
+ richTextLibraries = null;
1037
+ }
1038
+ return richTextLibraries;
1039
+ }
1040
+ let htmlSanitizer;
1041
+ /**
1042
+ * Detect whether the consuming app has installed `dompurify`. HTML from the
1043
+ * backend is only injected into the DOM when a sanitizer is available; without
1044
+ * it, values are rendered as plain text.
1045
+ */
1046
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1047
+ function getHtmlSanitizer() {
1048
+ var _a;
1049
+ if (htmlSanitizer !== undefined) {
1050
+ return htmlSanitizer;
1051
+ }
1052
+ try {
1053
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
1054
+ const dompurify = require('dompurify');
1055
+ const sanitizer = (_a = dompurify.default) !== null && _a !== void 0 ? _a : dompurify;
1056
+ htmlSanitizer = typeof (sanitizer === null || sanitizer === void 0 ? void 0 : sanitizer.sanitize) === 'function' ? sanitizer : null;
1057
+ }
1058
+ catch (_b) {
1059
+ // dompurify not installed -> render HTML as plain text
1060
+ htmlSanitizer = null;
1061
+ }
1062
+ return htmlSanitizer;
1063
+ }
995
1064
  /** Normalize a GeoJSON value (object, JSON string or null) to a string. */
996
1065
  function geometryValueToString(value) {
997
1066
  if (value === null || value === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drf-react-by-schema",
3
- "version": "0.28.22",
3
+ "version": "0.28.24",
4
4
  "description": "Components and Tools for building a React App having Django Rest Framework (DRF) as server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -85,8 +85,11 @@
85
85
  "@mui/material": "^6",
86
86
  "@mui/x-data-grid": "^7",
87
87
  "@mui/x-date-pickers": "^7",
88
+ "@tiptap/react": "^3.0.0",
89
+ "@tiptap/starter-kit": "^3.0.0",
88
90
  "axios": "^1",
89
91
  "dayjs": "^1",
92
+ "dompurify": "^3.0.0",
90
93
  "leaflet": "^1.9.0",
91
94
  "leaflet-draw": "^1.0.4",
92
95
  "react": "^18 || ^19",
@@ -98,6 +101,15 @@
98
101
  "yup": "^1"
99
102
  },
100
103
  "peerDependenciesMeta": {
104
+ "@tiptap/react": {
105
+ "optional": true
106
+ },
107
+ "@tiptap/starter-kit": {
108
+ "optional": true
109
+ },
110
+ "dompurify": {
111
+ "optional": true
112
+ },
101
113
  "leaflet": {
102
114
  "optional": true
103
115
  },