@difizen/libro-core 0.2.40 → 0.2.41-next.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.
Files changed (51) hide show
  1. package/es/cell/libro-cell-view.js +1 -3
  2. package/es/cell/libro-executable-cell-view.d.ts +2 -0
  3. package/es/cell/libro-executable-cell-view.d.ts.map +1 -1
  4. package/es/cell/libro-executable-cell-view.js +15 -0
  5. package/es/components/cell-protocol.d.ts +4 -0
  6. package/es/components/cell-protocol.d.ts.map +1 -1
  7. package/es/components/cell-protocol.js +1 -0
  8. package/es/components/dnd-cell-item-render.d.ts +2 -1
  9. package/es/components/dnd-cell-item-render.d.ts.map +1 -1
  10. package/es/components/dnd-cell-item-render.js +7 -1
  11. package/es/index.d.ts +1 -0
  12. package/es/index.d.ts.map +1 -1
  13. package/es/index.js +2 -1
  14. package/es/index.less +4 -7
  15. package/es/libro-model.d.ts +3 -0
  16. package/es/libro-model.d.ts.map +1 -1
  17. package/es/libro-model.js +25 -0
  18. package/es/libro-protocol.d.ts +1 -0
  19. package/es/libro-protocol.d.ts.map +1 -1
  20. package/es/libro-setting.js +1 -1
  21. package/es/libro-view.d.ts +2 -0
  22. package/es/libro-view.d.ts.map +1 -1
  23. package/es/libro-view.js +21 -1
  24. package/es/module.d.ts.map +1 -1
  25. package/es/module.js +4 -1
  26. package/es/slot/libro-slot-view.d.ts +4 -0
  27. package/es/slot/libro-slot-view.d.ts.map +1 -1
  28. package/es/slot/libro-slot-view.js +56 -5
  29. package/es/theme/libro-color-registry.d.ts.map +1 -1
  30. package/es/theme/libro-color-registry.js +7 -0
  31. package/es/utils/index.d.ts +8 -0
  32. package/es/utils/index.d.ts.map +1 -0
  33. package/es/utils/index.js +53 -0
  34. package/package.json +5 -5
  35. package/src/cell/libro-cell-view.tsx +1 -1
  36. package/src/cell/libro-executable-cell-view.ts +11 -0
  37. package/src/components/cell-protocol.ts +4 -0
  38. package/src/components/dnd-cell-item-render.tsx +12 -1
  39. package/src/components/dnd-component/default-dnd-content.tsx +15 -5
  40. package/src/components/dnd-component/dnd-list.tsx +23 -9
  41. package/src/components/libro-virtualized-render.tsx +14 -2
  42. package/src/index.less +14 -9
  43. package/src/index.tsx +1 -0
  44. package/src/libro-model.ts +10 -0
  45. package/src/libro-protocol.ts +3 -0
  46. package/src/libro-setting.ts +1 -1
  47. package/src/libro-view.tsx +30 -4
  48. package/src/module.ts +6 -0
  49. package/src/slot/libro-slot-view.tsx +32 -5
  50. package/src/theme/libro-color-registry.ts +5 -0
  51. package/src/utils/index.ts +48 -0
@@ -1,11 +1,16 @@
1
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
2
  var _dec, _dec2, _dec3, _class, _class2, _descriptor;
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); }); }; }
3
6
  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 }); }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
8
  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
9
  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
