uncial 0.0.4 → 0.0.6

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.
@@ -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 ?? {});
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ import SunIcon from 'phosphor-svelte/lib/SunIcon';
3
+ import MoonIcon from 'phosphor-svelte/lib/MoonIcon';
4
+ import MonitorIcon from 'phosphor-svelte/lib/MonitorIcon';
5
+ import { theme } from './theme.svelte.js';
6
+
7
+ $effect(() => {
8
+ theme.init();
9
+ });
10
+
11
+ const labels: Record<typeof theme.mode, string> = {
12
+ system: 'System theme (auto)',
13
+ light: 'Light theme',
14
+ dark: 'Dark theme',
15
+ };
16
+ </script>
17
+
18
+ <button
19
+ type="button"
20
+ class="btn btn-ghost btn-sm btn-square"
21
+ onclick={() => theme.cycle()}
22
+ aria-label={labels[theme.mode]}
23
+ title={labels[theme.mode]}
24
+ >
25
+ {#if theme.mode === 'light'}
26
+ <SunIcon size={18} weight="bold" />
27
+ {:else if theme.mode === 'dark'}
28
+ <MoonIcon size={18} weight="bold" />
29
+ {:else}
30
+ <MonitorIcon size={18} weight="bold" />
31
+ {/if}
32
+ </button>
@@ -0,0 +1,3 @@
1
+ declare const ThemeSwitcher: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type ThemeSwitcher = ReturnType<typeof ThemeSwitcher>;
3
+ export default ThemeSwitcher;
@@ -0,0 +1,8 @@
1
+ type ThemeMode = 'system' | 'light' | 'dark';
2
+ export declare const theme: {
3
+ readonly mode: ThemeMode;
4
+ apply: () => void;
5
+ cycle: () => void;
6
+ init: () => void;
7
+ };
8
+ export {};
@@ -0,0 +1,56 @@
1
+ const STORAGE_KEY = 'uncial-theme';
2
+ function createThemeState() {
3
+ let mode = $state('system');
4
+ function load() {
5
+ if (typeof window === 'undefined')
6
+ return 'system';
7
+ const stored = localStorage.getItem(STORAGE_KEY);
8
+ if (stored === 'light' || stored === 'dark' || stored === 'system')
9
+ return stored;
10
+ return 'system';
11
+ }
12
+ function apply() {
13
+ if (typeof document === 'undefined')
14
+ return;
15
+ const root = document.documentElement;
16
+ if (mode === 'light') {
17
+ root.dataset.theme = 'vellum';
18
+ }
19
+ else if (mode === 'dark') {
20
+ root.dataset.theme = 'vellum-dark';
21
+ }
22
+ else {
23
+ delete root.dataset.theme;
24
+ }
25
+ }
26
+ function save() {
27
+ if (typeof localStorage === 'undefined')
28
+ return;
29
+ localStorage.setItem(STORAGE_KEY, mode);
30
+ }
31
+ function cycle() {
32
+ if (mode === 'system')
33
+ mode = 'light';
34
+ else if (mode === 'light')
35
+ mode = 'dark';
36
+ else
37
+ mode = 'system';
38
+ apply();
39
+ save();
40
+ }
41
+ function init() {
42
+ if (typeof window === 'undefined')
43
+ return;
44
+ mode = load();
45
+ apply();
46
+ }
47
+ return {
48
+ get mode() {
49
+ return mode;
50
+ },
51
+ apply,
52
+ cycle,
53
+ init,
54
+ };
55
+ }
56
+ export const theme = createThemeState();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uncial",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "packageManager": "bun@1.3.10",
5
5
  "license": "MIT",
6
6
  "repository": {