@thomasfosterau/effect-richtext 0.0.0 → 0.1.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 (176) hide show
  1. package/LICENSE +48 -0
  2. package/README.md +117 -1
  3. package/dist/_virtual/_rolldown/runtime.js +12 -0
  4. package/dist/commands/commands.d.ts +323 -0
  5. package/dist/commands/commands.js +722 -0
  6. package/dist/commands/internal.js +43 -0
  7. package/dist/commands/keymaps.d.ts +46 -0
  8. package/dist/commands/keymaps.js +64 -0
  9. package/dist/commands.d.ts +3 -0
  10. package/dist/commands.js +3 -0
  11. package/dist/compat/commands.d.ts +250 -0
  12. package/dist/compat/commands.js +275 -0
  13. package/dist/compat/internal/core.d.ts +20 -0
  14. package/dist/compat/internal/core.js +148 -0
  15. package/dist/compat/internal/props.js +82 -0
  16. package/dist/compat/keymap.d.ts +21 -0
  17. package/dist/compat/keymap.js +38 -0
  18. package/dist/compat/model.d.ts +893 -0
  19. package/dist/compat/model.js +1212 -0
  20. package/dist/compat/orderedmap.d.ts +74 -0
  21. package/dist/compat/orderedmap.js +124 -0
  22. package/dist/compat/schema-basic.d.ts +38 -0
  23. package/dist/compat/schema-basic.js +238 -0
  24. package/dist/compat/schema-list.d.ts +81 -0
  25. package/dist/compat/schema-list.js +156 -0
  26. package/dist/compat/state.d.ts +415 -0
  27. package/dist/compat/state.js +689 -0
  28. package/dist/compat/test-builder.d.ts +98 -0
  29. package/dist/compat/test-builder.js +197 -0
  30. package/dist/compat/transform.d.ts +458 -0
  31. package/dist/compat/transform.js +803 -0
  32. package/dist/compat/view.d.ts +411 -0
  33. package/dist/compat/view.js +409 -0
  34. package/dist/dropcursor.d.ts +46 -0
  35. package/dist/dropcursor.js +176 -0
  36. package/dist/extensions/defaults.d.ts +716 -0
  37. package/dist/extensions/defaults.js +209 -0
  38. package/dist/extensions/editor.d.ts +246 -0
  39. package/dist/extensions/editor.js +271 -0
  40. package/dist/extensions/extension.d.ts +375 -0
  41. package/dist/extensions/extension.js +233 -0
  42. package/dist/extensions.d.ts +4 -0
  43. package/dist/extensions.js +4 -0
  44. package/dist/gapcursor.d.ts +66 -0
  45. package/dist/gapcursor.js +273 -0
  46. package/dist/history.d.ts +178 -0
  47. package/dist/history.js +412 -0
  48. package/dist/html.d.ts +158 -0
  49. package/dist/html.js +164 -0
  50. package/dist/inputrules.d.ts +271 -0
  51. package/dist/inputrules.js +321 -0
  52. package/dist/internal/attempt.js +15 -0
  53. package/dist/internal/json.js +29 -0
  54. package/dist/keymap/keymap.d.ts +130 -0
  55. package/dist/keymap/keymap.js +159 -0
  56. package/dist/keymap.d.ts +2 -0
  57. package/dist/keymap.js +1 -0
  58. package/dist/markdown/errors.d.ts +23 -0
  59. package/dist/markdown/errors.js +26 -0
  60. package/dist/markdown/from_markdown.d.ts +185 -0
  61. package/dist/markdown/from_markdown.js +266 -0
  62. package/dist/markdown/schema.d.ts +522 -0
  63. package/dist/markdown/schema.js +292 -0
  64. package/dist/markdown/to_markdown.d.ts +251 -0
  65. package/dist/markdown/to_markdown.js +413 -0
  66. package/dist/markdown.d.ts +5 -0
  67. package/dist/markdown.js +5 -0
  68. package/dist/model/attrsCodec.js +48 -0
  69. package/dist/model/comparedeep.js +17 -0
  70. package/dist/model/content.d.ts +232 -0
  71. package/dist/model/content.js +630 -0
  72. package/dist/model/diff.js +66 -0
  73. package/dist/model/dom.d.ts +3 -0
  74. package/dist/model/errors.d.ts +90 -0
  75. package/dist/model/errors.js +76 -0
  76. package/dist/model/fragment.d.ts +131 -0
  77. package/dist/model/fragment.js +262 -0
  78. package/dist/model/from_dom.d.ts +299 -0
  79. package/dist/model/from_dom.js +618 -0
  80. package/dist/model/json.d.ts +37 -0
  81. package/dist/model/json.js +126 -0
  82. package/dist/model/mark.d.ts +73 -0
  83. package/dist/model/mark.js +121 -0
  84. package/dist/model/node.d.ts +267 -0
  85. package/dist/model/node.js +434 -0
  86. package/dist/model/replace.d.ts +78 -0
  87. package/dist/model/replace.js +207 -0
  88. package/dist/model/resolvedpos.d.ts +196 -0
  89. package/dist/model/resolvedpos.js +305 -0
  90. package/dist/model/schema.d.ts +740 -0
  91. package/dist/model/schema.js +451 -0
  92. package/dist/model/to_dom.d.ts +169 -0
  93. package/dist/model/to_dom.js +238 -0
  94. package/dist/model.d.ts +12 -0
  95. package/dist/model.js +12 -0
  96. package/dist/placeholder.d.ts +53 -0
  97. package/dist/placeholder.js +79 -0
  98. package/dist/reactive/observer.d.ts +54 -0
  99. package/dist/reactive/observer.js +61 -0
  100. package/dist/reactive/selectors.d.ts +22 -0
  101. package/dist/reactive/selectors.js +61 -0
  102. package/dist/reactive/stateref.d.ts +72 -0
  103. package/dist/reactive/stateref.js +71 -0
  104. package/dist/reactive/streams.d.ts +83 -0
  105. package/dist/reactive/streams.js +85 -0
  106. package/dist/reactive.d.ts +16 -0
  107. package/dist/reactive.js +26 -0
  108. package/dist/schema-basic.d.ts +448 -0
  109. package/dist/schema-basic.js +269 -0
  110. package/dist/schema-list/commands.d.ts +66 -0
  111. package/dist/schema-list/commands.js +203 -0
  112. package/dist/schema-list.d.ts +92 -0
  113. package/dist/schema-list.js +100 -0
  114. package/dist/state/errors.d.ts +39 -0
  115. package/dist/state/errors.js +32 -0
  116. package/dist/state/plugin.d.ts +232 -0
  117. package/dist/state/plugin.js +82 -0
  118. package/dist/state/selection.d.ts +297 -0
  119. package/dist/state/selection.js +486 -0
  120. package/dist/state/state.d.ts +212 -0
  121. package/dist/state/state.js +489 -0
  122. package/dist/state/transaction.d.ts +145 -0
  123. package/dist/state/transaction.js +195 -0
  124. package/dist/state.d.ts +6 -0
  125. package/dist/state.js +6 -0
  126. package/dist/test-builder.d.ts +3582 -0
  127. package/dist/test-builder.js +239 -0
  128. package/dist/transform/attr_step.d.ts +60 -0
  129. package/dist/transform/attr_step.js +105 -0
  130. package/dist/transform/errors.d.ts +50 -0
  131. package/dist/transform/errors.js +35 -0
  132. package/dist/transform/map.d.ts +182 -0
  133. package/dist/transform/map.js +280 -0
  134. package/dist/transform/mark.js +98 -0
  135. package/dist/transform/mark_set_step.js +69 -0
  136. package/dist/transform/mark_step.d.ts +113 -0
  137. package/dist/transform/mark_step.js +225 -0
  138. package/dist/transform/replace.d.ts +18 -0
  139. package/dist/transform/replace.js +381 -0
  140. package/dist/transform/replace_step.d.ts +109 -0
  141. package/dist/transform/replace_step.js +175 -0
  142. package/dist/transform/step.d.ts +157 -0
  143. package/dist/transform/step.js +168 -0
  144. package/dist/transform/structure.d.ts +89 -0
  145. package/dist/transform/structure.js +350 -0
  146. package/dist/transform/transform.d.ts +248 -0
  147. package/dist/transform/transform.js +373 -0
  148. package/dist/transform.d.ts +10 -0
  149. package/dist/transform.js +10 -0
  150. package/dist/view/browser.js +39 -0
  151. package/dist/view/capturekeys.js +282 -0
  152. package/dist/view/clipboard.d.ts +8 -0
  153. package/dist/view/clipboard.js +245 -0
  154. package/dist/view/decoration.d.ts +339 -0
  155. package/dist/view/decoration.js +566 -0
  156. package/dist/view/dom.d.ts +18 -0
  157. package/dist/view/dom.js +140 -0
  158. package/dist/view/domchange.js +295 -0
  159. package/dist/view/domcoords.d.ts +22 -0
  160. package/dist/view/domcoords.js +448 -0
  161. package/dist/view/domobserver.d.ts +47 -0
  162. package/dist/view/domobserver.js +328 -0
  163. package/dist/view/errors.d.ts +18 -0
  164. package/dist/view/errors.js +21 -0
  165. package/dist/view/input.d.ts +58 -0
  166. package/dist/view/input.js +704 -0
  167. package/dist/view/selection.js +198 -0
  168. package/dist/view/view.d.ts +699 -0
  169. package/dist/view/view.js +623 -0
  170. package/dist/view/viewdesc.d.ts +236 -0
  171. package/dist/view/viewdesc.js +1205 -0
  172. package/dist/view-css.d.ts +43 -0
  173. package/dist/view-css.js +124 -0
  174. package/dist/view.d.ts +6 -0
  175. package/dist/view.js +4 -0
  176. package/package.json +200 -4
