@kerebron/extension-odt 0.0.8

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 (49) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +57 -0
  3. package/esm/editor/src/CoreEditor.d.ts +28 -0
  4. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  5. package/esm/editor/src/CoreEditor.js +170 -0
  6. package/esm/editor/src/Extension.d.ts +26 -0
  7. package/esm/editor/src/Extension.d.ts.map +1 -0
  8. package/esm/editor/src/Extension.js +33 -0
  9. package/esm/editor/src/ExtensionManager.d.ts +32 -0
  10. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  11. package/esm/editor/src/ExtensionManager.js +253 -0
  12. package/esm/editor/src/Mark.d.ts +18 -0
  13. package/esm/editor/src/Mark.d.ts.map +1 -0
  14. package/esm/editor/src/Mark.js +34 -0
  15. package/esm/editor/src/Node.d.ts +27 -0
  16. package/esm/editor/src/Node.d.ts.map +1 -0
  17. package/esm/editor/src/Node.js +43 -0
  18. package/esm/editor/src/commands/CommandManager.d.ts +20 -0
  19. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  20. package/esm/editor/src/commands/CommandManager.js +60 -0
  21. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  22. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  23. package/esm/editor/src/commands/createChainableState.js +29 -0
  24. package/esm/editor/src/commands/mod.d.ts +49 -0
  25. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  26. package/esm/editor/src/commands/mod.js +928 -0
  27. package/esm/editor/src/mod.d.ts +5 -0
  28. package/esm/editor/src/mod.d.ts.map +1 -0
  29. package/esm/editor/src/mod.js +4 -0
  30. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  31. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  32. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  33. package/esm/editor/src/types.d.ts +29 -0
  34. package/esm/editor/src/types.d.ts.map +1 -0
  35. package/esm/editor/src/types.js +1 -0
  36. package/esm/editor/src/utilities/createNodeFromContent.d.ts +12 -0
  37. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  38. package/esm/editor/src/utilities/createNodeFromContent.js +118 -0
  39. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +4 -0
  40. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  41. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  42. package/esm/extension-odt/src/ExtensionOdt.d.ts +7 -0
  43. package/esm/extension-odt/src/ExtensionOdt.d.ts.map +1 -0
  44. package/esm/extension-odt/src/ExtensionOdt.js +32 -0
  45. package/esm/extension-odt/src/OdtParser.d.ts +23 -0
  46. package/esm/extension-odt/src/OdtParser.d.ts.map +1 -0
  47. package/esm/extension-odt/src/OdtParser.js +315 -0
  48. package/esm/package.json +3 -0
  49. package/package.json +23 -0
