storyloco 2.0.1 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storyloco",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "A collection of slick Storyblok field plugins built with Svelte 5, TypeScript, and Tailwind CSS",
5
5
  "keywords": [
6
6
  "storyblok",
@@ -176,6 +176,23 @@ import type { ISbStoryData } from '@storyblok/js';`, "");
176
176
  // determine how many folders are in output_path
177
177
  const output_path_parts = out_dir.split("/");
178
178
  const import_path = output_path_parts.map(() => `..`).join("/");
179
+ // Replicates the storyblok CLI's `getComponentType` (no prefix/suffix), so these
180
+ // entries reference the interface names it generates below.
181
+ const type_name = (component) => {
182
+ const sanitized = component
183
+ .replace(/[^a-z0-9]/gi, "_")
184
+ .replace(/_+/g, "_")
185
+ .replace(/^_+|_+$/g, "");
186
+ const camel = sanitized
187
+ .replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
188
+ .replace(/_/g, "");
189
+ const pascal = camel ? camel[0].toUpperCase() + camel.slice(1) : camel;
190
+ return /^\d/.test(pascal) ? `_${pascal}` : pascal;
191
+ };
192
+ const content_types = new_components
193
+ .filter((component) => component.is_root)
194
+ .map((component) => component.name)
195
+ .sort();
179
196
  const header = `
180
197
  /**
181
198
  * AUTO-GENERATED FILE. DO NOT EDIT.
@@ -184,9 +201,23 @@ import type { ISbStoryData } from '@storyblok/js';`, "");
184
201
  */
185
202
 
186
203
  import type { StoryblokCustomPlugins } from "${import_path}/vite.config.js"
187
- import type { SbBlokData } from "@storyblok/svelte"
188
204
 
189
- export type Blok<T> = SbBlokData & T
205
+ /**
206
+ * No \`SbBlokData\` intersection: its string index signature would reject the
207
+ * generated interfaces, which (deliberately) declare no index signature.
208
+ */
209
+ export type Blok<T> = T & { component?: string; _uid?: string; _editable?: string }
210
+
211
+ /**
212
+ * Content-type (root) components keyed by component name — the bloks a story
213
+ * can be. The CLI types every component identically, so this comes from the
214
+ * space's component list instead.
215
+ */
216
+ export interface ContentTypes {
217
+ ${content_types.map((name) => `"${name}": ${type_name(name)}`).join("\n")}
218
+ }
219
+
220
+ export type ContentType = ContentTypes[keyof ContentTypes]
190
221
  `;
191
222
  let content = component_types.replace(`// This file was generated by the storyblok CLI.
192
223
  // DO NOT MODIFY THIS FILE BY HAND.`, header);
@@ -196,7 +196,10 @@ interface BlokFields {
196
196
  * </section>
197
197
  * ```
198
198
  */
199
- export declare function attrs<T extends BlokFields>(blok: SbBlokData & T): {
199
+ export declare function attrs<T extends BlokFields>(blok: T & {
200
+ _uid?: string;
201
+ _editable?: string;
202
+ }): {
200
203
  [x: symbol]: (node: HTMLElement) => void;
201
204
  id: string | undefined;
202
205
  };
@@ -186,6 +186,7 @@ export function handle_error(err) {
186
186
  export function attrs(blok) {
187
187
  return {
188
188
  [attach()](node) {
189
+ // SbBlokData is nominal ceremony here — editable only reads `_editable`.
189
190
  editable(node, blok);
190
191
  },
191
192
  id: blok.anchor || blok._uid,