fountainjs-editor 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.
- package/LICENSE +21 -0
- package/README.md +460 -0
- package/dist/fountainjs-react.cjs +1 -0
- package/dist/fountainjs-react.js +8 -0
- package/dist/fountainjs.cjs +1 -0
- package/dist/fountainjs.js +219 -0
- package/dist/index-1c508d95.js +1172 -0
- package/dist/index-cafd8e26.cjs +40 -0
- package/package.json +76 -0
- package/src/core/editor.ts +15 -0
- package/src/core/index.ts +6 -0
- package/src/core/plugin.ts +4 -0
- package/src/core/schema/index.ts +5 -0
- package/src/core/schema/mark-spec.ts +5 -0
- package/src/core/schema/mark.ts +7 -0
- package/src/core/schema/node-spec.ts +12 -0
- package/src/core/schema/node.ts +12 -0
- package/src/core/schema/schema.ts +17 -0
- package/src/core/selection.ts +17 -0
- package/src/core/state.ts +13 -0
- package/src/core/transaction/add-mark-step.ts +19 -0
- package/src/core/transaction/index.ts +9 -0
- package/src/core/transaction/insert-text-step.ts +18 -0
- package/src/core/transaction/remove-mark-step.ts +17 -0
- package/src/core/transaction/replace-step.ts +6 -0
- package/src/core/transaction/replace-text-step.ts +33 -0
- package/src/core/transaction/set-node-attrs-step.ts +30 -0
- package/src/core/transaction/step.ts +2 -0
- package/src/core/transaction/transaction.ts +8 -0
- package/src/core/transaction/transform.ts +23 -0
- package/src/extensions/index.ts +64 -0
- package/src/extensions/marks/em.ts +2 -0
- package/src/extensions/marks/strong.ts +2 -0
- package/src/extensions/nodes/bullet-list.ts +9 -0
- package/src/extensions/nodes/doc.ts +2 -0
- package/src/extensions/nodes/figcaption.ts +5 -0
- package/src/extensions/nodes/heading.ts +7 -0
- package/src/extensions/nodes/image-super-view.ts +90 -0
- package/src/extensions/nodes/image-super.ts +7 -0
- package/src/extensions/nodes/list-item.ts +9 -0
- package/src/extensions/nodes/paragraph.ts +2 -0
- package/src/extensions/nodes/table-cell.ts +5 -0
- package/src/extensions/nodes/table-row.ts +2 -0
- package/src/extensions/nodes/table.ts +5 -0
- package/src/extensions/nodes/text.ts +2 -0
- package/src/extensions/plugins/history.ts +12 -0
- package/src/extensions/plugins/markdown-shortcuts.ts +52 -0
- package/src/index.ts +12 -0
- package/src/react/FountainEditor.tsx +19 -0
- package/src/react/Navigator.tsx +36 -0
- package/src/react/index.ts +4 -0
- package/src/react/useFountain.ts +10 -0
- package/src/react/useNavigatorState.ts +41 -0
- package/src/view/dom-renderer.ts +77 -0
- package/src/view/index.ts +2 -0
- package/src/view/input.ts +74 -0
- package/src/view/node-view.ts +9 -0
- package/src/view/selection-handler.ts +76 -0
- package/src/view/view.ts +290 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
var h = Object.defineProperty;
|
|
2
|
+
var m = (s, t, e) => t in s ? h(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var a = (s, t, e) => (m(s, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { S as g, N as w } from "./index-1c508d95.js";
|
|
5
|
+
import { A as U, h as J, E as Y, j as q, F as B, M as G, l as K, a as Q, d as Z, R as j, c as tt, b as et, g as st, e as ot, f as nt, T as it, i as rt, u as at, k as lt } from "./index-1c508d95.js";
|
|
6
|
+
import "react";
|
|
7
|
+
class d {
|
|
8
|
+
constructor(t, e) {
|
|
9
|
+
a(this, "type");
|
|
10
|
+
a(this, "attrs");
|
|
11
|
+
this.type = t, this.attrs = e;
|
|
12
|
+
}
|
|
13
|
+
static fromJSON(t, e) {
|
|
14
|
+
const n = t.marks[e.type];
|
|
15
|
+
if (!n)
|
|
16
|
+
throw new Error(`Unknown mark type: ${e.type}`);
|
|
17
|
+
return new d(n, { ...e.attrs });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class z extends g {
|
|
21
|
+
constructor(t, e, n) {
|
|
22
|
+
super(), this.path = t, this.offset = e, this.text = n;
|
|
23
|
+
}
|
|
24
|
+
apply(t) {
|
|
25
|
+
let e = t, n = [];
|
|
26
|
+
for (const i of this.path)
|
|
27
|
+
n.push(e), e = e.content[i];
|
|
28
|
+
if (!e || !e.isText)
|
|
29
|
+
throw new Error("Target for InsertTextStep is not a text node.");
|
|
30
|
+
let l = e.withText((e.text || "").slice(0, this.offset) + this.text + (e.text || "").slice(this.offset));
|
|
31
|
+
for (let i = n.length - 1; i >= 0; i--) {
|
|
32
|
+
const r = n[i], c = [...r.content];
|
|
33
|
+
c[this.path[i]] = l, l = new w(r.type, r.attrs, c, r.text, r.marks);
|
|
34
|
+
}
|
|
35
|
+
return l;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
class p {
|
|
39
|
+
constructor(t) {
|
|
40
|
+
a(this, "spec");
|
|
41
|
+
this.spec = t;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const f = { content: "block+", toDOM() {
|
|
45
|
+
return ["div", 0];
|
|
46
|
+
} }, y = { content: "inline*", group: "block", toDOM() {
|
|
47
|
+
return ["p", 0];
|
|
48
|
+
} }, b = { group: "inline" }, x = {
|
|
49
|
+
attrs: { level: { default: 1 } },
|
|
50
|
+
content: "inline*",
|
|
51
|
+
group: "block",
|
|
52
|
+
toDOM(s) {
|
|
53
|
+
return [`h${s.attrs.level}`, 0];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
class S {
|
|
57
|
+
// The function to get the node's position
|
|
58
|
+
constructor(t, e, n) {
|
|
59
|
+
a(this, "dom");
|
|
60
|
+
a(this, "contentDOM");
|
|
61
|
+
a(this, "img");
|
|
62
|
+
a(this, "getPos");
|
|
63
|
+
// --- Resize Logic ---
|
|
64
|
+
a(this, "onResizeStart", (t) => {
|
|
65
|
+
t.preventDefault();
|
|
66
|
+
const e = t.clientX, n = this.dom.offsetWidth, o = (i) => {
|
|
67
|
+
const r = n + (i.clientX - e);
|
|
68
|
+
this.dom.style.width = `${r}px`;
|
|
69
|
+
}, l = () => {
|
|
70
|
+
window.removeEventListener("mousemove", o), window.removeEventListener("mouseup", l);
|
|
71
|
+
const i = this.getPos();
|
|
72
|
+
if (i === void 0)
|
|
73
|
+
return;
|
|
74
|
+
const r = { ...this.node.attrs, width: this.dom.style.width }, c = [i], u = this.view.editor.createTransaction().setNodeAttrs(c, r);
|
|
75
|
+
this.view.editor.dispatch(u);
|
|
76
|
+
};
|
|
77
|
+
window.addEventListener("mousemove", o), window.addEventListener("mouseup", l);
|
|
78
|
+
});
|
|
79
|
+
this.node = t, this.view = e, this.getPos = n, this.dom = document.createElement("figure"), this.dom.style.position = "relative", this.dom.style.margin = "1rem 0", this.dom.style.display = "inline-block", this.img = document.createElement("img"), this.updateImageAttributes(t.attrs), this.contentDOM = document.createElement("div");
|
|
80
|
+
const o = document.createElement("div");
|
|
81
|
+
o.style.position = "absolute", o.style.bottom = "5px", o.style.right = "5px", o.style.width = "10px", o.style.height = "10px", o.style.backgroundColor = "#007bff", o.style.cursor = "nwse-resize", o.style.border = "1px solid white", this.dom.appendChild(this.img), this.dom.appendChild(this.contentDOM), this.dom.appendChild(o), o.addEventListener("mousedown", this.onResizeStart);
|
|
82
|
+
}
|
|
83
|
+
// Called by the main EditorView when the node changes
|
|
84
|
+
update(t) {
|
|
85
|
+
return t.type !== this.node.type ? !1 : (this.updateImageAttributes(t.attrs), this.node = t, !0);
|
|
86
|
+
}
|
|
87
|
+
// Helper to sync node attributes to the DOM
|
|
88
|
+
updateImageAttributes(t) {
|
|
89
|
+
this.img.src = t.src, this.img.alt = t.alt, this.img.title = t.title, this.dom.style.width = t.width, this.img.style.width = "100%";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const v = {
|
|
93
|
+
group: "block",
|
|
94
|
+
content: "figcaption?",
|
|
95
|
+
attrs: { src: { default: "" }, alt: { default: "" }, title: { default: "" }, width: { default: "100%" } },
|
|
96
|
+
toDOM: (s) => {
|
|
97
|
+
const { src: t, alt: e, title: n, width: o } = s.attrs;
|
|
98
|
+
return ["figure", { style: `width: ${o};` }, ["img", { src: t, alt: e, title: n }], 0];
|
|
99
|
+
},
|
|
100
|
+
nodeView: S
|
|
101
|
+
}, M = {
|
|
102
|
+
content: "inline*",
|
|
103
|
+
toDOM: () => ["figcaption", { style: "text-align: center; color: #666; font-style: italic;" }, 0]
|
|
104
|
+
}, D = {
|
|
105
|
+
group: "block",
|
|
106
|
+
content: "table_row+",
|
|
107
|
+
toDOM() {
|
|
108
|
+
return ["table", { style: "border-collapse: collapse; width: 100%;" }, ["tbody", 0]];
|
|
109
|
+
}
|
|
110
|
+
}, E = { content: "table_cell+", toDOM() {
|
|
111
|
+
return ["tr", 0];
|
|
112
|
+
} }, k = {
|
|
113
|
+
content: "paragraph+",
|
|
114
|
+
attrs: { colspan: { default: 1 }, rowspan: { default: 1 } },
|
|
115
|
+
toDOM(s) {
|
|
116
|
+
return ["td", { style: "border: 1px solid #ddd; padding: 8px;", ...s.attrs }, 0];
|
|
117
|
+
}
|
|
118
|
+
}, O = {
|
|
119
|
+
group: "block",
|
|
120
|
+
content: "list_item+",
|
|
121
|
+
// Must contain one or more list_item nodes
|
|
122
|
+
toDOM() {
|
|
123
|
+
return ["ul", 0];
|
|
124
|
+
}
|
|
125
|
+
}, T = {
|
|
126
|
+
// A list item can contain paragraphs, and even nested lists.
|
|
127
|
+
content: "paragraph+ (bullet_list)?",
|
|
128
|
+
toDOM() {
|
|
129
|
+
return ["li", 0];
|
|
130
|
+
}
|
|
131
|
+
}, N = { toDOM() {
|
|
132
|
+
return ["strong", 0];
|
|
133
|
+
} }, R = { toDOM() {
|
|
134
|
+
return ["em", 0];
|
|
135
|
+
} }, _ = 100;
|
|
136
|
+
function A() {
|
|
137
|
+
return { done: [], undone: [] };
|
|
138
|
+
}
|
|
139
|
+
const L = new p({
|
|
140
|
+
state: {
|
|
141
|
+
init: A,
|
|
142
|
+
apply: (s, t) => {
|
|
143
|
+
if (s.steps.length > 0) {
|
|
144
|
+
const e = [...t.done, s];
|
|
145
|
+
return e.length > _ && e.shift(), { done: e, undone: [] };
|
|
146
|
+
}
|
|
147
|
+
return t;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
function H(s) {
|
|
152
|
+
return console.log("Undo command called (not implemented)"), !1;
|
|
153
|
+
}
|
|
154
|
+
function X(s) {
|
|
155
|
+
return console.log("Redo command called (not implemented)"), !1;
|
|
156
|
+
}
|
|
157
|
+
const $ = new p({}), F = {
|
|
158
|
+
nodes: {
|
|
159
|
+
doc: f,
|
|
160
|
+
paragraph: y,
|
|
161
|
+
text: b,
|
|
162
|
+
heading: x,
|
|
163
|
+
image_super: v,
|
|
164
|
+
figcaption: M,
|
|
165
|
+
table: D,
|
|
166
|
+
table_row: E,
|
|
167
|
+
table_cell: k,
|
|
168
|
+
bullet_list: O,
|
|
169
|
+
list_item: T
|
|
170
|
+
},
|
|
171
|
+
marks: {
|
|
172
|
+
strong: N,
|
|
173
|
+
em: R
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
export {
|
|
177
|
+
U as AddMarkStep,
|
|
178
|
+
F as CoreSchemaSpec,
|
|
179
|
+
J as Editor,
|
|
180
|
+
Y as EditorState,
|
|
181
|
+
q as EditorView,
|
|
182
|
+
B as FountainEditor,
|
|
183
|
+
z as InsertTextStep,
|
|
184
|
+
d as Mark,
|
|
185
|
+
G as MarkType,
|
|
186
|
+
K as Navigator,
|
|
187
|
+
w as Node,
|
|
188
|
+
Q as NodeType,
|
|
189
|
+
p as Plugin,
|
|
190
|
+
Z as RemoveMarkStep,
|
|
191
|
+
j as ReplaceStep,
|
|
192
|
+
tt as ReplaceTextStep,
|
|
193
|
+
et as Schema,
|
|
194
|
+
st as Selection,
|
|
195
|
+
ot as SetNodeAttrsStep,
|
|
196
|
+
g as Step,
|
|
197
|
+
nt as Transaction,
|
|
198
|
+
it as Transform,
|
|
199
|
+
O as bulletList,
|
|
200
|
+
rt as createEditor,
|
|
201
|
+
f as doc,
|
|
202
|
+
R as em,
|
|
203
|
+
M as figcaption,
|
|
204
|
+
x as heading,
|
|
205
|
+
L as historyPlugin,
|
|
206
|
+
v as imageSuper,
|
|
207
|
+
T as listItem,
|
|
208
|
+
$ as markdownShortcutsPlugin,
|
|
209
|
+
y as paragraph,
|
|
210
|
+
X as redo,
|
|
211
|
+
N as strong,
|
|
212
|
+
D as table,
|
|
213
|
+
k as tableCell,
|
|
214
|
+
E as tableRow,
|
|
215
|
+
b as text,
|
|
216
|
+
H as undo,
|
|
217
|
+
at as useFountain,
|
|
218
|
+
lt as useNavigatorState
|
|
219
|
+
};
|