@draftably/editor 0.2.0 → 0.4.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/README.md +5 -3
- package/dist/assets/engine.worker-C6o2x40z.js +7609 -0
- package/dist/element.js +171 -17
- package/dist/index.js +9837 -8468
- package/dist/types/src/cli/raster-fonts.d.ts +3 -0
- package/dist/types/src/components/canvas/Canvas.d.ts +4 -0
- package/dist/types/src/components/scene/NodeView.d.ts +7 -0
- package/dist/types/src/components/scene/parts.d.ts +7 -11
- package/dist/types/src/components/session-context.d.ts +4 -1
- package/dist/types/src/dsl/cells.d.ts +1 -0
- package/dist/types/src/dsl/compile.d.ts +15 -1
- package/dist/types/src/dsl/corridors.d.ts +38 -0
- package/dist/types/src/dsl/legend-notes.d.ts +14 -0
- package/dist/types/src/dsl/syntax.d.ts +3 -1
- package/dist/types/src/editor/css.d.ts +3 -0
- package/dist/types/src/editor/element.d.ts +8 -6
- package/dist/types/src/editor/internal.d.ts +483 -0
- package/dist/types/src/editor/mount.d.ts +70 -5
- package/dist/types/src/graph-api/core.d.ts +125 -0
- package/dist/types/src/model/appearance.d.ts +19 -0
- package/dist/types/src/model/colors.d.ts +10 -2
- package/dist/types/src/model/labels.d.ts +22 -6
- package/dist/types/src/model/types.d.ts +9 -0
- package/dist/types/src/runtime/anchors.d.ts +46 -0
- package/dist/types/src/runtime/camera.d.ts +41 -0
- package/dist/types/src/runtime/element-base.d.ts +40 -0
- package/dist/types/src/runtime/geometry.d.ts +72 -0
- package/dist/types/src/runtime/host.d.ts +46 -0
- package/dist/types/src/runtime/page-shared.d.ts +24 -0
- package/dist/types/src/runtime/policy.d.ts +7 -0
- package/dist/types/src/runtime/render.d.ts +10 -0
- package/dist/types/src/runtime/svg-renderer.d.ts +8 -0
- package/dist/types/src/runtime/types.d.ts +115 -0
- package/dist/types/src/runtime/version.d.ts +2 -0
- package/dist/types/src/runtime/viewer.d.ts +123 -0
- package/dist/types/src/state/active-session.d.ts +7 -1
- package/dist/types/src/state/dom-root.d.ts +8 -0
- package/dist/types/src/state/session/document.d.ts +3 -1
- package/dist/types/src/state/session/editor.d.ts +3 -2
- package/dist/types/src/state/session/index.d.ts +5 -1
- package/package.json +1 -1
- package/dist/assets/engine.worker-DwN9io_m.js +0 -6856
- package/dist/types/src/cli/png.d.ts +0 -23
- package/dist/types/src/model/embed.d.ts +0 -17
package/dist/element.js
CHANGED
|
@@ -1,9 +1,103 @@
|
|
|
1
|
-
import { mountEditor as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { mountEditor as E } from "./index.js";
|
|
2
|
+
const A = ["link", "contextmenu"], v = "0.4.0", h = v;
|
|
3
|
+
function b(t, e) {
|
|
4
|
+
if (t === e || typeof t == "function" && typeof e == "function") return !0;
|
|
5
|
+
if (!t || !e || typeof t != "object" || typeof e != "object" || Array.isArray(t) !== Array.isArray(e)) return !1;
|
|
6
|
+
const s = Object.keys(t).filter((r) => t[r] !== void 0), n = Object.keys(e).filter((r) => e[r] !== void 0);
|
|
7
|
+
return s.length === n.length && s.every((r) => b(t[r], e[r]));
|
|
8
|
+
}
|
|
9
|
+
function y(t, e) {
|
|
10
|
+
if (!Object.hasOwn(t, e)) return;
|
|
11
|
+
const s = t[e];
|
|
12
|
+
return delete t[e], s;
|
|
13
|
+
}
|
|
14
|
+
function k(t) {
|
|
15
|
+
const e = customElements.get(t)?.runtimeVersion;
|
|
16
|
+
e !== h && console.warn(
|
|
17
|
+
`<${t}> is already defined by @draftably runtime ${e ?? "unknown"}; this copy (${h}) is not used. Install one copy of the runtime.`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function c(t, e, s) {
|
|
21
|
+
return t.dispatchEvent(
|
|
22
|
+
new CustomEvent(`draft-${e}`, {
|
|
23
|
+
detail: s,
|
|
24
|
+
bubbles: !0,
|
|
25
|
+
cancelable: A.includes(e)
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function w(t, e, s) {
|
|
30
|
+
return {
|
|
31
|
+
status: "error",
|
|
32
|
+
revision: t,
|
|
33
|
+
error: {
|
|
34
|
+
ok: !1,
|
|
35
|
+
reason: "environment",
|
|
36
|
+
diagnostics: [
|
|
37
|
+
{
|
|
38
|
+
code: "DRAFT_ELEMENT_MOUNT",
|
|
39
|
+
severity: "error",
|
|
40
|
+
message: e instanceof Error ? e.message : s,
|
|
41
|
+
itemIds: []
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function M(t, e, s) {
|
|
48
|
+
if (!("preventDefault" in s)) return void c(t, e, s);
|
|
49
|
+
const { preventDefault: n, ...r } = s;
|
|
50
|
+
c(t, e, r) || n();
|
|
51
|
+
}
|
|
52
|
+
function S(t, e, s) {
|
|
53
|
+
const n = t.ownerDocument, r = typeof HTMLSlotElement < "u" && "assign" in HTMLSlotElement.prototype, f = /* @__PURE__ */ new WeakMap();
|
|
54
|
+
let a = /* @__PURE__ */ new Map(), m = [];
|
|
55
|
+
const g = () => {
|
|
56
|
+
if (r)
|
|
57
|
+
for (const i of m) {
|
|
58
|
+
let o = f.get(i.el);
|
|
59
|
+
o || (o = n.createElement("slot"), i.el.append(o), f.set(i.el, o)), o.assign(...a.get(i.slot) ?? []);
|
|
60
|
+
}
|
|
61
|
+
}, u = () => {
|
|
62
|
+
const i = [...a.keys()].join(`
|
|
63
|
+
`);
|
|
64
|
+
a = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const o of t.childNodes) {
|
|
66
|
+
const l = o instanceof Element ? o.getAttribute("data-draft-slot") : null;
|
|
67
|
+
l ? a.set(l, [...a.get(l) ?? [], o]) : o instanceof Element || o instanceof Text && o.data.trim();
|
|
68
|
+
}
|
|
69
|
+
[...a.keys()].join(`
|
|
70
|
+
`) !== i && s([...a.keys()]), g();
|
|
71
|
+
}, p = new MutationObserver(u), _ = new MutationObserver((i) => {
|
|
72
|
+
i.some((o) => o.target.parentNode === t) && u();
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
start() {
|
|
76
|
+
p.observe(t, { childList: !0 }), _.observe(t, {
|
|
77
|
+
subtree: !0,
|
|
78
|
+
attributes: !0,
|
|
79
|
+
attributeFilter: ["data-draft-slot"]
|
|
80
|
+
}), a = /* @__PURE__ */ new Map(), u();
|
|
81
|
+
},
|
|
82
|
+
stop() {
|
|
83
|
+
p.disconnect(), _.disconnect();
|
|
84
|
+
},
|
|
85
|
+
/** The handle's targets changed: put each slot's children in its target. */
|
|
86
|
+
setAnchors(i) {
|
|
87
|
+
m = i, g();
|
|
88
|
+
},
|
|
89
|
+
names: () => [...a.keys()]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const d = "draft-editor";
|
|
93
|
+
typeof customElements < "u" && (customElements.get(d) ? k(d) : customElements.define(
|
|
94
|
+
d,
|
|
4
95
|
class extends HTMLElement {
|
|
96
|
+
static runtimeVersion = h;
|
|
5
97
|
static observedAttributes = ["source"];
|
|
6
98
|
editor;
|
|
99
|
+
_options = {};
|
|
100
|
+
_scheduled = !1;
|
|
7
101
|
/** The text last sent to or received from the editor, so an echo is not redrawn. */
|
|
8
102
|
last = "";
|
|
9
103
|
get source() {
|
|
@@ -12,25 +106,85 @@ typeof customElements < "u" && !customElements.get("draft-editor") && customElem
|
|
|
12
106
|
set source(t) {
|
|
13
107
|
this.setAttribute("source", String(t ?? ""));
|
|
14
108
|
}
|
|
109
|
+
get options() {
|
|
110
|
+
return this._options;
|
|
111
|
+
}
|
|
112
|
+
set options(t) {
|
|
113
|
+
const e = this._options;
|
|
114
|
+
this._options = t ?? {}, this.editor && !b(e.storageKey, this._options.storageKey) && (this._destroy(), this._schedule());
|
|
115
|
+
}
|
|
15
116
|
constructor() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
117
|
+
super();
|
|
118
|
+
const t = y(this, "source"), e = y(this, "options");
|
|
119
|
+
e && (this._options = e), t !== void 0 && this.setAttribute("source", String(t));
|
|
120
|
+
const s = this.attachShadow({ mode: "open", slotAssignment: "manual" });
|
|
121
|
+
this._root = this.ownerDocument.createElement("div"), this._root.style.cssText = "display:flex;flex-direction:column;height:100%;min-height:0", s.append(this._root), this._slotting = S(
|
|
122
|
+
this,
|
|
123
|
+
null,
|
|
124
|
+
(n) => this.editor?.anchor(n)
|
|
125
|
+
);
|
|
20
126
|
}
|
|
127
|
+
_root;
|
|
128
|
+
_slotting;
|
|
21
129
|
connectedCallback() {
|
|
22
|
-
this.
|
|
23
|
-
source: this.last,
|
|
24
|
-
onChange: (t) => {
|
|
25
|
-
this.last = t, this.dispatchEvent(new CustomEvent("draft-change", { detail: t, bubbles: !0 }));
|
|
26
|
-
}
|
|
27
|
-
});
|
|
130
|
+
this._slotting.start(), this._schedule();
|
|
28
131
|
}
|
|
29
|
-
|
|
30
|
-
|
|
132
|
+
/** Mount once, in a microtask, so every property a framework sets in this tick lands first. */
|
|
133
|
+
_schedule() {
|
|
134
|
+
this._scheduled || (this._scheduled = !0, queueMicrotask(() => {
|
|
135
|
+
this._scheduled = !1, this.isConnected && !this.editor && this._mount();
|
|
136
|
+
}));
|
|
31
137
|
}
|
|
32
|
-
|
|
138
|
+
_setStatus(t) {
|
|
139
|
+
this.setAttribute("status", t);
|
|
140
|
+
}
|
|
141
|
+
_mount() {
|
|
142
|
+
this.last = this.getAttribute("source") ?? "", this._setStatus("loading");
|
|
143
|
+
const t = () => this._options;
|
|
144
|
+
let e;
|
|
145
|
+
try {
|
|
146
|
+
e = E(this._root, {
|
|
147
|
+
source: this.last,
|
|
148
|
+
onChange: (s) => {
|
|
149
|
+
this.last = s, c(this, "change", { source: s });
|
|
150
|
+
},
|
|
151
|
+
get storageKey() {
|
|
152
|
+
return t().storageKey;
|
|
153
|
+
},
|
|
154
|
+
get openLink() {
|
|
155
|
+
return t().openLink;
|
|
156
|
+
},
|
|
157
|
+
get confirm() {
|
|
158
|
+
return t().confirm;
|
|
159
|
+
},
|
|
160
|
+
get onInteract() {
|
|
161
|
+
return t().onInteract;
|
|
162
|
+
},
|
|
163
|
+
get detail() {
|
|
164
|
+
return t().detail;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} catch (s) {
|
|
168
|
+
const n = w(1, s, "The diagram editor could not start."), r = n.error.diagnostics[0].message;
|
|
169
|
+
this._setStatus("error"), this.setAttribute("data-error", r), c(this, "update", n);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.editor = e;
|
|
173
|
+
for (const s of ["anchors", "diagnostics", "camera", "select", "contextmenu"])
|
|
174
|
+
e.on(s, (n) => M(this, s, n));
|
|
175
|
+
e.on("anchors", ({ anchors: s }) => this._slotting.setAnchors(s)), e.anchor(this._slotting.names()), e.ready.then(
|
|
176
|
+
() => this.editor === e && this._setStatus("ready"),
|
|
177
|
+
() => this.editor === e && this._setStatus("error")
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
attributeChangedCallback(t, e, s) {
|
|
181
|
+
!this.editor || s === null || s === this.last || (this.last = s, this.editor.update(s));
|
|
182
|
+
}
|
|
183
|
+
_destroy() {
|
|
33
184
|
this.editor?.destroy(), this.editor = void 0;
|
|
34
185
|
}
|
|
186
|
+
disconnectedCallback() {
|
|
187
|
+
this._slotting.stop(), this._destroy(), this.removeAttribute("status"), this.removeAttribute("data-error");
|
|
188
|
+
}
|
|
35
189
|
}
|
|
36
|
-
);
|
|
190
|
+
));
|