uncial 0.0.3 → 0.0.5

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 CHANGED
@@ -6,8 +6,8 @@ Uncial is a backend-agnostic block editor built on Tiptap. It turns a normal fro
6
6
 
7
7
  Custom blocks can stay atomic or declare one default child content region for nested document flow.
8
8
 
9
- ![screenshot of the Uncial richtext and block editorwith a callout component selected](.github/images/image.png)
10
-
9
+ ![screenshot of the Uncial richtext and block editorwith a callout component selected](.github/images/basic%20editor.png)
10
+ ![screen recording demonstrating editing main page text and custom components](.github/images/basic%20text%20and%20component%20editing.gif)
11
11
  ## What ships today
12
12
 
13
13
  - Shared block definitions for editor and renderer
@@ -3,7 +3,7 @@ import type { NormalizedBlockComponentDefinition } from './runtime.js';
3
3
  export type AttrValidator<T> = (value: unknown) => value is T;
4
4
  export type AttrParser<T> = (value: unknown) => T | undefined;
5
5
  export type AttrSerializer = (value: unknown) => unknown;
6
- export type AttributeInputKind = 'text' | 'textarea' | 'number' | 'checkbox' | 'json' | 'richtext' | 'select';
6
+ export type AttributeInputKind = 'text' | 'textarea' | 'number' | 'checkbox' | 'json' | 'richtext' | 'select' | 'hidden' | (string & {});
7
7
  export interface AttributeOption<T> {
8
8
  value: T;
9
9
  label?: string;
@@ -93,6 +93,29 @@
93
93
  }
94
94
  }
95
95
 
