@alpaca-editor/core 1.0.3908 → 1.0.3912

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/tour/Tour.tsx CHANGED
@@ -2,6 +2,9 @@ import { useState, useEffect } from "react";
2
2
  import { useEditContext } from "../client-components";
3
3
  import { classNames } from "primereact/utils";
4
4
  import { EditContextType } from "../editor/client/editContext";
5
+ import { Logo } from "../editor/ui/Icons";
6
+ import { X } from "lucide-react";
7
+ import { ActionButton } from "../components/ActionButton";
5
8
 
6
9
  export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
7
10
  const [currentStep, setCurrentStep] = useState<string>("start-tour");
@@ -14,7 +17,7 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
14
17
 
15
18
  const waitForElement = (
16
19
  selector: string,
17
- timeout: number = 0
20
+ timeout: number = 0,
18
21
  ): Promise<DOMRect | undefined> => {
19
22
  if (selector.startsWith("iframe:")) {
20
23
  return waitForElementInIframe(selector.substring(7), timeout);
@@ -31,7 +34,7 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
31
34
  rect.left - extendFocus / 2,
32
35
  rect.top - extendFocus / 2,
33
36
  rect.width + extendFocus,
34
- rect.height + extendFocus
37
+ rect.height + extendFocus,
35
38
  );
36
39
 
37
40
  resolve(rect);
@@ -47,13 +50,13 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
47
50
 
48
51
  const waitForElementInIframe = (
49
52
  selector: string,
50
- timeout: number = 0
53
+ timeout: number = 0,
51
54
  ): Promise<DOMRect | undefined> => {
52
55
  return new Promise<DOMRect | undefined>((resolve, reject) => {
53
56
  const startTime = Date.now();
54
57
  const checkForElement = () => {
55
58
  const iframe = document.querySelector(
56
- "iframe.page-iframe"
59
+ "iframe.page-iframe",
57
60
  ) as HTMLIFrameElement;
58
61
  if (iframe && iframe.contentDocument) {
59
62
  const element = iframe.contentDocument.querySelector(selector);
@@ -64,14 +67,14 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
64
67
  elementRect.left + iframeRect.left,
65
68
  elementRect.top + iframeRect.top,
66
69
  elementRect.width,
67
- elementRect.height
70
+ elementRect.height,
68
71
  );
69
72
  const extendFocus = step?.extendFocus || 10;
70
73
  rect = new DOMRect(
71
74
  rect.left - extendFocus / 2,
72
75
  rect.top - extendFocus / 2,
73
76
  rect.width + extendFocus,
74
- rect.height + extendFocus
77
+ rect.height + extendFocus,
75
78
  );
76
79
 
77
80
  resolve(rect);
@@ -106,7 +109,7 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
106
109
 
107
110
  const waitForInput = (
108
111
  selector: string,
109
- minNumberOfCharacters: number = 1
112
+ minNumberOfCharacters: number = 1,
110
113
  ): Promise<void> => {
111
114
  return new Promise((resolve) => {
112
115
  const checkForInput = () => {
@@ -137,16 +140,16 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
137
140
 
138
141
  function setNativeValue(
139
142
  element: HTMLInputElement | HTMLTextAreaElement,
140
- value: string
143
+ value: string,
141
144
  ) {
142
145
  const valueSetter = Object.getOwnPropertyDescriptor(
143
146
  element.constructor.prototype,
144
- "value"
147
+ "value",
145
148
  )?.set;
146
149
  const prototype = Object.getPrototypeOf(element);
147
150
  const prototypeValueSetter = Object.getOwnPropertyDescriptor(
148
151
  prototype,
149
- "value"
152
+ "value",
150
153
  )?.set;
151
154
 
152
155
  if (valueSetter && valueSetter !== prototypeValueSetter) {
@@ -162,7 +165,7 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
162
165
  async function simulateTyping(
163
166
  element: HTMLInputElement | HTMLTextAreaElement,
164
167
  text: string,
165
- interval = 35
168
+ interval = 35,
166
169
  ) {
167
170
  let i = 0;
168
171
 
@@ -380,7 +383,7 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
380
383
 
381
384
  <div
382
385
  style={boxStyle}
383
- className="text-gray-800 flex flex-col items-center fade-in"
386
+ className="fade-in flex flex-col items-center text-gray-800"
384
387
  >
385
388
  {focusRect && (
386
389
  <svg
@@ -418,35 +421,40 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
418
421
  `}
419
422
  </style>
420
423
  <div
421
- className={`relative flex items-stretch justify-center bg-gray-50 rounded-lg border border-gray-800 gap-6 shadow-2xl`}
424
+ className={`border-theme-secondary relative flex items-stretch justify-center gap-6 rounded-lg border bg-gray-50 shadow-2xl`}
422
425
  style={bubbleStyle}
423
426
  >
424
- <div
425
- className="text-xs font-bold cursor-pointer flex items-center gap-2 absolute top-0 right-0 mr-2 mt-2"
426
- onClick={stopTour}
427
- >
428
- <i className="pi pi-times" />
429
- </div>
430
- <div className="flex flex-col items-center justify-center gap-2 bg-gray-200 p-6 rounded-l-lg">
431
- <AlpacaIcon />
427
+ <div className="flex flex-col items-end justify-end gap-2 pt-5">
428
+ <div className="bg-wizard-tour aspect-square w-40"></div>
432
429
  </div>
433
- <div className="flex flex-col items-end justify-center gap-3 p-4 ">
430
+ <div className="flex flex-col items-end justify-between gap-3 p-6">
434
431
  {/* Step Content */}
435
- <div className="opacity-100 text-2xl font-bold handwritten text-center flex flex-col items-center max-w-[450px]">
436
- <div className="text-4xl mb-4">{step.title}</div>
437
- <div>{step.description}</div>
432
+ <div className="flex items-start">
433
+ <div className="flex max-w-[450px] flex-col gap-2 text-center text-2xl text-gray-800">
434
+ <div className="flex items-center gap-3">
435
+ <Logo className="w-8" />
436
+ <div className="text-xl font-bold">{step.title}</div>
437
+ </div>
438
+ <div className="text-xs text-gray-500">{step.description}</div>
439
+ </div>
440
+ <button
441
+ className="text-2xs flex cursor-pointer items-center gap-2 font-bold"
442
+ onClick={stopTour}
443
+ >
444
+ <X className="h-4 w-4" />
445
+ </button>
438
446
  </div>
439
447
  {/* Render Buttons Defined in Step Data */}
440
448
  <div className="flex gap-2">
441
449
  {step.buttons &&
442
450
  step.buttons.map((button, index) => (
443
- <button
451
+ <ActionButton
444
452
  key={index}
445
453
  onClick={button.onClick}
446
454
  className={button.className}
447
455
  >
448
456
  {button.label}
449
- </button>
457
+ </ActionButton>
450
458
  ))}
451
459
  </div>
452
460
  </div>
@@ -458,101 +466,101 @@ export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
458
466
  </>
459
467
  );
460
468
  }
461
- function AlpacaIcon() {
462
- return (
463
- <svg
464
- height="80px"
465
- width="80px"
466
- version="1.1"
467
- id="Layer_1"
468
- xmlns="http://www.w3.org/2000/svg"
469
- viewBox="0 0 512 512"
470
- >
471
- <path
472
- style={{ fill: "#EBE4DD" }}
473
- d="M102.989,153.011v153.011C119.613,428.825,184.332,506.115,256,506.115
474
- s136.387-77.29,153.012-200.092V153.011H102.989z"
475
- />
476
- <path
477
- style={{ fill: "#D8CCBC" }}
478
- d="M255.999,153.011v353.103H256c71.668,0,136.387-77.29,153.012-200.092V153.011H255.999z"
479
- />
480
- <path
481
- style={{ fill: "#A58868" }}
482
- d="M273.655,435.494h-35.31c0,41.195-17.007,41.195-29.425,41.195V512
483
- c16.246,0,34.206-4.021,47.08-18.162C268.873,507.979,286.834,512,303.08,512v-35.31C290.662,476.69,273.655,476.69,273.655,435.494
484
- z"
485
- />
486
- <path
487
- style={{ fill: "#947859" }}
488
- d="M273.655,435.494H256v58.343C268.873,507.979,286.834,512,303.08,512v-35.31
489
- C290.662,476.69,273.655,476.69,273.655,435.494z"
490
- />
491
- <path
492
- style={{ fill: "#EBE4DD" }}
493
- d="M126.529,0C81.025,0,44.138,36.888,44.138,82.391s36.888,82.391,82.391,82.391V0z"
494
- />
495
- <path
496
- style={{ fill: "#D8CCBC" }}
497
- d="M385.471,164.782c45.503,0,82.391-36.888,82.391-82.391S430.975,0,385.471,0V164.782z"
498
- />
499
- <path
500
- style={{ fill: "#BFA993" }}
501
- d="M490.407,247.172c0.643-3.83,0.996-7.758,0.996-11.77c0-39.003-31.618-70.621-70.621-70.621
502
- s-70.621,31.618-70.621,70.621c0,4.012,0.352,7.94,0.995,11.77H490.407z"
503
- />
504
- <path
505
- style={{ fill: "#EDEDED" }}
506
- d="M420.782,306.023c39.003,0,70.621-31.618,70.621-70.621H350.161
507
- C350.161,274.405,381.779,306.023,420.782,306.023z"
508
- />
509
- <path
510
- style={{ fill: "#454449" }}
511
- d="M397.241,235.401c0,12.981,10.559,23.54,23.538,23.54h0.002c12.981,0.001,23.54-10.559,23.54-23.54
512
- H397.241z"
513
- />
514
- <path
515
- style={{ fill: "#BFA993" }}
516
- d="M160.844,247.172c0.643-3.83,0.995-7.758,0.995-11.77c0-39.003-31.618-70.621-70.621-70.621
517
- S20.598,196.4,20.598,235.402c0,4.012,0.352,7.94,0.995,11.77H160.844z"
518
- />
519
- <path
520
- style={{ fill: "#EDEDED" }}
521
- d="M91.218,306.023c39.003,0,70.621-31.618,70.621-70.621H20.598
522
- C20.598,274.405,52.216,306.023,91.218,306.023z"
523
- />
524
- <path
525
- style={{ fill: "#454449" }}
526
- d="M67.678,235.401c0,12.981,10.559,23.54,23.538,23.54h0.002c12.981,0.001,23.54-10.559,23.54-23.54
527
- H67.678z"
528
- />
529
- <path
530
- style={{ fill: "#D8CCBC" }}
531
- d="M391.356,107.187c0-15.527,4.902-33.778-5.082-46.69c-8.818-11.403-28.519-12.694-43.229-20.793
532
- c-12.822-7.059-23.38-23.527-39.415-27.235c-14.505-3.356-31.411,6.442-47.63,6.442c-16.218,0-33.125-9.796-47.631-6.442
533
- c-16.036,3.708-26.595,20.178-39.415,27.237c-14.71,8.099-34.41,9.391-43.227,20.792c-9.985,12.912-5.082,31.161-5.082,46.689
534
- s-4.902,33.778,5.082,46.69c8.818,11.403,28.519,12.693,43.229,20.793c12.821,7.059,23.379,23.527,39.413,27.235
535
- c14.505,3.356,31.412-6.442,47.63-6.442s33.125,9.796,47.632,6.442c16.034-3.708,26.592-20.176,39.413-27.237
536
- c14.709-8.099,34.411-9.391,43.228-20.792C396.259,140.965,391.356,122.715,391.356,107.187z"
537
- />
538
- <path
539
- style={{ fill: "#BFA993" }}
540
- d="M386.274,60.497c-8.818-11.403-28.519-12.694-43.229-20.793
541
- c-12.822-7.059-23.38-23.527-39.415-27.235c-14.505-3.356-31.411,6.442-47.63,6.442v176.552c16.218,0,33.125,9.796,47.632,6.442
542
- c16.034-3.708,26.592-20.176,39.413-27.237c14.709-8.099,34.411-9.391,43.228-20.792c9.985-12.912,5.082-31.161,5.082-46.689
543
- S396.259,73.409,386.274,60.497z"
544
- />
545
- <path
546
- style={{ fill: "#58575D" }}
547
- d="M293.664,406.069c-6.186,18.772-22.763,39.469-37.664,39.784
548
- c-14.901-0.315-31.478-21.012-37.664-39.784c-2.858-9.591,4.529-17.529,16.478-17.655c14.124,0,28.248,0,42.372,0
549
- C289.136,388.54,296.522,396.476,293.664,406.069z"
550
- />
551
- <path
552
- style={{ fill: "#454449" }}
553
- d="M277.186,388.414c-7.062,0-14.124,0-21.186,0v57.439c14.901-0.315,31.478-21.012,37.664-39.784
554
- C296.522,396.476,289.136,388.54,277.186,388.414z"
555
- />
556
- </svg>
557
- );
558
- }
469
+ // function AlpacaIcon() {
470
+ // return (
471
+ // <svg
472
+ // height="80px"
473
+ // width="80px"
474
+ // version="1.1"
475
+ // id="Layer_1"
476
+ // xmlns="http://www.w3.org/2000/svg"
477
+ // viewBox="0 0 512 512"
478
+ // >
479
+ // <path
480
+ // style={{ fill: "#EBE4DD" }}
481
+ // d="M102.989,153.011v153.011C119.613,428.825,184.332,506.115,256,506.115
482
+ // s136.387-77.29,153.012-200.092V153.011H102.989z"
483
+ // />
484
+ // <path
485
+ // style={{ fill: "#D8CCBC" }}
486
+ // d="M255.999,153.011v353.103H256c71.668,0,136.387-77.29,153.012-200.092V153.011H255.999z"
487
+ // />
488
+ // <path
489
+ // style={{ fill: "#A58868" }}
490
+ // d="M273.655,435.494h-35.31c0,41.195-17.007,41.195-29.425,41.195V512
491
+ // c16.246,0,34.206-4.021,47.08-18.162C268.873,507.979,286.834,512,303.08,512v-35.31C290.662,476.69,273.655,476.69,273.655,435.494
492
+ // z"
493
+ // />
494
+ // <path
495
+ // style={{ fill: "#947859" }}
496
+ // d="M273.655,435.494H256v58.343C268.873,507.979,286.834,512,303.08,512v-35.31
497
+ // C290.662,476.69,273.655,476.69,273.655,435.494z"
498
+ // />
499
+ // <path
500
+ // style={{ fill: "#EBE4DD" }}
501
+ // d="M126.529,0C81.025,0,44.138,36.888,44.138,82.391s36.888,82.391,82.391,82.391V0z"
502
+ // />
503
+ // <path
504
+ // style={{ fill: "#D8CCBC" }}
505
+ // d="M385.471,164.782c45.503,0,82.391-36.888,82.391-82.391S430.975,0,385.471,0V164.782z"
506
+ // />
507
+ // <path
508
+ // style={{ fill: "#BFA993" }}
509
+ // d="M490.407,247.172c0.643-3.83,0.996-7.758,0.996-11.77c0-39.003-31.618-70.621-70.621-70.621
510
+ // s-70.621,31.618-70.621,70.621c0,4.012,0.352,7.94,0.995,11.77H490.407z"
511
+ // />
512
+ // <path
513
+ // style={{ fill: "#EDEDED" }}
514
+ // d="M420.782,306.023c39.003,0,70.621-31.618,70.621-70.621H350.161
515
+ // C350.161,274.405,381.779,306.023,420.782,306.023z"
516
+ // />
517
+ // <path
518
+ // style={{ fill: "#454449" }}
519
+ // d="M397.241,235.401c0,12.981,10.559,23.54,23.538,23.54h0.002c12.981,0.001,23.54-10.559,23.54-23.54
520
+ // H397.241z"
521
+ // />
522
+ // <path
523
+ // style={{ fill: "#BFA993" }}
524
+ // d="M160.844,247.172c0.643-3.83,0.995-7.758,0.995-11.77c0-39.003-31.618-70.621-70.621-70.621
525
+ // S20.598,196.4,20.598,235.402c0,4.012,0.352,7.94,0.995,11.77H160.844z"
526
+ // />
527
+ // <path
528
+ // style={{ fill: "#EDEDED" }}
529
+ // d="M91.218,306.023c39.003,0,70.621-31.618,70.621-70.621H20.598
530
+ // C20.598,274.405,52.216,306.023,91.218,306.023z"
531
+ // />
532
+ // <path
533
+ // style={{ fill: "#454449" }}
534
+ // d="M67.678,235.401c0,12.981,10.559,23.54,23.538,23.54h0.002c12.981,0.001,23.54-10.559,23.54-23.54
535
+ // H67.678z"
536
+ // />
537
+ // <path
538
+ // style={{ fill: "#D8CCBC" }}
539
+ // d="M391.356,107.187c0-15.527,4.902-33.778-5.082-46.69c-8.818-11.403-28.519-12.694-43.229-20.793
540
+ // c-12.822-7.059-23.38-23.527-39.415-27.235c-14.505-3.356-31.411,6.442-47.63,6.442c-16.218,0-33.125-9.796-47.631-6.442
541
+ // c-16.036,3.708-26.595,20.178-39.415,27.237c-14.71,8.099-34.41,9.391-43.227,20.792c-9.985,12.912-5.082,31.161-5.082,46.689
542
+ // s-4.902,33.778,5.082,46.69c8.818,11.403,28.519,12.693,43.229,20.793c12.821,7.059,23.379,23.527,39.413,27.235
543
+ // c14.505,3.356,31.412-6.442,47.63-6.442s33.125,9.796,47.632,6.442c16.034-3.708,26.592-20.176,39.413-27.237
544
+ // c14.709-8.099,34.411-9.391,43.228-20.792C396.259,140.965,391.356,122.715,391.356,107.187z"
545
+ // />
546
+ // <path
547
+ // style={{ fill: "#BFA993" }}
548
+ // d="M386.274,60.497c-8.818-11.403-28.519-12.694-43.229-20.793
549
+ // c-12.822-7.059-23.38-23.527-39.415-27.235c-14.505-3.356-31.411,6.442-47.63,6.442v176.552c16.218,0,33.125,9.796,47.632,6.442
550
+ // c16.034-3.708,26.592-20.176,39.413-27.237c14.709-8.099,34.411-9.391,43.228-20.792c9.985-12.912,5.082-31.161,5.082-46.689
551
+ // S396.259,73.409,386.274,60.497z"
552
+ // />
553
+ // <path
554
+ // style={{ fill: "#58575D" }}
555
+ // d="M293.664,406.069c-6.186,18.772-22.763,39.469-37.664,39.784
556
+ // c-14.901-0.315-31.478-21.012-37.664-39.784c-2.858-9.591,4.529-17.529,16.478-17.655c14.124,0,28.248,0,42.372,0
557
+ // C289.136,388.54,296.522,396.476,293.664,406.069z"
558
+ // />
559
+ // <path
560
+ // style={{ fill: "#454449" }}
561
+ // d="M277.186,388.414c-7.062,0-14.124,0-21.186,0v57.439c14.901-0.315,31.478-21.012,37.664-39.784
562
+ // C296.522,396.476,289.136,388.54,277.186,388.414z"
563
+ // />
564
+ // </svg>
565
+ // );
566
+ // }
@@ -19,7 +19,7 @@ export function getDefaultTourSteps(
19
19
  firstComponentTextFieldId: string;
20
20
  firstComponentRichTextFieldName: string;
21
21
  firstComponentRichTextFieldId: string;
22
- }
22
+ },
23
23
  ) {
24
24
  const tourSteps: Record<string, TourStep> = {
25
25
  "start-tour": {
@@ -177,7 +177,7 @@ export function getDefaultTourSteps(
177
177
  await delay(5000);
178
178
  await waitForInput(
179
179
  `[data-field-id='${config.firstComponentTextFieldId}'] input`,
180
- 5
180
+ 5,
181
181
  );
182
182
  },
183
183
  nextStep: "see-content-update",
@@ -193,7 +193,7 @@ export function getDefaultTourSteps(
193
193
  await delay(5000);
194
194
  await waitForInput(
195
195
  `[data-field-id='${config.firstComponentTextFieldId}'] input`,
196
- 5
196
+ 5,
197
197
  );
198
198
  },
199
199
  nextStep: "edit-content-inline",
@@ -208,7 +208,7 @@ export function getDefaultTourSteps(
208
208
  await delay(5000);
209
209
  await waitForInput(
210
210
  `[data-field-id='${config.firstComponentRichTextFieldId}'] [contenteditable]`,
211
- 5
211
+ 5,
212
212
  );
213
213
  },
214
214
  nextStep: "ai-intro",
@@ -244,7 +244,7 @@ export function getDefaultTourSteps(
244
244
  (aiTerminal as HTMLTextAreaElement).focus();
245
245
  await simulateTyping(
246
246
  aiTerminal as HTMLTextAreaElement,
247
- `Plase add three components of type ${config.firstComponentTemplateName} with some funny dummy content to the page.`
247
+ `Plase add three components of type ${config.firstComponentTemplateName} with some funny dummy content to the page.`,
248
248
  );
249
249
  }
250
250
  },
@@ -282,7 +282,8 @@ export function getDefaultTourSteps(
282
282
  ],
283
283
  },
284
284
  error: {
285
- description: "Oops, something went wrong.",
285
+ title: "Oh no...",
286
+ description: "Something went wrong.",
286
287
  buttons: [
287
288
  {
288
289
  label: (
@@ -109,7 +109,8 @@ export function getPreviewTourSteps({
109
109
  },
110
110
 
111
111
  error: {
112
- description: "Oops, something went wrong.",
112
+ title: "Oh no...",
113
+ description: "Something went wrong.",
113
114
  buttons: [
114
115
  {
115
116
  label: (
package/styles.css CHANGED
@@ -261,6 +261,20 @@ body {
261
261
  opacity: 0.2;
262
262
  }
263
263
 
264
+ .bg-wizard-demo {
265
+ background-image: url("./images/wizard.png");
266
+ background-position: right;
267
+ background-size: contain;
268
+ background-repeat: no-repeat;
269
+ }
270
+
271
+ .bg-wizard-tour {
272
+ background-image: url("./images/wizard-tour.png");
273
+ background-position: right;
274
+ background-size: contain;
275
+ background-repeat: no-repeat;
276
+ }
277
+
264
278
  .p-tree {
265
279
  background-color: unset;
266
280
  }