@slicemachine/adapter-next 0.3.14-dev-next-release.5 → 0.3.14-dev-next-release.7

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/src/plugin.ts CHANGED
@@ -29,6 +29,7 @@ import { documentationRead } from "./hooks/documentation-read";
29
29
  import { projectInit } from "./hooks/project-init";
30
30
  import { sliceCreate } from "./hooks/slice-create";
31
31
  import { sliceSimulatorSetupRead } from "./hooks/sliceSimulator-setup-read";
32
+ import { sliceTemplateLibraryRead } from "./hooks/sliceTemplateLibrary-read";
32
33
  import { snippetRead } from "./hooks/snippet-read";
33
34
 
34
35
  export const plugin = defineSliceMachinePlugin<PluginOptions>({
@@ -155,6 +156,12 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
155
156
  });
156
157
  });
157
158
 
159
+ ////////////////////////////////////////////////////////////////
160
+ // slice-template-library:*
161
+ ////////////////////////////////////////////////////////////////
162
+
163
+ hook("slice-template-library:read", sliceTemplateLibraryRead);
164
+
158
165
  ////////////////////////////////////////////////////////////////
159
166
  // custom-type:*
160
167
  ////////////////////////////////////////////////////////////////
@@ -0,0 +1,561 @@
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
+ import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
3
+
4
+ import { pascalCase } from "../../lib/pascalCase";
5
+
6
+ import { stripIndent } from "common-tags";
7
+
8
+ export const mocks: SharedSliceContent[] = [
9
+ {
10
+ __TYPE__: "SharedSliceContent",
11
+ variation: "default",
12
+ primary: {
13
+ title: {
14
+ __TYPE__: "StructuredTextContent",
15
+ value: [
16
+ {
17
+ type: "heading1",
18
+ content: {
19
+ text: "Collector Slices kit",
20
+ spans: [],
21
+ },
22
+ direction: "ltr",
23
+ },
24
+ ],
25
+ },
26
+ paragraph: {
27
+ __TYPE__: "StructuredTextContent",
28
+ value: [
29
+ {
30
+ type: "paragraph",
31
+ content: {
32
+ text: "It’s very easy to create stylish and beautiful prototypes for your future projects, both graphical and dynamic.",
33
+ spans: [],
34
+ },
35
+ direction: "ltr",
36
+ },
37
+ ],
38
+ },
39
+ buttonLink: {
40
+ __TYPE__: "LinkContent",
41
+ value: {
42
+ __TYPE__: "ExternalLink",
43
+ url: "https://twitter.com/prismicio",
44
+ },
45
+ },
46
+ buttonlabel: {
47
+ __TYPE__: "FieldContent",
48
+ type: "Text",
49
+ value: "Click here",
50
+ },
51
+ image: {
52
+ origin: {
53
+ id: "9aOswReDKPo",
54
+ url: "https://images.unsplash.com/photo-1523049673857-eb18f1d7b578?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMzc0NjN8MHwxfHNlYXJjaHwxOXx8ZnJ1aXR8ZW58MHx8fHwxNjkzMjUxNTMxfDA&ixlib=rb-4.0.3&q=85",
55
+ width: 8040,
56
+ height: 6024,
57
+ },
58
+ url: "https://images.unsplash.com/photo-1523049673857-eb18f1d7b578?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMzc0NjN8MHwxfHNlYXJjaHwxOXx8ZnJ1aXR8ZW58MHx8fHwxNjkzMjUxNTMxfDA&ixlib=rb-4.0.3&q=85",
59
+ width: 8040,
60
+ height: 6024,
61
+ edit: {
62
+ background: "transparent",
63
+ zoom: 1,
64
+ crop: {
65
+ x: 0,
66
+ y: 0,
67
+ },
68
+ },
69
+ credits: null,
70
+ alt: "Example Image",
71
+ __TYPE__: "ImageContent",
72
+ thumbnails: {},
73
+ },
74
+ buttonLabel: {
75
+ __TYPE__: "FieldContent",
76
+ type: "Text",
77
+ value: "Learn more",
78
+ },
79
+ },
80
+ items: [],
81
+ },
82
+ {
83
+ __TYPE__: "SharedSliceContent",
84
+ variation: "alignLeft",
85
+ primary: {
86
+ image: {
87
+ origin: {
88
+ id: "euqiHwS38Rw",
89
+ url: "https://images.unsplash.com/photo-1595475207225-428b62bda831?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMzc0NjN8MHwxfHNlYXJjaHwyMHx8ZnJ1aXR8ZW58MHx8fHwxNjkzMjUxNTMxfDA&ixlib=rb-4.0.3&q=85",
90
+ width: 2500,
91
+ height: 2500,
92
+ },
93
+ url: "https://images.unsplash.com/photo-1595475207225-428b62bda831?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMzc0NjN8MHwxfHNlYXJjaHwyMHx8ZnJ1aXR8ZW58MHx8fHwxNjkzMjUxNTMxfDA&ixlib=rb-4.0.3&q=85",
94
+ width: 2500,
95
+ height: 2500,
96
+ edit: {
97
+ background: "transparent",
98
+ zoom: 1,
99
+ crop: {
100
+ x: 0,
101
+ y: 0,
102
+ },
103
+ },
104
+ credits: null,
105
+ alt: "Example Image",
106
+ __TYPE__: "ImageContent",
107
+ thumbnails: {},
108
+ },
109
+ title: {
110
+ __TYPE__: "StructuredTextContent",
111
+ value: [
112
+ {
113
+ type: "heading1",
114
+ content: {
115
+ text: "Collector Slices kit",
116
+ spans: [],
117
+ },
118
+ direction: "ltr",
119
+ },
120
+ ],
121
+ },
122
+ paragraph: {
123
+ __TYPE__: "StructuredTextContent",
124
+ value: [
125
+ {
126
+ type: "paragraph",
127
+ content: {
128
+ text: "It’s very easy to create stylish and beautiful prototypes for your future projects, both graphical and dynamic.",
129
+ spans: [],
130
+ },
131
+ direction: "ltr",
132
+ },
133
+ ],
134
+ },
135
+ buttonLink: {
136
+ __TYPE__: "LinkContent",
137
+ value: {
138
+ __TYPE__: "ExternalLink",
139
+ url: "https://prismic.io",
140
+ },
141
+ },
142
+ buttonLabel: {
143
+ __TYPE__: "FieldContent",
144
+ type: "Text",
145
+ value: "Learn more!",
146
+ },
147
+ },
148
+ items: [
149
+ {
150
+ __TYPE__: "GroupItemContent",
151
+ value: [],
152
+ },
153
+ ],
154
+ },
155
+ ];
156
+
157
+ export const createComponentContents = (
158
+ model: SharedSlice,
159
+ isTypeScriptProject: boolean,
160
+ ): string => {
161
+ const pascalName = pascalCase(model.name);
162
+
163
+ if (isTypeScriptProject) {
164
+ return stripIndent`
165
+ import { Content, isFilled } from "@prismicio/client";
166
+ import { PrismicNextLink, PrismicNextImage } from "@prismicio/next";
167
+ import {
168
+ PrismicRichText,
169
+ PrismicText,
170
+ SliceComponentProps
171
+ } from "@prismicio/react";
172
+
173
+ /**
174
+ * Props for \`${pascalName}\`.
175
+ */
176
+ export type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;
177
+
178
+ /**
179
+ * Component for "${model.name}" Slices.
180
+ */
181
+ const ${pascalName} = ({ slice }: ${pascalName}Props): JSX.Element => {
182
+ const alignment = slice.variation === "alignLeft" ? "left" : "center";
183
+
184
+ return (
185
+ <section
186
+ data-slice-type={slice.slice_type}
187
+ data-slice-variation={slice.variation}
188
+ className="es-bounded es-call-to-action"
189
+ >
190
+ <div className="es-bounded__content es-call-to-action__content">
191
+ {isFilled.image(slice.primary.image) && (
192
+ <PrismicNextImage
193
+ className="es-call-to-action__image"
194
+ field={slice.primary.image}
195
+ />
196
+ )}
197
+ <div className="es-call-to-action__content">
198
+ {isFilled.richText(slice.primary.title) && (
199
+ <h2 className="es-call-to-action__content__heading">
200
+ <PrismicText field={slice.primary.title} />
201
+ </h2>
202
+ )}
203
+ {isFilled.richText(slice.primary.paragraph) && (
204
+ <div className="es-call-to-action__content__paragraph">
205
+ <PrismicRichText field={slice.primary.paragraph} />
206
+ </div>
207
+ )}
208
+ </div>
209
+ {isFilled.link(slice.primary.buttonLink) && (
210
+ <PrismicNextLink
211
+ className="es-call-to-action__button"
212
+ field={slice.primary.buttonLink}
213
+ >
214
+ {slice.primary.buttonLabel || "Learn more…"}
215
+ </PrismicNextLink>
216
+ )}
217
+ </div>
218
+ <style>
219
+ {\`
220
+ .es-bounded {
221
+ padding: 8vw 2rem;
222
+ }
223
+
224
+ .es-bounded__content {
225
+ margin-left: auto;
226
+ margin-right: auto;
227
+ }
228
+
229
+ @media screen and (min-width: 640px) {
230
+ .es-bounded__content {
231
+ max-width: 90%;
232
+ }
233
+ }
234
+
235
+ @media screen and (min-width: 896px) {
236
+ .es-bounded__content {
237
+ max-width: 80%;
238
+ }
239
+ }
240
+
241
+ @media screen and (min-width: 1280px) {
242
+ .es-bounded__content {
243
+ max-width: 75%;
244
+ }
245
+ }
246
+
247
+ .es-call-to-action {
248
+ background-color: #fff;
249
+ color: #333;
250
+ }
251
+
252
+ .es-call-to-action__content {
253
+ display: grid;
254
+ gap: 2rem;
255
+ }
256
+
257
+ .es-call-to-action__image {
258
+ max-width: 14rem;
259
+ height: auto;
260
+ width: auto;
261
+ justify-self: \${alignment};
262
+ }
263
+
264
+ .es-call-to-action__content {
265
+ display: grid;
266
+ gap: 1rem;
267
+ justify-items: \${alignment};
268
+ }
269
+
270
+ .es-call-to-action__content__heading {
271
+ font-size: 2rem;
272
+ font-weight: 700;
273
+ text-align: \${alignment};
274
+ }
275
+
276
+ .es-call-to-action__content__paragraph {
277
+ font-size: 1.15rem;
278
+ max-width: 38rem;
279
+ text-align: \${alignment};
280
+ }
281
+
282
+ .es-call-to-action__button {
283
+ justify-self: \${alignment};
284
+ border-radius: 0.25rem;
285
+ display: inline-block;
286
+ font-size: 0.875rem;
287
+ line-height: 1.3;
288
+ padding: 1rem 2.625rem;
289
+ text-align: \${alignment};
290
+ transition: background-color 100ms linear;
291
+ background-color: #16745f;
292
+ color: #fff;
293
+ }
294
+
295
+ .es-call-to-action__button:hover {
296
+ background-color: #0d5e4c;
297
+ }
298
+ \`}
299
+ </style>
300
+ </section>
301
+ );
302
+ };
303
+
304
+ export default ${pascalName};
305
+ `;
306
+ }
307
+
308
+ return stripIndent`
309
+ import { isFilled } from "@prismicio/client";
310
+ import { PrismicNextLink, PrismicNextImage } from "@prismicio/next";
311
+ import {
312
+ PrismicRichText,
313
+ PrismicText,
314
+ SliceComponentProps
315
+ } from "@prismicio/react";
316
+
317
+ /**
318
+ * @typedef {import("@prismicio/client").Content.${pascalName}Slice} ${pascalName}Slice
319
+ * @typedef {import("@prismicio/react").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props
320
+ * @param {${pascalName}Props}
321
+ */
322
+ const ${pascalName} = ({ slice }) => {
323
+ const alignment = slice.variation === "alignLeft" ? "left" : "center";
324
+
325
+ return (
326
+ <section
327
+ data-slice-type={slice.slice_type}
328
+ data-slice-variation={slice.variation}
329
+ className="es-bounded es-call-to-action"
330
+ >
331
+ <div className="es-bounded__content es-call-to-action__content">
332
+ {isFilled.image(slice.primary.image) && (
333
+ <PrismicNextImage
334
+ className="es-call-to-action__image"
335
+ field={slice.primary.image}
336
+ />
337
+ )}
338
+ <div className="es-call-to-action__content">
339
+ {isFilled.richText(slice.primary.title) && (
340
+ <h2 className="es-call-to-action__content__heading">
341
+ <PrismicText field={slice.primary.title} />
342
+ </h2>
343
+ )}
344
+ {isFilled.richText(slice.primary.paragraph) && (
345
+ <div className="es-call-to-action__content__paragraph">
346
+ <PrismicRichText field={slice.primary.paragraph} />
347
+ </div>
348
+ )}
349
+ </div>
350
+ {isFilled.link(slice.primary.buttonLink) && (
351
+ <PrismicNextLink
352
+ className="es-call-to-action__button"
353
+ field={slice.primary.buttonLink}
354
+ >
355
+ {slice.primary.buttonLabel || "Learn more…"}
356
+ </PrismicNextLink>
357
+ )}
358
+ </div>
359
+ <style>
360
+ {\`
361
+ .es-bounded {
362
+ padding: 8vw 2rem;
363
+ }
364
+
365
+ .es-bounded__content {
366
+ margin-left: auto;
367
+ margin-right: auto;
368
+ }
369
+
370
+ @media screen and (min-width: 640px) {
371
+ .es-bounded__content {
372
+ max-width: 90%;
373
+ }
374
+ }
375
+
376
+ @media screen and (min-width: 896px) {
377
+ .es-bounded__content {
378
+ max-width: 80%;
379
+ }
380
+ }
381
+
382
+ @media screen and (min-width: 1280px) {
383
+ .es-bounded__content {
384
+ max-width: 75%;
385
+ }
386
+ }
387
+
388
+ .es-call-to-action {
389
+ background-color: #fff;
390
+ color: #333;
391
+ }
392
+
393
+ .es-call-to-action__content {
394
+ display: grid;
395
+ gap: 2rem;
396
+ }
397
+
398
+ .es-call-to-action__image {
399
+ max-width: 14rem;
400
+ height: auto;
401
+ width: auto;
402
+ justify-self: \${alignment};
403
+ }
404
+
405
+ .es-call-to-action__content {
406
+ display: grid;
407
+ gap: 1rem;
408
+ justify-items: \${alignment};
409
+ }
410
+
411
+ .es-call-to-action__content__heading {
412
+ font-size: 2rem;
413
+ font-weight: 700;
414
+ text-align: \${alignment};
415
+ }
416
+
417
+ .es-call-to-action__content__paragraph {
418
+ font-size: 1.15rem;
419
+ max-width: 38rem;
420
+ text-align: \${alignment};
421
+ }
422
+
423
+ .es-call-to-action__button {
424
+ justify-self: \${alignment};
425
+ border-radius: 0.25rem;
426
+ display: inline-block;
427
+ font-size: 0.875rem;
428
+ line-height: 1.3;
429
+ padding: 1rem 2.625rem;
430
+ text-align: \${alignment};
431
+ transition: background-color 100ms linear;
432
+ background-color: #16745f;
433
+ color: #fff;
434
+ }
435
+
436
+ .es-call-to-action__button:hover {
437
+ background-color: #0d5e4c;
438
+ }
439
+ \`}
440
+ </style>
441
+ </section>
442
+ );
443
+ };
444
+
445
+ export default ${pascalName};
446
+ `;
447
+ };
448
+
449
+ export const model: SharedSlice = {
450
+ id: "call_to_action",
451
+ type: "SharedSlice",
452
+ name: "CallToAction",
453
+ description: "CallToAction",
454
+ variations: [
455
+ {
456
+ id: "default",
457
+ name: "Default",
458
+ docURL: "...",
459
+ version: "initial",
460
+ description: "Default",
461
+ imageUrl: "",
462
+ primary: {
463
+ image: {
464
+ type: "Image",
465
+ config: { label: "Image", constraint: {}, thumbnails: [] },
466
+ },
467
+ title: {
468
+ type: "StructuredText",
469
+ config: {
470
+ label: "title",
471
+ placeholder: "",
472
+ allowTargetBlank: true,
473
+ single: "heading1,heading2,heading3,heading4,heading5,heading6",
474
+ },
475
+ },
476
+ paragraph: {
477
+ type: "StructuredText",
478
+ config: {
479
+ label: "paragraph",
480
+ placeholder: "",
481
+ allowTargetBlank: true,
482
+ single:
483
+ "paragraph,preformatted,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl",
484
+ },
485
+ },
486
+ buttonLink: {
487
+ type: "Link",
488
+ config: {
489
+ label: "buttonLink",
490
+ placeholder: "Redirect URL for CTA button",
491
+ allowTargetBlank: true,
492
+ select: null,
493
+ },
494
+ },
495
+ buttonLabel: {
496
+ type: "Text",
497
+ config: {
498
+ label: "buttonLabel",
499
+ placeholder: "Label for CTA button",
500
+ },
501
+ },
502
+ },
503
+ items: {},
504
+ },
505
+ {
506
+ id: "alignLeft",
507
+ name: "AlignLeft",
508
+ docURL: "...",
509
+ version: "initial",
510
+ description: "Default",
511
+ imageUrl: "",
512
+ primary: {
513
+ image: {
514
+ type: "Image",
515
+ config: { label: "Image", constraint: {}, thumbnails: [] },
516
+ },
517
+ title: {
518
+ type: "StructuredText",
519
+ config: {
520
+ label: "title",
521
+ placeholder: "",
522
+ allowTargetBlank: true,
523
+ single: "heading1,heading2,heading3,heading4,heading5,heading6",
524
+ },
525
+ },
526
+ paragraph: {
527
+ type: "StructuredText",
528
+ config: {
529
+ label: "paragraph",
530
+ placeholder: "",
531
+ allowTargetBlank: true,
532
+ single:
533
+ "paragraph,preformatted,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl",
534
+ },
535
+ },
536
+ buttonLink: {
537
+ type: "Link",
538
+ config: {
539
+ label: "buttonLink",
540
+ placeholder: "Redirect URL for CTA button",
541
+ allowTargetBlank: true,
542
+ select: null,
543
+ },
544
+ },
545
+ buttonLabel: {
546
+ type: "Text",
547
+ config: {
548
+ label: "buttonLabel",
549
+ placeholder: "Label for CTA button",
550
+ },
551
+ },
552
+ },
553
+ items: {},
554
+ },
555
+ ],
556
+ };
557
+
558
+ export const screenshotPaths = {
559
+ default: "CallToAction/screenshot-default.png",
560
+ alignLeft: "CallToAction/screenshot-alignLeft.png",
561
+ };