@storyblok/live-preview 0.2.0 → 0.3.0-alpha.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/dist/index.d.cts CHANGED
@@ -1097,17 +1097,37 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
1097
1097
  type Override<T, U> = Prettify<Omit<T, keyof U> & U>;
1098
1098
  //#endregion
1099
1099
  //#region src/generated/types/block.d.ts
1100
- /** Wire form: the MAPI object map keyed by field name. This is what `defineBlock` returns. */
1101
- type BlockSchema = Record<string, Field & {
1100
+ /**
1101
+ * Ordered array of named fields — the content-shape DSL form `defineBlock`
1102
+ * accepts and returns. A field's position in the array sets the order it appears
1103
+ * in the editor (mapped to the wire `pos` on push).
1104
+ */
1105
+ type BlockFields = ReadonlyArray<Field & {
1106
+ name: string;
1107
+ pos?: number;
1102
1108
  required?: boolean;
1103
1109
  }>;
1104
- /** A Storyblok block. */
1105
- type Block<TName extends string = string, TBlockSchema extends BlockSchema = BlockSchema, TIsRoot extends boolean = boolean, TIsNestable extends boolean = boolean, TComponentGroupUuid extends string | null = string | null> = Override<Component, {
1110
+ /**
1111
+ * A Storyblok block: a named, ordered set of content fields. Uses the
1112
+ * content-shape DSL `fields` array rather than the MAPI wire `schema` record.
1113
+ */
1114
+ type Block<TName extends string = string, TFields extends BlockFields = BlockFields, TIsRoot extends boolean = boolean, TIsNestable extends boolean = boolean> = Override<Omit<Component, 'schema' | 'component_group_uuid'>, {
1106
1115
  name: TName;
1107
- schema: TBlockSchema;
1116
+ fields: TFields;
1108
1117
  is_root?: TIsRoot;
1109
1118
  is_nestable?: TIsNestable;
1110
- component_group_uuid?: TComponentGroupUuid;
1119
+ /**
1120
+ * Escape hatch for pinning this block to a Storyblok UI-managed component
1121
+ * group by UUID. Component groups are normally maintained in code via the
1122
+ * schema directory layout; set this only if you intentionally manage groups
1123
+ * in the Storyblok UI, and fill in the group UUID yourself. When set,
1124
+ * `schema push` diffs it and sends it to the Management API; when omitted,
1125
+ * the block's remote group is left untouched.
1126
+ *
1127
+ * @deprecated Prefer maintaining component groups in code through the
1128
+ * directory layout.
1129
+ */
1130
+ component_group_uuid?: string | null;
1111
1131
  }>;
1112
1132
  /**
1113
1133
  * A root {@link Block} (`is_root: true`). Given a union of blocks, narrows to
@@ -1128,21 +1148,28 @@ type RootBlock<T extends Block = Block & {
1128
1148
  type NoBlocks$1 = false;
1129
1149
  /** True when `T` is the un-narrowed base `Block` (i.e. no specific block was supplied). */
1130
1150
  type IsBaseBlock<T> = [Block] extends [T] ? true : false;
1131
- type RequiredFieldKeys<T> = { [K in keyof T]: T[K] extends {
1151
+ /**
1152
+ * Maps a block's ordered `fields` array to its read content object, splitting
1153
+ * required (`required: true`) from optional fields. Each `F` is a member of the
1154
+ * field union, so it provably satisfies `FieldValue`'s `Field` constraint.
1155
+ */
1156
+ type ContentFields<TFields extends BlockFields, TBlocks> = Prettify<{ [F in TFields[number] as F extends {
1157
+ required: true;
1158
+ } ? F['name'] : never]: FieldValue<F, TBlocks> } & { [F in TFields[number] as F extends {
1132
1159
  required: true;
1133
- } ? K : never }[keyof T];
1134
- type OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;
1160
+ } ? never : F['name']]?: FieldValue<F, TBlocks> | null }>;
1161
+ /** Input (write) variant of {@link ContentFields}, resolving each field via {@link FieldValueInput}. */
1135
1162
  /**
1136
1163
  * Content object for a single block instance as returned by the Storyblok
1137
1164
  * Content Delivery API. Without a `TBlock` argument, this is the loose
1138
1165
  * runtime shape (any block, `_editable` optional). With a schema-typed
1139
- * `TBlock`, fields are narrowed per the block's schema.
1166
+ * `TBlock`, fields are narrowed per the block's `fields`.
1140
1167
  */
1141
1168
  type BlockContent<TBlock extends Block = Block, TBlocks = NoBlocks$1> = IsBaseBlock<TBlock> extends true ? BlockContentBase : TBlock extends any ? Prettify<{
1142
1169
  _uid: string;
1143
1170
  component: TBlock['name'];
1144
1171
  _editable?: string;
1145
- } & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> | null }> : never;
1172
+ } & ContentFields<TBlock['fields'], TBlocks>> : never;
1146
1173
  interface FieldTypeValueMap {
1147
1174
  text: string;
1148
1175
  textarea: string;
@@ -1167,15 +1194,15 @@ type IsNestable<T> = T extends {
1167
1194
  } ? false : T extends {
1168
1195
  is_nestable: true;
1169
1196
  } ? true : true;
1170
- type ApplyWhitelist<TField, TBlocks> = TField extends {
1171
- component_whitelist: ReadonlyArray<infer TWhitelisted extends string>;
1197
+ type ApplyAllow<TField, TBlocks> = TField extends {
1198
+ allow: ReadonlyArray<infer TAllowed extends string>;
1172
1199
  } ? Extract<TBlocks, {
1173
- name: TWhitelisted;
1200
+ name: TAllowed;
1174
1201
  }> : TBlocks extends any ? IsNestable<TBlocks> extends true ? TBlocks : never : never;
1175
1202
  /** Resolves a field definition to its runtime content value type (read). */
1176
1203
  type FieldValue<TField extends Field = Field, TBlocks = NoBlocks$1> = Prettify<TField extends {
1177
1204
  type: 'bloks';
1178
- } ? [TBlocks] extends [never] ? BlockContentBase[] : [TBlocks] extends [Block] ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlockContentBase[] : FieldTypeValueMap[TField['type']]>;
1205
+ } ? [TBlocks] extends [never] ? BlockContentBase[] : [TBlocks] extends [Block] ? BlockContent<ApplyAllow<TField, TBlocks>, TBlocks>[] : BlockContentBase[] : FieldTypeValueMap[TField['type']]>;
1179
1206
  //#endregion
1180
1207
  //#region src/editable.d.ts
1181
1208
  declare function storyblokEditable(block?: Pick<BlockContent, '_editable'>): {
package/dist/index.d.mts CHANGED
@@ -1097,17 +1097,37 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
1097
1097
  type Override<T, U> = Prettify<Omit<T, keyof U> & U>;
1098
1098
  //#endregion
1099
1099
  //#region src/generated/types/block.d.ts
1100
- /** Wire form: the MAPI object map keyed by field name. This is what `defineBlock` returns. */
1101
- type BlockSchema = Record<string, Field & {
1100
+ /**
1101
+ * Ordered array of named fields — the content-shape DSL form `defineBlock`
1102
+ * accepts and returns. A field's position in the array sets the order it appears
1103
+ * in the editor (mapped to the wire `pos` on push).
1104
+ */
1105
+ type BlockFields = ReadonlyArray<Field & {
1106
+ name: string;
1107
+ pos?: number;
1102
1108
  required?: boolean;
1103
1109
  }>;
1104
- /** A Storyblok block. */
1105
- type Block<TName extends string = string, TBlockSchema extends BlockSchema = BlockSchema, TIsRoot extends boolean = boolean, TIsNestable extends boolean = boolean, TComponentGroupUuid extends string | null = string | null> = Override<Component, {
1110
+ /**
1111
+ * A Storyblok block: a named, ordered set of content fields. Uses the
1112
+ * content-shape DSL `fields` array rather than the MAPI wire `schema` record.
1113
+ */
1114
+ type Block<TName extends string = string, TFields extends BlockFields = BlockFields, TIsRoot extends boolean = boolean, TIsNestable extends boolean = boolean> = Override<Omit<Component, 'schema' | 'component_group_uuid'>, {
1106
1115
  name: TName;
1107
- schema: TBlockSchema;
1116
+ fields: TFields;
1108
1117
  is_root?: TIsRoot;
1109
1118
  is_nestable?: TIsNestable;
1110
- component_group_uuid?: TComponentGroupUuid;
1119
+ /**
1120
+ * Escape hatch for pinning this block to a Storyblok UI-managed component
1121
+ * group by UUID. Component groups are normally maintained in code via the
1122
+ * schema directory layout; set this only if you intentionally manage groups
1123
+ * in the Storyblok UI, and fill in the group UUID yourself. When set,
1124
+ * `schema push` diffs it and sends it to the Management API; when omitted,
1125
+ * the block's remote group is left untouched.
1126
+ *
1127
+ * @deprecated Prefer maintaining component groups in code through the
1128
+ * directory layout.
1129
+ */
1130
+ component_group_uuid?: string | null;
1111
1131
  }>;
1112
1132
  /**
1113
1133
  * A root {@link Block} (`is_root: true`). Given a union of blocks, narrows to
@@ -1128,21 +1148,28 @@ type RootBlock<T extends Block = Block & {
1128
1148
  type NoBlocks$1 = false;
1129
1149
  /** True when `T` is the un-narrowed base `Block` (i.e. no specific block was supplied). */
1130
1150
  type IsBaseBlock<T> = [Block] extends [T] ? true : false;
1131
- type RequiredFieldKeys<T> = { [K in keyof T]: T[K] extends {
1151
+ /**
1152
+ * Maps a block's ordered `fields` array to its read content object, splitting
1153
+ * required (`required: true`) from optional fields. Each `F` is a member of the
1154
+ * field union, so it provably satisfies `FieldValue`'s `Field` constraint.
1155
+ */
1156
+ type ContentFields<TFields extends BlockFields, TBlocks> = Prettify<{ [F in TFields[number] as F extends {
1157
+ required: true;
1158
+ } ? F['name'] : never]: FieldValue<F, TBlocks> } & { [F in TFields[number] as F extends {
1132
1159
  required: true;
1133
- } ? K : never }[keyof T];
1134
- type OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;
1160
+ } ? never : F['name']]?: FieldValue<F, TBlocks> | null }>;
1161
+ /** Input (write) variant of {@link ContentFields}, resolving each field via {@link FieldValueInput}. */
1135
1162
  /**
1136
1163
  * Content object for a single block instance as returned by the Storyblok
1137
1164
  * Content Delivery API. Without a `TBlock` argument, this is the loose
1138
1165
  * runtime shape (any block, `_editable` optional). With a schema-typed
1139
- * `TBlock`, fields are narrowed per the block's schema.
1166
+ * `TBlock`, fields are narrowed per the block's `fields`.
1140
1167
  */
1141
1168
  type BlockContent<TBlock extends Block = Block, TBlocks = NoBlocks$1> = IsBaseBlock<TBlock> extends true ? BlockContentBase : TBlock extends any ? Prettify<{
1142
1169
  _uid: string;
1143
1170
  component: TBlock['name'];
1144
1171
  _editable?: string;
1145
- } & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> | null }> : never;
1172
+ } & ContentFields<TBlock['fields'], TBlocks>> : never;
1146
1173
  interface FieldTypeValueMap {
1147
1174
  text: string;
1148
1175
  textarea: string;
@@ -1167,15 +1194,15 @@ type IsNestable<T> = T extends {
1167
1194
  } ? false : T extends {
1168
1195
  is_nestable: true;
1169
1196
  } ? true : true;
1170
- type ApplyWhitelist<TField, TBlocks> = TField extends {
1171
- component_whitelist: ReadonlyArray<infer TWhitelisted extends string>;
1197
+ type ApplyAllow<TField, TBlocks> = TField extends {
1198
+ allow: ReadonlyArray<infer TAllowed extends string>;
1172
1199
  } ? Extract<TBlocks, {
1173
- name: TWhitelisted;
1200
+ name: TAllowed;
1174
1201
  }> : TBlocks extends any ? IsNestable<TBlocks> extends true ? TBlocks : never : never;
1175
1202
  /** Resolves a field definition to its runtime content value type (read). */
1176
1203
  type FieldValue<TField extends Field = Field, TBlocks = NoBlocks$1> = Prettify<TField extends {
1177
1204
  type: 'bloks';
1178
- } ? [TBlocks] extends [never] ? BlockContentBase[] : [TBlocks] extends [Block] ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlockContentBase[] : FieldTypeValueMap[TField['type']]>;
1205
+ } ? [TBlocks] extends [never] ? BlockContentBase[] : [TBlocks] extends [Block] ? BlockContent<ApplyAllow<TField, TBlocks>, TBlocks>[] : BlockContentBase[] : FieldTypeValueMap[TField['type']]>;
1179
1206
  //#endregion
1180
1207
  //#region src/editable.d.ts
1181
1208
  declare function storyblokEditable(block?: Pick<BlockContent, '_editable'>): {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/live-preview",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.0-alpha.0",
5
5
  "private": false,
6
6
  "description": "Official Live Preview integration for the Storyblok Headless CMS",
7
7
  "author": "Storyblok",