@perkyzz/emvb 0.1.0 → 0.2.1

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 (154) hide show
  1. package/README.md +6 -4
  2. package/THIRD_PARTY_NOTICES.md +32 -0
  3. package/licenses/fontawesome-free.LICENSE +165 -0
  4. package/licenses/lucide-static.LICENSE +43 -0
  5. package/licenses/remixicon.LICENSE +201 -0
  6. package/licenses/tabler-icons.LICENSE +21 -0
  7. package/package.json +9 -5
  8. package/src/admin/api.ts +27 -0
  9. package/src/admin/content-api.ts +72 -9
  10. package/src/admin/editor/Editor.tsx +89 -14
  11. package/src/admin/editor/EditorOverlay.tsx +12 -0
  12. package/src/admin/editor/SmallScreenNotice.tsx +4 -3
  13. package/src/admin/editor/TopBar.tsx +76 -12
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
  15. package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
  16. package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
  17. package/src/admin/editor/canvas/canvas-events.ts +20 -7
  18. package/src/admin/editor/canvas/tab-reveal.ts +66 -0
  19. package/src/admin/editor/canvas/vnode-react.tsx +21 -1
  20. package/src/admin/editor/dialogs.tsx +39 -0
  21. package/src/admin/editor/dnd/drop-target.ts +63 -16
  22. package/src/admin/editor/dnd/new-element.ts +76 -1
  23. package/src/admin/editor/editor-css.ts +101 -15
  24. package/src/admin/editor/host.ts +30 -0
  25. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  26. package/src/admin/editor/icons/library.ts +243 -0
  27. package/src/admin/editor/icons/set-format.ts +29 -0
  28. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  29. package/src/admin/editor/icons/sets/lucide.json +1 -0
  30. package/src/admin/editor/icons/sets/remix.json +1 -0
  31. package/src/admin/editor/icons/sets/tabler.json +1 -0
  32. package/src/admin/editor/panels/AddPanel.tsx +7 -3
  33. package/src/admin/editor/panels/ClassesSection.tsx +44 -6
  34. package/src/admin/editor/panels/ColorControl.tsx +268 -21
  35. package/src/admin/editor/panels/ElementPanel.tsx +237 -93
  36. package/src/admin/editor/panels/LayersPanel.tsx +303 -66
  37. package/src/admin/editor/panels/LeftPanel.tsx +4 -0
  38. package/src/admin/editor/panels/PageSettings.tsx +134 -5
  39. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  40. package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
  41. package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
  42. package/src/admin/editor/panels/VariableSection.tsx +47 -9
  43. package/src/admin/editor/panels/color-space.ts +195 -0
  44. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  45. package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
  46. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  47. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  48. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  49. package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
  50. package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
  51. package/src/admin/editor/panels/settings/EffectsControls.tsx +25 -16
  52. package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
  53. package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
  54. package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
  55. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  56. package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
  57. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  58. package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
  59. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
  60. package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
  61. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  62. package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
  63. package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
  64. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  65. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  66. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  67. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  68. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  69. package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
  70. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  71. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  72. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  73. package/src/admin/editor/panels/settings/length-units.ts +40 -7
  74. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  75. package/src/admin/editor/panels/settings/style-sections.ts +114 -11
  76. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  77. package/src/admin/editor/panels/site-list.tsx +3 -0
  78. package/src/admin/editor/restore-deleted.ts +80 -0
  79. package/src/admin/editor/shortcuts.ts +1 -1
  80. package/src/admin/editor/store.ts +35 -7
  81. package/src/admin/editor/useEditorCommands.ts +66 -5
  82. package/src/admin/editor/useEditorData.ts +29 -3
  83. package/src/admin/editor/useEditorShortcuts.ts +34 -2
  84. package/src/admin/editor/useNodeActions.ts +68 -6
  85. package/src/admin/editor/useSave.ts +60 -3
  86. package/src/admin/entry-status.ts +19 -0
  87. package/src/admin/icon-uploads-api.ts +44 -0
  88. package/src/admin/pages/PageList.tsx +22 -2
  89. package/src/admin/pages/ThemePartList.tsx +23 -4
  90. package/src/admin/pages/list-kit.tsx +52 -2
  91. package/src/admin/setup/spec.ts +7 -0
  92. package/src/admin/theme-api.ts +61 -14
  93. package/src/admin/ui.ts +17 -4
  94. package/src/astro/EmVBPage.astro +28 -2
  95. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  96. package/src/astro/floats/index.ts +1 -0
  97. package/src/astro/floats/runtime.ts +78 -0
  98. package/src/astro/forms-definitions.ts +22 -0
  99. package/src/astro/index.ts +1 -0
  100. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  101. package/src/astro/menu/index.ts +1 -0
  102. package/src/astro/menu/runtime.ts +37 -0
  103. package/src/astro/popups/runtime.ts +54 -4
  104. package/src/astro/render.ts +47 -13
  105. package/src/astro/resolve-theme.ts +168 -24
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +25 -5
  108. package/src/astro/theme-posts.ts +19 -1
  109. package/src/constants.ts +1 -1
  110. package/src/core/arrange.ts +98 -10
  111. package/src/core/clipboard.ts +91 -9
  112. package/src/core/css/generate.ts +21 -4
  113. package/src/core/design/classes.ts +95 -9
  114. package/src/core/design/transfer.ts +101 -2
  115. package/src/core/design/variables.ts +51 -11
  116. package/src/core/elements/dynamic-elements.ts +57 -5
  117. package/src/core/elements/field-id.ts +6 -0
  118. package/src/core/elements/form-elements.ts +23 -8
  119. package/src/core/elements/index.ts +267 -49
  120. package/src/core/elements/menu.ts +190 -0
  121. package/src/core/forms/definition.ts +11 -0
  122. package/src/core/index.ts +67 -3
  123. package/src/core/limits.ts +2 -0
  124. package/src/core/migrate/index.ts +51 -1
  125. package/src/core/nesting.ts +51 -0
  126. package/src/core/render/context.ts +7 -0
  127. package/src/core/render/dynamic-post.ts +39 -11
  128. package/src/core/render/extras.ts +22 -3
  129. package/src/core/render/form.ts +134 -36
  130. package/src/core/render/index.ts +123 -25
  131. package/src/core/render/loop.ts +10 -3
  132. package/src/core/render/pagination.ts +76 -0
  133. package/src/core/render/section.ts +5 -1
  134. package/src/core/render/tabs.ts +8 -4
  135. package/src/core/render/vnode.ts +1 -1
  136. package/src/core/sanitize/css.ts +197 -17
  137. package/src/core/sanitize/embed-url.ts +64 -7
  138. package/src/core/sanitize/svg-upload.ts +203 -0
  139. package/src/core/sanitize/svg.ts +102 -21
  140. package/src/core/schema/descriptors.ts +4 -0
  141. package/src/core/schema/design.ts +7 -2
  142. package/src/core/schema/layout.ts +210 -19
  143. package/src/core/schema/style.ts +87 -8
  144. package/src/core/tabs/presence.ts +9 -0
  145. package/src/core/theme/conditions.ts +4 -1
  146. package/src/core/theme/dynamic.ts +10 -0
  147. package/src/core/theme/float.ts +113 -0
  148. package/src/core/theme/pagination.ts +97 -0
  149. package/src/core/theme/part-types.ts +2 -0
  150. package/src/core/theme/popup-markup.ts +3 -1
  151. package/src/core/theme/popup-rules.ts +4 -3
  152. package/src/server/hooks.ts +20 -0
  153. package/src/server/icon-routes.ts +79 -0
  154. package/src/server/plugin.ts +5 -1
