@difizen/libro-markdown-cell 0.0.0-snapshot-20241017072317
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/LICENSE +21 -0
- package/README.md +1 -0
- package/es/index.d.ts +7 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +6 -0
- package/es/index.less +116 -0
- package/es/markdown-cell-contribution.d.ts +15 -0
- package/es/markdown-cell-contribution.d.ts.map +1 -0
- package/es/markdown-cell-contribution.js +59 -0
- package/es/markdown-cell-model.d.ts +11 -0
- package/es/markdown-cell-model.d.ts.map +1 -0
- package/es/markdown-cell-model.js +77 -0
- package/es/markdown-cell-module.d.ts +3 -0
- package/es/markdown-cell-module.d.ts.map +1 -0
- package/es/markdown-cell-module.js +21 -0
- package/es/markdown-cell-protocol.d.ts +5 -0
- package/es/markdown-cell-protocol.d.ts.map +1 -0
- package/es/markdown-cell-protocol.js +1 -0
- package/es/markdown-cell-view.d.ts +34 -0
- package/es/markdown-cell-view.d.ts.map +1 -0
- package/es/markdown-cell-view.js +210 -0
- package/es/markdown-preview.d.ts +7 -0
- package/es/markdown-preview.d.ts.map +1 -0
- package/es/markdown-preview.js +31 -0
- package/package.json +64 -0
- package/src/index.less +116 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +6 -0
- package/src/markdown-cell-contribution.ts +46 -0
- package/src/markdown-cell-model.ts +40 -0
- package/src/markdown-cell-module.ts +26 -0
- package/src/markdown-cell-protocol.ts +6 -0
- package/src/markdown-cell-view.tsx +175 -0
- package/src/markdown-preview.tsx +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Difizen Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# libro shared model
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './markdown-cell-contribution.js';
|
|
2
|
+
export * from './markdown-cell-model.js';
|
|
3
|
+
export * from './markdown-cell-module.js';
|
|
4
|
+
export * from './markdown-cell-protocol.js';
|
|
5
|
+
export * from './markdown-cell-view.js';
|
|
6
|
+
export * from './markdown-preview.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
|
package/es/index.js
ADDED
package/es/index.less
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
.libro-dnd-cell-container {
|
|
2
|
+
.markdown-cell-preview.libro-dnd-cell {
|
|
3
|
+
border: 1px solid transparent;
|
|
4
|
+
box-shadow: unset;
|
|
5
|
+
|
|
6
|
+
&.active.command-mode {
|
|
7
|
+
border: 1px solid rgb(55, 147, 239);
|
|
8
|
+
box-shadow: unset;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.libro-dnd-cell-preview {
|
|
12
|
+
display: block;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.libro-markdown-warpper-container {
|
|
16
|
+
.libro-markdown-preview {
|
|
17
|
+
min-height: 50px;
|
|
18
|
+
padding: 0 4px;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
|
|
21
|
+
img {
|
|
22
|
+
max-width: 100%;
|
|
23
|
+
max-height: 100%;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
a {
|
|
27
|
+
text-decoration: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
a:hover {
|
|
31
|
+
text-decoration: underline;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
a:focus,
|
|
35
|
+
input:focus,
|
|
36
|
+
select:focus,
|
|
37
|
+
textarea:focus {
|
|
38
|
+
outline: 1px solid -webkit-focus-ring-color;
|
|
39
|
+
outline-offset: -1px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
hr {
|
|
43
|
+
height: 2px;
|
|
44
|
+
border: 0;
|
|
45
|
+
border-bottom: 2px solid;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
div {
|
|
49
|
+
width: 100%;
|
|
50
|
+
min-height: 20px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Adjust margin of first item in markdown cell */
|
|
54
|
+
*:first-child {
|
|
55
|
+
margin-top: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* h1 tags don't need top margin */
|
|
59
|
+
h1:first-child {
|
|
60
|
+
margin-top: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Removes bottom margin when only one item exists in markdown cell */
|
|
64
|
+
#preview > *:only-child,
|
|
65
|
+
#preview > *:last-child {
|
|
66
|
+
margin-bottom: 0;
|
|
67
|
+
padding-bottom: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
table {
|
|
71
|
+
border-collapse: collapse;
|
|
72
|
+
border-spacing: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
table th,
|
|
76
|
+
table td {
|
|
77
|
+
border: 1px solid;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
table > thead > tr > th {
|
|
81
|
+
text-align: left;
|
|
82
|
+
border-bottom: 1px solid;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
table > thead > tr > th,
|
|
86
|
+
table > thead > tr > td,
|
|
87
|
+
table > tbody > tr > th,
|
|
88
|
+
table > tbody > tr > td {
|
|
89
|
+
padding: 5px 10px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
table > tbody > tr + tr > td {
|
|
93
|
+
border-top: 1px solid;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
blockquote {
|
|
97
|
+
margin: 0 7px 0 5px;
|
|
98
|
+
padding: 0 16px 0 10px;
|
|
99
|
+
border-left-width: 5px;
|
|
100
|
+
border-left-style: solid;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
code {
|
|
104
|
+
font-size: 1em;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pre code {
|
|
108
|
+
color: var(--mana-libro-text-default-color);
|
|
109
|
+
font-family: 12px;
|
|
110
|
+
line-height: 1.357em;
|
|
111
|
+
white-space: pre-wrap;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LanguageSpecRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import type { CellMeta, CellOptions, CellModel } from '@difizen/libro-core';
|
|
4
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
5
|
+
import { MarkdownCellModelFactory } from './markdown-cell-protocol.js';
|
|
6
|
+
import { MarkdownCellView } from './markdown-cell-view.js';
|
|
7
|
+
export declare class MarkdownCellContribution implements CellModelContribution, CellViewContribution, LanguageSpecContribution {
|
|
8
|
+
markdownCellModelFactory: MarkdownCellModelFactory;
|
|
9
|
+
cellMeta: CellMeta;
|
|
10
|
+
canHandle(options: CellOptions): number;
|
|
11
|
+
createModel(options: CellOptions): CellModel;
|
|
12
|
+
view: typeof MarkdownCellView;
|
|
13
|
+
registerLanguageSpec: (register: LanguageSpecRegistry) => void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=markdown-cell-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-cell-contribution.d.ts","sourceRoot":"","sources":["../src/markdown-cell-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGlF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qBAGa,wBACX,YAAW,qBAAqB,EAAE,oBAAoB,EAAE,wBAAwB;IAE9C,wBAAwB,EAAE,wBAAwB,CAAC;IAErF,QAAQ,EAAE,QAAQ,CAIhB;IAEF,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM;IAOvC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS;IAK5C,IAAI,0BAAoB;IAExB,oBAAoB,aAAc,oBAAoB,UAOpD;CACH"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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, _dec2, _class, _class2, _descriptor;
|
|
3
|
+
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
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); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
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
|
+
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
|
+
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.'); }
|
|
11
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
12
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
13
|
+
import { singleton, inject } from '@difizen/mana-app';
|
|
14
|
+
import { MarkdownCellModelFactory } from "./markdown-cell-protocol.js";
|
|
15
|
+
import { MarkdownCellView } from "./markdown-cell-view.js";
|
|
16
|
+
export var MarkdownCellContribution = (_dec = singleton({
|
|
17
|
+
contrib: [CellModelContribution, CellViewContribution, LanguageSpecContribution]
|
|
18
|
+
}), _dec2 = inject(MarkdownCellModelFactory), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
19
|
+
function MarkdownCellContribution() {
|
|
20
|
+
_classCallCheck(this, MarkdownCellContribution);
|
|
21
|
+
_initializerDefineProperty(this, "markdownCellModelFactory", _descriptor, this);
|
|
22
|
+
this.cellMeta = {
|
|
23
|
+
type: 'markdown',
|
|
24
|
+
name: 'Markdown',
|
|
25
|
+
order: 'c'
|
|
26
|
+
};
|
|
27
|
+
this.view = MarkdownCellView;
|
|
28
|
+
this.registerLanguageSpec = function (register) {
|
|
29
|
+
register.registerLanguageSpec({
|
|
30
|
+
name: 'Markdown',
|
|
31
|
+
language: 'markdown',
|
|
32
|
+
mime: 'text/x-markdown',
|
|
33
|
+
ext: ['.md', '.markdown', '.mkd', '.sh']
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
_createClass(MarkdownCellContribution, [{
|
|
38
|
+
key: "canHandle",
|
|
39
|
+
value: function canHandle(options) {
|
|
40
|
+
var _options$cell;
|
|
41
|
+
if ((options === null || options === void 0 || (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.cell_type) === this.cellMeta.type) {
|
|
42
|
+
return 999;
|
|
43
|
+
}
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "createModel",
|
|
48
|
+
value: function createModel(options) {
|
|
49
|
+
var model = this.markdownCellModelFactory(options);
|
|
50
|
+
return model;
|
|
51
|
+
}
|
|
52
|
+
}]);
|
|
53
|
+
return MarkdownCellContribution;
|
|
54
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "markdownCellModelFactory", [_dec2], {
|
|
55
|
+
configurable: true,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
initializer: null
|
|
59
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IMarkdownCell } from '@difizen/libro-common';
|
|
2
|
+
import type { LibroMarkdownCellModel } from '@difizen/libro-core';
|
|
3
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
4
|
+
export declare class MarkdownCellModel extends LibroCellModel implements LibroMarkdownCellModel {
|
|
5
|
+
mimeType: string;
|
|
6
|
+
constructor(options: CellOptions);
|
|
7
|
+
isEdit: boolean;
|
|
8
|
+
preview: string;
|
|
9
|
+
toJSON(): IMarkdownCell;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=markdown-cell-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-cell-model.d.ts","sourceRoot":"","sources":["../src/markdown-cell-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIlE,qBACa,iBACX,SAAQ,cACR,YAAW,sBAAsB;IAGxB,QAAQ,SAAqB;gBAEL,OAAO,EAAE,WAAW;IAWrD,MAAM,UAAS;IAGf,OAAO,SAAM;IAEJ,MAAM,IAAI,aAAa;CAQjC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
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, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3;
|
|
3
|
+
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
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); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
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
|
+
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
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
+
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); }; }
|
|
12
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
13
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
14
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
15
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
|
+
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; }
|
|
17
|
+
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.'); }
|
|
18
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
19
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
20
|
+
import { prop } from '@difizen/mana-app';
|
|
21
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
22
|
+
export var MarkdownCellModel = (_dec = transient(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function (_LibroCellModel) {
|
|
23
|
+
_inherits(MarkdownCellModel, _LibroCellModel);
|
|
24
|
+
var _super = _createSuper(MarkdownCellModel);
|
|
25
|
+
function MarkdownCellModel(options) {
|
|
26
|
+
var _options$cell, _options$cell3;
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, MarkdownCellModel);
|
|
29
|
+
_this = _super.call(this, options);
|
|
30
|
+
_initializerDefineProperty(_this, "mimeType", _descriptor, _assertThisInitialized(_this));
|
|
31
|
+
_initializerDefineProperty(_this, "isEdit", _descriptor2, _assertThisInitialized(_this));
|
|
32
|
+
_initializerDefineProperty(_this, "preview", _descriptor3, _assertThisInitialized(_this));
|
|
33
|
+
if ((_options$cell = options.cell) !== null && _options$cell !== void 0 && _options$cell.id) {
|
|
34
|
+
var _options$cell2;
|
|
35
|
+
_this.id = (_options$cell2 = options.cell) === null || _options$cell2 === void 0 ? void 0 : _options$cell2.id;
|
|
36
|
+
}
|
|
37
|
+
if ((_options$cell3 = options.cell) !== null && _options$cell3 !== void 0 && _options$cell3.source) {
|
|
38
|
+
var _options$cell4;
|
|
39
|
+
_this.value = concatMultilineString((_options$cell4 = options.cell) === null || _options$cell4 === void 0 ? void 0 : _options$cell4.source);
|
|
40
|
+
}
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
MarkdownCellModel = inject(CellOptions)(MarkdownCellModel, undefined, 0) || MarkdownCellModel;
|
|
44
|
+
_createClass(MarkdownCellModel, [{
|
|
45
|
+
key: "toJSON",
|
|
46
|
+
value: function toJSON() {
|
|
47
|
+
return {
|
|
48
|
+
id: this.id,
|
|
49
|
+
cell_type: 'markdown',
|
|
50
|
+
source: this.source,
|
|
51
|
+
metadata: this.metadata
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
return MarkdownCellModel;
|
|
56
|
+
}(LibroCellModel), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "mimeType", [_dec2], {
|
|
57
|
+
configurable: true,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
initializer: function initializer() {
|
|
61
|
+
return 'text/x-markdown';
|
|
62
|
+
}
|
|
63
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "isEdit", [_dec3], {
|
|
64
|
+
configurable: true,
|
|
65
|
+
enumerable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
initializer: function initializer() {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "preview", [_dec4], {
|
|
71
|
+
configurable: true,
|
|
72
|
+
enumerable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
initializer: function initializer() {
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-cell-module.d.ts","sourceRoot":"","sources":["../src/markdown-cell-module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,eAAO,MAAM,kBAAkB,YAgBJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import { MarkdownModule } from '@difizen/libro-markdown';
|
|
3
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
import { MarkdownCellContribution } from "./markdown-cell-contribution.js";
|
|
5
|
+
import { MarkdownCellModel } from "./markdown-cell-model.js";
|
|
6
|
+
import { MarkdownCellModelFactory } from "./markdown-cell-protocol.js";
|
|
7
|
+
import { MarkdownCellView } from "./markdown-cell-view.js";
|
|
8
|
+
export var MarkdownCellModule = ManaModule.create().register(MarkdownCellContribution, MarkdownCellView, MarkdownCellModel).register({
|
|
9
|
+
token: MarkdownCellModelFactory,
|
|
10
|
+
useFactory: function useFactory(ctx) {
|
|
11
|
+
return function (options) {
|
|
12
|
+
var child = ctx.container.createChild();
|
|
13
|
+
child.register({
|
|
14
|
+
token: CellOptions,
|
|
15
|
+
useValue: options
|
|
16
|
+
});
|
|
17
|
+
var model = child.get(MarkdownCellModel);
|
|
18
|
+
return model;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}).dependOn(MarkdownModule);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import type { MarkdownCellModel } from './markdown-cell-model.js';
|
|
3
|
+
export type MarkdownCellModelFactory = (options: CellOptions) => MarkdownCellModel;
|
|
4
|
+
export declare const MarkdownCellModelFactory: unique symbol;
|
|
5
|
+
//# sourceMappingURL=markdown-cell-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-cell-protocol.d.ts","sourceRoot":"","sources":["../src/markdown-cell-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,iBAAiB,CAAC;AACnF,eAAO,MAAM,wBAAwB,eAAqC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var MarkdownCellModelFactory = Symbol('MarkdownCellModelFactory');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" resolution-mode="require"/>
|
|
2
|
+
import type { CodeEditorViewOptions, IEditor } from '@difizen/libro-code-editor';
|
|
3
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
4
|
+
import type { CellCollapsible, CellViewOptions } from '@difizen/libro-core';
|
|
5
|
+
import { CellService, EditorStatus, LibroEditorCellView } from '@difizen/libro-core';
|
|
6
|
+
import { MarkdownParser } from '@difizen/libro-markdown';
|
|
7
|
+
import type { ViewSize } from '@difizen/mana-app';
|
|
8
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
9
|
+
import './index.less';
|
|
10
|
+
import type { MarkdownCellModel } from './markdown-cell-model.js';
|
|
11
|
+
export declare const MarkdownCell: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export declare class MarkdownCellView extends LibroEditorCellView implements CellCollapsible {
|
|
13
|
+
get wrapperCls(): "" | "markdown-cell-preview";
|
|
14
|
+
view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
|
|
15
|
+
viewManager: ViewManager;
|
|
16
|
+
editorAreaHeight: number;
|
|
17
|
+
noEditorAreaHeight: number;
|
|
18
|
+
editor: IEditor | undefined;
|
|
19
|
+
headingCollapsed: boolean;
|
|
20
|
+
collapsibleChildNumber: number;
|
|
21
|
+
editorStatus: EditorStatus;
|
|
22
|
+
get isEdit(): boolean | undefined;
|
|
23
|
+
get cellmodel(): MarkdownCellModel;
|
|
24
|
+
markdownParser: MarkdownParser;
|
|
25
|
+
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, codeEditorManager: CodeEditorManager, markdownParser: MarkdownParser);
|
|
26
|
+
onViewMount(): void;
|
|
27
|
+
onViewResize(size: ViewSize): void;
|
|
28
|
+
calcEditorAreaHeight(): number;
|
|
29
|
+
protected getEditorOption(): CodeEditorViewOptions;
|
|
30
|
+
shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
|
|
31
|
+
focus: (toEdit: boolean) => void;
|
|
32
|
+
blur: () => void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=markdown-cell-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-cell-view.d.ts","sourceRoot":"","sources":["../src/markdown-cell-view.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAGL,WAAW,EAGZ,MAAM,mBAAmB,CAAC;AAI3B,OAAO,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,eAAO,MAAM,YAAY,0FAmCxB,CAAC;AAEF,qBAEa,gBAAiB,SAAQ,mBAAoB,YAAW,eAAe;IAClF,IAAa,UAAU,iCAKtB;IACQ,IAAI,2FAAgB;IAE7B,WAAW,EAAE,WAAW,CAAC;IAGzB,gBAAgB,SAAK;IAGZ,kBAAkB,SAAK;IAExB,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAGpC,gBAAgB,UAAS;IAGzB,sBAAsB,SAAK;IAGlB,YAAY,EAAE,YAAY,CAA0B;IAE7D,IAAI,MAAM,wBAIT;IAED,IAAI,SAAS,sBAEZ;IAED,cAAc,EAAE,cAAc,CAAC;gBAGT,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EAClB,iBAAiB,EAAE,iBAAiB,EACvC,cAAc,EAAE,cAAc;IAS/C,WAAW;IAWX,YAAY,CAAC,IAAI,EAAE,QAAQ;IAMpC,oBAAoB;cAID,eAAe,IAAI,qBAAqB;IAiBlD,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAOtD,KAAK,WAAY,OAAO,UAS/B;IAEO,IAAI,aAEX;CACH"}
|
|
@@ -0,0 +1,210 @@
|
|
|
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, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
|
|
3
|
+
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
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); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
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
|
+
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
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
+
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); }; }
|
|
12
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
13
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
14
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
15
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
|
+
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; }
|
|
17
|
+
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.'); }
|
|
18
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
19
|
+
import { CellUri } from '@difizen/libro-common';
|
|
20
|
+
import { CellService, EditorStatus, LibroEditorCellView } from '@difizen/libro-core';
|
|
21
|
+
import { MarkdownParser } from '@difizen/libro-markdown';
|
|
22
|
+
import { getOrigin, prop, useInject, watch } from '@difizen/mana-app';
|
|
23
|
+
import { view, ViewInstance, ViewManager, ViewOption, ViewRender } from '@difizen/mana-app';
|
|
24
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
25
|
+
import { forwardRef, useEffect } from 'react';
|
|
26
|
+
import "./index.less";
|
|
27
|
+
import { MarkdownPreview } from "./markdown-preview.js";
|
|
28
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
|
+
export var MarkdownCell = /*#__PURE__*/forwardRef(function MarkdownCell(props, ref) {
|
|
30
|
+
var _instance$editorView3;
|
|
31
|
+
var instance = useInject(ViewInstance);
|
|
32
|
+
var isEdit = instance.isEdit;
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
var _instance$editorView;
|
|
35
|
+
if ((_instance$editorView = instance.editorView) !== null && _instance$editorView !== void 0 && _instance$editorView.editor) {
|
|
36
|
+
var _instance$editorView2;
|
|
37
|
+
instance.editor = getOrigin((_instance$editorView2 = instance.editorView) === null || _instance$editorView2 === void 0 ? void 0 : _instance$editorView2.editor);
|
|
38
|
+
}
|
|
39
|
+
}, [instance, (_instance$editorView3 = instance.editorView) === null || _instance$editorView3 === void 0 ? void 0 : _instance$editorView3.editor]);
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
if (instance.cellmodel.isEdit) {
|
|
42
|
+
instance.createEditor();
|
|
43
|
+
}
|
|
44
|
+
}, [instance, instance.cellmodel.isEdit]);
|
|
45
|
+
return /*#__PURE__*/_jsx("div", {
|
|
46
|
+
ref: ref,
|
|
47
|
+
tabIndex: 10,
|
|
48
|
+
onBlur: function onBlur(e) {
|
|
49
|
+
var _ref$current;
|
|
50
|
+
if (typeof ref !== 'function' && !(ref !== null && ref !== void 0 && (_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contains(e.relatedTarget))) {
|
|
51
|
+
instance.blur();
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
className: instance.className,
|
|
55
|
+
children: isEdit && instance.editorView ? /*#__PURE__*/_jsx(ViewRender, {
|
|
56
|
+
view: instance.editorView
|
|
57
|
+
}) : /*#__PURE__*/_jsx(MarkdownPreview, {
|
|
58
|
+
instance: instance
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
export var MarkdownCellView = (_dec = transient(), _dec2 = view('libro-markdown-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroEditorCellView) {
|
|
63
|
+
_inherits(MarkdownCellView, _LibroEditorCellView);
|
|
64
|
+
var _super = _createSuper(MarkdownCellView);
|
|
65
|
+
function MarkdownCellView(options, cellService, viewManager, codeEditorManager, markdownParser) {
|
|
66
|
+
var _this;
|
|
67
|
+
_classCallCheck(this, MarkdownCellView);
|
|
68
|
+
_this = _super.call(this, options, cellService);
|
|
69
|
+
_this.view = MarkdownCell;
|
|
70
|
+
_this.viewManager = void 0;
|
|
71
|
+
_initializerDefineProperty(_this, "editorAreaHeight", _descriptor, _assertThisInitialized(_this));
|
|
72
|
+
_initializerDefineProperty(_this, "noEditorAreaHeight", _descriptor2, _assertThisInitialized(_this));
|
|
73
|
+
_initializerDefineProperty(_this, "headingCollapsed", _descriptor3, _assertThisInitialized(_this));
|
|
74
|
+
_initializerDefineProperty(_this, "collapsibleChildNumber", _descriptor4, _assertThisInitialized(_this));
|
|
75
|
+
_initializerDefineProperty(_this, "editorStatus", _descriptor5, _assertThisInitialized(_this));
|
|
76
|
+
_this.markdownParser = void 0;
|
|
77
|
+
_this.focus = function (toEdit) {
|
|
78
|
+
if (toEdit) {
|
|
79
|
+
_this.cellmodel.isEdit = true;
|
|
80
|
+
} else {
|
|
81
|
+
var _this$container, _this$container2;
|
|
82
|
+
if ((_this$container = _this.container) !== null && _this$container !== void 0 && (_this$container = _this$container.current) !== null && _this$container !== void 0 && (_this$container = _this$container.parentElement) !== null && _this$container !== void 0 && _this$container.contains(document.activeElement)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
(_this$container2 = _this.container) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.current) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.parentElement) === null || _this$container2 === void 0 || _this$container2.focus();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
_this.blur = function () {
|
|
89
|
+
_this.cellmodel.isEdit = false;
|
|
90
|
+
};
|
|
91
|
+
_this.viewManager = viewManager;
|
|
92
|
+
_this.codeEditorManager = codeEditorManager;
|
|
93
|
+
_this.markdownParser = markdownParser;
|
|
94
|
+
_this.className = _this.className + ' markdown';
|
|
95
|
+
return _this;
|
|
96
|
+
}
|
|
97
|
+
MarkdownCellView = inject(MarkdownParser)(MarkdownCellView, undefined, 4) || MarkdownCellView;
|
|
98
|
+
MarkdownCellView = inject(CodeEditorManager)(MarkdownCellView, undefined, 3) || MarkdownCellView;
|
|
99
|
+
MarkdownCellView = inject(ViewManager)(MarkdownCellView, undefined, 2) || MarkdownCellView;
|
|
100
|
+
MarkdownCellView = inject(CellService)(MarkdownCellView, undefined, 1) || MarkdownCellView;
|
|
101
|
+
MarkdownCellView = inject(ViewOption)(MarkdownCellView, undefined, 0) || MarkdownCellView;
|
|
102
|
+
_createClass(MarkdownCellView, [{
|
|
103
|
+
key: "wrapperCls",
|
|
104
|
+
get: function get() {
|
|
105
|
+
if (!this.cellmodel.isEdit) {
|
|
106
|
+
return 'markdown-cell-preview';
|
|
107
|
+
}
|
|
108
|
+
return '';
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "isEdit",
|
|
112
|
+
get: function get() {
|
|
113
|
+
var _this$editorView;
|
|
114
|
+
return ((_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.view) && this.cellmodel.isEdit && this.parent.model.inputEditable;
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "cellmodel",
|
|
118
|
+
get: function get() {
|
|
119
|
+
return this.model;
|
|
120
|
+
}
|
|
121
|
+
}, {
|
|
122
|
+
key: "onViewMount",
|
|
123
|
+
value: function onViewMount() {
|
|
124
|
+
var _this2 = this;
|
|
125
|
+
if (this.cellmodel.isEdit) {
|
|
126
|
+
this.createEditor();
|
|
127
|
+
}
|
|
128
|
+
watch(this.parent.model, 'inputEditable', function () {
|
|
129
|
+
if (!_this2.parent.model.inputEditable) {
|
|
130
|
+
_this2.cellmodel.isEdit = false;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "onViewResize",
|
|
136
|
+
value: function onViewResize(size) {
|
|
137
|
+
if (size.height) {
|
|
138
|
+
this.editorAreaHeight = size.height;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "calcEditorAreaHeight",
|
|
143
|
+
value: function calcEditorAreaHeight() {
|
|
144
|
+
return this.editorAreaHeight;
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "getEditorOption",
|
|
148
|
+
value: function getEditorOption() {
|
|
149
|
+
var option = {
|
|
150
|
+
uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
|
|
151
|
+
model: this.model,
|
|
152
|
+
config: {
|
|
153
|
+
lineNumbers: false,
|
|
154
|
+
foldGutter: false,
|
|
155
|
+
lineWrap: 'on',
|
|
156
|
+
matchBrackets: false,
|
|
157
|
+
autoClosingBrackets: false
|
|
158
|
+
},
|
|
159
|
+
autoFocus: true
|
|
160
|
+
};
|
|
161
|
+
return option;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
165
|
+
}, {
|
|
166
|
+
key: "shouldEnterEditorMode",
|
|
167
|
+
value: function shouldEnterEditorMode(e) {
|
|
168
|
+
if (!this.cellmodel.isEdit) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
}]);
|
|
174
|
+
return MarkdownCellView;
|
|
175
|
+
}(LibroEditorCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "editorAreaHeight", [_dec3], {
|
|
176
|
+
configurable: true,
|
|
177
|
+
enumerable: true,
|
|
178
|
+
writable: true,
|
|
179
|
+
initializer: function initializer() {
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "noEditorAreaHeight", [_dec4], {
|
|
183
|
+
configurable: true,
|
|
184
|
+
enumerable: true,
|
|
185
|
+
writable: true,
|
|
186
|
+
initializer: function initializer() {
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "headingCollapsed", [_dec5], {
|
|
190
|
+
configurable: true,
|
|
191
|
+
enumerable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
initializer: function initializer() {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "collapsibleChildNumber", [_dec6], {
|
|
197
|
+
configurable: true,
|
|
198
|
+
enumerable: true,
|
|
199
|
+
writable: true,
|
|
200
|
+
initializer: function initializer() {
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "editorStatus", [_dec7], {
|
|
204
|
+
configurable: true,
|
|
205
|
+
enumerable: true,
|
|
206
|
+
writable: true,
|
|
207
|
+
initializer: function initializer() {
|
|
208
|
+
return EditorStatus.NOTLOADED;
|
|
209
|
+
}
|
|
210
|
+
})), _class2)) || _class) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-preview.d.ts","sourceRoot":"","sources":["../src/markdown-preview.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,eAAO,MAAM,eAAe,EAAE,EAAE,CAAC;IAAE,QAAQ,EAAE,gBAAgB,CAAA;CAAE,CA4B9D,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import "./index.less";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export var MarkdownPreview = function MarkdownPreview(_ref) {
|
|
5
|
+
var instance = _ref.instance;
|
|
6
|
+
var mktRef = useRef(null);
|
|
7
|
+
// const instance = useInject<MarkdownCellView>(ViewInstance);
|
|
8
|
+
|
|
9
|
+
var enterEdit = useCallback(function (e) {
|
|
10
|
+
if (!instance.parent.model.inputEditable) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
e.preventDefault();
|
|
14
|
+
instance.focus(true);
|
|
15
|
+
}, [instance]);
|
|
16
|
+
useEffect(function () {
|
|
17
|
+
if (mktRef.current) {
|
|
18
|
+
mktRef.current.innerHTML = instance.markdownParser.render(instance.model.value, {
|
|
19
|
+
cellId: instance.model.id
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}, [instance, instance.model.value]);
|
|
23
|
+
return /*#__PURE__*/_jsx("div", {
|
|
24
|
+
className: "libro-markdown-warpper-container",
|
|
25
|
+
onDoubleClick: enterEdit,
|
|
26
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
27
|
+
className: "libro-markdown-preview",
|
|
28
|
+
ref: mktRef
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-markdown-cell",
|
|
3
|
+
"version": "0.0.0-snapshot-20241017072317",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro",
|
|
7
|
+
"notebook",
|
|
8
|
+
"toc"
|
|
9
|
+
],
|
|
10
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"typings": "./es/index.d.ts",
|
|
16
|
+
"default": "./es/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./mock": {
|
|
19
|
+
"typings": "./es/mock/index.d.ts",
|
|
20
|
+
"default": "./es/mock/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./es/mock": {
|
|
23
|
+
"typings": "./es/mock/index.d.ts",
|
|
24
|
+
"default": "./es/mock/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"main": "es/index.js",
|
|
29
|
+
"module": "es/index.js",
|
|
30
|
+
"typings": "es/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"es",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=16"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^18.2.25"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@difizen/libro-core": "0.0.0-snapshot-20241017072317",
|
|
43
|
+
"@difizen/libro-common": "0.0.0-snapshot-20241017072317",
|
|
44
|
+
"@difizen/libro-code-editor": "0.0.0-snapshot-20241017072317",
|
|
45
|
+
"@difizen/libro-markdown": "0.0.0-snapshot-20241017072317",
|
|
46
|
+
"@difizen/mana-app": "latest",
|
|
47
|
+
"@types/markdown-it": "^12.2.3",
|
|
48
|
+
"markdown-it": "^13.0.1",
|
|
49
|
+
"markdown-it-anchor": "^8.6.5"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"setup": "father build",
|
|
53
|
+
"build": "father build",
|
|
54
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
55
|
+
"test:vitest": "vitest run",
|
|
56
|
+
"test:jest": "jest",
|
|
57
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
58
|
+
"coverage:vitest": "vitest run --coverage",
|
|
59
|
+
"coverage:jest": "jest --coverage",
|
|
60
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
61
|
+
"lint:eslint": "eslint src",
|
|
62
|
+
"typecheck:tsc": "tsc --noEmit"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/index.less
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
.libro-dnd-cell-container {
|
|
2
|
+
.markdown-cell-preview.libro-dnd-cell {
|
|
3
|
+
border: 1px solid transparent;
|
|
4
|
+
box-shadow: unset;
|
|
5
|
+
|
|
6
|
+
&.active.command-mode {
|
|
7
|
+
border: 1px solid rgb(55, 147, 239);
|
|
8
|
+
box-shadow: unset;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.libro-dnd-cell-preview {
|
|
12
|
+
display: block;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.libro-markdown-warpper-container {
|
|
16
|
+
.libro-markdown-preview {
|
|
17
|
+
min-height: 50px;
|
|
18
|
+
padding: 0 4px;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
|
|
21
|
+
img {
|
|
22
|
+
max-width: 100%;
|
|
23
|
+
max-height: 100%;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
a {
|
|
27
|
+
text-decoration: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
a:hover {
|
|
31
|
+
text-decoration: underline;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
a:focus,
|
|
35
|
+
input:focus,
|
|
36
|
+
select:focus,
|
|
37
|
+
textarea:focus {
|
|
38
|
+
outline: 1px solid -webkit-focus-ring-color;
|
|
39
|
+
outline-offset: -1px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
hr {
|
|
43
|
+
height: 2px;
|
|
44
|
+
border: 0;
|
|
45
|
+
border-bottom: 2px solid;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
div {
|
|
49
|
+
width: 100%;
|
|
50
|
+
min-height: 20px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Adjust margin of first item in markdown cell */
|
|
54
|
+
*:first-child {
|
|
55
|
+
margin-top: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* h1 tags don't need top margin */
|
|
59
|
+
h1:first-child {
|
|
60
|
+
margin-top: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Removes bottom margin when only one item exists in markdown cell */
|
|
64
|
+
#preview > *:only-child,
|
|
65
|
+
#preview > *:last-child {
|
|
66
|
+
margin-bottom: 0;
|
|
67
|
+
padding-bottom: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
table {
|
|
71
|
+
border-collapse: collapse;
|
|
72
|
+
border-spacing: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
table th,
|
|
76
|
+
table td {
|
|
77
|
+
border: 1px solid;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
table > thead > tr > th {
|
|
81
|
+
text-align: left;
|
|
82
|
+
border-bottom: 1px solid;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
table > thead > tr > th,
|
|
86
|
+
table > thead > tr > td,
|
|
87
|
+
table > tbody > tr > th,
|
|
88
|
+
table > tbody > tr > td {
|
|
89
|
+
padding: 5px 10px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
table > tbody > tr + tr > td {
|
|
93
|
+
border-top: 1px solid;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
blockquote {
|
|
97
|
+
margin: 0 7px 0 5px;
|
|
98
|
+
padding: 0 16px 0 10px;
|
|
99
|
+
border-left-width: 5px;
|
|
100
|
+
border-left-style: solid;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
code {
|
|
104
|
+
font-size: 1em;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pre code {
|
|
108
|
+
color: var(--mana-libro-text-default-color);
|
|
109
|
+
font-family: 12px;
|
|
110
|
+
line-height: 1.357em;
|
|
111
|
+
white-space: pre-wrap;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LanguageSpecRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { LanguageSpecContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import type { CellMeta, CellOptions, CellModel } from '@difizen/libro-core';
|
|
4
|
+
import { CellModelContribution, CellViewContribution } from '@difizen/libro-core';
|
|
5
|
+
import { singleton, inject } from '@difizen/mana-app';
|
|
6
|
+
|
|
7
|
+
import { MarkdownCellModelFactory } from './markdown-cell-protocol.js';
|
|
8
|
+
import { MarkdownCellView } from './markdown-cell-view.js';
|
|
9
|
+
|
|
10
|
+
@singleton({
|
|
11
|
+
contrib: [CellModelContribution, CellViewContribution, LanguageSpecContribution],
|
|
12
|
+
})
|
|
13
|
+
export class MarkdownCellContribution
|
|
14
|
+
implements CellModelContribution, CellViewContribution, LanguageSpecContribution
|
|
15
|
+
{
|
|
16
|
+
@inject(MarkdownCellModelFactory) markdownCellModelFactory: MarkdownCellModelFactory;
|
|
17
|
+
|
|
18
|
+
cellMeta: CellMeta = {
|
|
19
|
+
type: 'markdown',
|
|
20
|
+
name: 'Markdown',
|
|
21
|
+
order: 'c',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
canHandle(options: CellOptions): number {
|
|
25
|
+
if (options?.cell?.cell_type === this.cellMeta.type) {
|
|
26
|
+
return 999;
|
|
27
|
+
}
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
createModel(options: CellOptions): CellModel {
|
|
32
|
+
const model = this.markdownCellModelFactory(options);
|
|
33
|
+
return model;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
view = MarkdownCellView;
|
|
37
|
+
|
|
38
|
+
registerLanguageSpec = (register: LanguageSpecRegistry) => {
|
|
39
|
+
register.registerLanguageSpec({
|
|
40
|
+
name: 'Markdown',
|
|
41
|
+
language: 'markdown',
|
|
42
|
+
mime: 'text/x-markdown',
|
|
43
|
+
ext: ['.md', '.markdown', '.mkd', '.sh'],
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IMarkdownCell } from '@difizen/libro-common';
|
|
2
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
3
|
+
import type { LibroMarkdownCellModel } from '@difizen/libro-core';
|
|
4
|
+
import { CellOptions, LibroCellModel } from '@difizen/libro-core';
|
|
5
|
+
import { prop } from '@difizen/mana-app';
|
|
6
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
7
|
+
|
|
8
|
+
@transient()
|
|
9
|
+
export class MarkdownCellModel
|
|
10
|
+
extends LibroCellModel
|
|
11
|
+
implements LibroMarkdownCellModel
|
|
12
|
+
{
|
|
13
|
+
@prop()
|
|
14
|
+
override mimeType = 'text/x-markdown';
|
|
15
|
+
|
|
16
|
+
constructor(@inject(CellOptions) options: CellOptions) {
|
|
17
|
+
super(options);
|
|
18
|
+
if (options.cell?.id) {
|
|
19
|
+
this.id = options.cell?.id as string;
|
|
20
|
+
}
|
|
21
|
+
if (options.cell?.source) {
|
|
22
|
+
this.value = concatMultilineString(options.cell?.source);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@prop()
|
|
27
|
+
isEdit = false;
|
|
28
|
+
|
|
29
|
+
@prop()
|
|
30
|
+
preview = '';
|
|
31
|
+
|
|
32
|
+
override toJSON(): IMarkdownCell {
|
|
33
|
+
return {
|
|
34
|
+
id: this.id,
|
|
35
|
+
cell_type: 'markdown',
|
|
36
|
+
source: this.source,
|
|
37
|
+
metadata: this.metadata,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
import { MarkdownModule } from '@difizen/libro-markdown';
|
|
3
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import { MarkdownCellContribution } from './markdown-cell-contribution.js';
|
|
6
|
+
import { MarkdownCellModel } from './markdown-cell-model.js';
|
|
7
|
+
import { MarkdownCellModelFactory } from './markdown-cell-protocol.js';
|
|
8
|
+
import { MarkdownCellView } from './markdown-cell-view.js';
|
|
9
|
+
|
|
10
|
+
export const MarkdownCellModule = ManaModule.create()
|
|
11
|
+
.register(MarkdownCellContribution, MarkdownCellView, MarkdownCellModel)
|
|
12
|
+
.register({
|
|
13
|
+
token: MarkdownCellModelFactory,
|
|
14
|
+
useFactory: (ctx) => {
|
|
15
|
+
return (options: CellOptions) => {
|
|
16
|
+
const child = ctx.container.createChild();
|
|
17
|
+
child.register({
|
|
18
|
+
token: CellOptions,
|
|
19
|
+
useValue: options,
|
|
20
|
+
});
|
|
21
|
+
const model = child.get(MarkdownCellModel);
|
|
22
|
+
return model;
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
.dependOn(MarkdownModule);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CellOptions } from '@difizen/libro-core';
|
|
2
|
+
|
|
3
|
+
import type { MarkdownCellModel } from './markdown-cell-model.js';
|
|
4
|
+
|
|
5
|
+
export type MarkdownCellModelFactory = (options: CellOptions) => MarkdownCellModel;
|
|
6
|
+
export const MarkdownCellModelFactory = Symbol('MarkdownCellModelFactory');
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { CodeEditorViewOptions, IEditor } from '@difizen/libro-code-editor';
|
|
2
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
3
|
+
import { CellUri } from '@difizen/libro-common';
|
|
4
|
+
import type { CellCollapsible, CellViewOptions } from '@difizen/libro-core';
|
|
5
|
+
import { CellService, EditorStatus, LibroEditorCellView } from '@difizen/libro-core';
|
|
6
|
+
import { MarkdownParser } from '@difizen/libro-markdown';
|
|
7
|
+
import type { ViewSize } from '@difizen/mana-app';
|
|
8
|
+
import { getOrigin, prop, useInject, watch } from '@difizen/mana-app';
|
|
9
|
+
import {
|
|
10
|
+
view,
|
|
11
|
+
ViewInstance,
|
|
12
|
+
ViewManager,
|
|
13
|
+
ViewOption,
|
|
14
|
+
ViewRender,
|
|
15
|
+
} from '@difizen/mana-app';
|
|
16
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
17
|
+
import { forwardRef, useEffect } from 'react';
|
|
18
|
+
|
|
19
|
+
import './index.less';
|
|
20
|
+
import type { MarkdownCellModel } from './markdown-cell-model.js';
|
|
21
|
+
import { MarkdownPreview } from './markdown-preview.js';
|
|
22
|
+
|
|
23
|
+
export const MarkdownCell = forwardRef<HTMLDivElement>(
|
|
24
|
+
function MarkdownCell(props, ref) {
|
|
25
|
+
const instance = useInject<MarkdownCellView>(ViewInstance);
|
|
26
|
+
const isEdit = instance.isEdit;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (instance.editorView?.editor) {
|
|
29
|
+
instance.editor = getOrigin(instance.editorView?.editor);
|
|
30
|
+
}
|
|
31
|
+
}, [instance, instance.editorView?.editor]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (instance.cellmodel.isEdit) {
|
|
35
|
+
instance.createEditor();
|
|
36
|
+
}
|
|
37
|
+
}, [instance, instance.cellmodel.isEdit]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div
|
|
41
|
+
ref={ref}
|
|
42
|
+
tabIndex={10}
|
|
43
|
+
onBlur={(e) => {
|
|
44
|
+
if (typeof ref !== 'function' && !ref?.current?.contains(e.relatedTarget)) {
|
|
45
|
+
instance.blur();
|
|
46
|
+
}
|
|
47
|
+
}}
|
|
48
|
+
className={instance.className}
|
|
49
|
+
>
|
|
50
|
+
{isEdit && instance.editorView ? (
|
|
51
|
+
<ViewRender view={instance.editorView} />
|
|
52
|
+
) : (
|
|
53
|
+
<MarkdownPreview instance={instance} />
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
@transient()
|
|
61
|
+
@view('libro-markdown-cell-view')
|
|
62
|
+
export class MarkdownCellView extends LibroEditorCellView implements CellCollapsible {
|
|
63
|
+
override get wrapperCls() {
|
|
64
|
+
if (!this.cellmodel.isEdit) {
|
|
65
|
+
return 'markdown-cell-preview';
|
|
66
|
+
}
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
override view = MarkdownCell;
|
|
70
|
+
|
|
71
|
+
viewManager: ViewManager;
|
|
72
|
+
|
|
73
|
+
@prop()
|
|
74
|
+
editorAreaHeight = 0;
|
|
75
|
+
|
|
76
|
+
@prop()
|
|
77
|
+
override noEditorAreaHeight = 0;
|
|
78
|
+
|
|
79
|
+
declare editor: IEditor | undefined;
|
|
80
|
+
|
|
81
|
+
@prop()
|
|
82
|
+
headingCollapsed = false;
|
|
83
|
+
|
|
84
|
+
@prop()
|
|
85
|
+
collapsibleChildNumber = 0;
|
|
86
|
+
|
|
87
|
+
@prop()
|
|
88
|
+
override editorStatus: EditorStatus = EditorStatus.NOTLOADED;
|
|
89
|
+
|
|
90
|
+
get isEdit() {
|
|
91
|
+
return (
|
|
92
|
+
this.editorView?.view && this.cellmodel.isEdit && this.parent.model.inputEditable
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get cellmodel() {
|
|
97
|
+
return this.model as MarkdownCellModel;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
markdownParser: MarkdownParser;
|
|
101
|
+
|
|
102
|
+
constructor(
|
|
103
|
+
@inject(ViewOption) options: CellViewOptions,
|
|
104
|
+
@inject(CellService) cellService: CellService,
|
|
105
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
106
|
+
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
|
|
107
|
+
@inject(MarkdownParser) markdownParser: MarkdownParser,
|
|
108
|
+
) {
|
|
109
|
+
super(options, cellService);
|
|
110
|
+
this.viewManager = viewManager;
|
|
111
|
+
this.codeEditorManager = codeEditorManager;
|
|
112
|
+
this.markdownParser = markdownParser;
|
|
113
|
+
this.className = this.className + ' markdown';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override onViewMount() {
|
|
117
|
+
if (this.cellmodel.isEdit) {
|
|
118
|
+
this.createEditor();
|
|
119
|
+
}
|
|
120
|
+
watch(this.parent.model, 'inputEditable', () => {
|
|
121
|
+
if (!this.parent.model.inputEditable) {
|
|
122
|
+
this.cellmodel.isEdit = false;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
override onViewResize(size: ViewSize) {
|
|
128
|
+
if (size.height) {
|
|
129
|
+
this.editorAreaHeight = size.height;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
calcEditorAreaHeight() {
|
|
134
|
+
return this.editorAreaHeight;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
protected override getEditorOption(): CodeEditorViewOptions {
|
|
138
|
+
const option: CodeEditorViewOptions = {
|
|
139
|
+
uuid: CellUri.from(this.parent.model.id, this.model.id).toString(),
|
|
140
|
+
model: this.model,
|
|
141
|
+
config: {
|
|
142
|
+
lineNumbers: false,
|
|
143
|
+
foldGutter: false,
|
|
144
|
+
lineWrap: 'on',
|
|
145
|
+
matchBrackets: false,
|
|
146
|
+
autoClosingBrackets: false,
|
|
147
|
+
},
|
|
148
|
+
autoFocus: true,
|
|
149
|
+
};
|
|
150
|
+
return option;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
154
|
+
override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
|
|
155
|
+
if (!this.cellmodel.isEdit) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
override focus = (toEdit: boolean) => {
|
|
162
|
+
if (toEdit) {
|
|
163
|
+
this.cellmodel.isEdit = true;
|
|
164
|
+
} else {
|
|
165
|
+
if (this.container?.current?.parentElement?.contains(document.activeElement)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.container?.current?.parentElement?.focus();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
override blur = () => {
|
|
173
|
+
this.cellmodel.isEdit = false;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import './index.less';
|
|
5
|
+
import type { MarkdownCellView } from './markdown-cell-view.js';
|
|
6
|
+
|
|
7
|
+
export const MarkdownPreview: FC<{ instance: MarkdownCellView }> = ({ instance }) => {
|
|
8
|
+
const mktRef = useRef<HTMLDivElement>(null);
|
|
9
|
+
// const instance = useInject<MarkdownCellView>(ViewInstance);
|
|
10
|
+
|
|
11
|
+
const enterEdit: React.MouseEventHandler<HTMLDivElement> = useCallback(
|
|
12
|
+
(e) => {
|
|
13
|
+
if (!instance.parent.model.inputEditable) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
instance.focus(true);
|
|
18
|
+
},
|
|
19
|
+
[instance],
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (mktRef.current) {
|
|
24
|
+
mktRef.current.innerHTML = instance.markdownParser.render(instance.model.value, {
|
|
25
|
+
cellId: instance.model.id,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, [instance, instance.model.value]);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className="libro-markdown-warpper-container" onDoubleClick={enterEdit}>
|
|
32
|
+
<div className="libro-markdown-preview" ref={mktRef} />
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
};
|