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