@kerebron/editor 0.2.0 → 0.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.
Files changed (77) hide show
  1. package/assets/gapcursor.css +4 -11
  2. package/assets/index.css +1 -0
  3. package/assets/search.css +6 -0
  4. package/esm/CoreEditor.d.ts +31 -0
  5. package/esm/CoreEditor.d.ts.map +1 -0
  6. package/esm/CoreEditor.js +198 -0
  7. package/esm/DummyEditorView.d.ts +60 -0
  8. package/esm/DummyEditorView.d.ts.map +1 -0
  9. package/esm/DummyEditorView.js +277 -0
  10. package/esm/Extension.d.ts +26 -0
  11. package/esm/Extension.d.ts.map +1 -0
  12. package/esm/Extension.js +33 -0
  13. package/esm/ExtensionManager.d.ts +33 -0
  14. package/esm/ExtensionManager.d.ts.map +1 -0
  15. package/esm/ExtensionManager.js +272 -0
  16. package/esm/Mark.d.ts +20 -0
  17. package/esm/Mark.d.ts.map +1 -0
  18. package/esm/Mark.js +40 -0
  19. package/esm/Node.d.ts +29 -0
  20. package/esm/Node.d.ts.map +1 -0
  21. package/esm/Node.js +49 -0
  22. package/esm/commands/CommandManager.d.ts +16 -0
  23. package/esm/commands/CommandManager.d.ts.map +1 -0
  24. package/esm/commands/CommandManager.js +61 -0
  25. package/esm/commands/createChainableState.d.ts +3 -0
  26. package/esm/commands/createChainableState.d.ts.map +1 -0
  27. package/esm/commands/createChainableState.js +29 -0
  28. package/esm/commands/mod.d.ts +55 -0
  29. package/esm/commands/mod.d.ts.map +1 -0
  30. package/esm/commands/mod.js +883 -0
  31. package/esm/mod.d.ts +7 -0
  32. package/esm/mod.d.ts.map +1 -0
  33. package/esm/mod.js +6 -0
  34. package/esm/nodeToTreeString.d.ts +4 -0
  35. package/esm/nodeToTreeString.d.ts.map +1 -0
  36. package/esm/nodeToTreeString.js +58 -0
  37. package/esm/package.json +3 -0
  38. package/esm/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  39. package/esm/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  40. package/esm/plugins/input-rules/InputRulesPlugin.js +163 -0
  41. package/esm/plugins/input-rules/mod.d.ts +3 -0
  42. package/esm/plugins/input-rules/mod.d.ts.map +1 -0
  43. package/esm/plugins/input-rules/mod.js +2 -0
  44. package/esm/plugins/input-rules/rulebuilders.d.ts +5 -0
  45. package/esm/plugins/input-rules/rulebuilders.d.ts.map +1 -0
  46. package/esm/plugins/input-rules/rulebuilders.js +50 -0
  47. package/esm/plugins/keymap/keymap.d.ts +11 -0
  48. package/esm/plugins/keymap/keymap.d.ts.map +1 -0
  49. package/esm/plugins/keymap/keymap.js +125 -0
  50. package/esm/plugins/keymap/mod.d.ts +2 -0
  51. package/esm/plugins/keymap/mod.d.ts.map +1 -0
  52. package/esm/plugins/keymap/mod.js +1 -0
  53. package/esm/plugins/keymap/w3c-keyname.d.ts +4 -0
  54. package/esm/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  55. package/esm/plugins/keymap/w3c-keyname.js +124 -0
  56. package/esm/search/mod.d.ts +3 -0
  57. package/esm/search/mod.d.ts.map +1 -0
  58. package/esm/search/mod.js +2 -0
  59. package/esm/search/query.d.ts +45 -0
  60. package/esm/search/query.d.ts.map +1 -0
  61. package/esm/search/query.js +390 -0
  62. package/esm/search/search.d.ts +32 -0
  63. package/esm/search/search.d.ts.map +1 -0
  64. package/esm/search/search.js +212 -0
  65. package/esm/types.d.ts +34 -0
  66. package/esm/types.d.ts.map +1 -0
  67. package/esm/types.js +1 -0
  68. package/esm/utilities/createNodeFromContent.d.ts +9 -0
  69. package/esm/utilities/createNodeFromContent.d.ts.map +1 -0
  70. package/esm/utilities/createNodeFromContent.js +32 -0
  71. package/esm/utilities/getHtmlAttributes.d.ts +9 -0
  72. package/esm/utilities/getHtmlAttributes.d.ts.map +1 -0
  73. package/esm/utilities/getHtmlAttributes.js +47 -0
  74. package/esm/utilities/mod.d.ts +3 -0
  75. package/esm/utilities/mod.d.ts.map +1 -0
  76. package/esm/utilities/mod.js +2 -0
  77. package/package.json +8 -6
