@difizen/libro-shared-model 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/api.d.ts +639 -0
- package/es/api.d.ts.map +1 -0
- package/es/api.js +91 -0
- package/es/index.d.ts +4 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +3 -0
- package/es/utils.d.ts +18 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +41 -0
- package/es/ymodels.d.ts +656 -0
- package/es/ymodels.d.ts.map +1 -0
- package/es/ymodels.js +1778 -0
- package/package.json +57 -0
- package/src/api.ts +743 -0
- package/src/index.ts +3 -0
- package/src/utils.ts +46 -0
- package/src/ymodels.ts +1603 -0
package/es/api.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file defines the shared shared-models types.
|
|
3
|
+
*
|
|
4
|
+
* - Notebook Type.
|
|
5
|
+
* - Notebook Metadata Types.
|
|
6
|
+
* - Cell Types.
|
|
7
|
+
* - Cell Metadata Types.
|
|
8
|
+
*
|
|
9
|
+
* It also defines the shared changes to be used in the events.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Changes on Sequence-like data are expressed as Quill-inspired deltas.
|
|
13
|
+
*
|
|
14
|
+
* @source https://quilljs.com/docs/delta/
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ISharedBase defines common operations that can be performed on any shared object.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Implement an API for Context information on the shared information.
|
|
21
|
+
* This is used by, for example, docregistry to share the file-path of the edited content.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The ISharedText interface defines models that can be bound to a text editor like CodeMirror.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Text/Markdown/Code files are represented as ISharedFile
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Implements an API for INotebookContent
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Definition of the map changes for yjs.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* 类型转换器:将libro的cell type(string) 转换为 'code' | 'markdown' | 'raw' 三种之一
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* The namespace for `ISharedNotebook` class statics.
|
|
40
|
+
*/
|
|
41
|
+
export var ISharedNotebook;
|
|
42
|
+
/** Cell Types. */
|
|
43
|
+
/**
|
|
44
|
+
* Shared cell namespace
|
|
45
|
+
*/
|
|
46
|
+
export var SharedCell;
|
|
47
|
+
/**
|
|
48
|
+
* Implements an API for IBaseCell.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Implements an API for ICodeCell.
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Cell with attachment interface.
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Implements an API for IMarkdownCell.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Implements an API for IRawCell.
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Implements an API for IUnrecognizedCell.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Generic document change
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* The change types which occur on a list.
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* The changed object which is emitted by a list.
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* The change types which occur on an observable map.
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* The changed args object which is emitted by an observable map.
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* Text source change
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* Definition of the shared Notebook changes.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* File change
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Definition of the shared Cell changes.
|
|
91
|
+
*/
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
package/es/index.js
ADDED
package/es/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as Y from 'yjs';
|
|
2
|
+
import type * as models from './api.js';
|
|
3
|
+
export declare function convertYMapEventToMapChange(yMapEvent: Y.YMapEvent<any>): models.MapChange;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a mutual exclude function with the following property:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* const mutex = createMutex()
|
|
9
|
+
* mutex(() => {
|
|
10
|
+
* // This function is immediately executed
|
|
11
|
+
* mutex(() => {
|
|
12
|
+
* // This function is not executed, as the mutex is already active.
|
|
13
|
+
* })
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const createMutex: () => (f: () => void) => void;
|
|
18
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAE9B,OAAO,KAAK,KAAK,MAAM,MAAM,UAAU,CAAC;AAExC,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAC1B,MAAM,CAAC,SAAS,CAYlB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,YAAY,MAAM,IAAI,KAAK,IAYlD,CAAC"}
|
package/es/utils.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function convertYMapEventToMapChange(yMapEvent) {
|
|
2
|
+
var _this = this;
|
|
3
|
+
var changes = new Map();
|
|
4
|
+
yMapEvent.changes.keys.forEach(function (event, key) {
|
|
5
|
+
changes.set(key, {
|
|
6
|
+
action: event.action,
|
|
7
|
+
oldValue: event.oldValue,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
newValue: _this.ymeta.get(key)
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return changes;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a mutual exclude function with the following property:
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* const mutex = createMutex()
|
|
21
|
+
* mutex(() => {
|
|
22
|
+
* // This function is immediately executed
|
|
23
|
+
* mutex(() => {
|
|
24
|
+
* // This function is not executed, as the mutex is already active.
|
|
25
|
+
* })
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export var createMutex = function createMutex() {
|
|
30
|
+
var token = true;
|
|
31
|
+
return function (f) {
|
|
32
|
+
if (token) {
|
|
33
|
+
token = false;
|
|
34
|
+
try {
|
|
35
|
+
f();
|
|
36
|
+
} finally {
|
|
37
|
+
token = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|