@aphexcms/visual-editing 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.
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/lib/core.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CACR,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KACjD,IAAI,CAAC;IACV;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAuDD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,IAAI,CA+OhF"}
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/lib/core.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CACR,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KACjD,IAAI,CAAC;IACV;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAuDD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,IAAI,CAkPhF"}
package/dist/core.js CHANGED
@@ -161,7 +161,10 @@ export function enableAphexPreview(options = {}) {
161
161
  }
162
162
  function showOn(el) {
163
163
  activeEl = el;
164
- label.textContent = el.dataset.aphexField ?? '';
164
+ // Show the row number for a list entry — several rows of one list otherwise all
165
+ // hover as the same bare field name, with nothing to say which slot is which.
166
+ const idx = el.dataset.aphexArrayIndex;
167
+ label.textContent = (el.dataset.aphexField ?? '') + (idx != null ? `[${idx}]` : '');
165
168
  positionOn(el);
166
169
  overlay.style.display = 'block';
167
170
  }
@@ -29,6 +29,13 @@ export interface PreviewApi {
29
29
  readonly inPreview: boolean;
30
30
  /** The live document pushed by the editor, or `null` outside preview. */
31
31
  readonly document: Record<string, unknown> | null;
32
+ /**
33
+ * Schema type of the document currently open in the editor, or `null` outside preview.
34
+ * Use it when one page is reachable from several document types and an element should
35
+ * behave differently depending on which one is being edited — e.g. a menu row that
36
+ * reveals its slot in the open menu's list, but opens the dish when a dish is open.
37
+ */
38
+ readonly documentType: string | null;
32
39
  /** The live document merged over your server fallback: `const post = $derived(ve.live(data.post))`. */
33
40
  live<T>(fallback: T, options?: {
34
41
  type?: string;
@@ -41,19 +48,27 @@ export interface PreviewApi {
41
48
  */
42
49
  encode(value: string | null | undefined, payload?: EncodePayload): string;
43
50
  /**
44
- * Make any element click-to-edit a *specific* document — for app-level references
45
- * that aren't stored in the current document (e.g. an app-queried "list of posts"
46
- * block). Spread the returned attributes onto the element; clicking it in preview
47
- * opens that document in the studio. Returns `{}` outside preview.
51
+ * Make any element click-to-edit, for content the current document's own stega can't
52
+ * mark up. Spread the returned attributes onto the element; returns `{}` outside preview.
53
+ *
54
+ * Two targets, chosen by whether `id`/`type` are given:
55
+ * - **Another document** (`{ id, type }`) — an app-level reference not stored in the
56
+ * document being edited (e.g. an app-queried "list of posts" block). Clicking opens
57
+ * that document in the studio.
58
+ * - **A field of the open document** (`{ field, arrayIndex }`) — clicking reveals that
59
+ * field, and with `arrayIndex` the specific row, in the form pane. Use this for a
60
+ * list whose entries are references: revealing the row is what lets the author
61
+ * reorder or remove it, which opening the referenced document does not.
48
62
  *
49
63
  * @example
50
- * // {#each posts as post}
51
- * // <a href="/blog/{post.slug}" {...ve.edit({ id: post.id, type: 'blog_post' })}>…</a>
64
+ * // {...ve.edit({ id: post.id, type: 'blog_post' })} → opens that post
65
+ * // {...ve.edit({ field: 'items', arrayIndex: i })} → reveals row i of `items`
52
66
  */
53
67
  edit(target: {
54
- id: string;
55
- type: string;
68
+ id?: string;
69
+ type?: string;
56
70
  field?: string;
71
+ arrayIndex?: number;
57
72
  }): Record<string, string>;
58
73
  /**
59
74
  * Resolve an image field to `{ src, alt }` in one call — destructure it:
@@ -1 +1 @@
1
- {"version":3,"file":"use-preview.svelte.d.ts","sourceRoot":"","sources":["../src/lib/use-preview.svelte.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAI5D;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAEzE;AAED;gEACgE;AAChE,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAElD,KAAK,SAAS,GACX;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACvE,IAAI,GACJ,SAAS,CAAC;AAEb,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC7B,yDAAyD;IACzD,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,yEAAyE;IACzE,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,UAAU;IAC1B,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAClD,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,WAAW,aAAa;IAC7B,yDAAyD;IACzD,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,yEAAyE;IACzE,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,UAAU;IAC1B,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAClD;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,uGAAuG;IACvG,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,CAAC,CAAC;IAClE;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;IAC1E;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,MAAM,EAAE;QACZ,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,aAAa,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,IAAI,UAAU,CAmDvC"}
@@ -32,6 +32,9 @@ export function usePreview() {
32
32
  get document() {
33
33
  return ctx.current;
34
34
  },
35
+ get documentType() {
36
+ return ctx.currentType;
37
+ },
35
38
  live(fallback, options = {}) {
36
39
  if (options.type && ctx.currentType !== options.type)
37
40
  return fallback;
@@ -52,11 +55,19 @@ export function usePreview() {
52
55
  const attrs = {};
53
56
  if (ctx.current == null)
54
57
  return attrs; // not in preview — no attributes
55
- // `data-aphex-field` is what the overlay keys on to make an element clickable;
56
- // the id/type route the click to that document (the studio opens it).
58
+ // `data-aphex-field` is what the overlay keys on to make an element clickable,
59
+ // so it is always set. Adding id/type routes the click to *that* document (the
60
+ // studio opens it); leaving them off keeps the click on the open document, where
61
+ // `arrayIndex` picks out a single row. Both are only emitted together — the
62
+ // studio treats a cross-document click as such only when it has each half.
57
63
  attrs['data-aphex-field'] = target.field ?? 'title';
58
- attrs['data-aphex-document-id'] = target.id;
59
- attrs['data-aphex-document-type'] = target.type;
64
+ if (target.id && target.type) {
65
+ attrs['data-aphex-document-id'] = target.id;
66
+ attrs['data-aphex-document-type'] = target.type;
67
+ }
68
+ if (target.arrayIndex != null) {
69
+ attrs['data-aphex-array-index'] = String(target.arrayIndex);
70
+ }
60
71
  return attrs;
61
72
  },
62
73
  image(img) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aphexcms/visual-editing",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Visual editing overlay for AphexCMS — add click-to-edit overlays to your frontend",
5
5
  "license": "MIT",
6
6
  "publishConfig": {