@@ -0,0 +1,243 @@
1
+ import { getBundledIcon, sanitizeSvgMarkup } from "../../../core/index.ts";
2
+ import { serialize } from "../../../core/render/vnode.ts";
3
+ import type { UploadedIconItem } from "../../icon-uploads-api.ts";
4
+ import { fold } from "../../pages/list-kit.tsx";
5
+ import type { IconEntry, IconSetFile } from "./set-format.ts";
6
+
7
+ /**
8
+ * The Icon library (W-235): Lucide, Font Awesome Free, Tabler and Remix Icon, one lazily loaded
9
+ * JSON chunk per set (built by scripts/build-icon-sets.ts). Only the editor imports this; a picked
10
+ * icon is stored on the node as `iconId` + `iconSvg`, so public pages never load a set.
11
+ */
12
+ export type IconSetId = "lucide" | "fontawesome" | "tabler" | "remix";
13
+
14
+ type SetMeta = {
15
+ id: IconSetId;
16
+ label: string;
17
+ license: string;
18
+ styles: readonly { id: string; label: string; prefix: string }[];
19
+ };
20
+
21
+ /** What the sidebar shows before any set is loaded (checked against the set files in tests). */
22
+ export const ICON_SETS: readonly SetMeta[] = [
23
+ {
24
+ id: "lucide",
25
+ label: "Lucide",
26
+ license: "ISC",
27
+ styles: [{ id: "lucide", label: "Lucide", prefix: "lucide" }],
28
+ },
29
+ {
30
+ id: "fontawesome",
31
+ label: "Font Awesome",
32
+ license: "CC BY 4.0",
33
+ styles: [
34
+ { id: "solid", label: "Solid", prefix: "fa-solid" },
35
+ { id: "regular", label: "Regular", prefix: "fa-regular" },
36
+ { id: "brands", label: "Brands", prefix: "fa-brands" },
37
+ ],
38
+ },
39
+ {
40
+ id: "tabler",
41
+ label: "Tabler",
42
+ license: "MIT",
43
+ styles: [
44
+ { id: "outline", label: "Outline", prefix: "tabler" },
45
+ { id: "filled", label: "Filled", prefix: "tabler-filled" },
46
+ ],
47
+ },
48
+ {
49
+ id: "remix",
50
+ label: "Remix",
51
+ license: "Apache-2.0",
52
+ styles: [
53
+ { id: "line", label: "Line", prefix: "remix" },
54
+ { id: "fill", label: "Fill", prefix: "remix" },
55
+ ],
56
+ },
57
+ ];
58
+
59
+ /** A sidebar entry: everything, one set, or one style of a set. */
60
+ export type IconCategory = {
61
+ id: string;
62
+ label: string;
63
+ set?: IconSetId;
64
+ style?: string;
65
+ };
66
+
67
+ export const ALL_ICONS = "all";
68
+
69
+ /** W-239: the author's uploaded SVGs, stored as `upload:<id>`. */
70
+ export const UPLOADS = "uploads";
71
+ export const UPLOADS_CATEGORY: IconCategory = { id: UPLOADS, label: "My uploads" };
72
+ const UPLOAD_PREFIX = "upload:";
73
+
74
+ export const ICON_CATEGORIES: readonly IconCategory[] = [
75
+ { id: ALL_ICONS, label: "All icons" },
76
+ ...ICON_SETS.flatMap((set): IconCategory[] => [
77
+ { id: set.id, label: set.label, set: set.id },
78
+ ...(set.styles.length > 1
79
+ ? set.styles.map((style) => ({
80
+ id: `${set.id}/${style.id}`,
81
+ label: style.label,
82
+ set: set.id,
83
+ style: style.id,
84
+ }))
85
+ : []),
86
+ ]),
87
+ ];
88
+
89
+ /** One icon as the picker shows it. */
90
+ export type LibraryIcon = {
91
+ /** Stored as the node's iconId: `${prefix}:${name}`. */
92
+ id: string;
93
+ set: IconSetId | typeof UPLOADS;
94
+ setLabel: string;
95
+ style: string;
96
+ styleLabel: string;
97
+ name: string;
98
+ label: string;
99
+ /** Folded label, name, tags, set and style, for the word search. */
100
+ haystack: string;
101
+ /** Folded label and name only, to rank icons named for a search above icons tagged with it. */
102
+ named: string;
103
+ /** The complete `<svg>` stored on the node and shown in the tile. */
104
+ markup: string;
105
+ };
106
+
107
+ const LOADERS: Record<IconSetId, () => Promise<{ default: unknown }>> = {
108
+ lucide: () => import("./sets/lucide.json"),
109
+ fontawesome: () => import("./sets/fontawesome.json"),
110
+ tabler: () => import("./sets/tabler.json"),
111
+ remix: () => import("./sets/remix.json"),
112
+ };
113
+
114
+ const attrText = (attrs: Record<string, string>) =>
115
+ Object.entries(attrs)
116
+ .map(([name, value]) => ` ${name}="${value}"`)
117
+ .join("");
118
+
119
+ /** The icons of one set file, ready for the grid. */
120
+ function iconsOf(file: IconSetFile): LibraryIcon[] {
121
+ const styles = file.styles.map((style) => ({ style, root: attrText(style.attrs) }));
122
+ return file.icons.map((entry: IconEntry) => {
123
+ const [name, styleIndex, label, body, tags] = entry;
124
+ const picked = styles[styleIndex] ?? styles[0];
125
+ if (!picked) throw new Error(`EmVB: icon set ${file.id} has no styles`);
126
+ const { style, root } = picked;
127
+ const viewBox = entry[5] ?? style.viewBox;
128
+ return {
129
+ id: `${style.prefix}:${name}`,
130
+ set: file.id as IconSetId,
131
+ setLabel: file.label,
132
+ style: style.id,
133
+ styleLabel: style.label,
134
+ name,
135
+ label,
136
+ haystack: fold(`${label} ${name.replaceAll("-", " ")} ${tags} ${file.label} ${style.label}`),
137
+ named: fold(`${label} | ${name.replaceAll("-", " ")}`),
138
+ markup: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}"${root}>${body}</svg>`,
139
+ };
140
+ });
141
+ }
142
+
143
+ const loaded = new Map<IconSetId, Promise<LibraryIcon[]>>();
144
+
145
+ /** Loads a set once (a separate chunk the first time); later calls share the result. */
146
+ export function loadIconSet(id: IconSetId): Promise<LibraryIcon[]> {
147
+ let pending = loaded.get(id);
148
+ if (!pending) {
149
+ pending = LOADERS[id]().then((mod) => iconsOf(mod.default as IconSetFile));
150
+ // A failed load (offline, chunk gone after a deploy) can be tried again.
151
+ pending.catch(() => loaded.delete(id));
152
+ loaded.set(id, pending);
153
+ }
154
+ return pending;
155
+ }
156
+
157
+ /** The sets a category needs. */
158
+ export const setsFor = (category: IconCategory): IconSetId[] =>
159
+ category.set ? [category.set] : ICON_SETS.map((set) => set.id);
160
+
161
+ /**
162
+ * Icons in a category matching the search: every word, any order (as W-217), case and accents
163
+ * aside. With a search, icons named for it come first ("heart": Heart, then Heart off, then icons
164
+ * only tagged heart); each group keeps the sets' order.
165
+ */
166
+ export function filterIcons(
167
+ icons: readonly LibraryIcon[],
168
+ category: IconCategory,
169
+ query: string,
170
+ ): LibraryIcon[] {
171
+ const words = fold(query).split(/\s+/).filter(Boolean);
172
+ const matched = icons.filter(
173
+ (icon) =>
174
+ (!category.set || icon.set === category.set) &&
175
+ (!category.style || icon.style === category.style) &&
176
+ words.every((word) => icon.haystack.includes(word)),
177
+ );
178
+ if (words.length === 0) return matched;
179
+ const phrase = words.join(" ");
180
+ const rank = (icon: LibraryIcon) => {
181
+ const [label, name] = icon.named.split(" | ");
182
+ if (label === phrase || name === phrase) return 0;
183
+ return words.every((word) => icon.named.includes(word)) ? 1 : 2;
184
+ };
185
+ const ranks = new Map(matched.map((icon) => [icon, rank(icon)]));
186
+ // toSorted is stable, so each rank keeps the sets' order.
187
+ return matched.toSorted((a, b) => (ranks.get(a) ?? 2) - (ranks.get(b) ?? 2));
188
+ }
189
+
190
+ const SET_OF_PREFIX = new Map<string, IconSetId>(
191
+ ICON_SETS.flatMap((set) => set.styles.map((style) => [style.prefix, set.id] as const)),
192
+ );
193
+
194
+ /**
195
+ * Where a stored iconId lives: `fa-solid:rocket` → Font Awesome, Solid. A bundled id from before
196
+ * the library ("star") is the Lucide icon of the same name.
197
+ */
198
+ export function locateIcon(
199
+ iconId: string,
200
+ ): { set: IconSetId | typeof UPLOADS; style: string; id: string } | undefined {
201
+ if (iconId.startsWith(UPLOAD_PREFIX)) return { set: UPLOADS, style: UPLOADS, id: iconId };
202
+ const colon = iconId.indexOf(":");
203
+ if (colon < 0)
204
+ return getBundledIcon(iconId)
205
+ ? { set: "lucide", style: "lucide", id: `lucide:${iconId}` }
206
+ : undefined;
207
+ const prefix = iconId.slice(0, colon);
208
+ const set = SET_OF_PREFIX.get(prefix);
209
+ if (!set) return undefined;
210
+ const styles = ICON_SETS.find((item) => item.id === set)?.styles ?? [];
211
+ const style =
212
+ set === "remix"
213
+ ? iconId.endsWith("-fill")
214
+ ? "fill"
215
+ : "line"
216
+ : (styles.find((item) => item.prefix === prefix)?.id ?? set);
217
+ return { set, style, id: iconId };
218
+ }
219
+
220
+ /**
221
+ * Uploaded icons as grid tiles (W-239). The server stored them sanitized; they are sanitized
222
+ * again here before the tile shows them, and one that no longer passes is left out.
223
+ */
224
+ export function uploadedIcons(items: readonly UploadedIconItem[]): LibraryIcon[] {
225
+ return items.flatMap((item): LibraryIcon[] => {
226
+ const tree = sanitizeSvgMarkup(item.svg);
227
+ if (!tree) return [];
228
+ return [
229
+ {
230
+ id: `${UPLOAD_PREFIX}${item.id}`,
231
+ set: UPLOADS,
232
+ setLabel: UPLOADS_CATEGORY.label,
233
+ style: UPLOADS,
234
+ styleLabel: UPLOADS_CATEGORY.label,
235
+ name: item.id,
236
+ label: item.name,
237
+ haystack: fold(item.name),
238
+ named: fold(`${item.name} | ${item.id}`),
239
+ markup: serialize(tree),
240
+ },
241
+ ];
242
+ });
243
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The Icon library set files (W-234): one JSON per set in ./sets, built by
3
+ * `scripts/build-icon-sets.ts` from the pinned icon packages and loaded lazily by the editor.
4
+ */
5
+ export type IconSetStyle = {
6
+ /** Sidebar sub-item id inside the set ("solid", "outline"…). */
7
+ id: string;
8
+ label: string;
9
+ /** The stored icon id is `${prefix}:${name}` ("fa-solid:rocket", "lucide:rocket"). */
10
+ prefix: string;
11
+ /** viewBox used when an icon doesn't carry its own. */
12
+ viewBox: string;
13
+ /** Root `<svg>` presentation attributes (stroke or fill style). */
14
+ attrs: Record<string, string>;
15
+ };
16
+
17
+ /** `[name, style index, label, inner SVG markup, search tags, viewBox?]` */
18
+ export type IconEntry =
19
+ | [string, number, string, string, string]
20
+ | [string, number, string, string, string, string];
21
+
22
+ export type IconSetFile = {
23
+ id: string;
24
+ label: string;
25
+ version: string;
26
+ license: string;
27
+ styles: IconSetStyle[];
28
+ icons: IconEntry[];
29
+ };