@jbpark/live-editor 4.4.0 → 4.6.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/README.ko.md +4 -1
- package/README.md +7 -3
- package/dist/{boundary-B17cepvm.js → boundary-BLB80tyw.js} +8 -5
- package/dist/boundary-BLB80tyw.js.map +1 -0
- package/dist/cache-B0-XcIxJ.js.map +1 -1
- package/dist/{compile-DDfk5P25.js → compile-Dxas-D05.js} +3 -3
- package/dist/compile-Dxas-D05.js.map +1 -0
- package/dist/{constants-h1JAgOeW.js → constants-DU17Tdwo.js} +3 -3
- package/dist/constants-DU17Tdwo.js.map +1 -0
- package/dist/{context-DB5kW3qe.js → context-B8MzP7_p.js} +11 -5
- package/dist/context-B8MzP7_p.js.map +1 -0
- package/dist/{core-CRsAGpei.js → core-Bgfek364.js} +2 -2
- package/dist/core-Bgfek364.js.map +1 -0
- package/dist/{detect-typescript-CCj9ALXc.js → detect-typescript-Dr_oLniM.js} +2 -2
- package/dist/detect-typescript-Dr_oLniM.js.map +1 -0
- package/dist/dnd/index.d.ts +1 -1
- package/dist/dnd/index.js +1 -1
- package/dist/{dnd-BE5ZizqX.js → dnd-UoJILA75.js} +973 -885
- package/dist/dnd-UoJILA75.js.map +1 -0
- package/dist/{document-BDn_f08_.js → document-CGbe6bSV.js} +7739 -7736
- package/dist/document-CGbe6bSV.js.map +1 -0
- package/dist/editor/index.js +2 -2
- package/dist/{editor-DQ8Q--qR.js → editor-CMElfHer.js} +2 -2
- package/dist/editor-CMElfHer.js.map +1 -0
- package/dist/editor-caches-ClMvdcQF.js.map +1 -1
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +2 -2
- package/dist/{error-DWhxQEom.js → error-CN_GCnXB.js} +13 -6
- package/dist/error-CN_GCnXB.js.map +1 -0
- package/dist/{index-Dgh1JTX3.d.ts → index-C69Lv-jR.d.ts} +72 -69
- package/dist/{index-C4SGQ3Ci.d.ts → index-CRwEhJ7w.d.ts} +4 -1
- package/dist/{index-f7ijuNTa.d.ts → index-DKYUxi-E.d.ts} +115 -155
- package/dist/index-DrWtSKXu.d.ts +11 -0
- package/dist/index.d.ts +18 -18
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/{ast-dYb78955.js → items-B6OXxcLG.js} +588 -718
- package/dist/items-B6OXxcLG.js.map +1 -0
- package/dist/messages-CSrMI4Rm.js +133 -0
- package/dist/messages-CSrMI4Rm.js.map +1 -0
- package/dist/messages-IBPs4TkZ.d.ts +130 -0
- package/dist/preview/index.js +2 -2
- package/dist/{preview-BnaCEFsF.js → preview-CtyG5UbH.js} +6 -4
- package/dist/preview-CtyG5UbH.js.map +1 -0
- package/dist/provider/index.d.ts +3 -8
- package/dist/provider/index.js +3 -2
- package/dist/{sections-CBVMO8Jl.js → sections-BYWOBISr.js} +9 -4
- package/dist/sections-BYWOBISr.js.map +1 -0
- package/dist/states-Ci1AvoQ9.js.map +1 -1
- package/dist/style.css +505 -21
- package/dist/{use-dynamic-tailwind-Bcipc1hL.js → use-dynamic-tailwind-BP1toJkW.js} +66 -40
- package/dist/use-dynamic-tailwind-BP1toJkW.js.map +1 -0
- package/dist/utils/ast/index.d.ts +3 -2
- package/dist/utils/ast/index.js +150 -3
- package/dist/utils/ast/index.js.map +1 -0
- package/dist/utils/index.d.ts +30 -13
- package/dist/utils/index.js +26 -6
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/tailwind/index.js.map +1 -1
- package/dist/validate-DB59Z_Nx.d.ts +100 -0
- package/dist/validate-iLo8IONY.js +64 -0
- package/dist/validate-iLo8IONY.js.map +1 -0
- package/package.json +3 -3
- package/dist/ast-dYb78955.js.map +0 -1
- package/dist/boundary-B17cepvm.js.map +0 -1
- package/dist/compile-DDfk5P25.js.map +0 -1
- package/dist/constants-h1JAgOeW.js.map +0 -1
- package/dist/context-DB5kW3qe.js.map +0 -1
- package/dist/core-CRsAGpei.js.map +0 -1
- package/dist/detect-typescript-CCj9ALXc.js.map +0 -1
- package/dist/dnd-BE5ZizqX.js.map +0 -1
- package/dist/document-BDn_f08_.js.map +0 -1
- package/dist/editor-DQ8Q--qR.js.map +0 -1
- package/dist/error-DWhxQEom.js.map +0 -1
- package/dist/preview-BnaCEFsF.js.map +0 -1
- package/dist/sections-CBVMO8Jl.js.map +0 -1
- package/dist/use-dynamic-tailwind-Bcipc1hL.js.map +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { t as ValidationMessages } from "./validate-DB59Z_Nx.js";
|
|
2
|
+
//#region src/components/context/messages.d.ts
|
|
3
|
+
interface LiveMessages {
|
|
4
|
+
section: {
|
|
5
|
+
moveUp: string;
|
|
6
|
+
moveDown: string;
|
|
7
|
+
duplicate: string;
|
|
8
|
+
delete: string;
|
|
9
|
+
};
|
|
10
|
+
canvas: {
|
|
11
|
+
palette: string;
|
|
12
|
+
properties: string;
|
|
13
|
+
pickElement: string;
|
|
14
|
+
pickElementActive: string;
|
|
15
|
+
dropHere: string;
|
|
16
|
+
dropAtBottom: string;
|
|
17
|
+
empty: string;
|
|
18
|
+
emptyHintTouch: string;
|
|
19
|
+
emptyHintDrag: string;
|
|
20
|
+
syntaxError: string;
|
|
21
|
+
syntaxErrorDetail: string;
|
|
22
|
+
missingContainer: (containerId: string) => string;
|
|
23
|
+
missingContainerDetail: (containerId: string) => string;
|
|
24
|
+
stale: string;
|
|
25
|
+
};
|
|
26
|
+
panel: {
|
|
27
|
+
selectSection: string;
|
|
28
|
+
noEditableElements: string;
|
|
29
|
+
readOnly: string;
|
|
30
|
+
expressionPreserved: string;
|
|
31
|
+
useCodeEditor: string;
|
|
32
|
+
invalidValue: string;
|
|
33
|
+
urlPlaceholder: string;
|
|
34
|
+
numberPlaceholder: string;
|
|
35
|
+
textPlaceholder: string;
|
|
36
|
+
};
|
|
37
|
+
items: {
|
|
38
|
+
heading: (count: number) => string;
|
|
39
|
+
add: string;
|
|
40
|
+
item: (position: number) => string;
|
|
41
|
+
reorder: (item: string) => string;
|
|
42
|
+
moveUp: string;
|
|
43
|
+
moveDown: string;
|
|
44
|
+
delete: string;
|
|
45
|
+
collapseAll: string;
|
|
46
|
+
expandAll: string;
|
|
47
|
+
unreadable: string;
|
|
48
|
+
empty: string;
|
|
49
|
+
structureLocked: string;
|
|
50
|
+
noNestedBindings: string;
|
|
51
|
+
};
|
|
52
|
+
children: {
|
|
53
|
+
heading: (count: number) => string;
|
|
54
|
+
add: string;
|
|
55
|
+
child: (position: number, tagName: string) => string;
|
|
56
|
+
moveUp: string;
|
|
57
|
+
moveDown: string;
|
|
58
|
+
delete: string;
|
|
59
|
+
editableBindings: string;
|
|
60
|
+
childNodes: string;
|
|
61
|
+
};
|
|
62
|
+
selection: {
|
|
63
|
+
count: (count: number) => string;
|
|
64
|
+
duplicate: string;
|
|
65
|
+
moveUp: string;
|
|
66
|
+
moveDown: string;
|
|
67
|
+
delete: string;
|
|
68
|
+
clear: string;
|
|
69
|
+
};
|
|
70
|
+
editErrors: {
|
|
71
|
+
updateFailed: (label: string) => string;
|
|
72
|
+
cannotEdit: (label: string) => string;
|
|
73
|
+
cannotRemove: (label: string) => string;
|
|
74
|
+
attributeNotFound: (property: string) => string;
|
|
75
|
+
bindingNotDeclared: (target: {
|
|
76
|
+
label: string;
|
|
77
|
+
property?: string;
|
|
78
|
+
}) => string;
|
|
79
|
+
duplicateBinding: (target: {
|
|
80
|
+
count: number;
|
|
81
|
+
label: string;
|
|
82
|
+
property?: string;
|
|
83
|
+
}) => string;
|
|
84
|
+
reservedProperty: (property: string) => string;
|
|
85
|
+
requiredProperty: (property: string) => string;
|
|
86
|
+
noBinding: string;
|
|
87
|
+
elementNotFound: string;
|
|
88
|
+
unsupportedSyntax: (property: string) => string;
|
|
89
|
+
selfClosing: (property: string) => string;
|
|
90
|
+
checkConsole: string;
|
|
91
|
+
syntaxError: string;
|
|
92
|
+
syntaxErrorDetail: string;
|
|
93
|
+
missingContainer: (containerId: string) => string;
|
|
94
|
+
missingContainerDetail: (containerId: string) => string;
|
|
95
|
+
sectionParseFailed: string;
|
|
96
|
+
itemsParseFailed: string;
|
|
97
|
+
itemUpdateFailed: string;
|
|
98
|
+
itemUpdateFailedDetail: string;
|
|
99
|
+
};
|
|
100
|
+
announcements: {
|
|
101
|
+
instructions: string;
|
|
102
|
+
section: string;
|
|
103
|
+
pickedUp: (name: string) => string;
|
|
104
|
+
movedTo: (name: string, position: number, total: number) => string;
|
|
105
|
+
notOver: (name: string) => string;
|
|
106
|
+
droppedAt: (name: string, position: number, total: number) => string;
|
|
107
|
+
dropped: (name: string) => string;
|
|
108
|
+
cancelled: (name: string) => string;
|
|
109
|
+
itemOver: (name: string, over: string) => string;
|
|
110
|
+
itemMoved: (name: string, over: string) => string;
|
|
111
|
+
};
|
|
112
|
+
errors: {
|
|
113
|
+
default: string;
|
|
114
|
+
compile: string;
|
|
115
|
+
runtime: string;
|
|
116
|
+
rendering: string;
|
|
117
|
+
sectionUnavailable: string;
|
|
118
|
+
sectionNotRendered: string;
|
|
119
|
+
tryAgain: string;
|
|
120
|
+
unknown: string;
|
|
121
|
+
unhandledRejection: string;
|
|
122
|
+
};
|
|
123
|
+
validation: ValidationMessages;
|
|
124
|
+
}
|
|
125
|
+
type LiveMessagesInput = { [Group in keyof LiveMessages]?: Partial<LiveMessages[Group]>; };
|
|
126
|
+
declare const defaultMessages: LiveMessages;
|
|
127
|
+
declare const useLiveMessages: () => LiveMessages;
|
|
128
|
+
//#endregion
|
|
129
|
+
export { useLiveMessages as i, LiveMessagesInput as n, defaultMessages as r, LiveMessages as t };
|
|
130
|
+
//# sourceMappingURL=messages-IBPs4TkZ.d.ts.map
|
package/dist/preview/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { r as baseModules } from "../use-dynamic-tailwind-
|
|
2
|
-
import { t as Preview } from "../preview-
|
|
1
|
+
import { r as baseModules } from "../use-dynamic-tailwind-BP1toJkW.js";
|
|
2
|
+
import { t as Preview } from "../preview-CtyG5UbH.js";
|
|
3
3
|
export { baseModules, Preview as default };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { i as useLiveMessages } from "./messages-CSrMI4Rm.js";
|
|
1
2
|
import { i as usePreview, r as useError } from "./states-Ci1AvoQ9.js";
|
|
2
3
|
import { t as cn } from "./cn-CAnad2vL.js";
|
|
3
|
-
import {
|
|
4
|
-
import { t as Error } from "./error-
|
|
4
|
+
import { i as Frame, n as useCompiledModule, t as useDynamicTailwind } from "./use-dynamic-tailwind-BP1toJkW.js";
|
|
5
|
+
import { t as Error } from "./error-CN_GCnXB.js";
|
|
5
6
|
import { useMemo } from "react";
|
|
6
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
//#region src/components/preview/defaults.ts
|
|
@@ -12,6 +13,7 @@ const NO_MODULES = {};
|
|
|
12
13
|
const Client = ({ code: _code, className, showError, props = NO_PROPS, modules = NO_MODULES, frame, dynamicTailwind = false, provider }) => {
|
|
13
14
|
const { code } = usePreview();
|
|
14
15
|
const { error, setError } = useError();
|
|
16
|
+
const messages = useLiveMessages();
|
|
15
17
|
const isError = !!showError && !!error;
|
|
16
18
|
const classNames = cn(isError && "hidden", className);
|
|
17
19
|
const effectiveCode = _code === void 0 ? code : _code;
|
|
@@ -25,7 +27,7 @@ const Client = ({ code: _code, className, showError, props = NO_PROPS, modules =
|
|
|
25
27
|
className: cn("relative h-full w-full", classNames),
|
|
26
28
|
children: /* @__PURE__ */ jsx(Error, {
|
|
27
29
|
message: module.error,
|
|
28
|
-
title:
|
|
30
|
+
title: messages.errors.compile
|
|
29
31
|
})
|
|
30
32
|
}), /* @__PURE__ */ jsx(Error.Runtime, { open: isError })] });
|
|
31
33
|
const Component = module?.exports?.default;
|
|
@@ -83,4 +85,4 @@ const Preview = ({ code, props = NO_PROPS, modules = NO_MODULES, dynamicTailwind
|
|
|
83
85
|
//#endregion
|
|
84
86
|
export { Preview as t };
|
|
85
87
|
|
|
86
|
-
//# sourceMappingURL=preview-
|
|
88
|
+
//# sourceMappingURL=preview-CtyG5UbH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-CtyG5UbH.js","names":["LiveError"],"sources":["../src/components/preview/defaults.ts","../src/components/preview/client.tsx","../src/components/preview/preview.tsx"],"sourcesContent":["// Stable defaults for optional object props. A `= {}` default is a new\n// object on every render, which re-runs every memo keyed on it — the merged\n// module map, and so `compile()` — even when the caller passed nothing (#348).\nexport const NO_PROPS: Record<string, unknown> = {};\nexport const NO_MODULES: Record<string, unknown> = {};\n","'use client';\n\nimport { useMemo } from 'react';\n\nimport { useLiveMessages } from '~/components/context/messages';\nimport { useError, usePreview } from '~/components/context/states';\nimport LiveError from '~/components/error';\nimport Frame, { type FrameProps } from '~/components/frame';\nimport { cn } from '~/utils/cn';\n\nimport { NO_MODULES, NO_PROPS } from './defaults';\nimport { type Props } from './preview';\nimport { useCompiledModule } from './use-compiled-module';\nimport { useDynamicTailwind } from './use-dynamic-tailwind';\n\nconst Client = ({\n code: _code,\n className,\n showError,\n props = NO_PROPS,\n modules = NO_MODULES,\n frame,\n dynamicTailwind = false,\n provider,\n}: Props) => {\n const { code } = usePreview();\n const { error, setError } = useError();\n const messages = useLiveMessages();\n const isError = !!showError && !!error;\n\n const classNames = cn(isError && 'hidden', className);\n\n const effectiveCode = _code === undefined ? code : _code;\n\n const module = useCompiledModule(effectiveCode, modules);\n\n // Attached to the wrapper below; scans the rendered DOM so classes coming\n // from an imported component are picked up too. See the hook for details.\n const { ref: contentRef, css: dynamicCSS } = useDynamicTailwind(\n effectiveCode,\n dynamicTailwind,\n );\n\n const componentProps = useMemo(\n () => ({\n ...props,\n }),\n [props],\n );\n\n const renderProvider = (component: React.ReactNode) => {\n return provider ? provider(component) : component;\n };\n\n if (module && module.error) {\n return (\n <>\n <div className={cn('relative h-full w-full', classNames)}>\n <LiveError message={module.error} title={messages.errors.compile} />\n </div>\n <LiveError.Runtime open={isError} />\n </>\n );\n }\n\n const Component = module?.exports?.default;\n\n if (!Component) {\n return null;\n }\n\n return (\n <>\n {frame ? (\n <div className={cn('h-full w-full', classNames)}>\n <Frame {...(frame as FrameProps)}>\n {container => (\n <div ref={contentRef} style={{ display: 'contents' }}>\n <LiveError.Boundary\n resetKeys={[effectiveCode]}\n onError={(e: Error) => setError(e.message)}\n >\n {renderProvider(\n <LiveError.Guard onError={e => setError(e.message)}>\n <Component {...componentProps} container={container} />\n {dynamicTailwind && dynamicCSS && (\n <style>{dynamicCSS}</style>\n )}\n </LiveError.Guard>,\n )}\n </LiveError.Boundary>\n </div>\n )}\n </Frame>\n </div>\n ) : (\n <div\n ref={contentRef}\n className={cn(\n 'relative h-full w-full overflow-x-hidden overflow-y-auto',\n classNames,\n )}\n style={{\n isolation: 'isolate',\n transform: 'translateZ(0)',\n containerType: 'inline-size',\n }}\n >\n <LiveError.Boundary\n resetKeys={[effectiveCode]}\n onError={e => setError(e.message)}\n >\n {renderProvider(\n <LiveError.Guard onError={e => setError(e.message)}>\n <Component {...componentProps} />\n {dynamicTailwind && dynamicCSS && <style>{dynamicCSS}</style>}\n </LiveError.Guard>,\n )}\n </LiveError.Boundary>\n </div>\n )}\n <LiveError.Runtime open={isError} />\n </>\n );\n};\n\nexport default Client;\n","import type React from 'react';\n\nimport type { FrameProps } from '../frame';\nimport Client from './client';\nimport { NO_MODULES, NO_PROPS } from './defaults';\n\nexport interface Props extends React.ComponentPropsWithRef<'div'> {\n code?: string;\n showError?: boolean;\n props?: Record<string, unknown>;\n container?: HTMLElement | null;\n frame?: boolean | FrameProps;\n modules?: Record<string, unknown>;\n dynamicTailwind?: boolean;\n provider?: (children: React.ReactNode) => React.ReactNode;\n}\n\n// `Live.Preview`: a thin wrapper around `Client`, which compiles, handles\n// errors and wraps the frame. One render path for both `code` and the\n// provider's code (#187).\nconst Preview = ({\n code,\n props = NO_PROPS,\n modules = NO_MODULES,\n dynamicTailwind = false,\n provider,\n ...restProps\n}: Props) => {\n return (\n <Client\n code={code}\n props={props}\n modules={modules}\n dynamicTailwind={dynamicTailwind}\n provider={provider}\n {...restProps}\n />\n );\n};\n\nexport default Preview;\n"],"mappings":";;;;;;;;AAGA,MAAa,WAAoC,CAAC;AAClD,MAAa,aAAsC,CAAC;;;ACWpD,MAAM,UAAU,EACd,MAAM,OACN,WACA,WACA,QAAQ,UACR,UAAU,YACV,OACA,kBAAkB,OAClB,eACW;CACX,MAAM,EAAE,SAAS,WAAW;CAC5B,MAAM,EAAE,OAAO,aAAa,SAAS;CACrC,MAAM,WAAW,gBAAgB;CACjC,MAAM,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC;CAEjC,MAAM,aAAa,GAAG,WAAW,UAAU,SAAS;CAEpD,MAAM,gBAAgB,UAAU,KAAA,IAAY,OAAO;CAEnD,MAAM,SAAS,kBAAkB,eAAe,OAAO;CAIvD,MAAM,EAAE,KAAK,YAAY,KAAK,eAAe,mBAC3C,eACA,eACF;CAEA,MAAM,iBAAiB,eACd,EACL,GAAG,MACL,IACA,CAAC,KAAK,CACR;CAEA,MAAM,kBAAkB,cAA+B;EACrD,OAAO,WAAW,SAAS,SAAS,IAAI;CAC1C;CAEA,IAAI,UAAU,OAAO,OACnB,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;EAAK,WAAW,GAAG,0BAA0B,UAAU;EACrD,UAAA,oBAACA,OAAD;GAAW,SAAS,OAAO;GAAO,OAAO,SAAS,OAAO;EAAU,CAAA;CAChE,CAAA,GACL,oBAACA,MAAU,SAAX,EAAmB,MAAM,QAAU,CAAA,CACnC,EAAA,CAAA;CAIN,MAAM,YAAY,QAAQ,SAAS;CAEnC,IAAI,CAAC,WACH,OAAO;CAGT,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,QACC,oBAAC,OAAD;EAAK,WAAW,GAAG,iBAAiB,UAAU;EAC5C,UAAA,oBAAC,OAAD;GAAO,GAAK;GACT,WAAA,cACC,oBAAC,OAAD;IAAK,KAAK;IAAY,OAAO,EAAE,SAAS,WAAW;IACjD,UAAA,oBAACA,MAAU,UAAX;KACE,WAAW,CAAC,aAAa;KACzB,UAAU,MAAa,SAAS,EAAE,OAAO;KAExC,UAAA,eACC,qBAACA,MAAU,OAAX;MAAiB,UAAS,MAAK,SAAS,EAAE,OAAO;MAAjD,UAAA,CACE,oBAAC,WAAD;OAAW,GAAI;OAA2B;MAAY,CAAA,GACrD,mBAAmB,cAClB,oBAAC,SAAD,EAAA,UAAQ,WAAkB,CAAA,CAEb;KACnB,CAAA,CAAA;IACkB,CAAA;GACjB,CAAA;EAEF,CAAA;CACJ,CAAA,IAEL,oBAAC,OAAD;EACE,KAAK;EACL,WAAW,GACT,4DACA,UACF;EACA,OAAO;GACL,WAAW;GACX,WAAW;GACX,eAAe;EACjB;EAEA,UAAA,oBAACA,MAAU,UAAX;GACE,WAAW,CAAC,aAAa;GACzB,UAAS,MAAK,SAAS,EAAE,OAAO;GAE/B,UAAA,eACC,qBAACA,MAAU,OAAX;IAAiB,UAAS,MAAK,SAAS,EAAE,OAAO;IAAjD,UAAA,CACE,oBAAC,WAAD,EAAW,GAAI,eAAiB,CAAA,GAC/B,mBAAmB,cAAc,oBAAC,SAAD,EAAA,UAAQ,WAAkB,CAAA,CAC7C;GACnB,CAAA,CAAA;EACkB,CAAA;CACjB,CAAA,GAEP,oBAACA,MAAU,SAAX,EAAmB,MAAM,QAAU,CAAA,CACnC,EAAA,CAAA;AAEN;;;ACxGA,MAAM,WAAW,EACf,MACA,QAAQ,UACR,UAAU,YACV,kBAAkB,OAClB,UACA,GAAG,gBACQ;CACX,OACE,oBAAC,QAAD;EACQ;EACC;EACE;EACQ;EACP;EACV,GAAI;CACL,CAAA;AAEL"}
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
}) => React.JSX.Element;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { ContextProvider as default };
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { i as useLiveMessages, n as LiveMessagesInput, r as defaultMessages, t as LiveMessages } from "../messages-IBPs4TkZ.js";
|
|
2
|
+
import { n as Props, t as ContextProvider } from "../index-DrWtSKXu.js";
|
|
3
|
+
export { type LiveMessages, type LiveMessagesInput, type Props, ContextProvider as default, defaultMessages, useLiveMessages };
|
package/dist/provider/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { i as useLiveMessages, n as defaultMessages } from "../messages-CSrMI4Rm.js";
|
|
2
|
+
import { t as ContextProvider } from "../context-B8MzP7_p.js";
|
|
3
|
+
export { ContextProvider as default, defaultMessages, useLiveMessages };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as generateSectionPreview, l as parseDocument, o as generateSectionPreviews, s as getSections, u as replaceDocumentSections } from "./document-
|
|
2
|
-
import { i as DEFAULT_CONTAINER_ID, u as documentTemplate } from "./constants-
|
|
1
|
+
import { a as generateSectionPreview, c as inspectDocument, l as parseDocument, o as generateSectionPreviews, s as getSections, u as replaceDocumentSections } from "./document-CGbe6bSV.js";
|
|
2
|
+
import { i as DEFAULT_CONTAINER_ID, u as documentTemplate } from "./constants-DU17Tdwo.js";
|
|
3
3
|
//#region src/utils/sections.ts
|
|
4
4
|
const extractSections = (code, options) => {
|
|
5
5
|
const doc = parseDocument(code, options);
|
|
@@ -18,7 +18,12 @@ const createDocument = ({ containerId = DEFAULT_CONTAINER_ID } = {}) => {
|
|
|
18
18
|
if (!/^[^\s"'<>{}]+$/.test(containerId)) throw new Error(`createDocument: containerId must be a plain element id, got ${JSON.stringify(containerId)}`);
|
|
19
19
|
return documentTemplate(containerId);
|
|
20
20
|
};
|
|
21
|
+
const checkDocument = (code, options) => {
|
|
22
|
+
const inspection = inspectDocument(code, options);
|
|
23
|
+
if (inspection.ok) return { ok: true };
|
|
24
|
+
return { ...inspection };
|
|
25
|
+
};
|
|
21
26
|
//#endregion
|
|
22
|
-
export {
|
|
27
|
+
export { generateSections as a, generateSection as i, createDocument as n, replaceSections as o, extractSections as r, checkDocument as t };
|
|
23
28
|
|
|
24
|
-
//# sourceMappingURL=sections-
|
|
29
|
+
//# sourceMappingURL=sections-BYWOBISr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sections-BYWOBISr.js","names":[],"sources":["../src/utils/sections.ts"],"sourcesContent":["import { DEFAULT_CONTAINER_ID, documentTemplate } from '~/constants';\nimport type { Section } from '~/types';\n\nimport {\n type DocumentOptions,\n type DocumentProblem,\n type SectionOptions,\n createSectionPreviewCache,\n generateSectionPreview,\n generateSectionPreviews,\n getSections,\n inspectDocument,\n parseDocument,\n replaceDocumentSections,\n} from './ast/document';\n\nexport const extractSections = (\n code: string,\n options?: SectionOptions,\n): Section[] => {\n const doc = parseDocument(code, options);\n\n return doc ? getSections(doc, options) : [];\n};\n\nexport const replaceSections = (\n code: string,\n sections: string[],\n options?: DocumentOptions,\n): string => {\n return replaceDocumentSections(code, sections, options);\n};\n\nexport const generateSection = (\n code: string,\n fullCode: string,\n options?: DocumentOptions,\n) => {\n return generateSectionPreview(fullCode, code, options);\n};\n\n// `generateSection()` for every section, from one parse of `fullCode`. An\n// unchanged section gets the same string as before, so `React.memo` can skip\n// it.\nexport const generateSections = (\n codes: string[],\n fullCode: string,\n options?: DocumentOptions,\n): string[] => {\n return generateSectionPreviews(fullCode, codes, options);\n};\n\n// A new, empty document `Live.Dnd` can add sections to: an `App` component\n// rendering the container element and nothing else. Start a controlled\n// `Live.Dnd` from this rather than an empty string, which has no container,\n// so nothing dropped on the canvas would land anywhere (#449). Pass the same\n// `containerId` you give `Live.Dnd`.\nexport const createDocument = ({\n containerId = DEFAULT_CONTAINER_ID,\n}: DocumentOptions = {}): string => {\n // The id is written into a JSX attribute as-is, so anything that could end\n // the attribute or the tag is refused rather than producing broken source.\n if (!/^[^\\s\"'<>{}]+$/.test(containerId)) {\n throw new Error(\n `createDocument: containerId must be a plain element id, got ${JSON.stringify(containerId)}`,\n );\n }\n\n return documentTemplate(containerId);\n};\n\n// Whether `Live.Dnd` can edit a document: it parses, and it has the\n// container. A host can check one before saving or loading it, and gets the\n// same reasons `Live.Dnd` reports through `onEditError` (#522).\nexport type DocumentCheck = { ok: true } | ({ ok: false } & DocumentProblem);\n\nexport const checkDocument = (\n code: string,\n options?: DocumentOptions,\n): DocumentCheck => {\n const inspection = inspectDocument(code, options);\n\n if (inspection.ok) {\n return { ok: true };\n }\n\n // A copy: the inspection is cached and shared with `Live.Dnd`.\n return { ...inspection };\n};\n\n// `generateSections()` that reuses unchanged previews between calls (#131).\n// Keep one instance per editor, as `Live.Dnd` does.\nexport { createSectionPreviewCache };\nexport type {\n DocumentOptions,\n DocumentProblem,\n SectionOptions,\n SectionPreviewCache,\n} from './ast/document';\n"],"mappings":";;;AAgBA,MAAa,mBACX,MACA,YACc;CACd,MAAM,MAAM,cAAc,MAAM,OAAO;CAEvC,OAAO,MAAM,YAAY,KAAK,OAAO,IAAI,CAAC;AAC5C;AAEA,MAAa,mBACX,MACA,UACA,YACW;CACX,OAAO,wBAAwB,MAAM,UAAU,OAAO;AACxD;AAEA,MAAa,mBACX,MACA,UACA,YACG;CACH,OAAO,uBAAuB,UAAU,MAAM,OAAO;AACvD;AAKA,MAAa,oBACX,OACA,UACA,YACa;CACb,OAAO,wBAAwB,UAAU,OAAO,OAAO;AACzD;AAOA,MAAa,kBAAkB,EAC7B,cAAc,yBACK,CAAC,MAAc;CAGlC,IAAI,CAAC,iBAAiB,KAAK,WAAW,GACpC,MAAM,IAAI,MACR,+DAA+D,KAAK,UAAU,WAAW,GAC3F;CAGF,OAAO,iBAAiB,WAAW;AACrC;AAOA,MAAa,iBACX,MACA,YACkB;CAClB,MAAM,aAAa,gBAAgB,MAAM,OAAO;CAEhD,IAAI,WAAW,IACb,OAAO,EAAE,IAAI,KAAK;CAIpB,OAAO,EAAE,GAAG,WAAW;AACzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"states-Ci1AvoQ9.js","names":[],"sources":["../src/components/context/states.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type { Dispatch, SetStateAction } from 'react';\n\nexport interface PreviewContextType {\n code: string;\n setCode: Dispatch<SetStateAction<string>>;\n}\n\nexport interface ErrorContextType {\n error: string | null;\n setError: Dispatch<SetStateAction<string | null>>;\n}\n\n// `undefined`
|
|
1
|
+
{"version":3,"file":"states-Ci1AvoQ9.js","names":[],"sources":["../src/components/context/states.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\nimport type { Dispatch, SetStateAction } from 'react';\n\nexport interface PreviewContextType {\n code: string;\n setCode: Dispatch<SetStateAction<string>>;\n}\n\nexport interface ErrorContextType {\n error: string | null;\n setError: Dispatch<SetStateAction<string | null>>;\n}\n\n// `undefined` outside a provider, so `usePreview` and `useError` can throw\n// there instead of silently doing nothing.\nexport const PreviewContext = createContext<PreviewContextType | undefined>(\n undefined,\n);\n\nexport const ErrorContext = createContext<ErrorContextType | undefined>(\n undefined,\n);\n\nexport const usePreview = () => {\n const context = useContext(PreviewContext);\n\n if (context === undefined) {\n throw new Error('usePreview must be used within <Live> (ContextProvider)');\n }\n\n return context;\n};\n\nexport const useError = () => {\n const context = useContext(ErrorContext);\n\n if (context === undefined) {\n throw new Error('useError must be used within <Live> (ContextProvider)');\n }\n\n return context;\n};\n"],"mappings":";;AAiBA,MAAa,iBAAiB,cAC5B,KAAA,CACF;AAEA,MAAa,eAAe,cAC1B,KAAA,CACF;AAEA,MAAa,mBAAmB;CAC9B,MAAM,UAAU,WAAW,cAAc;CAEzC,IAAI,YAAY,KAAA,GACd,MAAM,IAAI,MAAM,yDAAyD;CAG3E,OAAO;AACT;AAEA,MAAa,iBAAiB;CAC5B,MAAM,UAAU,WAAW,YAAY;CAEvC,IAAI,YAAY,KAAA,GACd,MAAM,IAAI,MAAM,uDAAuD;CAGzE,OAAO;AACT"}
|