@@ -0,0 +1,5 @@
1
+ export * from './CoreEditor.js';
2
+ export * from './Extension.js';
3
+ export * from './Mark.js';
4
+ export * from './Node.js';
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/editor/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './CoreEditor.js';
2
+ export * from './Extension.js';
3
+ export * from './Mark.js';
4
+ export * from './Node.js';
@@ -0,0 +1,23 @@
1
+ import { Command, EditorState, Plugin, Transaction } from 'prosemirror-state';
2
+ export declare class InputRule {
3
+ readonly match: RegExp;
4
+ handler: (state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null;
5
+ undoable: boolean;
6
+ inCode: boolean | 'only';
7
+ constructor(match: RegExp, handler: string | ((state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null), options?: {
8
+ undoable?: boolean;
9
+ inCode?: boolean | 'only';
10
+ });
11
+ }
12
+ type PluginState = {
13
+ transform: Transaction;
14
+ from: number;
15
+ to: number;
16
+ text: string;
17
+ } | null;
18
+ export declare class InputRulesPlugin extends Plugin<PluginState> {
19
+ constructor(rules: readonly InputRule[]);
20
+ }
21
+ export declare const undoInputRule: Command;
22
+ export {};
23
+ //# sourceMappingURL=InputRulesPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputRulesPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/input-rules/InputRulesPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,MAAM,EAEN,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAO3B,qBAAa,SAAS;IA8BlB,QAAQ,CAAC,KAAK,EAAE,MAAM;IA5BxB,OAAO,EAAE,CACP,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,KACR,WAAW,GAAG,IAAI,CAAC;IAGxB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;gBAmBd,KAAK,EAAE,MAAM,EACtB,OAAO,EACH,MAAM,GACN,CAAC,CACD,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,KACR,WAAW,GAAG,IAAI,CAAC,EAC1B,OAAO,GAAE;QAIP,QAAQ,CAAC,EAAE,OAAO,CAAC;QAInB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;KACtB;CAST;AA0BD,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CAAC;AAKT,qBAAa,gBAAiB,SAAQ,MAAM,CAAC,WAAW,CAAC;gBAC3C,KAAK,EAAE,SAAS,SAAS,EAAE;CAgCxC;AAsCD,eAAO,MAAM,aAAa,EAAE,OA4B3B,CAAC"}
@@ -0,0 +1,163 @@
1
+ import { Plugin, } from 'prosemirror-state';
2
+ /// Input rules are regular expressions describing a piece of text
3
+ /// that, when typed, causes something to happen. This might be
4
+ /// changing two dashes into an emdash, wrapping a paragraph starting
5
+ /// with `"> "` into a blockquote, or something entirely different.
6
+ export class InputRule {
7
+ // :: (RegExp, union<string, (state: EditorState, match: [string], start: number, end: number) → ?Transaction>)
8
+ /// Create an input rule. The rule applies when the user typed
9
+ /// something and the text directly in front of the cursor matches
10
+ /// `match`, which should end with `$`.
11
+ ///
12
+ /// The `handler` can be a string, in which case the matched text, or
13
+ /// the first matched group in the regexp, is replaced by that
14
+ /// string.
15
+ ///
16
+ /// Or a it can be a function, which will be called with the match
17
+ /// array produced by
18
+ /// [`RegExp.exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec),
19
+ /// as well as the start and end of the matched range, and which can
20
+ /// return a [transaction](#state.Transaction) that describes the
21
+ /// rule's effect, or null to indicate the input was not handled.
22
+ constructor(
23
+ /// @internal
24
+ match, handler, options = {}) {
25
+ Object.defineProperty(this, "match", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: match
30
+ });
31
+ /// @internal
32
+ Object.defineProperty(this, "handler", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ /// @internal
39
+ Object.defineProperty(this, "undoable", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "inCode", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ this.match = match;
52
+ this.handler = typeof handler == 'string'
53
+ ? stringHandler(handler)
54
+ : handler;
55
+ this.undoable = options.undoable !== false;
56
+ this.inCode = options.inCode || false;
57
+ }
58
+ }
59
+ function stringHandler(string) {
60
+ return function (state, match, start, end) {
61
+ let insert = string;
62
+ if (match[1]) {
63
+ let offset = match[0].lastIndexOf(match[1]);
64
+ insert += match[0].slice(offset + match[1].length);
65
+ start += offset;
66
+ let cutOff = start - end;
67
+ if (cutOff > 0) {
68
+ insert = match[0].slice(offset - cutOff, offset) + insert;
69
+ start = end;
70
+ }
71
+ }
72
+ return state.tr.insertText(insert, start, end);
73
+ };
74
+ }
75
+ const MAX_MATCH = 500;
76
+ /// Create an input rules plugin. When enabled, it will cause text
77
+ /// input that matches any of the given rules to trigger the rule's
78
+ /// action.
79
+ export class InputRulesPlugin extends Plugin {
80
+ constructor(rules) {
81
+ super({
82
+ state: {
83
+ init() {
84
+ return null;
85
+ },
86
+ apply(tr, prev) {
87
+ let stored = tr.getMeta(this);
88
+ if (stored)
89
+ return stored;
90
+ return tr.selectionSet || tr.docChanged ? null : prev;
91
+ },
92
+ },
93
+ props: {
94
+ handleTextInput(view, from, to, text) {
95
+ return run(view, from, to, text, rules, InputRulesPlugin);
96
+ },
97
+ handleDOMEvents: {
98
+ compositionend: (view) => {
99
+ setTimeout(() => {
100
+ let { $cursor } = view.state.selection;
101
+ if ($cursor) {
102
+ run(view, $cursor.pos, $cursor.pos, '', rules, plugin);
103
+ }
104
+ });
105
+ },
106
+ },
107
+ },
108
+ isInputRules: true,
109
+ });
110
+ }
111
+ }
112
+ function run(view, from, to, text, rules, plugin) {
113
+ if (view.composing)
114
+ return false;
115
+ let state = view.state, $from = state.doc.resolve(from);
116
+ let textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, null, '\ufffc') + text;
117
+ for (let i = 0; i < rules.length; i++) {
118
+ let rule = rules[i];
119
+ if ($from.parent.type.spec.code) {
120
+ if (!rule.inCode)
121
+ continue;
122
+ }
123
+ else if (rule.inCode === 'only') {
124
+ continue;
125
+ }
126
+ let match = rule.match.exec(textBefore);
127
+ let tr = match &&
128
+ rule.handler(state, match, from - (match[0].length - text.length), to);
129
+ if (!tr)
130
+ continue;
131
+ if (rule.undoable)
132
+ tr.setMeta(plugin, { transform: tr, from, to, text });
133
+ view.dispatch(tr);
134
+ return true;
135
+ }
136
+ return false;
137
+ }
138
+ /// This is a command that will undo an input rule, if applying such a
139
+ /// rule was the last thing that the user did.
140
+ export const undoInputRule = (state, dispatch) => {
141
+ let plugins = state.plugins;
142
+ for (let i = 0; i < plugins.length; i++) {
143
+ let plugin = plugins[i], undoable;
144
+ if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
145
+ if (dispatch) {
146
+ let tr = state.tr, toUndo = undoable.transform;
147
+ for (let j = toUndo.steps.length - 1; j >= 0; j--) {
148
+ tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
149
+ }
150
+ if (undoable.text) {
151
+ let marks = tr.doc.resolve(undoable.from).marks();
152
+ tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
153
+ }
154
+ else {
155
+ tr.delete(undoable.from, undoable.to);
156
+ }
157
+ dispatch(tr);
158
+ }
159
+ return true;
160
+ }
161
+ }
162
+ return false;
163
+ };
@@ -0,0 +1,29 @@
1
+ import type { ParseOptions } from 'prosemirror-model';
2
+ import type { Extension } from './Extension.js';
3
+ import type { Mark } from './Mark.js';
4
+ import type { Node } from './Node.js';
5
+ export type AnyExtension = (Extension | Node | Mark) & {
6
+ requires: Set<AnyExtension | string>;
7
+ };
8
+ export type Extensions = AnyExtension[];
9
+ export type Content = JSONContent | JSONContent[] | null;
10
+ export interface EditorOptions {
11
+ element: Element;
12
+ content: Content;
13
+ parseOptions: ParseOptions;
14
+ extensions: Extensions;
15
+ topNode?: string;
16
+ }
17
+ export type JSONContent = {
18
+ type?: string;
19
+ attrs?: Record<string, any>;
20
+ content?: JSONContent[];
21
+ marks?: {
22
+ type: string;
23
+ attrs?: Record<string, any>;
24
+ [key: string]: any;
25
+ }[];
26
+ text?: string;
27
+ [key: string]: any;
28
+ };
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/editor/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG;IACrD,QAAQ,EAAE,GAAG,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC;CACtC,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,YAAY,EAAE,CAAC;AAExC,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,WAAW,EAAE,GAAG,IAAI,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Fragment, Node as ProseMirrorNode, type ParseOptions, Schema } from 'prosemirror-model';
2
+ import type { Content } from '../types.js';
3
+ export type CreateNodeFromContentOptions = {
4
+ slice?: boolean;
5
+ parseOptions?: ParseOptions;
6
+ errorOnInvalidContent?: boolean;
7
+ };
8
+ export declare function elementFromString(value: string): HTMLElement;
9
+ export declare function createNodeFromHTML(content: string, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
10
+ export declare function createNodeFromObject(content: Content | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
11
+ export declare function createNodeFromContent(content: string | Content | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
12
+ //# sourceMappingURL=createNodeFromContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNodeFromContent.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/createNodeFromContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,IAAI,IAAI,eAAe,EACvB,KAAK,YAAY,EACjB,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,4BAA4B,GAAG;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAqBF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAQ5D;AAGD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAiE5B;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,QAAQ,EAC7C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAwC5B;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,eAAe,GAAG,QAAQ,EACtD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAiB5B"}
@@ -0,0 +1,118 @@
1
+ import { DOMParser, Fragment, Node as ProseMirrorNode, Schema, } from 'prosemirror-model';
2
+ const removeWhitespaces = (node) => {
3
+ const children = node.childNodes;
4
+ for (let i = children.length - 1; i >= 0; i -= 1) {
5
+ const child = children[i];
6
+ if (child.nodeType === 3 && child.nodeValue &&
7
+ /^(\n\s\s|\n)$/.test(child.nodeValue)) {
8
+ node.removeChild(child);
9
+ }
10
+ else if (child.nodeType === 1) {
11
+ removeWhitespaces(child);
12
+ }
13
+ }
14
+ return node;
15
+ };
16
+ export function elementFromString(value) {
17
+ // add a wrapper to preserve leading and trailing whitespace
18
+ const wrappedValue = `<body>${value}</body>`;
19
+ const html = new globalThis.DOMParser().parseFromString(wrappedValue, 'text/html').body;
20
+ return removeWhitespaces(html);
21
+ }
22
+ // TODO: refactor to converters?
23
+ export function createNodeFromHTML(content, schema, options) {
24
+ options = {
25
+ slice: true,
26
+ parseOptions: {},
27
+ ...options,
28
+ };
29
+ // Check for invalid content
30
+ if (options.errorOnInvalidContent) {
31
+ let hasInvalidContent = false;
32
+ let invalidContent = '';
33
+ // A copy of the current schema with a catch-all node at the end
34
+ const contentCheckSchema = new Schema({
35
+ topNode: schema.spec.topNode,
36
+ marks: schema.spec.marks,
37
+ // Prosemirror's schemas are executed such that: the last to execute, matches last
38
+ // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle
39
+ nodes: schema.spec.nodes.append({
40
+ __unknown__catch__all__node: {
41
+ content: 'inline*',
42
+ group: 'block',
43
+ parseDOM: [
44
+ {
45
+ tag: '*',
46
+ getAttrs: (e) => {
47
+ // If this is ever called, we know that the content has something that we don't know how to handle in the schema
48
+ hasInvalidContent = true;
49
+ // Try to stringify the element for a more helpful error message
50
+ invalidContent = typeof e === 'string' ? e : e.outerHTML;
51
+ return null;
52
+ },
53
+ },
54
+ ],
55
+ },
56
+ }),
57
+ });
58
+ if (options.slice) {
59
+ DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions);
60
+ }
61
+ else {
62
+ DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions);
63
+ }
64
+ if (options.errorOnInvalidContent && hasInvalidContent) {
65
+ throw new Error('Invalid HTML content', {
66
+ cause: new Error(`Invalid element found: ${invalidContent}`),
67
+ });
68
+ }
69
+ }
70
+ const parser = DOMParser.fromSchema(schema);
71
+ if (options.slice) {
72
+ return parser.parseSlice(elementFromString(content), options.parseOptions)
73
+ .content;
74
+ }
75
+ return parser.parse(elementFromString(content), options.parseOptions);
76
+ }
77
+ export function createNodeFromObject(content, schema, options) {
78
+ options = {
79
+ slice: true,
80
+ parseOptions: {},
81
+ ...options,
82
+ };
83
+ try {
84
+ // if the JSON Content is an array of nodes, create a fragment for each node
85
+ if (Array.isArray(content) && content.length > 0) {
86
+ return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
87
+ }
88
+ const node = schema.nodeFromJSON(content);
89
+ if (options.errorOnInvalidContent) {
90
+ node.check();
91
+ }
92
+ return node;
93
+ }
94
+ catch (error) {
95
+ if (options.errorOnInvalidContent) {
96
+ throw new Error('Invalid JSON content', {
97
+ cause: error,
98
+ });
99
+ }
100
+ console.warn('Invalid content.', 'Passed value:', content, 'Error:', error);
101
+ // TODO: refactor using EMPTY_DOC prop?
102
+ return createNodeFromHTML('', schema, options);
103
+ }
104
+ }
105
+ export function createNodeFromContent(content, schema, options) {
106
+ if (content instanceof ProseMirrorNode || content instanceof Fragment) {
107
+ return content;
108
+ }
109
+ const isJSONContent = typeof content === 'object' && content !== null;
110
+ const isTextContent = typeof content === 'string';
111
+ if (isJSONContent) {
112
+ createNodeFromObject(content, schema, options);
113
+ }
114
+ if (isTextContent) {
115
+ return createNodeFromHTML(content, schema, options);
116
+ }
117
+ return createNodeFromHTML('', schema, options);
118
+ }
@@ -0,0 +1,4 @@
1
+ export declare function getHtmlAttributes(extension: any, node: any): {};
2
+ export declare function setHtmlAttributes(extension: any, element: any): {};
3
+ export declare function addAttributesToSchema(spec: any, extension: any): void;
4
+ //# sourceMappingURL=getHtmlAttributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHtmlAttributes.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/getHtmlAttributes.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,SAAS,KAAA,EAAE,IAAI,KAAA,MAkBhD;AAED,wBAAgB,iBAAiB,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA,MAcnD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,KAAA,EAAE,SAAS,KAAA,QAcpD"}
@@ -0,0 +1,47 @@
1
+ export function getHtmlAttributes(extension, node) {
2
+ const attrs = {};
3
+ if (extension.attributes) {
4
+ for (const [key, value] of Object.entries(extension.attributes)) {
5
+ if ('undefined' !== typeof node.attrs[key]) {
6
+ attrs[key] = node.attrs[key];
7
+ }
8
+ else {
9
+ if (value.toDom) {
10
+ attrs[key] = value.toDom(node);
11
+ }
12
+ else {
13
+ attrs[key] = value.default;
14
+ }
15
+ }
16
+ }
17
+ }
18
+ return attrs;
19
+ }
20
+ export function setHtmlAttributes(extension, element) {
21
+ const attrs = {};
22
+ if (extension.attributes) {
23
+ for (const [key, value] of Object.entries(extension.attributes)) {
24
+ if (value.fromDom) {
25
+ attrs[key] = value.fromDom(element);
26
+ }
27
+ else {
28
+ attrs[key] = value.default;
29
+ }
30
+ }
31
+ }
32
+ return attrs;
33
+ }
34
+ export function addAttributesToSchema(spec, extension) {
35
+ const attrs = {};
36
+ if (extension.attributes) {
37
+ if (!spec.attrs) {
38
+ spec.attrs = {};
39
+ }
40
+ for (const [key, value] of Object.entries(extension.attributes)) {
41
+ spec.attrs[key] = value;
42
+ if (!value.toDom) {
43
+ value.toDom = (node) => node.attrs[key];
44
+ }
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,7 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ import { type Converter, Extension } from '../../editor/src/mod.js';
3
+ export declare class ExtensionOdt extends Extension {
4
+ name: string;
5
+ getConverters(schema: Schema): Record<string, Converter>;
6
+ }
7
+ //# sourceMappingURL=ExtensionOdt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionOdt.d.ts","sourceRoot":"","sources":["../../../src/extension-odt/src/ExtensionOdt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,KAAK,SAAS,EAAmB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAMrF,qBAAa,YAAa,SAAQ,SAAS;IACzC,IAAI,SAAS;IAEb,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CAsBzD"}
@@ -0,0 +1,32 @@
1
+ import { Extension } from '../../editor/src/mod.js';
2
+ import { parse_content, parse_styles, unzip } from '@kerebron/odt-wasm';
3
+ import { OdtParser } from './OdtParser.js';
4
+ export class ExtensionOdt extends Extension {
5
+ constructor() {
6
+ super(...arguments);
7
+ Object.defineProperty(this, "name", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: 'odt'
12
+ });
13
+ }
14
+ getConverters(schema) {
15
+ return {
16
+ 'application/vnd.oasis.opendocument.text': {
17
+ fromDoc(document) {
18
+ throw new Error('Not implemented');
19
+ },
20
+ toDoc(content) {
21
+ const files = unzip(content);
22
+ const stylesTree = parse_styles(files.get('styles.xml'));
23
+ const contentTree = parse_content(files.get('content.xml'));
24
+ // console.log(JSON.stringify(stylesTree, null, 2).split('\n').slice(0, 20).join('\n'));
25
+ // console.log(JSON.stringify(contentTree, null, 2).split('\n').slice(0, 20).join('\n'));
26
+ const parser = new OdtParser(schema);
27
+ return parser.parse({ ...files, contentTree, stylesTree });
28
+ },
29
+ },
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,23 @@
1
+ import { Attrs, Node, Schema } from 'prosemirror-model';
2
+ interface OdtElement {
3
+ }
4
+ export interface ParseSpec {
5
+ node?: string;
6
+ children?: (node: OdtElement) => OdtElement[];
7
+ text?: (node: OdtElement) => string;
8
+ block?: string | ((node: OdtElement) => string);
9
+ mark?: string;
10
+ attrs?: Attrs | null;
11
+ getAttrs?: (token: OdtElement, style: Style) => Attrs | null;
12
+ ignore?: boolean;
13
+ }
14
+ interface Style {
15
+ '@name': string;
16
+ }
17
+ export declare class OdtParser {
18
+ private readonly schema;
19
+ constructor(schema: Schema);
20
+ parse(files: any): Node | null;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=OdtParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OdtParser.d.ts","sourceRoot":"","sources":["../../../src/extension-odt/src/OdtParser.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,IAAI,EAEJ,MAAM,EACP,MAAM,mBAAmB,CAAC;AAE3B,UAAU,UAAU;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;IAE9C,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM,CAAC;IAEpC,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM,CAAC,CAAC;IAEhD,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IAErB,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,KAAK,KACT,KAAK,GAAG,IAAI,CAAC;IAElB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAaD,UAAU,KAAK;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AA4UD,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAI3C,KAAK,CAAC,KAAK,EAAE,GAAG;CAkBjB"}