10
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
11
  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
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
13
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
9
14
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
15
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
16
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -41,11 +46,11 @@ export var LibroExtensionViewComponent = /*#__PURE__*/forwardRef(function LibroE
41
46
  } else {
42
47
  var activeView = filteredChildren.find(function (item) {
43
48
  return instance.active && equals(item, instance.active);
44
- }) || filteredChildren[filteredChildren.length - 1];
49
+ });
45
50
  return /*#__PURE__*/_jsxs("div", {
46
51
  className: 'libro-slot-container',
47
52
  ref: ref,
48
- children: [/*#__PURE__*/_jsx(ViewRender, {
53
+ children: [activeView && /*#__PURE__*/_jsx(ViewRender, {
49
54
  view: activeView
50
55
  }), instance.children.map(function (item) {
51
56
  return !isDisplayView(item) && /*#__PURE__*/_jsx(ViewRender, {
@@ -68,9 +73,55 @@ export var LibroSlotView = (_dec = transient(), _dec2 = view('libro-slot-view'),
68
73
  _this.label = null;
69
74
  _this.view = LibroExtensionViewComponent;
70
75
  _initializerDefineProperty(_this, "sort", _descriptor, _assertThisInitialized(_this));
76
+ // sort?: boolean = true;
77
+ _this.history = [];
71
78
  return _this;
72
- } // sort?: boolean = true;
73
- return _createClass(LibroSlotView);
79
+ }
80
+ _createClass(LibroSlotView, [{
81
+ key: "addView",
82
+ value: function () {
83
+ var _addView = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(viewInstance, option) {
84
+ var toDispose;
85
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
86
+ while (1) switch (_context.prev = _context.next) {
87
+ case 0:
88
+ if (option !== null && option !== void 0 && option.reveal) {
89
+ this.history.push(viewInstance);
90
+ }
91
+ toDispose = _get(_getPrototypeOf(LibroSlotView.prototype), "addView", this).call(this, viewInstance, option);
92
+ return _context.abrupt("return", toDispose);
93
+ case 3:
94
+ case "end":
95
+ return _context.stop();
96
+ }
97
+ }, _callee, this);
98
+ }));
99
+ function addView(_x, _x2) {
100
+ return _addView.apply(this, arguments);
101
+ }
102
+ return addView;
103
+ }()
104
+ }, {
105
+ key: "revertActive",
106
+ value: function revertActive() {
107
+ var _this2 = this;
108
+ var index = this.history.findIndex(function (item) {
109
+ var _this2$active;
110
+ return item.id === ((_this2$active = _this2.active) === null || _this2$active === void 0 ? void 0 : _this2$active.id);
111
+ });
112
+ if (index < 0) {
113
+ return;
114
+ }
115
+ this.history.splice(index, 1);
116
+ if (this.history.length > 0) {
117
+ var last = this.history[this.history.length - 1];
118
+ this.active = last;
119
+ } else {
120
+ this.active = undefined;
121
+ }
122
+ }
123
+ }]);
124
+ return LibroSlotView;
74
125
  }(DefaultSlotView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "sort", [_dec3], {
75
126
  configurable: true,
76
127
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"file":"libro-color-registry.d.ts","sourceRoot":"","sources":["../../src/theme/libro-color-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,qBACa,kBAAmB,YAAW,iBAAiB;IAC1D,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;CA2X5C"}
1
+ {"version":3,"file":"libro-color-registry.d.ts","sourceRoot":"","sources":["../../src/theme/libro-color-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,qBACa,kBAAmB,YAAW,iBAAiB;IAC1D,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;CAgY5C"}
@@ -410,6 +410,13 @@ export var LibroColorRegistry = (_dec = singleton({
410
410
  light: '#212121'
411
411
  },
412
412
  description: ''
413
+ }, {
414
+ id: 'libro.editor.class.color',
415
+ defaults: {
416
+ dark: '#6868f3',
417
+ light: '#0000ff'
418
+ },
419
+ description: ''
413
420
  }, {
414
421
  id: 'libro.editor.def.color',
415
422
  defaults: {
@@ -0,0 +1,8 @@
1
+ import type { RefObject } from 'react';
2
+ type Size = {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export declare function useSize(ref: RefObject<HTMLDivElement>): Size | undefined;
7
+ export {};
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAsBvC,KAAK,IAAI,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9C,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,CAuBxE"}
@@ -0,0 +1,53 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useUnmount } from '@difizen/mana-app';
8
+ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
9
+ function useRafState(initialState) {
10
+ var ref = useRef(0);
11
+ var _useState = useState(initialState),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ state = _useState2[0],
14
+ setState = _useState2[1];
15
+ var setRafState = useCallback(function (value) {
16
+ cancelAnimationFrame(ref.current);
17
+ ref.current = requestAnimationFrame(function () {
18
+ setState(value);
19
+ });
20
+ }, []);
21
+ useUnmount(function () {
22
+ cancelAnimationFrame(ref.current);
23
+ });
24
+ return [state, setRafState];
25
+ }
26
+ export function useSize(ref) {
27
+ var _useRafState = useRafState(),
28
+ _useRafState2 = _slicedToArray(_useRafState, 2),
29
+ size = _useRafState2[0],
30
+ setSize = _useRafState2[1];
31
+ useLayoutEffect(function () {
32
+ var el = ref === null || ref === void 0 ? void 0 : ref.current;
33
+ if (!el) {
34
+ return;
35
+ }
36
+ var resizeObserver = new ResizeObserver(function (entries) {
37
+ entries.forEach(function (entry) {
38
+ var _entry$target = entry.target,
39
+ clientWidth = _entry$target.clientWidth,
40
+ clientHeight = _entry$target.clientHeight;
41
+ setSize({
42
+ width: clientWidth,
43
+ height: clientHeight
44
+ });
45
+ });
46
+ });
47
+ resizeObserver.observe(el);
48
+ return function () {
49
+ resizeObserver.disconnect();
50
+ };
51
+ }, [ref, setSize]);
52
+ return size;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-core",
3
- "version": "0.2.40",
3
+ "version": "0.2.41-next.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -34,10 +34,10 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@ant-design/icons": "^5.1.0",
37
- "@difizen/libro-code-editor": "^0.2.40",
38
- "@difizen/libro-common": "^0.2.40",
39
- "@difizen/libro-shared-model": "^0.2.40",
40
- "@difizen/libro-virtualized": "^0.2.40",
37
+ "@difizen/libro-code-editor": "^0.2.41-next.0",
38
+ "@difizen/libro-common": "^0.2.41-next.0",
39
+ "@difizen/libro-shared-model": "^0.2.41-next.0",
40
+ "@difizen/libro-virtualized": "^0.2.41-next.0",
41
41
  "@difizen/mana-app": "latest",
42
42
  "@difizen/mana-l10n": "latest",
43
43
  "@difizen/mana-react": "latest",
@@ -137,7 +137,7 @@ export class LibroCellView extends BaseView implements CellView {
137
137
  super.dispose();
138
138
  }
139
139
  toJSON(): LibroCell {
140
- const meta = { ...(this.model.toJSON() as LibroCell), outputs: [] };
140
+ const meta = { ...(this.model.toJSON() as LibroCell) };
141
141
  const modelContribution = this.cellService.findModelProvider(this.model.options);
142
142
  if (modelContribution?.cellMeta.nbformatType) {
143
143
  meta.metadata.libroCellType = modelContribution?.cellMeta.type;
@@ -1,3 +1,4 @@
1
+ import type { ICodeCell } from '@difizen/libro-common';
1
2
  import { watch } from '@difizen/mana-app';
2
3
  import { ViewOption } from '@difizen/mana-app';
3
4
  import { inject } from '@difizen/mana-app';
@@ -6,6 +7,7 @@ import type { CellModel } from '../libro-protocol.js';
6
7
  import type { CellViewOptions } from '../libro-protocol.js';
7
8
  import type { BaseOutputArea } from '../output/index.js';
8
9
 
10
+ import type { LibroCell } from './libro-cell-protocol.js';
9
11
  import { CellService } from './libro-cell-protocol.js';
10
12
  import { EditorCellView, LibroEditorCellView } from './libro-edit-cell-view.js';
11
13
  import { ExecutableCellModel } from './libro-executable-cell-model.js';
@@ -78,6 +80,15 @@ export abstract class LibroEditableExecutableCellView
78
80
  }),
79
81
  );
80
82
  }
83
+
84
+ override toJSON(): LibroCell {
85
+ const meta = super.toJSON();
86
+ return {
87
+ ...meta,
88
+ source: meta.source ?? this.options.cell.source,
89
+ outputs: this.outputArea?.toJSON() ?? [],
90
+ } as ICodeCell;
91
+ }
81
92
  }
82
93
 
83
94
  /**
@@ -10,6 +10,10 @@ export type CellInputBottonBlankProvider = FC<{ cell: CellView }>;
10
10
 
11
11
  export const CellInputBottonBlankProvider = Symbol('CellInputBottonBlankProvider');
12
12
 
13
+ export type CellOutputTopProvider = FC<{ cell: CellView }>;
14
+
15
+ export const CellOutputTopProvider = Symbol('CellOutputTopProvider');
16
+
13
17
  export type CellOutputBottomBlankProvider = FC<{ cell: CellView }>;
14
18
 
15
19
  export const CellOutputBottomBlankProvider = Symbol('CellOutputBottomBlankProvider');
@@ -42,7 +42,10 @@ import {
42
42
  } from '../material-from-designer.js';
43
43
  import { hasErrorOutput } from '../output/index.js';
44
44
 
45
- import { CellOutputBottomBlankProvider } from './cell-protocol.js';
45
+ import {
46
+ CellOutputBottomBlankProvider,
47
+ CellOutputTopProvider,
48
+ } from './cell-protocol.js';
46
49
  import {
47
50
  CellExecutionTimeProvider,
48
51
  CellInputBottonBlankProvider,
@@ -129,6 +132,7 @@ export const CellOutputContent: React.FC<{ cell: CellView }> = memo(
129
132
  const CellOutputBottomBlank = useInject<CellOutputBottomBlankProvider>(
130
133
  CellOutputBottomBlankProvider,
131
134
  );
135
+ const CellOutputTopBlank = useInject<CellOutputTopProvider>(CellOutputTopProvider);
132
136
  const CellExecutionTime = useInject<CellExecutionTimeProvider>(
133
137
  CellExecutionTimeProvider,
134
138
  );
@@ -156,6 +160,7 @@ export const CellOutputContent: React.FC<{ cell: CellView }> = memo(
156
160
  className={`libro-cell-output-content ${hasOutputsScrolled ? 'scrolled' : ''} `}
157
161
  >
158
162
  <CellExecutionTime cell={cell} />
163
+ <CellOutputTopBlank cell={cell} />
159
164
  <CellOutputVisulization cell={cell} />
160
165
  {observableCell.outputArea.length > 0 && <ViewRender view={cell.outputArea} />}
161
166
  <CellOutputBottomBlank cell={cell} />
@@ -182,6 +187,12 @@ export const LibroCellOutputBottomBlank: CellOutputBottomBlankProvider = forward
182
187
  },
183
188
  );
184
189
 
190
+ export const LibroCellTopBlank: CellOutputTopProvider = forwardRef(
191
+ function LibroCellTopBlank() {
192
+ return null;
193
+ },
194
+ );
195
+
185
196
  export const LibroCellVisualization: CellOutputVisulizationProvider = forwardRef(
186
197
  function LibroCellVisualization() {
187
198
  return null;
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable react-hooks/exhaustive-deps */
2
2
  import { getOrigin, useInject, ViewInstance } from '@difizen/mana-app';
3
3
  import { useConfigurationValue } from '@difizen/mana-app';
4
+ import { Button } from 'antd';
4
5
  import type { Identifier } from 'dnd-core';
5
6
  import React, {
6
7
  useCallback,
@@ -30,7 +31,11 @@ export interface Dragparams {
30
31
  index: number;
31
32
  }
32
33
 
33
- export const DndCellContainer: React.FC<DndContentProps> = ({ cell, index }) => {
34
+ export const DndCellContainer: React.FC<DndContentProps> = ({
35
+ cell,
36
+ index,
37
+ position,
38
+ }) => {
34
39
  const ref = useRef<HTMLDivElement>(null);
35
40
  const instance = useInject<LibroView>(ViewInstance);
36
41
  const [multiSelectionWhenShiftClick] = useConfigurationValue(
@@ -285,7 +290,10 @@ export const DndCellContainer: React.FC<DndContentProps> = ({ cell, index }) =>
285
290
  ref={ref}
286
291
  id={cell.id}
287
292
  >
288
- <BetweenCellContent index={index} addCell={cell.parent.addCellAbove} />
293
+ <BetweenCellContent
294
+ index={position || index}
295
+ addCell={cell.parent.addCellAbove}
296
+ />
289
297
  {isDragOver && <div className="libro-drag-hoverline" />}
290
298
  {isMouseOverDragArea && <HolderOutlined className="libro-handle-style" />}
291
299
  <div
@@ -311,12 +319,14 @@ export const DndCellContainer: React.FC<DndContentProps> = ({ cell, index }) =>
311
319
  </div>
312
320
  {isCollapsible && cell.headingCollapsed && cell.collapsibleChildNumber > 0 && (
313
321
  <div className="libro-cell-collapsed-expander">
314
- <button
322
+ <Button
315
323
  className="libro-cell-expand-button"
316
324
  onClick={() => instance.collapseCell(cell, false)}
325
+ icon={<PlusOutlined className="" />}
326
+ type="default"
317
327
  >
318
- <PlusOutlined className="" /> {cell.collapsibleChildNumber} cell hidden
319
- </button>
328
+ {cell.collapsibleChildNumber} cell hidden
329
+ </Button>
320
330
  </div>
321
331
  )}
322
332
  </div>
@@ -31,15 +31,29 @@ export const DndCellRender: FC<DndContentProps> = memo(function DndCellRender({
31
31
  });
32
32
 
33
33
  // 定义一个函数用于渲染非虚拟列表时的单元格
34
- const renderNonVirtualListCells = (cells: CellView[]) => (
35
- <div style={{ height: '100%', overflow: 'visible' }}>
36
- {cells
37
- .filter((cell) => !cell.collapsedHidden)
38
- .map((cell, index) => (
39
- <DndCellRender cell={cell} key={cell.id} index={index} />
40
- ))}
41
- </div>
42
- );
34
+ const renderNonVirtualListCells = (cells: CellView[]) => {
35
+ let position = -1;
36
+ return (
37
+ <div style={{ height: '100%', overflow: 'visible' }}>
38
+ {cells
39
+ // .filter((cell) => !cell.collapsedHidden)
40
+ .map((cell, index) => {
41
+ position += 1;
42
+ if (cell.collapsedHidden) {
43
+ return null;
44
+ }
45
+ return (
46
+ <DndCellRender
47
+ cell={cell}
48
+ key={cell.id}
49
+ index={index}
50
+ position={position}
51
+ />
52
+ );
53
+ })}
54
+ </div>
55
+ );
56
+ };
43
57
 
44
58
  export const DndCellsRender = forwardRef<
45
59
  HTMLDivElement,
@@ -131,6 +131,7 @@ export const LibroCellsOutputRender: React.FC<{
131
131
 
132
132
  // 绘制所有的非编辑器区域
133
133
  const noEditorArea = useMemo(() => {
134
+ let position = -1;
134
135
  return (
135
136
  <div
136
137
  style={{
@@ -142,9 +143,20 @@ export const LibroCellsOutputRender: React.FC<{
142
143
  ref={noEditorAreaRef}
143
144
  >
144
145
  {cells
145
- .filter((cell) => cell.collapsedHidden === false)
146
+ // .filter((cell) => cell.collapsedHidden === false)
146
147
  .map((cell, index) => {
147
- return <DndCellRender cell={cell} key={cell.id} index={index} />;
148
+ position += 1;
149
+ if (cell.collapsedHidden) {
150
+ return null;
151
+ }
152
+ return (
153
+ <DndCellRender
154
+ cell={cell}
155
+ key={cell.id}
156
+ index={index}
157
+ position={position}
158
+ />
159
+ );
148
160
  })}
149
161
  {addCellButtons}
150
162
  </div>
package/src/index.less CHANGED
@@ -188,6 +188,7 @@
188
188
  padding-left: 72px;
189
189
 
190
190
  .libro-cell-expand-button {
191
+ height: 24px;
191
192
  padding: 0 12px;
192
193
  }
193
194
  }
@@ -250,12 +251,12 @@
250
251
 
251
252
  &.active.command-mode.error,
252
253
  &.error {
253
- border: 1px solid var(--mana-libro-error-color) !important;
254
+ border: 1px solid var(--mana-libro-error-color);
254
255
  box-shadow: unset;
255
256
  }
256
257
 
257
258
  &.active.edit-mode.error {
258
- border: 1px solid var(--mana-libro-error-color) !important;
259
+ border: 1px solid var(--mana-libro-error-color);
259
260
  box-shadow: rgba(237, 19, 69, 25%) 0 0 0 2px;
260
261
  }
261
262
 
@@ -545,7 +546,7 @@
545
546
 
546
547
  .libro-view-content-left {
547
548
  position: relative;
548
- width: calc(100% - 40px);
549
+ width: calc(100% - 20px);
549
550
  height: 100%;
550
551
 
551
552
  // &.libro-view-content-has-right {
@@ -585,6 +586,10 @@
585
586
  }
586
587
  }
587
588
 
589
+ .libro-output-area {
590
+ padding-top: 12px;
591
+ }
592
+
588
593
  .libro-cell-output-content {
589
594
  &.scrolled {
590
595
  .libro-output-area {
@@ -594,6 +599,11 @@
594
599
  }
595
600
  }
596
601
 
602
+ .libro-cell-output-content:has(.libro-output-area),
603
+ .libro-cell-output-content:has(.libro-cell-bottom-blank) {
604
+ border-top: 1px solid var(--mana-libro-code-border-color);
605
+ }
606
+
597
607
  .libro-cell-output-scroll-button {
598
608
  position: absolute;
599
609
  top: 4px;
@@ -635,6 +645,7 @@
635
645
  .libro-view-content-right {
636
646
  flex: 1;
637
647
  margin-left: 40px;
648
+ height: calc(100% - 40px);
638
649
  }
639
650
 
640
651
  .libro-totop-button {
@@ -755,12 +766,6 @@
755
766
  text-align: right;
756
767
  }
757
768
 
758
- .libro-output-area {
759
- padding-top: 18px;
760
- border-top: 1px solid var(--mana-libro-code-border-color);
761
- // overflow: hidden;
762
- }
763
-
764
769
  .libro-tooltip {
765
770
  text-align: center;
766
771
  }
package/src/index.tsx CHANGED
@@ -23,3 +23,4 @@ export * from './virtualized-manager.js';
23
23
  export * from './virtualized-manager-helper.js';
24
24
  export * from './libro-workspace-service.js';
25
25
  export * from './libro-context-key.js';
26
+ export * from './utils/index.js';
@@ -67,6 +67,11 @@ export class LibroModel implements NotebookModel, DndListModel {
67
67
  return this.onSourceChangedEmitter.event;
68
68
  }
69
69
 
70
+ protected onRestartEmitter: Emitter<void> = new Emitter();
71
+ get onRestart() {
72
+ return this.onRestartEmitter.event;
73
+ }
74
+
70
75
  protected onCellContentChangedEmitter: Emitter<ICellContentChange> = new Emitter();
71
76
  get onCellContentChanged() {
72
77
  return this.onCellContentChangedEmitter.event;
@@ -439,6 +444,10 @@ export class LibroModel implements NotebookModel, DndListModel {
439
444
  this.insertCells([cell], position, mode);
440
445
  };
441
446
 
447
+ async restart() {
448
+ this.onRestartEmitter.fire();
449
+ }
450
+
442
451
  insertCells = (cells: CellView[], position?: number, mode?: string) => {
443
452
  // 非初始化阶段才需要自动滚动
444
453
  if (!this.isInitialized) {
@@ -458,6 +467,7 @@ export class LibroModel implements NotebookModel, DndListModel {
458
467
  this.cellViewCache.set(cell.model.id, cell);
459
468
  return cell.toJSON();
460
469
  });
470
+
461
471
  getOrigin(this.sharedModel).transact(() => {
462
472
  const insertIndex = position ?? this.sharedModel.cells.length;
463
473
  getOrigin(this.sharedModel).insertCells(insertIndex, cellData);
@@ -207,6 +207,8 @@ export interface BaseNotebookModel {
207
207
  */
208
208
  onChange?: () => void;
209
209
 
210
+ onRestart?: Event<void>;
211
+
210
212
  onSourceChange?: (cells: CellView[]) => void;
211
213
 
212
214
  onCellContentChange: (changes: ICellContentChange) => void;
@@ -409,6 +411,7 @@ export interface DndListModel {
409
411
  export interface DndContentProps {
410
412
  cell: CellView;
411
413
  index: number;
414
+ position: number;
412
415
  }
413
416
 
414
417
  export interface DndItemProps {
@@ -81,7 +81,7 @@ export const RightContentFixed: ConfigurationNode<boolean> = {
81
81
  description: l10n.t('libroview的右边栏是否相对固定'),
82
82
  title: l10n.t('右侧内容是否相对固定'),
83
83
  type: 'checkbox',
84
- defaultValue: false,
84
+ defaultValue: true,
85
85
  schema: {
86
86
  type: 'boolean',
87
87
  },
@@ -69,6 +69,7 @@ import {
69
69
  RightContentFixed,
70
70
  } from './libro-setting.js';
71
71
  import { LibroSlotManager, LibroSlotView } from './slot/index.js';
72
+ import { useSize } from './utils/index.js';
72
73
  import { VirtualizedManagerHelper } from './virtualized-manager-helper.js';
73
74
  import type { VirtualizedManager } from './virtualized-manager.js';
74
75
  import './index.less';
@@ -138,11 +139,23 @@ export const LibroContentComponent = memo(function LibroContentComponent() {
138
139
  ) {
139
140
  libroViewContentRef.current.style.cssText = 'display: block;';
140
141
  libroViewRightContentRef.current.style.cssText =
141
- 'position: absolute;top:44px;right:20px';
142
- libroViewLeftContentRef.current.style.cssText = 'padding-right: 80px;';
142
+ 'position: absolute;top:40px;right:20px';
143
+ libroViewLeftContentRef.current.style.cssText = 'padding-right: 20px;';
143
144
  }
144
145
  }, [rightContentFixed]);
145
146
 
147
+ const rightSize = useSize(libroViewRightContentRef);
148
+ let leftContentStyles = {};
149
+ let rightContentStyles = {};
150
+ if (rightSize?.width && rightSize?.width > 0) {
151
+ leftContentStyles = {
152
+ width: `calc(100% - ${rightSize.width}px)`,
153
+ };
154
+ rightContentStyles = {
155
+ marginLeft: 0,
156
+ };
157
+ }
158
+
146
159
  return (
147
160
  <>
148
161
  {headerVisible && (
@@ -155,7 +168,11 @@ export const LibroContentComponent = memo(function LibroContentComponent() {
155
168
  onScroll={handleScroll}
156
169
  ref={libroViewContentRef}
157
170
  >
158
- <div className="libro-view-content-left" ref={libroViewLeftContentRef}>
171
+ <div
172
+ className="libro-view-content-left"
173
+ style={leftContentStyles}
174
+ ref={libroViewLeftContentRef}
175
+ >
159
176
  <DndContext>
160
177
  <CustomDragLayer />
161
178
  <DndList libroView={instance} ref={ref}>
@@ -166,7 +183,11 @@ export const LibroContentComponent = memo(function LibroContentComponent() {
166
183
  </DndList>
167
184
  </DndContext>
168
185
  </div>
169
- <div className="libro-view-content-right" ref={libroViewRightContentRef}>
186
+ <div
187
+ className="libro-view-content-right"
188
+ style={rightContentStyles}
189
+ ref={libroViewRightContentRef}
190
+ >
170
191
  {/* {tocVisible && instance.toc && <ViewRender view={instance.toc} />} */}
171
192
  <Slot
172
193
  name={libroSlotManager.getSlotName(instance, 'right')}
@@ -305,6 +326,11 @@ export class LibroView extends BaseView implements NotebookView {
305
326
  return this.onBlurEmitter.event;
306
327
  }
307
328
 
329
+ onRestartEmitter: Emitter = new Emitter();
330
+ get onRestart() {
331
+ return this.onRestartEmitter.event;
332
+ }
333
+
308
334
  @inject(CellService) cellService: CellService;
309
335
  @inject(LibroService) libroService: LibroService;
310
336
  @inject(LibroSlotManager) libroSlotManager: LibroSlotManager;