@difizen/libro-output 0.3.28 → 0.3.30
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/es/display-data-output/display-data-output-contribution.d.ts +6 -1
- package/es/display-data-output/display-data-output-contribution.d.ts.map +1 -1
- package/es/display-data-output/display-data-output-contribution.js +205 -7
- package/es/display-data-output/display-data-output-model.d.ts +1 -1
- package/es/display-data-output/display-data-output-model.d.ts.map +1 -1
- package/es/display-data-output/display-data-output-model.js +12 -13
- package/es/display-data-output/display-data-output-module.d.ts.map +1 -1
- package/es/display-data-output/display-data-output-module.js +3 -1
- package/es/display-data-output/display-data-output-setting-contribution.d.ts +5 -0
- package/es/display-data-output/display-data-output-setting-contribution.d.ts.map +1 -0
- package/es/display-data-output/display-data-output-setting-contribution.js +23 -0
- package/es/display-data-output/display-data-output-setting.d.ts +6 -0
- package/es/display-data-output/display-data-output-setting.d.ts.map +1 -0
- package/es/display-data-output/display-data-output-setting.js +63 -0
- package/es/display-data-output/image-upload-service.d.ts +36 -0
- package/es/display-data-output/image-upload-service.d.ts.map +1 -0
- package/es/display-data-output/image-upload-service.js +108 -0
- package/es/display-data-output/index.d.ts +3 -0
- package/es/display-data-output/index.d.ts.map +1 -1
- package/es/display-data-output/index.js +4 -1
- package/es/error-output/error-output-model.d.ts +1 -1
- package/es/stream-output/stream-output-model.d.ts +2 -2
- package/package.json +4 -4
- package/src/display-data-output/display-data-output-contribution.ts +137 -4
- package/src/display-data-output/display-data-output-model.tsx +20 -12
- package/src/display-data-output/display-data-output-module.ts +3 -1
- package/src/display-data-output/display-data-output-setting-contribution.ts +20 -0
- package/src/display-data-output/display-data-output-setting.ts +58 -0
- package/src/display-data-output/image-upload-service.ts +69 -0
- package/src/display-data-output/index.ts +3 -0
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { IOutput } from '@difizen/libro-common';
|
|
2
2
|
import type { IOutputOptions } from '@difizen/libro-core';
|
|
3
3
|
import { OutputContribution } from '@difizen/libro-core';
|
|
4
|
-
import { ViewManager } from '@difizen/mana-app';
|
|
4
|
+
import { ViewManager, ConfigurationService } from '@difizen/mana-app';
|
|
5
5
|
import { DisplayDataOutputModel } from './display-data-output-model.js';
|
|
6
|
+
import { ImageUploadService } from './image-upload-service.js';
|
|
6
7
|
export declare class DisplayDataOutputContribution implements OutputContribution {
|
|
7
8
|
viewManager: ViewManager;
|
|
9
|
+
configurationService: ConfigurationService;
|
|
10
|
+
imageUploadService: ImageUploadService;
|
|
8
11
|
canHandle: (output: IOutput) => 100 | 1;
|
|
9
12
|
factory(output: IOutputOptions): Promise<DisplayDataOutputModel>;
|
|
13
|
+
private preprocessImageData;
|
|
14
|
+
private processImageDataInBundle;
|
|
10
15
|
}
|
|
11
16
|
//# sourceMappingURL=display-data-output-contribution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display-data-output-contribution.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"display-data-output-contribution.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAGL,WAAW,EACX,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAOxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAW/D,qBACa,6BAA8B,YAAW,kBAAkB;IACjD,WAAW,EAAE,WAAW,CAAC;IAChB,oBAAoB,EAAE,oBAAoB,CAAC;IAC7C,kBAAkB,EAAE,kBAAkB,CAAC;IAEnE,SAAS,WAAY,OAAO,aAQ1B;IAEI,OAAO,CAAC,MAAM,EAAE,cAAc;YAMtB,mBAAmB;YA2DnB,wBAAwB;CA8CvC"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3;
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1
11
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var
|
|
12
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
13
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
14
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3
15
|
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
17
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -8,16 +20,21 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
8
20
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
21
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
10
22
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
23
|
+
import { getBundleOptions } from '@difizen/libro-common';
|
|
11
24
|
import { OutputContribution } from '@difizen/libro-core';
|
|
12
|
-
import { inject, singleton } from '@difizen/mana-app';
|
|
13
|
-
import { ViewManager } from '@difizen/mana-app';
|
|
25
|
+
import { inject, singleton, ViewManager, ConfigurationService } from '@difizen/mana-app';
|
|
14
26
|
import { DisplayDataOutputModel } from "./display-data-output-model.js";
|
|
27
|
+
import { ImageProcessingEnabled, ImageProcessingRemoveOriginal, ImageProcessingSizeThreshold, ImageProcessingSupportedMimeTypes } from "./display-data-output-setting.js";
|
|
28
|
+
import { ImageUploadService } from "./image-upload-service.js";
|
|
29
|
+
var IMAGE_URL_MIME_TYPE = 'image/vnd.libro.image-url';
|
|
15
30
|
export var DisplayDataOutputContribution = (_dec = singleton({
|
|
16
31
|
contrib: OutputContribution
|
|
17
|
-
}), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
32
|
+
}), _dec2 = inject(ViewManager), _dec3 = inject(ConfigurationService), _dec4 = inject(ImageUploadService), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
18
33
|
function DisplayDataOutputContribution() {
|
|
19
34
|
_classCallCheck(this, DisplayDataOutputContribution);
|
|
20
35
|
_initializerDefineProperty(this, "viewManager", _descriptor, this);
|
|
36
|
+
_initializerDefineProperty(this, "configurationService", _descriptor2, this);
|
|
37
|
+
_initializerDefineProperty(this, "imageUploadService", _descriptor3, this);
|
|
21
38
|
this.canHandle = function (output) {
|
|
22
39
|
if (output.output_type === 'display_data' || output.output_type === 'execute_result') {
|
|
23
40
|
return 100;
|
|
@@ -27,9 +44,180 @@ export var DisplayDataOutputContribution = (_dec = singleton({
|
|
|
27
44
|
}
|
|
28
45
|
_createClass(DisplayDataOutputContribution, [{
|
|
29
46
|
key: "factory",
|
|
30
|
-
value: function
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
value: function () {
|
|
48
|
+
var _factory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(output) {
|
|
49
|
+
var processedOutput;
|
|
50
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
51
|
+
while (1) switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
_context.next = 2;
|
|
54
|
+
return this.preprocessImageData(output);
|
|
55
|
+
case 2:
|
|
56
|
+
processedOutput = _context.sent;
|
|
57
|
+
return _context.abrupt("return", this.viewManager.getOrCreateView(DisplayDataOutputModel, processedOutput));
|
|
58
|
+
case 4:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context.stop();
|
|
61
|
+
}
|
|
62
|
+
}, _callee, this);
|
|
63
|
+
}));
|
|
64
|
+
function factory(_x) {
|
|
65
|
+
return _factory.apply(this, arguments);
|
|
66
|
+
}
|
|
67
|
+
return factory;
|
|
68
|
+
}()
|
|
69
|
+
}, {
|
|
70
|
+
key: "preprocessImageData",
|
|
71
|
+
value: function () {
|
|
72
|
+
var _preprocessImageData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
73
|
+
var enabled, sizeThreshold, removeOriginal, supportedMimeTypes, imageConfig, hasUploadFunction, _getBundleOptions, data, processedData, processedOutput;
|
|
74
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
75
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
76
|
+
case 0:
|
|
77
|
+
_context2.next = 2;
|
|
78
|
+
return this.configurationService.get(ImageProcessingEnabled);
|
|
79
|
+
case 2:
|
|
80
|
+
enabled = _context2.sent;
|
|
81
|
+
_context2.next = 5;
|
|
82
|
+
return this.configurationService.get(ImageProcessingSizeThreshold);
|
|
83
|
+
case 5:
|
|
84
|
+
sizeThreshold = _context2.sent;
|
|
85
|
+
_context2.next = 8;
|
|
86
|
+
return this.configurationService.get(ImageProcessingRemoveOriginal);
|
|
87
|
+
case 8:
|
|
88
|
+
removeOriginal = _context2.sent;
|
|
89
|
+
_context2.next = 11;
|
|
90
|
+
return this.configurationService.get(ImageProcessingSupportedMimeTypes);
|
|
91
|
+
case 11:
|
|
92
|
+
supportedMimeTypes = _context2.sent;
|
|
93
|
+
// 合并配置
|
|
94
|
+
imageConfig = {
|
|
95
|
+
enabled: enabled,
|
|
96
|
+
sizeThreshold: sizeThreshold,
|
|
97
|
+
removeOriginal: removeOriginal,
|
|
98
|
+
supportedMimeTypes: supportedMimeTypes
|
|
99
|
+
}; // 如果未启用图片处理,直接返回原始选项
|
|
100
|
+
if (imageConfig.enabled) {
|
|
101
|
+
_context2.next = 15;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return _context2.abrupt("return", options);
|
|
105
|
+
case 15:
|
|
106
|
+
// 检查是否有可用的上传函数
|
|
107
|
+
hasUploadFunction = this.imageUploadService.hasUploadFunction();
|
|
108
|
+
if (hasUploadFunction) {
|
|
109
|
+
_context2.next = 18;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
return _context2.abrupt("return", options);
|
|
113
|
+
case 18:
|
|
114
|
+
_getBundleOptions = getBundleOptions(options.output), data = _getBundleOptions.data;
|
|
115
|
+
if (!(!data || _typeof(data) !== 'object')) {
|
|
116
|
+
_context2.next = 21;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
return _context2.abrupt("return", options);
|
|
120
|
+
case 21:
|
|
121
|
+
_context2.prev = 21;
|
|
122
|
+
_context2.next = 24;
|
|
123
|
+
return this.processImageDataInBundle(data, imageConfig);
|
|
124
|
+
case 24:
|
|
125
|
+
processedData = _context2.sent;
|
|
126
|
+
// 创建新的输出选项,包含处理后的数据
|
|
127
|
+
processedOutput = _objectSpread(_objectSpread({}, options.output), {}, {
|
|
128
|
+
data: processedData
|
|
129
|
+
});
|
|
130
|
+
return _context2.abrupt("return", _objectSpread(_objectSpread({}, options), {}, {
|
|
131
|
+
output: processedOutput
|
|
132
|
+
}));
|
|
133
|
+
case 29:
|
|
134
|
+
_context2.prev = 29;
|
|
135
|
+
_context2.t0 = _context2["catch"](21);
|
|
136
|
+
console.warn('图片预处理失败,使用原始数据:', _context2.t0);
|
|
137
|
+
return _context2.abrupt("return", options);
|
|
138
|
+
case 33:
|
|
139
|
+
case "end":
|
|
140
|
+
return _context2.stop();
|
|
141
|
+
}
|
|
142
|
+
}, _callee2, this, [[21, 29]]);
|
|
143
|
+
}));
|
|
144
|
+
function preprocessImageData(_x2) {
|
|
145
|
+
return _preprocessImageData.apply(this, arguments);
|
|
146
|
+
}
|
|
147
|
+
return preprocessImageData;
|
|
148
|
+
}()
|
|
149
|
+
}, {
|
|
150
|
+
key: "processImageDataInBundle",
|
|
151
|
+
value: function () {
|
|
152
|
+
var _processImageDataInBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(data, config) {
|
|
153
|
+
var processedData, supportedMimeTypes, sizeThreshold, removeOriginal, _i, _Object$entries, _Object$entries$_i, mimeType, content, base64Data, uploadedUrl;
|
|
154
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
155
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
156
|
+
case 0:
|
|
157
|
+
if (!(!data || _typeof(data) !== 'object')) {
|
|
158
|
+
_context3.next = 2;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
return _context3.abrupt("return", data);
|
|
162
|
+
case 2:
|
|
163
|
+
processedData = _objectSpread({}, data);
|
|
164
|
+
supportedMimeTypes = config.supportedMimeTypes, sizeThreshold = config.sizeThreshold, removeOriginal = config.removeOriginal; // 已经有 IMAGE_URL_MIME_TYPE 无需处理
|
|
165
|
+
if (!processedData[IMAGE_URL_MIME_TYPE]) {
|
|
166
|
+
_context3.next = 6;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
return _context3.abrupt("return", processedData);
|
|
170
|
+
case 6:
|
|
171
|
+
_i = 0, _Object$entries = Object.entries(data);
|
|
172
|
+
case 7:
|
|
173
|
+
if (!(_i < _Object$entries.length)) {
|
|
174
|
+
_context3.next = 26;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), mimeType = _Object$entries$_i[0], content = _Object$entries$_i[1];
|
|
178
|
+
if (!(supportedMimeTypes.includes(mimeType) && typeof content === 'string')) {
|
|
179
|
+
_context3.next = 23;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
_context3.prev = 10;
|
|
183
|
+
if (!(content.length > sizeThreshold)) {
|
|
184
|
+
_context3.next = 18;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
base64Data = content.startsWith('data:') ? content.split(',')[1] : content; // 上传图片并替换为 URL
|
|
188
|
+
_context3.next = 15;
|
|
189
|
+
return this.imageUploadService.uploadImage(base64Data, mimeType);
|
|
190
|
+
case 15:
|
|
191
|
+
uploadedUrl = _context3.sent;
|
|
192
|
+
processedData[IMAGE_URL_MIME_TYPE] = uploadedUrl;
|
|
193
|
+
if (removeOriginal) {
|
|
194
|
+
delete processedData[mimeType];
|
|
195
|
+
}
|
|
196
|
+
case 18:
|
|
197
|
+
_context3.next = 23;
|
|
198
|
+
break;
|
|
199
|
+
case 20:
|
|
200
|
+
_context3.prev = 20;
|
|
201
|
+
_context3.t0 = _context3["catch"](10);
|
|
202
|
+
console.warn("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25 (".concat(mimeType, "):"), _context3.t0);
|
|
203
|
+
// 保持原始数据
|
|
204
|
+
case 23:
|
|
205
|
+
_i++;
|
|
206
|
+
_context3.next = 7;
|
|
207
|
+
break;
|
|
208
|
+
case 26:
|
|
209
|
+
return _context3.abrupt("return", processedData);
|
|
210
|
+
case 27:
|
|
211
|
+
case "end":
|
|
212
|
+
return _context3.stop();
|
|
213
|
+
}
|
|
214
|
+
}, _callee3, this, [[10, 20]]);
|
|
215
|
+
}));
|
|
216
|
+
function processImageDataInBundle(_x3, _x4) {
|
|
217
|
+
return _processImageDataInBundle.apply(this, arguments);
|
|
218
|
+
}
|
|
219
|
+
return processImageDataInBundle;
|
|
220
|
+
}()
|
|
33
221
|
}]);
|
|
34
222
|
return DisplayDataOutputContribution;
|
|
35
223
|
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
|
|
@@ -37,4 +225,14 @@ export var DisplayDataOutputContribution = (_dec = singleton({
|
|
|
37
225
|
enumerable: true,
|
|
38
226
|
writable: true,
|
|
39
227
|
initializer: null
|
|
228
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "configurationService", [_dec3], {
|
|
229
|
+
configurable: true,
|
|
230
|
+
enumerable: true,
|
|
231
|
+
writable: true,
|
|
232
|
+
initializer: null
|
|
233
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "imageUploadService", [_dec4], {
|
|
234
|
+
configurable: true,
|
|
235
|
+
enumerable: true,
|
|
236
|
+
writable: true,
|
|
237
|
+
initializer: null
|
|
40
238
|
})), _class2)) || _class);
|
|
@@ -8,7 +8,7 @@ export declare class DisplayDataOutputModel extends LibroOutputView implements B
|
|
|
8
8
|
renderFactory?: IRendererFactory;
|
|
9
9
|
constructor(options: IOutputOptions);
|
|
10
10
|
getRenderFactory(): IRendererFactory | undefined;
|
|
11
|
-
view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
11
|
+
view: import("react").ForwardRefExoticComponent<Omit<Record<string, never>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
12
12
|
toJSON(): {
|
|
13
13
|
output_type: string;
|
|
14
14
|
data: import("@difizen/libro-common").PartialJSONValue | import("@difizen/libro-common").IMimeBundle | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display-data-output-model.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-model.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"display-data-output-model.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-model.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAavF,OAAO,eAAe,CAAC;AAyBvB,qBAEa,sBAAuB,SAAQ,eAAgB,YAAW,cAAc;IACvD,kBAAkB,EAAE,mBAAmB,CAAC;IACpE,aAAa,CAAC,EAAE,gBAAgB,CAAC;gBACD,OAAO,EAAE,cAAc;IAQvD,gBAAgB;IAUP,IAAI,gIAAgC;IACpC,MAAM;;;;;;;;;;;;;IAgBN,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;CAMxC"}
|
|
@@ -20,27 +20,26 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
|
|
|
20
20
|
import { getBundleOptions } from '@difizen/libro-common';
|
|
21
21
|
import { LibroOutputView } from '@difizen/libro-core';
|
|
22
22
|
import { RenderMimeRegistry } from '@difizen/libro-rendermime';
|
|
23
|
-
import { getOrigin, useInject, view, ViewInstance, ViewOption } from '@difizen/mana-app';
|
|
24
|
-
import {
|
|
25
|
-
import { forwardRef } from 'react';
|
|
23
|
+
import { getOrigin, useInject, view, ViewInstance, ViewOption, inject, transient } from '@difizen/mana-app';
|
|
24
|
+
import { createElement, forwardRef } from 'react';
|
|
26
25
|
import "../index.less";
|
|
27
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
26
|
var DisplayDataOutputModelRender = /*#__PURE__*/forwardRef(function DisplayDataOutputModelRender(_props, ref) {
|
|
29
27
|
var output = useInject(ViewInstance);
|
|
30
28
|
var model = getOrigin(output);
|
|
31
29
|
var factory = model.getRenderFactory();
|
|
32
30
|
var children = null;
|
|
33
|
-
if (factory) {
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
if (factory && factory.render) {
|
|
32
|
+
var renderFunction = factory.render;
|
|
33
|
+
if (typeof renderFunction === 'function') {
|
|
34
|
+
children = renderFunction({
|
|
35
|
+
model: model
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
|
-
return /*#__PURE__*/
|
|
39
|
+
return /*#__PURE__*/createElement('div', {
|
|
40
40
|
ref: ref,
|
|
41
|
-
className: 'libro-display-data-container'
|
|
42
|
-
|
|
43
|
-
});
|
|
41
|
+
className: 'libro-display-data-container'
|
|
42
|
+
}, children);
|
|
44
43
|
});
|
|
45
44
|
export var DisplayDataOutputModel = (_dec = transient(), _dec2 = view('libro-display-data-output-model'), _dec3 = inject(RenderMimeRegistry), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroOutputView) {
|
|
46
45
|
_inherits(DisplayDataOutputModel, _LibroOutputView);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display-data-output-module.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"display-data-output-module.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,eAAO,MAAM,uBAAuB,YAEY,CAAC"}
|
|
@@ -3,4 +3,6 @@ import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
|
|
|
3
3
|
import { ManaModule } from '@difizen/mana-app';
|
|
4
4
|
import { DisplayDataOutputContribution } from "./display-data-output-contribution.js";
|
|
5
5
|
import { DisplayDataOutputModel } from "./display-data-output-model.js";
|
|
6
|
-
|
|
6
|
+
import { DisplayDataOutputSettingContribution } from "./display-data-output-setting-contribution.js";
|
|
7
|
+
import { ImageUploadService } from "./image-upload-service.js";
|
|
8
|
+
export var DisplayDataOutputModule = ManaModule.create().register(DisplayDataOutputModel, DisplayDataOutputContribution, DisplayDataOutputSettingContribution, ImageUploadService).dependOn(OutputModule, LibroRenderMimeModule);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ConfigurationContribution } from '@difizen/mana-app';
|
|
2
|
+
export declare class DisplayDataOutputSettingContribution implements ConfigurationContribution {
|
|
3
|
+
registerConfigurations(): (import("@difizen/mana-app").ConfigurationNode<boolean> | import("@difizen/mana-app").ConfigurationNode<number> | import("@difizen/mana-app").ConfigurationNode<string[]>)[];
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=display-data-output-setting-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-data-output-setting-contribution.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-setting-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AASzE,qBACa,oCAAqC,YAAW,yBAAyB;IACpF,sBAAsB;CAQvB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import { singleton, ConfigurationContribution } from '@difizen/mana-app';
|
|
9
|
+
import { ImageProcessingEnabled, ImageProcessingSizeThreshold, ImageProcessingRemoveOriginal, ImageProcessingSupportedMimeTypes } from "./display-data-output-setting.js";
|
|
10
|
+
export var DisplayDataOutputSettingContribution = (_dec = singleton({
|
|
11
|
+
contrib: ConfigurationContribution
|
|
12
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
13
|
+
function DisplayDataOutputSettingContribution() {
|
|
14
|
+
_classCallCheck(this, DisplayDataOutputSettingContribution);
|
|
15
|
+
}
|
|
16
|
+
_createClass(DisplayDataOutputSettingContribution, [{
|
|
17
|
+
key: "registerConfigurations",
|
|
18
|
+
value: function registerConfigurations() {
|
|
19
|
+
return [ImageProcessingEnabled, ImageProcessingSizeThreshold, ImageProcessingRemoveOriginal, ImageProcessingSupportedMimeTypes];
|
|
20
|
+
}
|
|
21
|
+
}]);
|
|
22
|
+
return DisplayDataOutputSettingContribution;
|
|
23
|
+
}()) || _class);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ConfigurationNode } from '@difizen/mana-app';
|
|
2
|
+
export declare const ImageProcessingEnabled: ConfigurationNode<boolean>;
|
|
3
|
+
export declare const ImageProcessingSizeThreshold: ConfigurationNode<number>;
|
|
4
|
+
export declare const ImageProcessingRemoveOriginal: ConfigurationNode<boolean>;
|
|
5
|
+
export declare const ImageProcessingSupportedMimeTypes: ConfigurationNode<string[]>;
|
|
6
|
+
//# sourceMappingURL=display-data-output-setting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-data-output-setting.d.ts","sourceRoot":"","sources":["../../src/display-data-output/display-data-output-setting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,eAAO,MAAM,sBAAsB,EAAE,iBAAiB,CAAC,OAAO,CAS7D,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,iBAAiB,CAAC,MAAM,CAUlE,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,iBAAiB,CAAC,OAAO,CASpE,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,iBAAiB,CAAC,MAAM,EAAE,CAmBzE,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
2
|
+
|
|
3
|
+
// 图片处理配置项
|
|
4
|
+
export var ImageProcessingEnabled = {
|
|
5
|
+
id: 'libro.output.imageProcessing.enabled',
|
|
6
|
+
description: l10n.t('是否启用图片处理功能'),
|
|
7
|
+
title: l10n.t('启用图片处理'),
|
|
8
|
+
type: 'checkbox',
|
|
9
|
+
defaultValue: true,
|
|
10
|
+
schema: {
|
|
11
|
+
type: 'boolean'
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export var ImageProcessingSizeThreshold = {
|
|
15
|
+
id: 'libro.output.imageProcessing.sizeThreshold',
|
|
16
|
+
description: l10n.t('图片处理的大小阈值(字符数)'),
|
|
17
|
+
title: l10n.t('图片大小阈值'),
|
|
18
|
+
type: 'inputnumber',
|
|
19
|
+
defaultValue: 1000,
|
|
20
|
+
schema: {
|
|
21
|
+
type: 'number',
|
|
22
|
+
minimum: 0
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export var ImageProcessingRemoveOriginal = {
|
|
26
|
+
id: 'libro.output.imageProcessing.removeOriginal',
|
|
27
|
+
description: l10n.t('上传图片后是否移除原始base64数据'),
|
|
28
|
+
title: l10n.t('移除原始数据'),
|
|
29
|
+
type: 'checkbox',
|
|
30
|
+
defaultValue: true,
|
|
31
|
+
schema: {
|
|
32
|
+
type: 'boolean'
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export var ImageProcessingSupportedMimeTypes = {
|
|
36
|
+
id: 'libro.output.imageProcessing.supportedMimeTypes',
|
|
37
|
+
description: l10n.t('支持处理的图片MIME类型'),
|
|
38
|
+
title: l10n.t('支持的图片类型'),
|
|
39
|
+
type: 'select',
|
|
40
|
+
defaultValue: ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml'],
|
|
41
|
+
schema: {
|
|
42
|
+
type: 'array',
|
|
43
|
+
items: {
|
|
44
|
+
type: 'string'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
options: [{
|
|
48
|
+
label: 'PNG',
|
|
49
|
+
value: 'image/png'
|
|
50
|
+
}, {
|
|
51
|
+
label: 'JPEG',
|
|
52
|
+
value: 'image/jpeg'
|
|
53
|
+
}, {
|
|
54
|
+
label: 'GIF',
|
|
55
|
+
value: 'image/gif'
|
|
56
|
+
}, {
|
|
57
|
+
label: 'WebP',
|
|
58
|
+
value: 'image/webp'
|
|
59
|
+
}, {
|
|
60
|
+
label: 'SVG',
|
|
61
|
+
value: 'image/svg+xml'
|
|
62
|
+
}]
|
|
63
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface ImageUploadFunction {
|
|
2
|
+
(base64Data: string, mimeType: string): Promise<string>;
|
|
3
|
+
}
|
|
4
|
+
export interface ImageUploadCallbacks {
|
|
5
|
+
onUploadSuccess?: (originalBase64: string, uploadedUrl: string) => void;
|
|
6
|
+
onUploadError?: (error: Error, base64Data: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare class ImageUploadService {
|
|
9
|
+
private uploadFunction?;
|
|
10
|
+
private callbacks;
|
|
11
|
+
/**
|
|
12
|
+
* 设置图片上传函数
|
|
13
|
+
*/
|
|
14
|
+
setUploadFunction(uploadFunction: ImageUploadFunction): void;
|
|
15
|
+
/**
|
|
16
|
+
* 设置上传回调函数
|
|
17
|
+
*/
|
|
18
|
+
setCallbacks(callbacks: ImageUploadCallbacks): void;
|
|
19
|
+
/**
|
|
20
|
+
* 获取图片上传函数
|
|
21
|
+
*/
|
|
22
|
+
getUploadFunction(): ImageUploadFunction | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 获取上传回调函数
|
|
25
|
+
*/
|
|
26
|
+
getCallbacks(): ImageUploadCallbacks;
|
|
27
|
+
/**
|
|
28
|
+
* 上传图片
|
|
29
|
+
*/
|
|
30
|
+
uploadImage(base64Data: string, mimeType: string): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* 检查是否已配置上传函数
|
|
33
|
+
*/
|
|
34
|
+
hasUploadFunction(): boolean;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=image-upload-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-upload-service.d.ts","sourceRoot":"","sources":["../../src/display-data-output/image-upload-service.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACxE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5D;AAED,qBACa,kBAAkB;IAC7B,OAAO,CAAC,cAAc,CAAC,CAAsB;IAC7C,OAAO,CAAC,SAAS,CAA4B;IAE7C;;OAEG;IACH,iBAAiB,CAAC,cAAc,EAAE,mBAAmB,GAAG,IAAI;IAI5D;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAInD;;OAEG;IACH,iBAAiB,IAAI,mBAAmB,GAAG,SAAS;IAIpD;;OAEG;IACH,YAAY,IAAI,oBAAoB;IAIpC;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAexE;;OAEG;IACH,iBAAiB,IAAI,OAAO;CAG7B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
import { singleton } from '@difizen/mana-app';
|
|
15
|
+
export var ImageUploadService = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
16
|
+
function ImageUploadService() {
|
|
17
|
+
_classCallCheck(this, ImageUploadService);
|
|
18
|
+
this.callbacks = {};
|
|
19
|
+
}
|
|
20
|
+
_createClass(ImageUploadService, [{
|
|
21
|
+
key: "setUploadFunction",
|
|
22
|
+
value:
|
|
23
|
+
/**
|
|
24
|
+
* 设置图片上传函数
|
|
25
|
+
*/
|
|
26
|
+
function setUploadFunction(uploadFunction) {
|
|
27
|
+
this.uploadFunction = uploadFunction;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 设置上传回调函数
|
|
32
|
+
*/
|
|
33
|
+
}, {
|
|
34
|
+
key: "setCallbacks",
|
|
35
|
+
value: function setCallbacks(callbacks) {
|
|
36
|
+
this.callbacks = _objectSpread(_objectSpread({}, this.callbacks), callbacks);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 获取图片上传函数
|
|
41
|
+
*/
|
|
42
|
+
}, {
|
|
43
|
+
key: "getUploadFunction",
|
|
44
|
+
value: function getUploadFunction() {
|
|
45
|
+
return this.uploadFunction;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 获取上传回调函数
|
|
50
|
+
*/
|
|
51
|
+
}, {
|
|
52
|
+
key: "getCallbacks",
|
|
53
|
+
value: function getCallbacks() {
|
|
54
|
+
return this.callbacks;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 上传图片
|
|
59
|
+
*/
|
|
60
|
+
}, {
|
|
61
|
+
key: "uploadImage",
|
|
62
|
+
value: (function () {
|
|
63
|
+
var _uploadImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(base64Data, mimeType) {
|
|
64
|
+
var _this$callbacks$onUpl, _this$callbacks, _uploadedUrl, _this$callbacks$onUpl2, _this$callbacks2;
|
|
65
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
66
|
+
while (1) switch (_context.prev = _context.next) {
|
|
67
|
+
case 0:
|
|
68
|
+
if (this.uploadFunction) {
|
|
69
|
+
_context.next = 2;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
throw new Error('Upload function not configured');
|
|
73
|
+
case 2:
|
|
74
|
+
_context.prev = 2;
|
|
75
|
+
_context.next = 5;
|
|
76
|
+
return this.uploadFunction(base64Data, mimeType);
|
|
77
|
+
case 5:
|
|
78
|
+
_uploadedUrl = _context.sent;
|
|
79
|
+
(_this$callbacks$onUpl = (_this$callbacks = this.callbacks).onUploadSuccess) === null || _this$callbacks$onUpl === void 0 || _this$callbacks$onUpl.call(_this$callbacks, base64Data, _uploadedUrl);
|
|
80
|
+
return _context.abrupt("return", _uploadedUrl);
|
|
81
|
+
case 10:
|
|
82
|
+
_context.prev = 10;
|
|
83
|
+
_context.t0 = _context["catch"](2);
|
|
84
|
+
(_this$callbacks$onUpl2 = (_this$callbacks2 = this.callbacks).onUploadError) === null || _this$callbacks$onUpl2 === void 0 || _this$callbacks$onUpl2.call(_this$callbacks2, _context.t0, base64Data);
|
|
85
|
+
throw _context.t0;
|
|
86
|
+
case 14:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee, this, [[2, 10]]);
|
|
91
|
+
}));
|
|
92
|
+
function uploadImage(_x, _x2) {
|
|
93
|
+
return _uploadImage.apply(this, arguments);
|
|
94
|
+
}
|
|
95
|
+
return uploadImage;
|
|
96
|
+
}()
|
|
97
|
+
/**
|
|
98
|
+
* 检查是否已配置上传函数
|
|
99
|
+
*/
|
|
100
|
+
)
|
|
101
|
+
}, {
|
|
102
|
+
key: "hasUploadFunction",
|
|
103
|
+
value: function hasUploadFunction() {
|
|
104
|
+
return !!this.uploadFunction;
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
return ImageUploadService;
|
|
108
|
+
}()) || _class);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './display-data-output-contribution.js';
|
|
2
2
|
export * from './display-data-output-model.js';
|
|
3
3
|
export * from './display-data-output-module.js';
|
|
4
|
+
export * from './display-data-output-setting.js';
|
|
5
|
+
export * from './display-data-output-setting-contribution.js';
|
|
6
|
+
export * from './image-upload-service.js';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/display-data-output/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/display-data-output/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export * from "./display-data-output-contribution.js";
|
|
2
2
|
export * from "./display-data-output-model.js";
|
|
3
|
-
export * from "./display-data-output-module.js";
|
|
3
|
+
export * from "./display-data-output-module.js";
|
|
4
|
+
export * from "./display-data-output-setting.js";
|
|
5
|
+
export * from "./display-data-output-setting-contribution.js";
|
|
6
|
+
export * from "./image-upload-service.js";
|
|
@@ -9,7 +9,7 @@ export declare class ErrorOutputModel extends LibroOutputView implements BaseOut
|
|
|
9
9
|
output_type: string;
|
|
10
10
|
ename: import("@difizen/libro-common").PartialJSONValue | undefined;
|
|
11
11
|
evalue: import("@difizen/libro-common").PartialJSONValue | undefined;
|
|
12
|
-
traceback: import("@difizen/libro-common").PartialJSONValue |
|
|
12
|
+
traceback: string[] | import("@difizen/libro-common").PartialJSONValue | undefined;
|
|
13
13
|
};
|
|
14
14
|
showErrorDetail: boolean;
|
|
15
15
|
}
|
|
@@ -14,9 +14,9 @@ export declare class StreamOutputModel extends LibroOutputView implements BaseOu
|
|
|
14
14
|
name: string | number | boolean | Partial<{
|
|
15
15
|
[key: string]: import("@difizen/libro-common").PartialJSONValue;
|
|
16
16
|
}> | import("@difizen/libro-common").PartialJSONValue[] | null | undefined;
|
|
17
|
-
text: string | number | boolean | Partial<{
|
|
17
|
+
text: string | number | boolean | string[] | Partial<{
|
|
18
18
|
[key: string]: import("@difizen/libro-common").PartialJSONValue;
|
|
19
|
-
}> | import("@difizen/libro-common").PartialJSONValue[] |
|
|
19
|
+
}> | import("@difizen/libro-common").PartialJSONValue[] | null | undefined;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=stream-output-model.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-output",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-common": "^0.3.
|
|
36
|
-
"@difizen/libro-core": "^0.3.
|
|
37
|
-
"@difizen/libro-rendermime": "^0.3.
|
|
35
|
+
"@difizen/libro-common": "^0.3.30",
|
|
36
|
+
"@difizen/libro-core": "^0.3.30",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.3.30",
|
|
38
38
|
"@difizen/mana-app": "latest",
|
|
39
39
|
"@difizen/mana-l10n": "^0.1.32",
|
|
40
40
|
"markdown-it": "^13.0.1"
|
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
import type { IOutput } from '@difizen/libro-common';
|
|
2
|
+
import { getBundleOptions } from '@difizen/libro-common';
|
|
2
3
|
import type { IOutputOptions } from '@difizen/libro-core';
|
|
3
4
|
import { OutputContribution } from '@difizen/libro-core';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import {
|
|
6
|
+
inject,
|
|
7
|
+
singleton,
|
|
8
|
+
ViewManager,
|
|
9
|
+
ConfigurationService,
|
|
10
|
+
} from '@difizen/mana-app';
|
|
6
11
|
|
|
7
12
|
import { DisplayDataOutputModel } from './display-data-output-model.js';
|
|
13
|
+
import {
|
|
14
|
+
ImageProcessingEnabled,
|
|
15
|
+
ImageProcessingRemoveOriginal,
|
|
16
|
+
ImageProcessingSizeThreshold,
|
|
17
|
+
ImageProcessingSupportedMimeTypes,
|
|
18
|
+
} from './display-data-output-setting.js';
|
|
19
|
+
import { ImageUploadService } from './image-upload-service.js';
|
|
20
|
+
|
|
21
|
+
interface ImageProcessingConfig {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
supportedMimeTypes: string[];
|
|
24
|
+
removeOriginal: boolean;
|
|
25
|
+
sizeThreshold: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const IMAGE_URL_MIME_TYPE = 'image/vnd.libro.image-url';
|
|
8
29
|
|
|
9
30
|
@singleton({ contrib: OutputContribution })
|
|
10
31
|
export class DisplayDataOutputContribution implements OutputContribution {
|
|
11
32
|
@inject(ViewManager) viewManager: ViewManager;
|
|
33
|
+
@inject(ConfigurationService) configurationService: ConfigurationService;
|
|
34
|
+
@inject(ImageUploadService) imageUploadService: ImageUploadService;
|
|
35
|
+
|
|
12
36
|
canHandle = (output: IOutput) => {
|
|
13
37
|
if (
|
|
14
38
|
output.output_type === 'display_data' ||
|
|
@@ -18,7 +42,116 @@ export class DisplayDataOutputContribution implements OutputContribution {
|
|
|
18
42
|
}
|
|
19
43
|
return 1;
|
|
20
44
|
};
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
|
|
46
|
+
async factory(output: IOutputOptions) {
|
|
47
|
+
// 在构造模型之前预处理图片数据
|
|
48
|
+
const processedOutput = await this.preprocessImageData(output);
|
|
49
|
+
return this.viewManager.getOrCreateView(DisplayDataOutputModel, processedOutput);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private async preprocessImageData(options: IOutputOptions): Promise<IOutputOptions> {
|
|
53
|
+
// 从配置服务中读取配置值
|
|
54
|
+
const enabled =
|
|
55
|
+
await this.configurationService.get<boolean>(ImageProcessingEnabled);
|
|
56
|
+
const sizeThreshold = await this.configurationService.get<number>(
|
|
57
|
+
ImageProcessingSizeThreshold,
|
|
58
|
+
);
|
|
59
|
+
const removeOriginal = await this.configurationService.get<boolean>(
|
|
60
|
+
ImageProcessingRemoveOriginal,
|
|
61
|
+
);
|
|
62
|
+
const supportedMimeTypes = await this.configurationService.get<string[]>(
|
|
63
|
+
ImageProcessingSupportedMimeTypes,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// 合并配置
|
|
67
|
+
const imageConfig: ImageProcessingConfig = {
|
|
68
|
+
enabled,
|
|
69
|
+
sizeThreshold,
|
|
70
|
+
removeOriginal,
|
|
71
|
+
supportedMimeTypes,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// 如果未启用图片处理,直接返回原始选项
|
|
75
|
+
if (!imageConfig.enabled) {
|
|
76
|
+
return options;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 检查是否有可用的上传函数
|
|
80
|
+
const hasUploadFunction = this.imageUploadService.hasUploadFunction();
|
|
81
|
+
|
|
82
|
+
if (!hasUploadFunction) {
|
|
83
|
+
return options;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { data } = getBundleOptions(options.output);
|
|
87
|
+
|
|
88
|
+
if (!data || typeof data !== 'object') {
|
|
89
|
+
return options;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const processedData = await this.processImageDataInBundle(data, imageConfig);
|
|
94
|
+
|
|
95
|
+
// 创建新的输出选项,包含处理后的数据
|
|
96
|
+
const processedOutput = {
|
|
97
|
+
...options.output,
|
|
98
|
+
data: processedData,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...options,
|
|
103
|
+
output: processedOutput,
|
|
104
|
+
};
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.warn('图片预处理失败,使用原始数据:', error);
|
|
107
|
+
return options;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async processImageDataInBundle(
|
|
112
|
+
data: IOutput,
|
|
113
|
+
config: ImageProcessingConfig,
|
|
114
|
+
): Promise<IOutput> {
|
|
115
|
+
if (!data || typeof data !== 'object') {
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const processedData = { ...data };
|
|
120
|
+
const { supportedMimeTypes, sizeThreshold, removeOriginal } = config;
|
|
121
|
+
|
|
122
|
+
// 已经有 IMAGE_URL_MIME_TYPE 无需处理
|
|
123
|
+
if (processedData[IMAGE_URL_MIME_TYPE]) {
|
|
124
|
+
return processedData;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (const [mimeType, content] of Object.entries(data)) {
|
|
128
|
+
if (supportedMimeTypes.includes(mimeType) && typeof content === 'string') {
|
|
129
|
+
try {
|
|
130
|
+
// 检查是否超过阈值
|
|
131
|
+
if (content.length > sizeThreshold) {
|
|
132
|
+
const base64Data = content.startsWith('data:')
|
|
133
|
+
? content.split(',')[1]
|
|
134
|
+
: content;
|
|
135
|
+
|
|
136
|
+
// 上传图片并替换为 URL
|
|
137
|
+
const uploadedUrl = await this.imageUploadService.uploadImage(
|
|
138
|
+
base64Data,
|
|
139
|
+
mimeType,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
processedData[IMAGE_URL_MIME_TYPE] = uploadedUrl;
|
|
143
|
+
|
|
144
|
+
if (removeOriginal) {
|
|
145
|
+
delete processedData[mimeType];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.warn(`上传图片失败 (${mimeType}):`, error);
|
|
150
|
+
// 保持原始数据
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return processedData;
|
|
23
156
|
}
|
|
24
157
|
}
|
|
@@ -10,26 +10,34 @@ import {
|
|
|
10
10
|
view,
|
|
11
11
|
ViewInstance,
|
|
12
12
|
ViewOption,
|
|
13
|
+
inject,
|
|
14
|
+
transient,
|
|
13
15
|
} from '@difizen/mana-app';
|
|
14
|
-
import {
|
|
15
|
-
import { forwardRef } from 'react';
|
|
16
|
+
import type { ReactNode } from 'react';
|
|
17
|
+
import { createElement, forwardRef } from 'react';
|
|
16
18
|
|
|
17
19
|
import '../index.less';
|
|
18
20
|
|
|
19
|
-
const DisplayDataOutputModelRender = forwardRef<HTMLDivElement
|
|
20
|
-
function DisplayDataOutputModelRender(_props, ref) {
|
|
21
|
+
const DisplayDataOutputModelRender = forwardRef<HTMLDivElement, Record<string, never>>(
|
|
22
|
+
function DisplayDataOutputModelRender(_props, ref): React.ReactElement {
|
|
21
23
|
const output = useInject<DisplayDataOutputModel>(ViewInstance);
|
|
22
24
|
const model = getOrigin(output);
|
|
25
|
+
|
|
23
26
|
const factory = model.getRenderFactory();
|
|
24
|
-
let children = null;
|
|
25
|
-
if (factory) {
|
|
26
|
-
const
|
|
27
|
-
|
|
27
|
+
let children: ReactNode = null;
|
|
28
|
+
if (factory && factory.render) {
|
|
29
|
+
const renderFunction = factory.render;
|
|
30
|
+
if (typeof renderFunction === 'function') {
|
|
31
|
+
children = renderFunction({ model });
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
|
-
return (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
return createElement(
|
|
35
|
+
'div',
|
|
36
|
+
{
|
|
37
|
+
ref,
|
|
38
|
+
className: 'libro-display-data-container',
|
|
39
|
+
},
|
|
40
|
+
children,
|
|
33
41
|
);
|
|
34
42
|
},
|
|
35
43
|
);
|
|
@@ -4,7 +4,9 @@ import { ManaModule } from '@difizen/mana-app';
|
|
|
4
4
|
|
|
5
5
|
import { DisplayDataOutputContribution } from './display-data-output-contribution.js';
|
|
6
6
|
import { DisplayDataOutputModel } from './display-data-output-model.js';
|
|
7
|
+
import { DisplayDataOutputSettingContribution } from './display-data-output-setting-contribution.js';
|
|
8
|
+
import { ImageUploadService } from './image-upload-service.js';
|
|
7
9
|
|
|
8
10
|
export const DisplayDataOutputModule = ManaModule.create()
|
|
9
|
-
.register(DisplayDataOutputModel, DisplayDataOutputContribution)
|
|
11
|
+
.register(DisplayDataOutputModel, DisplayDataOutputContribution, DisplayDataOutputSettingContribution, ImageUploadService)
|
|
10
12
|
.dependOn(OutputModule, LibroRenderMimeModule);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { singleton, ConfigurationContribution } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ImageProcessingEnabled,
|
|
5
|
+
ImageProcessingSizeThreshold,
|
|
6
|
+
ImageProcessingRemoveOriginal,
|
|
7
|
+
ImageProcessingSupportedMimeTypes,
|
|
8
|
+
} from './display-data-output-setting.js';
|
|
9
|
+
|
|
10
|
+
@singleton({ contrib: ConfigurationContribution })
|
|
11
|
+
export class DisplayDataOutputSettingContribution implements ConfigurationContribution {
|
|
12
|
+
registerConfigurations() {
|
|
13
|
+
return [
|
|
14
|
+
ImageProcessingEnabled,
|
|
15
|
+
ImageProcessingSizeThreshold,
|
|
16
|
+
ImageProcessingRemoveOriginal,
|
|
17
|
+
ImageProcessingSupportedMimeTypes,
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ConfigurationNode } from '@difizen/mana-app';
|
|
2
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
3
|
+
|
|
4
|
+
// 图片处理配置项
|
|
5
|
+
export const ImageProcessingEnabled: ConfigurationNode<boolean> = {
|
|
6
|
+
id: 'libro.output.imageProcessing.enabled',
|
|
7
|
+
description: l10n.t('是否启用图片处理功能'),
|
|
8
|
+
title: l10n.t('启用图片处理'),
|
|
9
|
+
type: 'checkbox',
|
|
10
|
+
defaultValue: true,
|
|
11
|
+
schema: {
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const ImageProcessingSizeThreshold: ConfigurationNode<number> = {
|
|
17
|
+
id: 'libro.output.imageProcessing.sizeThreshold',
|
|
18
|
+
description: l10n.t('图片处理的大小阈值(字符数)'),
|
|
19
|
+
title: l10n.t('图片大小阈值'),
|
|
20
|
+
type: 'inputnumber',
|
|
21
|
+
defaultValue: 1000,
|
|
22
|
+
schema: {
|
|
23
|
+
type: 'number',
|
|
24
|
+
minimum: 0,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const ImageProcessingRemoveOriginal: ConfigurationNode<boolean> = {
|
|
29
|
+
id: 'libro.output.imageProcessing.removeOriginal',
|
|
30
|
+
description: l10n.t('上传图片后是否移除原始base64数据'),
|
|
31
|
+
title: l10n.t('移除原始数据'),
|
|
32
|
+
type: 'checkbox',
|
|
33
|
+
defaultValue: true,
|
|
34
|
+
schema: {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const ImageProcessingSupportedMimeTypes: ConfigurationNode<string[]> = {
|
|
40
|
+
id: 'libro.output.imageProcessing.supportedMimeTypes',
|
|
41
|
+
description: l10n.t('支持处理的图片MIME类型'),
|
|
42
|
+
title: l10n.t('支持的图片类型'),
|
|
43
|
+
type: 'select',
|
|
44
|
+
defaultValue: ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml'],
|
|
45
|
+
schema: {
|
|
46
|
+
type: 'array',
|
|
47
|
+
items: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
options: [
|
|
52
|
+
{ label: 'PNG', value: 'image/png' },
|
|
53
|
+
{ label: 'JPEG', value: 'image/jpeg' },
|
|
54
|
+
{ label: 'GIF', value: 'image/gif' },
|
|
55
|
+
{ label: 'WebP', value: 'image/webp' },
|
|
56
|
+
{ label: 'SVG', value: 'image/svg+xml' },
|
|
57
|
+
],
|
|
58
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
export interface ImageUploadFunction {
|
|
4
|
+
(base64Data: string, mimeType: string): Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ImageUploadCallbacks {
|
|
8
|
+
onUploadSuccess?: (originalBase64: string, uploadedUrl: string) => void;
|
|
9
|
+
onUploadError?: (error: Error, base64Data: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@singleton()
|
|
13
|
+
export class ImageUploadService {
|
|
14
|
+
private uploadFunction?: ImageUploadFunction;
|
|
15
|
+
private callbacks: ImageUploadCallbacks = {};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 设置图片上传函数
|
|
19
|
+
*/
|
|
20
|
+
setUploadFunction(uploadFunction: ImageUploadFunction): void {
|
|
21
|
+
this.uploadFunction = uploadFunction;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 设置上传回调函数
|
|
26
|
+
*/
|
|
27
|
+
setCallbacks(callbacks: ImageUploadCallbacks): void {
|
|
28
|
+
this.callbacks = { ...this.callbacks, ...callbacks };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 获取图片上传函数
|
|
33
|
+
*/
|
|
34
|
+
getUploadFunction(): ImageUploadFunction | undefined {
|
|
35
|
+
return this.uploadFunction;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 获取上传回调函数
|
|
40
|
+
*/
|
|
41
|
+
getCallbacks(): ImageUploadCallbacks {
|
|
42
|
+
return this.callbacks;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 上传图片
|
|
47
|
+
*/
|
|
48
|
+
async uploadImage(base64Data: string, mimeType: string): Promise<string> {
|
|
49
|
+
if (!this.uploadFunction) {
|
|
50
|
+
throw new Error('Upload function not configured');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const uploadedUrl = await this.uploadFunction(base64Data, mimeType);
|
|
55
|
+
this.callbacks.onUploadSuccess?.(base64Data, uploadedUrl);
|
|
56
|
+
return uploadedUrl;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.callbacks.onUploadError?.(error as Error, base64Data);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 检查是否已配置上传函数
|
|
65
|
+
*/
|
|
66
|
+
hasUploadFunction(): boolean {
|
|
67
|
+
return !!this.uploadFunction;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export * from './display-data-output-contribution.js';
|
|
2
2
|
export * from './display-data-output-model.js';
|
|
3
3
|
export * from './display-data-output-module.js';
|
|
4
|
+
export * from './display-data-output-setting.js';
|
|
5
|
+
export * from './display-data-output-setting-contribution.js';
|
|
6
|
+
export * from './image-upload-service.js';
|