96
+ function chooseCustomAttribute(name: string, inputKind: string): void {
97
+ window.dispatchEvent(
98
+ new CustomEvent('uncial:choose-attribute', {
99
+ detail: {
100
+ inputKind,
101
+ name,
102
+ attrs: controllerState.draftAttrs,
103
+ setAttrs: (attrs: Record<string, unknown>) => {
104
+ for (const [key, value] of Object.entries(attrs)) {
105
+ controller.setDraftAttr(key, value);
106
+ }
107
+ }
108
+ }
109
+ })
110
+ );
111
+ }
112
+
113
+ function isBuiltInInputKind(inputKind: string): boolean {
114
+ return ['checkbox', 'number', 'richtext', 'select', 'textarea', 'json', 'text', 'hidden'].includes(
115
+ inputKind
116
+ );
117
+ }
118
+
96
119
  function startChildDrag(event: PointerEvent, index: number): void {
97
120
  event.stopPropagation();
98
121
  draggingChildIndex = index;
@@ -150,11 +173,24 @@
150
173
  </p>
151
174
  {#each selectedAttributeSpecs as [name, spec] (name)}
152
175
  {@const inputKind = inferAttributeInputKind(spec)}
176
+ {#if inputKind === 'hidden'}
177
+ {@const _hidden = null}
178
+ {:else}
153
179
  <div class="form-control mb-3 grid gap-1">
154
180
  <span class="label-text text-xs font-semibold uppercase tracking-wide opacity-70"
155
181
  >{name}</span
156
182
  >
157
- {#if inputKind === 'checkbox'}
183
+ {#if !isBuiltInInputKind(inputKind)}
184
+ <button
185
+ type="button"
186
+ class="btn btn-outline btn-sm justify-start"
187
+ onclick={() => chooseCustomAttribute(name, inputKind)}
188
+ >
189
+ {controllerState.draftAttrs[name]
190
+ ? `Change ${name}: ${controllerState.draftAttrs[name]}`
191
+ : `Choose ${name}`}
192
+ </button>
193
+ {:else if inputKind === 'checkbox'}
158
194
  <input
159
195
  class="checkbox checkbox-sm"
160
196
  type="checkbox"
@@ -224,6 +260,7 @@
224
260
  <span class="text-xs text-error">{controllerState.validationErrors[name]}</span>
225
261
  {/if}
226
262
  </div>
263
+ {/if}
227
264
  {/each}
228
265
  <div
229
266
  class="sticky -bottom-4 flex flex-wrap items-center justify-between gap-2 bg-base-100 pt-3"
@@ -10,6 +10,7 @@
10
10
  blockId: string;
11
11
  label: string;
12
12
  draggable?: boolean;
13
+ updateAttributes?: (attrs: Record<string, unknown>) => void;
13
14
  onActivate?: () => void;
14
15
  }
15
16
 
@@ -27,6 +28,7 @@
27
28
  blockId,
28
29
  label,
29
30
  draggable = true,
31
+ updateAttributes,
30
32
  onActivate
31
33
  }: Props = $props();
32
34
 
@@ -35,7 +37,8 @@
35
37
  const componentProps = $derived({
36
38
  ...attrs,
37
39
  content,
38
- children
40
+ children,
41
+ updateAttributes
39
42
  });
40
43
 
41
44
  function handleActivationPointerDown(event: PointerEvent): void {
@@ -7,6 +7,7 @@ interface Props {
7
7
  blockId: string;
8
8
  label: string;
9
9
  draggable?: boolean;
10
+ updateAttributes?: (attrs: Record<string, unknown>) => void;
10
11
  onActivate?: () => void;
11
12
  }
12
13
  declare const BlockNodeView: Component<Props, {}, "">;
@@ -81,6 +81,7 @@
81
81
  {@const RenderComponent = getSvelteRenderComponent(block.components.render.component)}
82
82
  <RenderComponent
83
83
  {...blockAttrs}
84
+ {...((block as unknown as { renderProps?: Record<string, unknown> }).renderProps ?? {})}
84
85
  content={blockContent}
85
86
  children={block.content ? blockChildren : undefined}
86
87
  />
@@ -19,7 +19,7 @@ function safeParseJSON(raw) {
19
19
  export function getBlockDefaultAttrs(block) {
20
20
  return normalizeBlockAttributes(block, {});
21
21
  }
22
- function mountBlockEditorComponent(block, node, container, contentDOM, mounted, onActivate, getPos) {
22
+ function mountBlockEditorComponent(block, node, container, contentDOM, mounted, editor, onActivate, getPos) {
23
23
  mounted?.destroy();
24
24
  const createEditorMount = block.components.editor.plugin.createEditorMount;
25
25
  if (!createEditorMount) {
@@ -36,6 +36,7 @@ function mountBlockEditorComponent(block, node, container, contentDOM, mounted,
36
36
  blockId: block.id,
37
37
  label: block.label,
38
38
  draggable: block.behaviors.draggable ?? true,
39
+ updateAttributes: (attrs) => editor?.chain().focus().updateAttributes(block.id, attrs).run(),
39
40
  onActivate: getPos && onActivate ? () => onActivate(getPos()) : undefined
40
41
  }
41
42
  });
@@ -50,7 +51,7 @@ function isInteractiveNodeViewEvent(event) {
50
51
  return false;
51
52
  return Boolean(target.closest('input, textarea, select, button:not([data-drag-handle]), a[href]'));
52
53
  }
53
- function createBlockNodeView(block, node, getPos, onActivate) {
54
+ function createBlockNodeView(block, node, getPos, onActivate, editor) {
54
55
  const dom = document.createElement(block.behaviors.inline ? 'span' : 'div');
55
56
  dom.className = 'uncial-nodeview';
56
57
  dom.dataset.uncialBlockId = block.id;
@@ -69,7 +70,7 @@ function createBlockNodeView(block, node, getPos, onActivate) {
69
70
  contentDOM.className = 'uncial-nodeview-content';
70
71
  }
71
72
  let mounted = null;
72
- mounted = mountBlockEditorComponent(block, node, dom, contentDOM, mounted, onActivate, getPos);
73
+ mounted = mountBlockEditorComponent(block, node, dom, contentDOM, mounted, editor, onActivate, getPos);
73
74
  syncBlockPosition();
74
75
  return {
75
76
  dom,
@@ -84,7 +85,7 @@ function createBlockNodeView(block, node, getPos, onActivate) {
84
85
  return true;
85
86
  }
86
87
  lastAttrs = nextAttrs;
87
- mounted = mountBlockEditorComponent(block, nextNode, dom, contentDOM, mounted, onActivate, getPos);
88
+ mounted = mountBlockEditorComponent(block, nextNode, dom, contentDOM, mounted, editor, onActivate, getPos);
88
89
  return true;
89
90
  },
90
91
  stopEvent(event) {
@@ -145,7 +146,7 @@ function createBlockNodeExtension(block, containerContentExpression, onActivate)
145
146
  return [{ tag: block.html?.parseTag ?? `div[data-uncial-block="${block.id}"]` }];
146
147
  },
147
148
  addNodeView() {
148
- return ({ node, getPos }) => createBlockNodeView(block, node, getPos, onActivate);
149
+ return ({ node, getPos, editor }) => createBlockNodeView(block, node, getPos, onActivate, editor);
149
150
  },
150
151
  renderHTML({ HTMLAttributes, node }) {
151
152
  const normalizedAttrs = normalizeBlockAttributes(block, node.attrs ?? {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uncial",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "packageManager": "bun@1.3.10",
5
5
  "license": "MIT",
6
6
  "repository": {