package/esm/types.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { Node as ProseMirrorNode, 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
+ export type AnyExtensionOrReq = AnyExtension | {
7
+ requires: Array<AnyExtensionOrReq | string>;
8
+ };
9
+ export type Content = JSONContent | JSONContent[] | null;
10
+ export interface EditorOptions {
11
+ element: Element;
12
+ content: Content;
13
+ parseOptions: ParseOptions;
14
+ extensions: AnyExtensionOrReq[];
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
+ export type Attribute<T> = {
30
+ fromDom?: (element: HTMLElement) => T;
31
+ default: T;
32
+ toDom?: (node: ProseMirrorNode) => T;
33
+ };
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/E,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,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAC7C,QAAQ,EAAE,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,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,iBAAiB,EAAE,CAAC;IAChC,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;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,CAAC;CACtC,CAAC"}
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Fragment, Node as ProseMirrorNode, Schema } from 'prosemirror-model';
2
+ import type { JSONContent } from '../types.js';
3
+ export type CreateNodeFromContentOptions = {
4
+ errorOnInvalidContent?: boolean;
5
+ };
6
+ export declare function createNodeFromObject(content: JSONContent | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode;
7
+ export declare function createNodeFromArray(content: JSONContent[], schema: Schema): Fragment;
8
+ export declare function createNodeFromContent(content: JSONContent | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
9
+ //# sourceMappingURL=createNodeFromContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNodeFromContent.d.ts","sourceRoot":"","sources":["../../src/utilities/createNodeFromContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,MAAM,4BAA4B,GAAG;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,EACjD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,CA0BjB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EAAE,EACtB,MAAM,EAAE,MAAM,GACb,QAAQ,CAIV;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,EACjD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAY5B"}
@@ -0,0 +1,32 @@
1
+ import { Fragment, Node as ProseMirrorNode } from 'prosemirror-model';
2
+ export function createNodeFromObject(content, schema, options) {
3
+ try {
4
+ const node = schema.nodeFromJSON(content);
5
+ if (options?.errorOnInvalidContent) {
6
+ node.check();
7
+ }
8
+ return node;
9
+ }
10
+ catch (error) {
11
+ if (options?.errorOnInvalidContent) {
12
+ throw new Error('Invalid JSON content', {
13
+ cause: error,
14
+ });
15
+ }
16
+ console.warn('Invalid content.', 'Passed value:', content, 'Error:', error);
17
+ return schema.topNodeType.createAndFill(null, []);
18
+ }
19
+ }
20
+ export function createNodeFromArray(content, schema) {
21
+ return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
22
+ }
23
+ export function createNodeFromContent(content, schema, options) {
24
+ if (content instanceof ProseMirrorNode || content instanceof Fragment) {
25
+ return content;
26
+ }
27
+ const isJSONContent = typeof content === 'object' && content !== null;
28
+ if (isJSONContent) {
29
+ return createNodeFromObject(content, schema, options);
30
+ }
31
+ return schema.topNodeType.createAndFill(null, []);
32
+ }
@@ -0,0 +1,9 @@
1
+ import type { MarkSpec, Node as ProseMirrorNode, NodeSpec } from 'prosemirror-model';
2
+ import type { Mark } from '../Mark.js';
3
+ import type { Node } from '../Node.js';
4
+ type MarkOfNode = Mark | Node;
5
+ export declare function getHtmlAttributes(extension: MarkOfNode, node: ProseMirrorNode): Record<string, any>;
6
+ export declare function setHtmlAttributes(extension: MarkOfNode, element: HTMLElement): Record<string, any>;
7
+ export declare function addAttributesToSchema(spec: MarkSpec | NodeSpec, extension: MarkOfNode): void;
8
+ export {};
9
+ //# sourceMappingURL=getHtmlAttributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHtmlAttributes.d.ts","sourceRoot":"","sources":["../../src/utilities/getHtmlAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,IAAI,IAAI,eAAe,EACvB,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,KAAK,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9B,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,eAAe,uBAmBtB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,uBAc5E;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,GAAG,QAAQ,EACzB,SAAS,EAAE,UAAU,QAetB"}
@@ -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,3 @@
1
+ export * from './getHtmlAttributes.js';
2
+ export * from './createNodeFromContent.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/utilities/mod.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './getHtmlAttributes.js';
2
+ export * from './createNodeFromContent.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/editor",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -13,17 +13,19 @@
13
13
  "./plugins/input-rules": {
14
14
  "import": "./esm/plugins/input-rules/mod.js"
15
15
  },
16
+ "./plugins/keymap": {
17
+ "import": "./esm/plugins/keymap/mod.js"
18
+ },
19
+ "./search": {
20
+ "import": "./esm/search/mod.js"
21
+ },
16
22
  "./utilities": {
17
23
  "import": "./esm/utilities/mod.js"
18
24
  }
19
25
  },
20
26
  "scripts": {},
21
- "files": [
22
- "assets/*.css"
23
- ],
24
27
  "dependencies": {
25
- "prosemirror-keymap": "1.2.2",
26
- "prosemirror-model": "1.25.1",
28
+ "prosemirror-model": "1.25.2",
27
29
  "prosemirror-state": "1.4.3",
28
30
  "prosemirror-transform": "1.10.4",
29
31
  "prosemirror-view": "1.40.0"