@avocadostudio-ai/cli 0.3.2 → 0.3.3
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/README.md +29 -6
- package/dist/index.js +62 -18
- package/editor-dist/assets/{Editor-EPSED64A-CH6D2Zb0.js → Editor-EPSED64A-BQPpPIMn.js} +1 -1
- package/editor-dist/assets/{PuckPrototypeRoute-dMA7e2BV.js → PuckPrototypeRoute-CEtarLZd.js} +5 -5
- package/editor-dist/assets/{Render-CU35UAWV-BWX6H-wh.js → Render-CU35UAWV-BDSgP-dU.js} +1 -1
- package/editor-dist/assets/{chunk-2CNEFIQP-D3Yc-Xrd.js → chunk-2CNEFIQP-B3HjHnn-.js} +1 -1
- package/editor-dist/assets/{full-N67EAB2Q-7saRehQj.js → full-N67EAB2Q-Cyb-fFUR.js} +1 -1
- package/editor-dist/assets/index-8s1LXOA6.js +737 -0
- package/editor-dist/assets/{index-Zan79wWH.js → index-B0cipFdl.js} +1 -1
- package/editor-dist/assets/{index-QORB5JJO.js → index-CIC8kldS.js} +1 -1
- package/editor-dist/assets/index-CP6dYNly.css +1 -0
- package/editor-dist/assets/{loaded-F37CNCVG-D-0xAHVt.js → loaded-F37CNCVG-DH7tNu-q.js} +1 -1
- package/editor-dist/assets/{loaded-H325ZSK5-BpxUZ0no.js → loaded-H325ZSK5-C47h6_LL.js} +1 -1
- package/editor-dist/assets/{loaded-MIY725CK-DnDCzL_F.js → loaded-MIY725CK-DcYvDg9R.js} +1 -1
- package/editor-dist/index.html +2 -2
- package/package.json +2 -2
- package/editor-dist/assets/index-C0aP_ANq.css +0 -1
- package/editor-dist/assets/index-bSQ3lNnY.js +0 -699
package/README.md
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
# @avocadostudio-ai/cli
|
|
2
2
|
|
|
3
|
-
Self-host launcher for the Avocado Studio editor UI. Serves a prebuilt editor bundle and points it at any
|
|
3
|
+
Self-host launcher for the Avocado Studio editor UI. Serves a prebuilt editor bundle and points it at any Avocado Studio orchestrator you control.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**This package is the editor UI and nothing else.** There is no third service to
|
|
6
|
+
deploy, and for most sites there is no separate orchestrator to deploy either —
|
|
7
|
+
see [Library mode](#library-mode-the-common-case) before following the Quick
|
|
8
|
+
Start, which describes the standalone deployment.
|
|
9
|
+
|
|
10
|
+
## Library mode: the common case
|
|
11
|
+
|
|
12
|
+
If your site mounts `createOrchestrator` from `@avocadostudio-ai/site-sdk` — the
|
|
13
|
+
path the [integration docs](https://docs.avocadostudio.dev/integration/nextjs-integration)
|
|
14
|
+
describe — the orchestrator is already running *inside your site*, at
|
|
15
|
+
`/api/avocado`. Point the CLI at it:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx @avocadostudio-ai/cli start \
|
|
19
|
+
--orchestrator http://localhost:3000/api/avocado \
|
|
20
|
+
--preview http://localhost:3000
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Two commands total, in two terminals: your `dev` script, and this. Substitute
|
|
24
|
+
your own port — `3000` is the Next.js default, not a requirement. The default
|
|
25
|
+
`--orchestrator` value below (`http://localhost:4200`) is for the standalone
|
|
26
|
+
server and is **wrong for library mode**; pass the flag.
|
|
27
|
+
|
|
28
|
+
## Quick Start (standalone orchestrator)
|
|
6
29
|
|
|
7
30
|
```bash
|
|
8
31
|
npx @avocadostudio-ai/cli start --orchestrator https://your-orchestrator.example.com
|
|
@@ -20,8 +43,8 @@ npx @avocadostudio-ai/cli start \
|
|
|
20
43
|
|
|
21
44
|
## What You Need
|
|
22
45
|
|
|
23
|
-
- An
|
|
24
|
-
- A site that integrates
|
|
46
|
+
- An orchestrator the editor can reach — either mounted in your site (library mode, above) or deployed separately.
|
|
47
|
+
- A site that integrates [`@avocadostudio-ai/site-sdk`](https://www.npmjs.com/package/@avocadostudio-ai/site-sdk) so the editor can load, edit, and publish to it. Its README is the fullest reference for both modes.
|
|
25
48
|
- Node.js 22+.
|
|
26
49
|
|
|
27
50
|
## Flags
|
|
@@ -46,13 +69,13 @@ This means the same prebuilt bundle works against any orchestrator — no rebuil
|
|
|
46
69
|
|
|
47
70
|
The CLI ships a frozen editor build that speaks postMessage protocol `site-editor/v1`. On startup it probes the orchestrator's `/health` endpoint and warns if the reported `protocolVersion` does not match. The warning does not block startup — the editor may still work if the protocol changes were backwards-compatible.
|
|
48
71
|
|
|
49
|
-
Pin the CLI version to your orchestrator deployment if you want strict compatibility
|
|
72
|
+
Pin the CLI version to your orchestrator deployment if you want strict compatibility — `npx @avocadostudio-ai/cli@<version> start ...`, using the version your site's `@avocadostudio-ai/*` packages are on. Keep the two in step: the CLI ships a frozen editor build, so a CLI several releases behind your site is the usual cause of an editor that loads and then behaves oddly.
|
|
50
73
|
|
|
51
74
|
## What This Is Not
|
|
52
75
|
|
|
53
76
|
- **Not an auth layer.** The orchestrator handles auth via its `/auth/status` and `/auth/verify` routes; set `ACCESS_PASSWORD_HASH` on the orchestrator side. The CLI doesn't proxy or gate requests.
|
|
54
77
|
- **Not a managed service.** No telemetry is sent anywhere. If you want the hosted Avocado Studio with managed orchestrator + eval pipeline, see the project homepage.
|
|
55
|
-
- **Not
|
|
78
|
+
- **Not an orchestrator.** This CLI is the editor UI. The orchestrator runs either inside your site (`createOrchestrator`, the common case) or separately (Render, Fly, Docker, your own box). Either way it is not in this package — but "separately" is not the only option, and reading this line as "you must deploy a third service" is the misreading it used to invite.
|
|
56
79
|
|
|
57
80
|
## License
|
|
58
81
|
|
package/dist/index.js
CHANGED
|
@@ -13922,7 +13922,16 @@ var f = {
|
|
|
13922
13922
|
text: (label) => ({ kind: "text", label }),
|
|
13923
13923
|
longtext: (label) => ({ kind: "text", label, multiline: true }),
|
|
13924
13924
|
richtext: (label) => ({ kind: "richtext", label }),
|
|
13925
|
+
/** A resource address — an iframe src, a video file. Never an internal page. */
|
|
13925
13926
|
url: (label) => ({ kind: "url", label, inlineEditable: false }),
|
|
13927
|
+
/** A navigation target: an internal page, or an external URL / mailto / tel / anchor. */
|
|
13928
|
+
link: (label) => ({ kind: "link", label, inlineEditable: false }),
|
|
13929
|
+
/**
|
|
13930
|
+
* The "open in new tab" companion for a link prop. Named by convention
|
|
13931
|
+
* (`newTabKeyFor`) so the property panel renders it inside the link control
|
|
13932
|
+
* rather than as a row of its own — the same pairing as `image`/`imageAlt`.
|
|
13933
|
+
*/
|
|
13934
|
+
newTab: (label = "Open in new tab") => ({ kind: "boolean", label, inlineEditable: false }),
|
|
13926
13935
|
image: (label, imageSpec) => ({ kind: "image", label, inlineEditable: false, ...imageSpec ? { imageSpec } : {} }),
|
|
13927
13936
|
imageAlt: (label) => ({ kind: "imageAlt", label }),
|
|
13928
13937
|
headingLevel: () => ({ kind: "headingLevel", label: "Heading type", inlineEditable: false })
|
|
@@ -13935,13 +13944,15 @@ registerBlock("Hero", {
|
|
|
13935
13944
|
subheading: external_exports.string().min(1),
|
|
13936
13945
|
ctaText: external_exports.string().min(1),
|
|
13937
13946
|
ctaHref: external_exports.string().min(1),
|
|
13947
|
+
ctaNewTab: external_exports.boolean().optional(),
|
|
13938
13948
|
imageUrl: external_exports.string().min(1),
|
|
13939
13949
|
imageAlt: external_exports.string().min(1),
|
|
13940
13950
|
imagePosition: external_exports.enum(["left", "right", "full"]).default("right").catch("right"),
|
|
13941
13951
|
textAlign: external_exports.enum(["left", "center"]).default("left").catch("left"),
|
|
13942
13952
|
eyebrow: external_exports.string().optional(),
|
|
13943
13953
|
secondaryCtaText: external_exports.string().optional(),
|
|
13944
|
-
secondaryCtaHref: external_exports.string().optional()
|
|
13954
|
+
secondaryCtaHref: external_exports.string().optional(),
|
|
13955
|
+
secondaryCtaNewTab: external_exports.boolean().optional()
|
|
13945
13956
|
}),
|
|
13946
13957
|
meta: {
|
|
13947
13958
|
displayName: "Hero",
|
|
@@ -13951,14 +13962,16 @@ registerBlock("Hero", {
|
|
|
13951
13962
|
heading: f.text("Heading"),
|
|
13952
13963
|
subheading: f.text("Subheading"),
|
|
13953
13964
|
ctaText: f.text("CTA button text"),
|
|
13954
|
-
ctaHref: f.
|
|
13965
|
+
ctaHref: f.link("CTA link"),
|
|
13966
|
+
ctaNewTab: f.newTab(),
|
|
13955
13967
|
imageUrl: f.image("Hero image", { aspectRatio: "landscape", width: 1536, height: 1024 }),
|
|
13956
13968
|
imageAlt: f.imageAlt("Hero image alt text"),
|
|
13957
13969
|
imagePosition: { kind: "enum", label: "Image position", options: ["left", "right", "full"], inlineEditable: false },
|
|
13958
13970
|
textAlign: { kind: "enum", label: "Text alignment", options: ["left", "center"], inlineEditable: false },
|
|
13959
13971
|
eyebrow: f.text("Eyebrow text"),
|
|
13960
13972
|
secondaryCtaText: f.text("Secondary CTA text"),
|
|
13961
|
-
secondaryCtaHref: f.
|
|
13973
|
+
secondaryCtaHref: f.link("Secondary CTA link"),
|
|
13974
|
+
secondaryCtaNewTab: f.newTab(),
|
|
13962
13975
|
headingLevel: f.headingLevel()
|
|
13963
13976
|
}
|
|
13964
13977
|
}
|
|
@@ -14060,8 +14073,10 @@ registerBlock("CTA", {
|
|
|
14060
14073
|
description: external_exports.string().min(1),
|
|
14061
14074
|
ctaText: external_exports.string().min(1),
|
|
14062
14075
|
ctaHref: external_exports.string().min(1),
|
|
14076
|
+
ctaNewTab: external_exports.boolean().optional(),
|
|
14063
14077
|
secondaryCtaText: external_exports.string().optional(),
|
|
14064
|
-
secondaryCtaHref: external_exports.string().optional()
|
|
14078
|
+
secondaryCtaHref: external_exports.string().optional(),
|
|
14079
|
+
secondaryCtaNewTab: external_exports.boolean().optional()
|
|
14065
14080
|
}),
|
|
14066
14081
|
meta: {
|
|
14067
14082
|
displayName: "Call to Action",
|
|
@@ -14071,9 +14086,11 @@ registerBlock("CTA", {
|
|
|
14071
14086
|
title: f.text("Headline"),
|
|
14072
14087
|
description: f.longtext("Description"),
|
|
14073
14088
|
ctaText: f.text("Button text"),
|
|
14074
|
-
ctaHref: f.
|
|
14089
|
+
ctaHref: f.link("Button link"),
|
|
14090
|
+
ctaNewTab: f.newTab(),
|
|
14075
14091
|
secondaryCtaText: f.text("Secondary button text"),
|
|
14076
|
-
secondaryCtaHref: f.
|
|
14092
|
+
secondaryCtaHref: f.link("Secondary button link"),
|
|
14093
|
+
secondaryCtaNewTab: f.newTab(),
|
|
14077
14094
|
headingLevel: f.headingLevel()
|
|
14078
14095
|
}
|
|
14079
14096
|
}
|
|
@@ -14086,6 +14103,7 @@ registerBlock("Card", {
|
|
|
14086
14103
|
description: external_exports.string().min(1),
|
|
14087
14104
|
ctaText: external_exports.string().min(1),
|
|
14088
14105
|
ctaHref: external_exports.string().min(1),
|
|
14106
|
+
ctaNewTab: external_exports.boolean().optional(),
|
|
14089
14107
|
imageUrl: external_exports.string().min(1).optional(),
|
|
14090
14108
|
imageAlt: external_exports.string().min(1).optional(),
|
|
14091
14109
|
variant: external_exports.enum(["default", "full-bleed"]).default("default").catch("default")
|
|
@@ -14098,7 +14116,8 @@ registerBlock("Card", {
|
|
|
14098
14116
|
title: f.text("Card title"),
|
|
14099
14117
|
description: f.longtext("Card description"),
|
|
14100
14118
|
ctaText: f.text("Button text"),
|
|
14101
|
-
ctaHref: f.
|
|
14119
|
+
ctaHref: f.link("Button link"),
|
|
14120
|
+
ctaNewTab: f.newTab(),
|
|
14102
14121
|
imageUrl: f.image("Card image", { aspectRatio: "landscape", width: 768, height: 512 }),
|
|
14103
14122
|
imageAlt: f.imageAlt("Card image alt text"),
|
|
14104
14123
|
variant: { kind: "enum", label: "Variant", options: ["default", "full-bleed"], inlineEditable: false },
|
|
@@ -14121,6 +14140,7 @@ registerBlock("CardGrid", {
|
|
|
14121
14140
|
description: external_exports.string().min(1),
|
|
14122
14141
|
ctaText: external_exports.string().min(1),
|
|
14123
14142
|
ctaHref: external_exports.string().min(1),
|
|
14143
|
+
ctaNewTab: external_exports.boolean().optional(),
|
|
14124
14144
|
imageUrl: external_exports.string().min(1).optional(),
|
|
14125
14145
|
imageAlt: external_exports.string().min(1).optional()
|
|
14126
14146
|
})
|
|
@@ -14144,7 +14164,8 @@ registerBlock("CardGrid", {
|
|
|
14144
14164
|
title: f.text("Card title"),
|
|
14145
14165
|
description: f.longtext("Card description"),
|
|
14146
14166
|
ctaText: f.text("Button text"),
|
|
14147
|
-
ctaHref: f.
|
|
14167
|
+
ctaHref: f.link("Button link"),
|
|
14168
|
+
ctaNewTab: f.newTab(),
|
|
14148
14169
|
imageUrl: f.image("Card image", { aspectRatio: "landscape", width: 768, height: 512 }),
|
|
14149
14170
|
imageAlt: f.imageAlt("Card image alt text")
|
|
14150
14171
|
}
|
|
@@ -14212,6 +14233,7 @@ var twoColumnChild = external_exports.object({
|
|
|
14212
14233
|
text: external_exports.string().optional(),
|
|
14213
14234
|
label: external_exports.string().optional(),
|
|
14214
14235
|
href: external_exports.string().optional(),
|
|
14236
|
+
newTab: external_exports.boolean().optional(),
|
|
14215
14237
|
src: external_exports.string().optional(),
|
|
14216
14238
|
alt: external_exports.string().optional(),
|
|
14217
14239
|
poster: external_exports.string().optional(),
|
|
@@ -14223,7 +14245,8 @@ var twoColumnItemFields = {
|
|
|
14223
14245
|
type: { kind: "enum", label: "Component type", options: ["heading", "subheading", "paragraph", "list", "cta", "ctas", "image", "video"] },
|
|
14224
14246
|
text: f.longtext("Text content"),
|
|
14225
14247
|
label: f.text("Button label"),
|
|
14226
|
-
href: f.
|
|
14248
|
+
href: f.link("Link URL"),
|
|
14249
|
+
newTab: f.newTab(),
|
|
14227
14250
|
src: f.image("Media source", { aspectRatio: "portrait", width: 768, height: 1024 }),
|
|
14228
14251
|
alt: f.imageAlt("Alt text"),
|
|
14229
14252
|
poster: f.image("Video poster image", { aspectRatio: "landscape", width: 768, height: 512 })
|
|
@@ -14293,7 +14316,8 @@ registerBlock("Footer", {
|
|
|
14293
14316
|
var navLinkLeaf = external_exports.object({
|
|
14294
14317
|
id: external_exports.string().optional(),
|
|
14295
14318
|
label: external_exports.string().min(1),
|
|
14296
|
-
href: external_exports.string().min(1)
|
|
14319
|
+
href: external_exports.string().min(1),
|
|
14320
|
+
newTab: external_exports.boolean().optional()
|
|
14297
14321
|
});
|
|
14298
14322
|
registerBlock("SiteHeader", {
|
|
14299
14323
|
schema: external_exports.object({
|
|
@@ -14320,7 +14344,8 @@ registerBlock("SiteHeader", {
|
|
|
14320
14344
|
label: "Nav links",
|
|
14321
14345
|
itemFields: {
|
|
14322
14346
|
label: f.text("Link label"),
|
|
14323
|
-
href: f.
|
|
14347
|
+
href: f.link("Link URL"),
|
|
14348
|
+
newTab: f.newTab()
|
|
14324
14349
|
}
|
|
14325
14350
|
}
|
|
14326
14351
|
}
|
|
@@ -14355,6 +14380,7 @@ registerBlock("Banner", {
|
|
|
14355
14380
|
variant: external_exports.enum(["info", "success", "warning"]).default("info").catch("info"),
|
|
14356
14381
|
ctaText: external_exports.string().optional(),
|
|
14357
14382
|
ctaHref: external_exports.string().optional(),
|
|
14383
|
+
ctaNewTab: external_exports.boolean().optional(),
|
|
14358
14384
|
backgroundColor: external_exports.string().optional(),
|
|
14359
14385
|
textColor: external_exports.string().optional()
|
|
14360
14386
|
}),
|
|
@@ -14366,7 +14392,8 @@ registerBlock("Banner", {
|
|
|
14366
14392
|
text: f.text("Banner text"),
|
|
14367
14393
|
variant: { kind: "enum", label: "Variant", options: ["info", "success", "warning"], inlineEditable: false },
|
|
14368
14394
|
ctaText: f.text("Button label"),
|
|
14369
|
-
ctaHref: f.
|
|
14395
|
+
ctaHref: f.link("Button link"),
|
|
14396
|
+
ctaNewTab: f.newTab(),
|
|
14370
14397
|
backgroundColor: { kind: "color", label: "Background color", inlineEditable: false },
|
|
14371
14398
|
textColor: { kind: "color", label: "Text color", inlineEditable: false }
|
|
14372
14399
|
}
|
|
@@ -14383,7 +14410,8 @@ registerBlock("Carousel", {
|
|
|
14383
14410
|
heading: external_exports.string().optional(),
|
|
14384
14411
|
description: external_exports.string().optional(),
|
|
14385
14412
|
ctaText: external_exports.string().optional(),
|
|
14386
|
-
ctaHref: external_exports.string().optional()
|
|
14413
|
+
ctaHref: external_exports.string().optional(),
|
|
14414
|
+
ctaNewTab: external_exports.boolean().optional()
|
|
14387
14415
|
})).min(1),
|
|
14388
14416
|
autoplay: external_exports.enum(["true", "false"]).default("false").catch("false"),
|
|
14389
14417
|
interval: external_exports.number().optional()
|
|
@@ -14405,7 +14433,8 @@ registerBlock("Carousel", {
|
|
|
14405
14433
|
heading: f.text("Heading"),
|
|
14406
14434
|
description: f.longtext("Description"),
|
|
14407
14435
|
ctaText: f.text("Button label"),
|
|
14408
|
-
ctaHref: f.
|
|
14436
|
+
ctaHref: f.link("Button link"),
|
|
14437
|
+
ctaNewTab: f.newTab()
|
|
14409
14438
|
}
|
|
14410
14439
|
}
|
|
14411
14440
|
}
|
|
@@ -14490,8 +14519,11 @@ registerBlock("Table", {
|
|
|
14490
14519
|
fields: {
|
|
14491
14520
|
title: f.text("Section title"),
|
|
14492
14521
|
headingLevel: f.headingLevel(),
|
|
14493
|
-
|
|
14494
|
-
|
|
14522
|
+
// Both are lists of scalars, which `FieldKind` cannot name — the panel
|
|
14523
|
+
// recognises the value's shape instead: `headers` edits one per line,
|
|
14524
|
+
// `rows` (string[][]) is shown there and edited cell-by-cell in the page.
|
|
14525
|
+
headers: f.text("Column headers (one per line)"),
|
|
14526
|
+
rows: f.text("Table rows (edit cells in the page)"),
|
|
14495
14527
|
striped: { kind: "enum", label: "Striped rows", options: ["true", "false"], inlineEditable: false }
|
|
14496
14528
|
}
|
|
14497
14529
|
}
|
|
@@ -14559,7 +14591,7 @@ var jsonSchemaLikeSchema = external_exports.lazy(
|
|
|
14559
14591
|
}).catchall(external_exports.unknown())
|
|
14560
14592
|
);
|
|
14561
14593
|
var fieldMetaSchema = external_exports.object({
|
|
14562
|
-
kind: external_exports.enum(["text", "richtext", "url", "image", "imageAlt", "enum", "color", "number", "boolean", "headingLevel"]),
|
|
14594
|
+
kind: external_exports.enum(["text", "richtext", "url", "link", "image", "imageAlt", "enum", "color", "number", "boolean", "headingLevel"]),
|
|
14563
14595
|
label: external_exports.string().optional(),
|
|
14564
14596
|
inlineEditable: external_exports.boolean().optional(),
|
|
14565
14597
|
options: external_exports.array(external_exports.string()).optional(),
|
|
@@ -15041,7 +15073,19 @@ var chatStartResponseSchema = external_exports.object({
|
|
|
15041
15073
|
error: external_exports.string().optional()
|
|
15042
15074
|
}).passthrough();
|
|
15043
15075
|
var slugsResponseSchema = external_exports.object({
|
|
15044
|
-
slugs: external_exports.array(external_exports.string()).optional()
|
|
15076
|
+
slugs: external_exports.array(external_exports.string()).optional(),
|
|
15077
|
+
/*
|
|
15078
|
+
* The same pages the `slugs` array names, with the title and the URL that
|
|
15079
|
+
* `/draft/slugs` has always returned beside them. The editor parsed this
|
|
15080
|
+
* response and kept only the bare slugs, so the link picker had nothing to
|
|
15081
|
+
* label a page with; `path` is what a locale-prefixed site navigates to when
|
|
15082
|
+
* it differs from the slug (see docs/ideas/page-identity-punch-list.md).
|
|
15083
|
+
*/
|
|
15084
|
+
pages: external_exports.array(external_exports.object({
|
|
15085
|
+
slug: external_exports.string(),
|
|
15086
|
+
path: external_exports.string().optional(),
|
|
15087
|
+
title: external_exports.string().optional()
|
|
15088
|
+
}).passthrough()).optional()
|
|
15045
15089
|
}).passthrough();
|
|
15046
15090
|
var bootstrapResponseSchema = external_exports.object({
|
|
15047
15091
|
slugs: external_exports.array(external_exports.string()).optional()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as b}from"./chunk-2CNEFIQP-
|
|
1
|
+
import{P as b}from"./chunk-2CNEFIQP-B3HjHnn-.js";import{u as y,a as j,E as L,_ as m,L as M,b as p,o as P,i as A}from"./PuckPrototypeRoute-CEtarLZd.js";import{r as s,j as g}from"./index-8s1LXOA6.js";import{E as N,u as U}from"./index-B0cipFdl.js";import"./index-CIC8kldS.js";A();A();function C({content:a,onChange:x,extensions:v,editable:d=!0,onFocusChange:o,name:c}){const[i,E]=P(null,50,{leading:!0,maxWait:200}),l=s.useRef(!1),S=s.useRef(""),f=s.useRef(null),R=!!f.current,_=j(t=>t.state.ui.field.focus===c),T=t=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{S.current===t&&(f.current=null)},200)},u=y(),e=U({extensions:v,content:a,editable:d,immediatelyRender:!1,parseOptions:{preserveWhitespace:"full"},onUpdate:({editor:t})=>{if(l.current||!_){u.getState().setUi({field:{focus:c}});return}const r=t.getHTML(),{from:n,to:h}=t.state.selection;E({from:n,to:h,html:r}),T(r),S.current=r}});return s.useEffect(()=>{if(!e)return;const t=()=>{o==null||o(e)};return e.on("focus",t),()=>{e.off("focus",t)}},[e,o]),s.useEffect(()=>{if(i){const{ui:t}=u.getState().state;x(i.html,{field:m(p({},t.field),{metadata:{from:i.from,to:i.to}})})}},[e,i,x,u,c]),s.useEffect(()=>{e==null||e.setEditable(d)},[e,d]),s.useEffect(()=>{var t;if(!e||R||e.getHTML()===a)return;l.current=!0,e.commands.setContent(a,{emitUpdate:!1});const{ui:n}=u.getState().state;typeof((t=n.field.metadata)==null?void 0:t.from)<"u"&&e.commands.setTextSelection({from:n.field.metadata.from,to:n.field.metadata.to}),l.current=!1},[a,e,u]),e}var F=s.memo(a=>{const{onChange:x,content:v,readOnly:d=!1,field:o,inline:c=!1,onFocus:i,id:E,name:l}=a,{tiptap:S={},options:f}=o,{extensions:R=[]}=S,_=s.useMemo(()=>[b.configure(f),...R],[o,R]),T=y(),u=`${l}${c?"::inline":""}`,e=C({content:v,onChange:x,extensions:_,editable:!d,name:u,onFocusChange:r=>{if(r){const n=T.getState();T.setState({currentRichText:{field:o,editor:r,id:E,inline:c},state:m(p({},n.state),{ui:m(p({},n.state.ui),{field:m(p({},n.state.ui.field),{focus:u})})})}),i==null||i(r)}}}),t=j(r=>{var n,h;return!c&&((n=r.currentRichText)==null?void 0:n.id)===E&&((h=r.currentRichText)!=null&&h.inlineComponentId)?r.currentRichText.editor:e});return e?g.jsx(L,m(p({},a),{editor:e,menu:g.jsx(M,{field:o,editor:t,readOnly:d}),children:g.jsx(N,{editor:e,className:"rich-text"})})):null});F.displayName="Editor";export{F as Editor};
|