@medway-ui/native 1.2.0 → 1.3.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/lib/commonjs/editor/NoteEditor.js +710 -0
- package/lib/commonjs/editor/NoteEditor.js.map +1 -0
- package/lib/commonjs/editor/editorHtml.generated.js +21 -0
- package/lib/commonjs/editor/editorHtml.generated.js.map +1 -0
- package/lib/commonjs/editor/index.js +33 -0
- package/lib/commonjs/editor/index.js.map +1 -0
- package/lib/commonjs/editor/protocol.js +88 -0
- package/lib/commonjs/editor/protocol.js.map +1 -0
- package/lib/module/editor/NoteEditor.js +705 -0
- package/lib/module/editor/NoteEditor.js.map +1 -0
- package/lib/module/editor/editorHtml.generated.js +17 -0
- package/lib/module/editor/editorHtml.generated.js.map +1 -0
- package/lib/module/editor/index.js +5 -0
- package/lib/module/editor/index.js.map +1 -0
- package/lib/module/editor/protocol.js +83 -0
- package/lib/module/editor/protocol.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/editor/NoteEditor.d.ts +82 -0
- package/lib/typescript/editor/NoteEditor.d.ts.map +1 -0
- package/lib/typescript/editor/editorHtml.generated.d.ts +13 -0
- package/lib/typescript/editor/editorHtml.generated.d.ts.map +1 -0
- package/lib/typescript/editor/index.d.ts +6 -0
- package/lib/typescript/editor/index.d.ts.map +1 -0
- package/lib/typescript/editor/protocol.d.ts +153 -0
- package/lib/typescript/editor/protocol.d.ts.map +1 -0
- package/package.json +24 -1
- package/setup/metro.js +27 -5
- package/src/editor/NoteEditor.tsx +802 -0
- package/src/editor/editorHtml.generated.ts +14 -0
- package/src/editor/index.ts +13 -0
- package/src/editor/protocol.ts +184 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EDITOR_HTML","exports"],"sourceRoot":"../../../src","sources":["editor/editorHtml.generated.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,WAAmB,GAAAC,OAAA,CAAAD,WAAA,GAAG,i5haAAi5ha","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "EDITOR_PROTOCOL_VERSION", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _protocol.EDITOR_PROTOCOL_VERSION;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "EDITOR_RECEIVE_HANDLER", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _protocol.EDITOR_RECEIVE_HANDLER;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "NoteEditor", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _NoteEditor.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "isEditorMessage", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _protocol.isEditorMessage;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _NoteEditor = _interopRequireDefault(require("./NoteEditor.js"));
|
|
31
|
+
var _protocol = require("./protocol.js");
|
|
32
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_NoteEditor","_interopRequireDefault","require","_protocol","e","__esModule","default"],"sourceRoot":"../../../src","sources":["editor/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AAIoB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isEditorMessage = exports.EDITOR_RECEIVE_HANDLER = exports.EDITOR_PROTOCOL_VERSION = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Transport between React Native and the Tiptap editor inside the WebView. Both
|
|
9
|
+
* sides compile against this file — the bundle imports it through the `@/`
|
|
10
|
+
* alias in `editor-bundle/vite.config.ts`.
|
|
11
|
+
*
|
|
12
|
+
* Invariants:
|
|
13
|
+
* - The document never crosses the bridge on keystrokes: the editor emits
|
|
14
|
+
* `change` with a revision counter, and the native side asks with
|
|
15
|
+
* `getDocument`.
|
|
16
|
+
* - Every message is validated on arrival (`isEditorMessage`: envelope plus the
|
|
17
|
+
* required fields of its variant) — the WebView renders student content, so
|
|
18
|
+
* its output is untrusted input. Documents get a second pass through
|
|
19
|
+
* `normalizeDocument` before reaching the host.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bumped whenever the message shapes below change. The native side refuses to
|
|
24
|
+
* talk to a bundle that reports a different version, which turns a stale
|
|
25
|
+
* `editorHtml.generated.ts` into a clear error instead of silent breakage.
|
|
26
|
+
*/
|
|
27
|
+
const EDITOR_PROTOCOL_VERSION = exports.EDITOR_PROTOCOL_VERSION = 3;
|
|
28
|
+
|
|
29
|
+
/** Name of the global the WebView bundle installs to receive native messages. */
|
|
30
|
+
const EDITOR_RECEIVE_HANDLER = exports.EDITOR_RECEIVE_HANDLER = '__medwayNoteEditorReceive';
|
|
31
|
+
const isRecord = value => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
32
|
+
const isString = value => typeof value === 'string';
|
|
33
|
+
|
|
34
|
+
/** Rejects `NaN` and the infinities, which `JSON.parse` can still produce. */
|
|
35
|
+
const isFiniteNumber = value => typeof value === 'number' && Number.isFinite(value);
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* `Record<Union, …>` rather than an array so it is exhaustive: adding a variant
|
|
39
|
+
* to `EditorToNativeMessage` without listing it here stops compiling, instead
|
|
40
|
+
* of letting `isEditorMessage` reject the new type at runtime — which would
|
|
41
|
+
* look like the message never arrived, not like a build error.
|
|
42
|
+
*
|
|
43
|
+
* Each entry checks the fields its own variant declares, so narrowing to the
|
|
44
|
+
* union is backed by the payload and not by `type` alone: a `document` without
|
|
45
|
+
* `doc`/`requestId`, or a `ready` without `protocol`, is rejected here instead
|
|
46
|
+
* of blowing up at the use site.
|
|
47
|
+
*
|
|
48
|
+
* `state`, `slash` and `doc` are checked as objects rather than field by field:
|
|
49
|
+
* their shapes belong to `@medway-ui/notes-core` and are validated there — for
|
|
50
|
+
* `doc`, by the `normalizeDocument` pass the native side runs before handing a
|
|
51
|
+
* document to the host.
|
|
52
|
+
*/
|
|
53
|
+
const EDITOR_MESSAGE_VALIDATORS = {
|
|
54
|
+
ready: message => isFiniteNumber(message.protocol),
|
|
55
|
+
state: message => isRecord(message.state),
|
|
56
|
+
change: message => isFiniteNumber(message.revision),
|
|
57
|
+
document: message => isString(message.requestId) && isFiniteNumber(message.revision) && isRecord(message.doc),
|
|
58
|
+
slash: message => isRecord(message.slash),
|
|
59
|
+
resize: message => isFiniteNumber(message.height),
|
|
60
|
+
linkPress: message => isString(message.href),
|
|
61
|
+
backspaceAtDocStart: () => true,
|
|
62
|
+
imageRemoved: message => isString(message.src),
|
|
63
|
+
error: message => isString(message.message)
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Guard for anything arriving from the WebView: checks the envelope *and* the
|
|
68
|
+
* required fields of the variant its `type` names. Establishes the shape, not
|
|
69
|
+
* the contents — a `document` payload's `doc` still goes through
|
|
70
|
+
* `normalizeDocument` before the native side hands it to the host.
|
|
71
|
+
*/
|
|
72
|
+
const isEditorMessage = value => {
|
|
73
|
+
if (!isRecord(value)) return false;
|
|
74
|
+
const {
|
|
75
|
+
type
|
|
76
|
+
} = value;
|
|
77
|
+
if (typeof type !== 'string') return false;
|
|
78
|
+
|
|
79
|
+
// `hasOwnProperty`, not `in`: `in` walks the prototype chain, so a `type` of
|
|
80
|
+
// `"toString"` or `"constructor"` matches any plain object literal.
|
|
81
|
+
// `Object.hasOwn` would read better but is ES2022 and `lib` here is ES2020.
|
|
82
|
+
if (!Object.prototype.hasOwnProperty.call(EDITOR_MESSAGE_VALIDATORS, type)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return EDITOR_MESSAGE_VALIDATORS[type](value);
|
|
86
|
+
};
|
|
87
|
+
exports.isEditorMessage = isEditorMessage;
|
|
88
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EDITOR_PROTOCOL_VERSION","exports","EDITOR_RECEIVE_HANDLER","isRecord","value","Array","isArray","isString","isFiniteNumber","Number","isFinite","EDITOR_MESSAGE_VALIDATORS","ready","message","protocol","state","change","revision","document","requestId","doc","slash","resize","height","linkPress","href","backspaceAtDocStart","imageRemoved","src","error","isEditorMessage","type","Object","prototype","hasOwnProperty","call"],"sourceRoot":"../../../src","sources":["editor/protocol.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,CAAC;;AAExC;AACO,MAAME,sBAAsB,GAAAD,OAAA,CAAAC,sBAAA,GAAG,2BAA2B;AAmFjE,MAAMC,QAAQ,GAAIC,KAAc,IAC9B,OAAOA,KAAK,KAAK,QAAQ,IAAI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