@@ -0,0 +1,20 @@
1
+ import "effect/Effect";
2
+ /** @internal */
3
+ export declare const CORE: unique symbol;
4
+ /**
5
+ * Error type raised by `Node.replace` when given an invalid replacement.
6
+ *
7
+ * @since 0.1.0
8
+ * @category errors
9
+ */
10
+ export declare class ReplaceError extends Error {}
11
+ /**
12
+ * An error thrown when a transform step fails or a structural
13
+ * transform is invalid.
14
+ *
15
+ * @since 0.1.0
16
+ * @category errors
17
+ */
18
+ export declare class TransformError extends Error {
19
+ get name(): string;
20
+ }
@@ -0,0 +1,148 @@
1
+ import * as Arr from "effect/Array";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Option from "effect/Option";
4
+ import * as Predicate from "effect/Predicate";
5
+ import * as Match from "effect/Match";
6
+ import * as Cause from "effect/Cause";
7
+ import * as Exit from "effect/Exit";
8
+ // src/compat/internal/core.ts
9
+ /**
10
+ * Shared machinery of the ProseMirror compatibility layer: the link
11
+ * between facade objects and the core objects they wrap, and the
12
+ * conversion of core errors into ProseMirror's exceptions.
13
+ *
14
+ * Every facade stores its core object under the `CORE` symbol. Core
15
+ * objects are wrapped on demand by `wrap`, which looks up a factory
16
+ * registered for the core object's class (walking the prototype chain)
17
+ * and caches the facade in a `WeakMap`, so that the same core object
18
+ * always yields the same facade.
19
+ *
20
+ * @internal
21
+ */
22
+ /** @internal */
23
+ const CORE = Symbol.for("effect-richtext/compat/core");
24
+ const facades = /* @__PURE__ */ new WeakMap();
25
+ const factories = /* @__PURE__ */ new WeakMap();
26
+ /** Associate a facade with its core object. @internal */
27
+ const link = (facade, core) => {
28
+ facade[CORE] = core;
29
+ facades.set(core, facade);
30
+ return facade;
31
+ };
32
+ /** Create a facade for `core` without running the facade's constructor. @internal */
33
+ const adopt = (proto, core) => link(Object.create(proto), core);
34
+ /**
35
+ * Register the facade factory for instances of a core class (and its
36
+ * subclasses, unless they have their own factory). @internal
37
+ */
38
+ const registerWrapper = (coreClass, f) => {
39
+ factories.set(coreClass.prototype, f);
40
+ };
41
+ /** The facade for a core value (or the value itself if it has none). @internal */
42
+ const wrap = (x) => {
43
+ if (x === null || typeof x !== "object") return x;
44
+ const known = facades.get(x);
45
+ if (known) return known;
46
+ if (CORE in x) return x;
47
+ for (let proto = Object.getPrototypeOf(x); proto; proto = Object.getPrototypeOf(proto)) {
48
+ const f = factories.get(proto);
49
+ if (f) {
50
+ const facade = f(x);
51
+ if (!facades.has(x)) link(facade, x);
52
+ return facade;
53
+ }
54
+ }
55
+ return x;
56
+ };
57
+ /** The core object behind a facade (or the value itself). @internal */
58
+ const unwrap = (x) => x !== null && typeof x === "object" && CORE in x ? x[CORE] : x;
59
+ /**
60
+ * Core objects created for user subclasses of facade classes are
61
+ * instances of core subclasses whose methods call the facade's
62
+ * overrides. They store the prototype holding the core's own
63
+ * implementations under `BASE`. @internal
64
+ */
65
+ const BASE = Symbol.for("effect-richtext/compat/base");
66
+ /** Call a core method, bypassing the overrides that delegate to a facade. @internal */
67
+ const callBase = (core, method, args = []) => {
68
+ const proto = core[BASE];
69
+ return (proto ? proto[method] : core[method]).apply(core, args);
70
+ };
71
+ /** Read a core getter, bypassing the overrides that delegate to a facade. @internal */
72
+ const getBase = (core, prop) => {
73
+ for (let proto = core[BASE]; proto; proto = Object.getPrototypeOf(proto)) {
74
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
75
+ if (desc) return desc.get ? desc.get.call(core) : desc.value;
76
+ }
77
+ return core[prop];
78
+ };
79
+ /** Whether a value is a facade. @internal */
80
+ const isFacade = (x) => x !== null && typeof x === "object" && CORE in x;
81
+ const arrayFacades = /* @__PURE__ */ new WeakMap();
82
+ const arrayCores = /* @__PURE__ */ new WeakMap();
83
+ /**
84
+ * Wrap an array of core objects, caching the result so that the same
85
+ * core array yields the same facade array. @internal
86
+ */
87
+ const wrapArray = (arr) => {
88
+ let found = arrayFacades.get(arr);
89
+ if (!found) {
90
+ found = Arr.isReadonlyArrayEmpty(arr) ? emptyFacadeArray : arr.map(wrap);
91
+ if (found !== emptyFacadeArray) arrayCores.set(found, arr);
92
+ arrayFacades.set(arr, found);
93
+ }
94
+ return found;
95
+ };
96
+ const emptyFacadeArray = [];
97
+ /** Set the core array that the shared empty facade array unwraps to. @internal */
98
+ const setEmptyCoreArray = (core) => {
99
+ arrayCores.set(emptyFacadeArray, core);
100
+ };
101
+ /** Unwrap an array of facades (reusing the original core array when possible). @internal */
102
+ const unwrapArray = (arr) => {
103
+ const found = arrayCores.get(arr);
104
+ if (found) return found;
105
+ for (let i = 0; i < arr.length; i++) if (isFacade(arr[i])) return arr.map(unwrap);
106
+ return arr;
107
+ };
108
+ /**
109
+ * Error type raised by `Node.replace` when given an invalid replacement.
110
+ *
111
+ * @since 0.1.0
112
+ * @category errors
113
+ */
114
+ var ReplaceError = class extends Error {};
115
+ /**
116
+ * An error thrown when a transform step fails or a structural
117
+ * transform is invalid.
118
+ *
119
+ * @since 0.1.0
120
+ * @category errors
121
+ */
122
+ var TransformError = class extends Error {
123
+ get name() {
124
+ return "TransformError";
125
+ }
126
+ };
127
+ const proseMirrorError = (tag, message) => Match.value(tag).pipe(Match.when("ReplaceError", () => new ReplaceError(message)), Match.whenOr("TransformError", "StepError", () => new TransformError(message)), Match.when("SchemaDefinitionError", () => message.indexOf("(in content expression") > -1 ? new SyntaxError(message) : new RangeError(message)), Match.whenOr("PositionError", "ContentError", "AttributeError", "JSONError", "DOMSpecError", "SelectionError", "StateError", "KeymapError", "ViewError", () => new RangeError(message)), Match.option);
128
+ /** Convert a core (tagged) error into the exception ProseMirror would throw. @internal */
129
+ const convertError = (e) => {
130
+ if (e === null || typeof e !== "object" || !("_tag" in e) || !Predicate.isString(e._tag)) return e;
131
+ const message = "message" in e && Predicate.isString(e.message) ? e.message : e._tag;
132
+ return Option.getOrElse(proseMirrorError(e._tag, message), () => e);
133
+ };
134
+ /** Run `f`, converting core errors into ProseMirror's exceptions. @internal */
135
+ const guard = (f) => {
136
+ try {
137
+ return f();
138
+ } catch (e) {
139
+ throw convertError(e);
140
+ }
141
+ };
142
+ /** Run an effect synchronously, throwing (converted) failures and defects. @internal */
143
+ const runSync = (effect) => {
144
+ const exit = Effect.runSyncExit(effect);
145
+ if (Exit.isSuccess(exit)) return exit.value;
146
+ throw convertError(Cause.squash(exit.cause));
147
+ };
148
+ export { BASE, CORE, ReplaceError, TransformError, adopt, callBase, convertError, getBase, guard, isFacade, link, registerWrapper, runSync, setEmptyCoreArray, unwrap, unwrapArray, wrap, wrapArray };
@@ -0,0 +1,82 @@
1
+ import { runSync, unwrap, unwrapArray, wrap, wrapArray } from "./core.js";
2
+ import * as Effect from "effect/Effect";
3
+ // src/compat/internal/props.ts
4
+ /**
5
+ * Translation of ProseMirror-style editor props (functions receiving
6
+ * and returning facades) into core editor props (functions receiving
7
+ * and returning core objects), and back.
8
+ *
9
+ * Arguments are converted with `wrap` and results with `unwrap`, which
10
+ * covers every prop except the few that take callbacks or return
11
+ * objects with methods (`handleTextInput`, `nodeViews`, `markViews`,
12
+ * `handleDOMEvents`), which are handled explicitly. Translations are
13
+ * cached per function/object, so that re-translating the same props
14
+ * yields identical core props (the view compares e.g. node view
15
+ * constructors by identity).
16
+ *
17
+ * @internal
18
+ */
19
+ const wrapArgs = (args) => {
20
+ return Array.from(args, (arg) => wrap(arg));
21
+ };
22
+ const unwrapResult = (result) => Array.isArray(result) ? unwrapArray(result) : unwrap(result);
23
+ const cached = (cache, key, make) => {
24
+ if (!cache) return make();
25
+ let found = cache.get(key);
26
+ if (found === void 0) cache.set(key, found = make());
27
+ return found;
28
+ };
29
+ /** Wrap a ProseMirror-style function so that it can be called with core values. @internal */
30
+ const toCoreFunction = (f, self) => function(...args) {
31
+ return unwrapResult(f.apply(self, wrapArgs(args)));
32
+ };
33
+ /** Wrap a core function so that it can be called with facades. @internal */
34
+ const fromCoreFunction = (f, self) => function(...args) {
35
+ let result = f.apply(self, args.map((a) => Array.isArray(a) ? unwrapArray(a) : unwrap(a)));
36
+ if (Effect.isEffect(result)) result = runSync(result);
37
+ return Array.isArray(result) ? wrapArray(result) : wrap(result);
38
+ };
39
+ /** Adapt a ProseMirror-style node or mark view object for the core view. @internal */
40
+ const viewObjectToCore = (view) => view && new Proxy(view, { get(target, prop) {
41
+ const value = target[prop];
42
+ if (prop === "update" && typeof value === "function") return (node, decorations, inner) => target.update(wrap(node), wrapArray(decorations), wrap(inner));
43
+ return typeof value === "function" ? value.bind(target) : value;
44
+ } });
45
+ const translateViews = (views, cache) => {
46
+ const result = {};
47
+ for (const name in views) {
48
+ const ctor = views[name];
49
+ result[name] = ctor && cached(cache, ctor, () => (...args) => viewObjectToCore(ctor(...wrapArgs(args))));
50
+ }
51
+ return result;
52
+ };
53
+ /**
54
+ * Translate a set of ProseMirror-style props into core props. Function
55
+ * props are called with `self` as `this`. @internal
56
+ */
57
+ const propsToCore = (props, self, cache, target = {}) => {
58
+ for (const name in props) {
59
+ const value = props[name];
60
+ if (name === "handleDOMEvents" && value) target[name] = cached(cache, value, () => propsToCore(value, self, cache));
61
+ else if ((name === "nodeViews" || name === "markViews") && value) target[name] = cached(cache, value, () => translateViews(value, cache));
62
+ else if (name === "handleTextInput" && typeof value === "function") target[name] = cached(cache, value, () => (view, from, to, text, deflt) => value.call(self, wrap(view), from, to, text, () => wrap(deflt())));
63
+ else if (name === "plugins" && Array.isArray(value)) target[name] = unwrapArray(value);
64
+ else if (typeof value === "function") target[name] = cached(cache, value, () => toCoreFunction(value, self));
65
+ else target[name] = unwrap(value);
66
+ }
67
+ return target;
68
+ };
69
+ /** Translate core props into ProseMirror-style props. @internal */
70
+ const propsFromCore = (props, self) => {
71
+ const target = {};
72
+ for (const name in props) {
73
+ const value = props[name];
74
+ if (name === "handleDOMEvents" && value) target[name] = propsFromCore(value, self);
75
+ else if (name === "nodeViews" || name === "markViews") target[name] = value;
76
+ else if (name === "plugins" && Array.isArray(value)) target[name] = wrapArray(value);
77
+ else if (typeof value === "function") target[name] = fromCoreFunction(value, self);
78
+ else target[name] = wrap(value);
79
+ }
80
+ return target;
81
+ };
82
+ export { fromCoreFunction, propsFromCore, propsToCore, toCoreFunction, viewObjectToCore };
@@ -0,0 +1,21 @@
1
+ import { Command, Plugin } from "./state.js";
2
+ import { EditorView } from "./view.js";
3
+ /**
4
+ * Create a keymap plugin for the given set of bindings.
5
+ *
6
+ * @since 0.1.0
7
+ * @category constructors
8
+ */
9
+ export declare function keymap(bindings: {
10
+ [key: string]: Command;
11
+ }): Plugin;
12
+ /**
13
+ * Given a set of bindings (using the same format as `keymap`), return a
14
+ * keydown handler that handles them.
15
+ *
16
+ * @since 0.1.0
17
+ * @category constructors
18
+ */
19
+ export declare function keydownHandler(bindings: {
20
+ [key: string]: Command;
21
+ }): (view: EditorView, event: KeyboardEvent) => boolean;
@@ -0,0 +1,38 @@
1
+ import { matchBindings, normalizeBindings } from "../keymap/keymap.js";
2
+ import { guard } from "./internal/core.js";
3
+ import { Plugin } from "./state.js";
4
+ // src/compat/keymap.ts
5
+ /**
6
+ * A `prosemirror-keymap`-compatible module. Key names are normalized
7
+ * and matched by the core keymap; the bound ProseMirror-style commands
8
+ * are called directly with the view's `state`, `dispatch` and the view.
9
+ *
10
+ * Ported API surface from prosemirror-keymap (MIT, Marijn Haverbeke and others).
11
+ *
12
+ * @since 0.1.0
13
+ */
14
+ /**
15
+ * Create a keymap plugin for the given set of bindings.
16
+ *
17
+ * @since 0.1.0
18
+ * @category constructors
19
+ */
20
+ function keymap(bindings) {
21
+ return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
22
+ }
23
+ /**
24
+ * Given a set of bindings (using the same format as `keymap`), return a
25
+ * keydown handler that handles them.
26
+ *
27
+ * @since 0.1.0
28
+ * @category constructors
29
+ */
30
+ function keydownHandler(bindings) {
31
+ const map = guard(() => normalizeBindings(bindings));
32
+ return function(view, event) {
33
+ const candidates = matchBindings(map, event);
34
+ for (let i = 0; i < candidates.length; i++) if (candidates[i](view.state, view.dispatch, view)) return true;
35
+ return false;
36
+ };
37
+ }
38
+ export { keydownHandler, keymap };