@makeswift/runtime 0.28.10-canary.1 → 0.28.10-canary.11
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/cjs/api/graphql/documents/queries.js +0 -42
- package/dist/cjs/api/graphql/documents/queries.js.map +1 -1
- package/dist/cjs/api/graphql/generated/types.js.map +1 -1
- package/dist/cjs/api/graphql-api-client.js +1 -18
- package/dist/cjs/api/graphql-api-client.js.map +1 -1
- package/dist/cjs/api/makeswift-api-resources-client.js +2 -8
- package/dist/cjs/api/makeswift-api-resources-client.js.map +1 -1
- package/dist/cjs/api/rest-api-client.js +27 -1
- package/dist/cjs/api/rest-api-client.js.map +1 -1
- package/dist/cjs/api/table-record-client.js +47 -0
- package/dist/cjs/api/table-record-client.js.map +1 -0
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/api-handler/handlers/table-record.js +63 -0
- package/dist/cjs/api-handler/handlers/table-record.js.map +1 -0
- package/dist/cjs/api-handler/index.js +3 -0
- package/dist/cjs/api-handler/index.js.map +1 -1
- package/dist/cjs/client/index.js +17 -5
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/components/builtin/Form/Form.js +2 -2
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/controls/index.js +10 -0
- package/dist/cjs/controls/index.js.map +1 -1
- package/dist/cjs/controls/rich-text/control.js.map +1 -1
- package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +1 -1
- package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +3 -18
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/react/server/index.js +2 -0
- package/dist/cjs/react/server/index.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text/ReadOnlyText.js +1 -0
- package/dist/cjs/runtimes/react/controls/rich-text/ReadOnlyText.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +12 -14
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js +2 -12
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.js +10 -3
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.js +2 -2
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js +4 -4
- package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +15 -15
- package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/index.js +9 -3
- package/dist/cjs/runtimes/react/controls/rich-text-v2/index.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js +46 -0
- package/dist/cjs/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js.map +1 -0
- package/dist/cjs/runtimes/react/controls/rich-text-v2/{rich-text-v2.js → rich-text-v2-value.js} +10 -14
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/{use-graphql-api-client.js → use-table-record-client.js} +9 -9
- package/dist/cjs/runtimes/react/hooks/use-table-record-client.js.map +1 -0
- package/dist/cjs/runtimes/react/react-runtime-core.js +14 -3
- package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +0 -1
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/server/components/element-data.js +6 -2
- package/dist/cjs/runtimes/react/server/components/element-data.js.map +1 -1
- package/dist/cjs/runtimes/react/server/components/element.js +20 -2
- package/dist/cjs/runtimes/react/server/components/element.js.map +1 -1
- package/dist/cjs/runtimes/react/server/components/renderer.js +1 -2
- package/dist/cjs/runtimes/react/server/components/renderer.js.map +1 -1
- package/dist/cjs/runtimes/react/server/components/server-elements-cache.js +7 -0
- package/dist/cjs/runtimes/react/server/components/server-elements-cache.js.map +1 -1
- package/dist/cjs/runtimes/react/server/css/client-css.js +2 -2
- package/dist/cjs/runtimes/react/server/css/client-css.js.map +1 -1
- package/dist/cjs/runtimes/react/server/index.js +3 -0
- package/dist/cjs/runtimes/react/server/index.js.map +1 -1
- package/dist/cjs/runtimes/react/server/injectable-props.js +17 -0
- package/dist/cjs/runtimes/react/server/injectable-props.js.map +1 -0
- package/dist/cjs/runtimes/react/server/render-context.js +1 -6
- package/dist/cjs/runtimes/react/server/render-context.js.map +1 -1
- package/dist/cjs/runtimes/react/testing/react-runtime.js +3 -4
- package/dist/cjs/runtimes/react/testing/react-runtime.js.map +1 -1
- package/dist/cjs/runtimes/react/testing/render-to-string.js +44 -0
- package/dist/cjs/runtimes/react/testing/render-to-string.js.map +1 -0
- package/dist/cjs/state/modules/components-meta.js.map +1 -1
- package/dist/cjs/unstable-framework-support/index.js +3 -0
- package/dist/cjs/unstable-framework-support/index.js.map +1 -1
- package/dist/esm/api/graphql/documents/queries.js +0 -39
- package/dist/esm/api/graphql/documents/queries.js.map +1 -1
- package/dist/esm/api/graphql/generated/types.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +2 -24
- package/dist/esm/api/graphql-api-client.js.map +1 -1
- package/dist/esm/api/makeswift-api-resources-client.js +2 -8
- package/dist/esm/api/makeswift-api-resources-client.js.map +1 -1
- package/dist/esm/api/rest-api-client.js +27 -1
- package/dist/esm/api/rest-api-client.js.map +1 -1
- package/dist/esm/api/table-record-client.js +23 -0
- package/dist/esm/api/table-record-client.js.map +1 -0
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/api-handler/handlers/table-record.js +29 -0
- package/dist/esm/api-handler/handlers/table-record.js.map +1 -0
- package/dist/esm/api-handler/index.js +3 -0
- package/dist/esm/api-handler/index.js.map +1 -1
- package/dist/esm/client/index.js +17 -5
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/components/builtin/Form/Form.js +2 -2
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/controls/index.js +10 -0
- package/dist/esm/controls/index.js.map +1 -1
- package/dist/esm/controls/rich-text/control.js.map +1 -1
- package/dist/esm/controls/rich-text-v2/rich-text-v2.js +1 -1
- package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +1 -16
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/react/server/index.js +2 -0
- package/dist/esm/react/server/index.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text/ReadOnlyText.js +1 -0
- package/dist/esm/runtimes/react/controls/rich-text/ReadOnlyText.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +11 -13
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/index.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.js +10 -3
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.js +2 -2
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js +4 -4
- package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +19 -17
- package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/index.js +4 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/index.js.map +1 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js +12 -0
- package/dist/esm/runtimes/react/controls/rich-text-v2/render-rich-text-v2.js.map +1 -0
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js +17 -0
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2-value.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-table-record-client.js +11 -0
- package/dist/esm/runtimes/react/hooks/use-table-record-client.js.map +1 -0
- package/dist/esm/runtimes/react/react-runtime-core.js +14 -3
- package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +0 -1
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/server/components/element-data.js +6 -2
- package/dist/esm/runtimes/react/server/components/element-data.js.map +1 -1
- package/dist/esm/runtimes/react/server/components/element.js +20 -2
- package/dist/esm/runtimes/react/server/components/element.js.map +1 -1
- package/dist/esm/runtimes/react/server/components/renderer.js +2 -3
- package/dist/esm/runtimes/react/server/components/renderer.js.map +1 -1
- package/dist/esm/runtimes/react/server/components/server-elements-cache.js +6 -0
- package/dist/esm/runtimes/react/server/components/server-elements-cache.js.map +1 -1
- package/dist/esm/runtimes/react/server/css/client-css.js +2 -2
- package/dist/esm/runtimes/react/server/css/client-css.js.map +1 -1
- package/dist/esm/runtimes/react/server/index.js +2 -0
- package/dist/esm/runtimes/react/server/index.js.map +1 -1
- package/dist/esm/runtimes/react/server/injectable-props.js +1 -0
- package/dist/esm/runtimes/react/server/injectable-props.js.map +1 -0
- package/dist/esm/runtimes/react/server/render-context.js +1 -6
- package/dist/esm/runtimes/react/server/render-context.js.map +1 -1
- package/dist/esm/runtimes/react/testing/react-runtime.js +3 -4
- package/dist/esm/runtimes/react/testing/react-runtime.js.map +1 -1
- package/dist/esm/runtimes/react/testing/render-to-string.js +20 -0
- package/dist/esm/runtimes/react/testing/render-to-string.js.map +1 -0
- package/dist/esm/state/modules/components-meta.js.map +1 -1
- package/dist/esm/unstable-framework-support/index.js +2 -0
- package/dist/esm/unstable-framework-support/index.js.map +1 -1
- package/dist/types/api/graphql/documents/queries.d.ts +0 -3
- package/dist/types/api/graphql/documents/queries.d.ts.map +1 -1
- package/dist/types/api/graphql/generated/types.d.ts +0 -71
- package/dist/types/api/graphql/generated/types.d.ts.map +1 -1
- package/dist/types/api/graphql-api-client.d.ts +0 -4
- package/dist/types/api/graphql-api-client.d.ts.map +1 -1
- package/dist/types/api/makeswift-api-resources-client.d.ts +1 -3
- package/dist/types/api/makeswift-api-resources-client.d.ts.map +1 -1
- package/dist/types/api/rest-api-client.d.ts +3 -1
- package/dist/types/api/rest-api-client.d.ts.map +1 -1
- package/dist/types/api/table-record-client.d.ts +13 -0
- package/dist/types/api/table-record-client.d.ts.map +1 -0
- package/dist/types/api-handler/handlers/table-record.d.ts +6 -0
- package/dist/types/api-handler/handlers/table-record.d.ts.map +1 -0
- package/dist/types/api-handler/index.d.ts +2 -1
- package/dist/types/api-handler/index.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +4 -3
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/controls/index.d.ts +1 -1
- package/dist/types/controls/index.d.ts.map +1 -1
- package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
- package/dist/types/next/tests/server.api-handler-table-record.test.d.ts +2 -0
- package/dist/types/next/tests/server.api-handler-table-record.test.d.ts.map +1 -0
- package/dist/types/react/server/index.d.ts +1 -1
- package/dist/types/react/server/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text/ReadOnlyText.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts +4 -8
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.d.ts +1 -3
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.d.ts +1 -3
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.d.ts +2 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +5 -5
- package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/index.d.ts +7 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/render-rich-text-v2.d.ts +5 -0
- package/dist/types/runtimes/react/controls/rich-text-v2/render-rich-text-v2.d.ts.map +1 -0
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2-value.d.ts +8 -0
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2-value.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-table-record-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-table-record-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/react-runtime-core.d.ts +20 -7
- package/dist/types/runtimes/react/react-runtime-core.d.ts.map +1 -1
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/components/__tests__/element.test.d.ts +2 -0
- package/dist/types/runtimes/react/server/components/__tests__/element.test.d.ts.map +1 -0
- package/dist/types/runtimes/react/server/components/element-data.d.ts +2 -1
- package/dist/types/runtimes/react/server/components/element-data.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/components/element.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/components/renderer.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/components/server-elements-cache.d.ts +4 -0
- package/dist/types/runtimes/react/server/components/server-elements-cache.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/css/client-css.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/index.d.ts +1 -0
- package/dist/types/runtimes/react/server/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/injectable-props.d.ts +5 -0
- package/dist/types/runtimes/react/server/injectable-props.d.ts.map +1 -0
- package/dist/types/runtimes/react/server/render-context.d.ts +2 -1
- package/dist/types/runtimes/react/server/render-context.d.ts.map +1 -1
- package/dist/types/runtimes/react/testing/react-runtime.d.ts +5 -4
- package/dist/types/runtimes/react/testing/react-runtime.d.ts.map +1 -1
- package/dist/types/runtimes/react/testing/render-to-string.d.ts +3 -0
- package/dist/types/runtimes/react/testing/render-to-string.d.ts.map +1 -0
- package/dist/types/slate/InlineModePlugin/index.d.ts +1 -1
- package/dist/types/state/modules/components-meta.d.ts +2 -0
- package/dist/types/state/modules/components-meta.d.ts.map +1 -1
- package/dist/types/unstable-framework-support/index.d.ts +1 -0
- package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +0 -1
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js.map +0 -1
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js +0 -23
- package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +0 -1
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js +0 -11
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js.map +0 -1
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +0 -9
- package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +0 -1
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts +0 -3
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment, forwardRef, useRef, isValidElement, act } from "react";
|
|
3
|
-
import { renderToReadableStream } from "react-dom/server";
|
|
4
3
|
import { JSDOM } from "jsdom";
|
|
5
4
|
import { render, screen } from "@testing-library/react";
|
|
6
5
|
import "@testing-library/jest-dom";
|
|
@@ -9,27 +8,13 @@ import { setIsInBuilder } from "../../../../state/actions/internal/read-only-act
|
|
|
9
8
|
import { MakeswiftComponent } from "../../../../runtimes/react/components/MakeswiftComponent";
|
|
10
9
|
import { Page } from "../../page";
|
|
11
10
|
import { isServer } from "../../../../utils/is-server";
|
|
11
|
+
import { renderToString } from "../../../../runtimes/react/testing/render-to-string";
|
|
12
12
|
import * as Testing from "../../../testing";
|
|
13
13
|
const ROOT_ID = "00000000-0000-0000-0000-000000000000";
|
|
14
14
|
const ELEMENT_ID = "11111111-1111-1111-1111-111111111111";
|
|
15
15
|
const renderProp = (prop) => prop === void 0 ? "undefined" : isValidElement(prop) ? prop : JSON.stringify(prop);
|
|
16
16
|
const propSnapshot = (prop) => prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? "");
|
|
17
17
|
const parseStringifiedProp = (prop) => prop === "undefined" ? void 0 : JSON.parse(prop);
|
|
18
|
-
async function streamToString(stream) {
|
|
19
|
-
const reader = stream.getReader();
|
|
20
|
-
const decoder = new TextDecoder();
|
|
21
|
-
let result = "";
|
|
22
|
-
while (true) {
|
|
23
|
-
const { done, value } = await reader.read();
|
|
24
|
-
if (done)
|
|
25
|
-
break;
|
|
26
|
-
result += decoder.decode(value, { stream: true });
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
async function renderToString(element) {
|
|
31
|
-
return await streamToString(await renderToReadableStream(element));
|
|
32
|
-
}
|
|
33
18
|
async function serverSideRender(children) {
|
|
34
19
|
const serverInsertedCallbacks = [];
|
|
35
20
|
const elementTree = /* @__PURE__ */ jsx(ServerInsertedHTMLContext.Provider, { value: (handler) => serverInsertedCallbacks.push(handler), children });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function streamToString(stream: ReadableStream) {\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n\n let result = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n result += decoder.decode(value, { stream: true })\n }\n\n return result\n}\n\nasync function renderToString(element: ReactNode) {\n return await streamToString(await renderToReadableStream(element))\n}\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\n/**\n * In read-write mode, the runtime opens a `MessageChannel` to the builder\n * parent frame; jsdom doesn't implement `MessageChannel`, so stub them to keep\n * the read-write setup from throwing.\n */\nfunction stubBuilderMessageChannel(): () => void {\n const postMessageSpy = jest.spyOn(window, 'postMessage').mockImplementation(() => {})\n\n const originalMessageChannel = window.MessageChannel\n const stubPort = () => ({ onmessage: null, postMessage: () => {}, close: () => {} })\n window.MessageChannel = class {\n port1 = stubPort()\n port2 = stubPort()\n } as unknown as typeof MessageChannel\n\n return () => {\n postMessageSpy.mockRestore()\n window.MessageChannel = originalMessageChannel\n }\n}\n\nexport async function testPageControlPropRendering<D extends ControlDefinition>(\n controlDefinition: D,\n {\n toData,\n value,\n locale,\n cacheData,\n expectedRenders,\n registerComponents,\n action,\n rootElements = [],\n isInBuilder = false,\n isReadOnly = true,\n }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<CacheData>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n isInBuilder?: boolean\n isReadOnly?: boolean\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const testComponentMeta = {\n type: 'TestComponent',\n label: 'Test Component',\n }\n\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = {\n key: ELEMENT_ID,\n type: testComponentMeta.type,\n props: {\n propKey: controlData,\n },\n }\n\n const runtime = Testing.createReactRuntime()\n runtime.protoStore.dispatch(setIsInBuilder(isInBuilder))\n registerComponents?.(runtime)\n\n // Act\n runtime.registerComponent(\n forwardRef<HTMLDivElement, { propKey?: any }>(({ propKey }, ref) => {\n const renderCount = useRef(0)\n ++renderCount.current\n\n return (\n <div ref={ref}>\n <div data-testid={renderCountTestId}>{renderCount.current}</div>\n <div data-testid={testId}>{renderProp(propKey)}</div>\n </div>\n )\n }),\n {\n ...testComponentMeta,\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n const testElementTree = (component: ReactNode) => {\n // The runtime enters the read-write state when a non-null site version is\n // passed\n const siteVersion = isReadOnly ? null : { token: 'test-token', version: 'draft' }\n return (\n <Testing.ReactProvider runtime={runtime} siteVersion={siteVersion}>\n {component}\n </Testing.ReactProvider>\n )\n }\n\n if (!isServer()) {\n const restoreMessageChannel = isReadOnly ? null : stubBuilderMessageChannel()\n\n const rootElementData: ElementData = Testing.createRootComponent(\n [elementData, ...rootElements],\n ROOT_ID,\n )\n\n const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData })\n\n // Assert\n await act(async () => render(testElementTree(<Page snapshot={snapshot} />)))\n\n if (action) {\n await act(async () => {\n await action(screen.getByTestId(testId))\n })\n }\n\n expect(snapshot).toMatchSnapshot('snapshot')\n expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot('resolvedValue')\n\n if (expectedRenders != null) {\n expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders)\n }\n\n restoreMessageChannel?.()\n } else {\n // test server-side rendering using a component snapshot\n console.assert(action == null)\n console.assert(rootElements.length === 0)\n\n const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData })\n const elementTree = testElementTree(\n <MakeswiftComponent snapshot={snapshot} {...testComponentMeta} />,\n )\n\n const document = await serverSideRender(elementTree)\n const getByTestId = (id: string): HTMLElement | null =>\n document.querySelector(`[data-testid=\"${id}\"]`)\n\n expect(propSnapshot(getByTestId(testId))).toMatchSnapshot('resolvedValue')\n expect([...document.querySelectorAll('style')].map(n => n.textContent)).toMatchSnapshot(\n 'component styles',\n )\n expect(Number(getByTestId(renderCountTestId)?.textContent)).toBe(1)\n }\n}\n"],"mappings":"AAsDI,cAoGI,YApGJ;AAtDJ,SAAyB,UAAU,YAAY,QAAQ,gBAAgB,WAAW;AAClF,SAAS,8BAA8B;AACvC,SAAS,aAAa;AACtB,SAAS,QAAQ,cAAc;AAC/B,OAAO;AACP,SAAS,iCAAiC;AAM1C,SAAS,sBAAsB;AAE/B,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,YAAY,aAAa;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEnB,MAAM,aAAa,CAAC,SAClB,SAAS,SAAY,cAAc,eAAe,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI;AAEtF,MAAM,eAAe,CAAC,SACpB,MAAM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AAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\n\nimport { renderToString } from '../../../../runtimes/react/testing/render-to-string'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\n/**\n * In read-write mode, the runtime opens a `MessageChannel` to the builder\n * parent frame; jsdom doesn't implement `MessageChannel`, so stub them to keep\n * the read-write setup from throwing.\n */\nfunction stubBuilderMessageChannel(): () => void {\n const postMessageSpy = jest.spyOn(window, 'postMessage').mockImplementation(() => {})\n\n const originalMessageChannel = window.MessageChannel\n const stubPort = () => ({ onmessage: null, postMessage: () => {}, close: () => {} })\n window.MessageChannel = class {\n port1 = stubPort()\n port2 = stubPort()\n } as unknown as typeof MessageChannel\n\n return () => {\n postMessageSpy.mockRestore()\n window.MessageChannel = originalMessageChannel\n }\n}\n\nexport async function testPageControlPropRendering<D extends ControlDefinition>(\n controlDefinition: D,\n {\n toData,\n value,\n locale,\n cacheData,\n expectedRenders,\n registerComponents,\n action,\n rootElements = [],\n isInBuilder = false,\n isReadOnly = true,\n }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<CacheData>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n isInBuilder?: boolean\n isReadOnly?: boolean\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const testComponentMeta = {\n type: 'TestComponent',\n label: 'Test Component',\n }\n\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = {\n key: ELEMENT_ID,\n type: testComponentMeta.type,\n props: {\n propKey: controlData,\n },\n }\n\n const runtime = Testing.createReactRuntime()\n runtime.protoStore.dispatch(setIsInBuilder(isInBuilder))\n registerComponents?.(runtime)\n\n // Act\n runtime.registerComponent(\n forwardRef<HTMLDivElement, { propKey?: any }>(({ propKey }, ref) => {\n const renderCount = useRef(0)\n ++renderCount.current\n\n return (\n <div ref={ref}>\n <div data-testid={renderCountTestId}>{renderCount.current}</div>\n <div data-testid={testId}>{renderProp(propKey)}</div>\n </div>\n )\n }),\n {\n ...testComponentMeta,\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n const testElementTree = (component: ReactNode) => {\n // The runtime enters the read-write state when a non-null site version is\n // passed\n const siteVersion = isReadOnly ? null : { token: 'test-token', version: 'draft' }\n return (\n <Testing.ReactProvider runtime={runtime} siteVersion={siteVersion}>\n {component}\n </Testing.ReactProvider>\n )\n }\n\n if (!isServer()) {\n const restoreMessageChannel = isReadOnly ? null : stubBuilderMessageChannel()\n\n const rootElementData: ElementData = Testing.createRootComponent(\n [elementData, ...rootElements],\n ROOT_ID,\n )\n\n const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData })\n\n // Assert\n await act(async () => render(testElementTree(<Page snapshot={snapshot} />)))\n\n if (action) {\n await act(async () => {\n await action(screen.getByTestId(testId))\n })\n }\n\n expect(snapshot).toMatchSnapshot('snapshot')\n expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot('resolvedValue')\n\n if (expectedRenders != null) {\n expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders)\n }\n\n restoreMessageChannel?.()\n } else {\n // test server-side rendering using a component snapshot\n console.assert(action == null)\n console.assert(rootElements.length === 0)\n\n const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData })\n const elementTree = testElementTree(\n <MakeswiftComponent snapshot={snapshot} {...testComponentMeta} />,\n )\n\n const document = await serverSideRender(elementTree)\n const getByTestId = (id: string): HTMLElement | null =>\n document.querySelector(`[data-testid=\"${id}\"]`)\n\n expect(propSnapshot(getByTestId(testId))).toMatchSnapshot('resolvedValue')\n expect([...document.querySelectorAll('style')].map(n => n.textCont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E,WAAO,CAAC,GAAG,SAAS,iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/react/server/index.ts"],"sourcesContent":["export {\n type ServerRenderContext,\n RenderElementPayload,\n RenderContext as MakeswiftRenderContext,\n setRenderContext,\n getRenderContext,\n ServerCSSCollector,\n ServerElement,\n RSCElementRenderer,\n MakeswiftComponent,\n Slot,\n} from '../../runtimes/react/server'\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/react/server/index.ts"],"sourcesContent":["export {\n type ServerRenderContext,\n collectServerElements,\n RenderElementPayload,\n RenderContext as MakeswiftRenderContext,\n setRenderContext,\n getRenderContext,\n ServerCSSCollector,\n ServerElement,\n RSCElementRenderer,\n MakeswiftComponent,\n Slot,\n} from '../../runtimes/react/server'\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text/ReadOnlyText.tsx"],"sourcesContent":["import { cx } from '@emotion/css'\nimport { ForwardedRef, forwardRef } from 'react'\nimport { Descendant, Text } from 'slate'\n\nimport { Slate, RichTextValue, richTextDTOtoDAO } from '@makeswift/controls'\n\nimport { useResponsiveStyle } from '../../../../components/utils/responsive-style'\nimport { InlineType, BlockType } from '../../../../slate/types'\nimport { useStyle } from '../../use-style'\nimport useEnhancedTypography, { useTypographyClassName } from '../typography'\nimport { Link } from '../../../../components/shared/Link'\n\ntype Props = {\n id?: string\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst ReadOnlyText = forwardRef(function ReadOnlyText(\n { id, text, width, margin }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendants = text == null ? [] : richTextDTOtoDAO(text)\n const descendantsAsString = getText(descendants)\n\n return (\n <div\n ref={ref}\n id={id}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n className={cx(width, margin)}\n >\n {descendantsAsString === '' ? <Placeholder /> : <Descendants descendants={descendants} />}\n </div>\n )\n})\n\nexport default ReadOnlyText\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\nexport interface TextProps {\n descendant: Text\n}\n\nexport function TextElement({ descendant }: TextProps) {\n const enhancedTypography = useEnhancedTypography(descendant.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span className={typographyClassName}>\n {descendant.text === '' ? '\\uFEFF' : descendant.text}\n </span>\n )\n}\n\nexport interface InlineProps {\n descendant: Slate.Inline\n}\n\nfunction InlineElement({ descendant }: InlineProps) {\n const linkClassName = useStyle({ textDecoration: 'none' })\n\n switch (descendant.type) {\n case InlineType.Code:\n return (\n <code>\n <Descendants descendants={descendant.children} />\n </code>\n )\n\n case InlineType.SuperScript:\n return (\n <sup>\n <Descendants descendants={descendant.children} />\n </sup>\n )\n\n case InlineType.SubScript:\n return (\n <sub>\n <Descendants descendants={descendant.children} />\n </sub>\n )\n\n case InlineType.Link:\n return (\n <Link className={linkClassName} link={descendant.link ?? undefined}>\n <Descendants descendants={descendant.children} />\n </Link>\n )\n }\n}\n\nexport interface BlockProps {\n descendant: Slate.Block\n}\n\nexport function BlockElement({ descendant }: BlockProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([descendant.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n const quoteStyle = useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n })\n\n switch (descendant.type) {\n case BlockType.Default:\n case BlockType.Paragraph:\n return (\n <p className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote className={cx(...blockStyles, quoteStyle)}>\n <Descendants descendants={descendant.children} />\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </span>\n )\n default:\n return null\n }\n}\n\nfunction Descendants({ descendants }: { descendants: Descendant[] }) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (Slate.isText(descendant)) {\n return <TextElement key={index} descendant={descendant} />\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return <InlineElement key={index} descendant={descendant} />\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.Default:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement key={index} descendant={descendant} />\n default:\n return null\n }\n })}\n </>\n )\n}\n\nfunction isBlock(descendant: Descendant): descendant is Slate.Block {\n if ('text' in descendant) return false\n\n switch (descendant.type) {\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.Default:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return true\n\n default:\n return false\n }\n}\n\nfunction getTextByDescendant(descendant: Descendant): string {\n if ('text' in descendant) {\n return descendant.text ?? ''\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return descendant.children.map(descendant => getTextByDescendant(descendant)).join('') ?? ''\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.Default:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return (\n descendant.children\n .map(descendant => getTextByDescendant(descendant))\n .join(descendant.children.every(isBlock) ? '\\n' : '') ?? ''\n )\n default:\n return ''\n }\n}\n\nfunction getText(descendant: Descendant[]): string {\n return descendant.map(getTextByDescendant).join('\\n')\n}\n"],"mappings":"AA0CoC,SA8KhC,UA9KgC;AA1CpC,SAAS,UAAU;AACnB,SAAuB,kBAAkB;AAGzC,SAAS,OAAsB,wBAAwB;AAEvD,SAAS,0BAA0B;AACnC,SAAS,YAAY,iBAAiB;AACtC,SAAS,gBAAgB;AACzB,OAAO,yBAAyB,8BAA8B;AAC9D,SAAS,YAAY;AASrB,MAAM,eAAe,WAAW,SAASA,cACvC,EAAE,IAAI,MAAM,OAAO,OAAO,GAC1B,KACA;AACA,QAAM,cAAc,QAAQ,OAAO,CAAC,IAAI,iBAAiB,IAAI;AAC7D,QAAM,sBAAsB,QAAQ,WAAW;AAE/C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAML,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAAA,MACA,WAAW,GAAG,OAAO,MAAM;AAAA,MAE1B,kCAAwB,KAAK,oBAAC,eAAY,IAAK,oBAAC,eAAY,aAA0B;AAAA;AAAA,EACzF;AAEJ,CAAC;AAED,IAAO,uBAAQ;AAEf,SAAS,YAAY,EAAE,OAAO,qBAAqB,GAAsB;AACvE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,SAAS;AAAA,QAClB,SAAS;AAAA,QACT,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,SAAS;AAAA,QACT,eAA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IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AACb,aAAO;AAAA,IAET;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,oBAAoB,YAAgC;AAC3D,MAAI,UAAU,YAAY;AACxB,WAAO,WAAW,QAAQ;AAAA,EAC5B;AAEA,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AACd,aAAO,WAAW,SAAS,IAAI,CAAAC,gBAAc,oBAAoBA,WAAU,CAAC,EAAE,KAAK,EAAE,KAAK;AAAA,IAC5F,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AACb,aACE,WAAW,SACR,IAAI,CAAAA,gBAAc,oBAAoBA,WAAU,CAAC,EACjD,KAAK,WAAW,SAAS,MAAM,OAAO,IAAI,OAAO,EAAE,KAAK;AAAA,IAE/D;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,QAAQ,YAAkC;AACjD,SAAO,WAAW,IAAI,mBAAmB,EAAE,KAAK,IAAI;AACtD;","names":["ReadOnlyText","descendant"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text/ReadOnlyText.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@emotion/css'\nimport { ForwardedRef, forwardRef } from 'react'\nimport { Descendant, Text } from 'slate'\n\nimport { Slate, RichTextValue, richTextDTOtoDAO } from '@makeswift/controls'\n\nimport { useResponsiveStyle } from '../../../../components/utils/responsive-style'\nimport { InlineType, BlockType } from '../../../../slate/types'\nimport { useStyle } from '../../use-style'\nimport useEnhancedTypography, { useTypographyClassName } from '../typography'\nimport { Link } from '../../../../components/shared/Link'\n\ntype Props = {\n id?: string\n text?: RichTextValue\n width?: string\n margin?: string\n}\n\nconst ReadOnlyText = forwardRef(function ReadOnlyText(\n { id, text, width, margin }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendants = text == null ? [] : richTextDTOtoDAO(text)\n const descendantsAsString = getText(descendants)\n\n return (\n <div\n ref={ref}\n id={id}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n className={cx(width, margin)}\n >\n {descendantsAsString === '' ? <Placeholder /> : <Descendants descendants={descendants} />}\n </div>\n )\n})\n\nexport default ReadOnlyText\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\nexport interface TextProps {\n descendant: Text\n}\n\nexport function TextElement({ descendant }: TextProps) {\n const enhancedTypography = useEnhancedTypography(descendant.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n\n return (\n <span className={typographyClassName}>\n {descendant.text === '' ? '\\uFEFF' : descendant.text}\n </span>\n )\n}\n\nexport interface InlineProps {\n descendant: Slate.Inline\n}\n\nfunction InlineElement({ descendant }: InlineProps) {\n const linkClassName = useStyle({ textDecoration: 'none' })\n\n switch (descendant.type) {\n case InlineType.Code:\n return (\n <code>\n <Descendants descendants={descendant.children} />\n </code>\n )\n\n case InlineType.SuperScript:\n return (\n <sup>\n <Descendants descendants={descendant.children} />\n </sup>\n )\n\n case InlineType.SubScript:\n return (\n <sub>\n <Descendants descendants={descendant.children} />\n </sub>\n )\n\n case InlineType.Link:\n return (\n <Link className={linkClassName} link={descendant.link ?? undefined}>\n <Descendants descendants={descendant.children} />\n </Link>\n )\n }\n}\n\nexport interface BlockProps {\n descendant: Slate.Block\n}\n\nexport function BlockElement({ descendant }: BlockProps) {\n const blockStyles = [\n useStyle({ margin: 0 }),\n useStyle(useResponsiveStyle([descendant.textAlign], ([textAlign = 'left']) => ({ textAlign }))),\n ]\n const quoteStyle = useStyle({\n padding: '0.5em 10px',\n fontSize: '1.25em',\n fontWeight: '300',\n borderLeft: '5px solid rgba(0, 0, 0, 0.1)',\n })\n\n switch (descendant.type) {\n case BlockType.Default:\n case BlockType.Paragraph:\n return (\n <p className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </p>\n )\n case BlockType.Heading1:\n return (\n <h1 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h1>\n )\n case BlockType.Heading2:\n return (\n <h2 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h2>\n )\n case BlockType.Heading3:\n return (\n <h3 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h3>\n )\n case BlockType.Heading4:\n return (\n <h4 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h4>\n )\n case BlockType.Heading5:\n return (\n <h5 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h5>\n )\n case BlockType.Heading6:\n return (\n <h6 className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </h6>\n )\n case BlockType.BlockQuote:\n return (\n <blockquote className={cx(...blockStyles, quoteStyle)}>\n <Descendants descendants={descendant.children} />\n </blockquote>\n )\n case BlockType.OrderedList:\n return (\n <ol className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ol>\n )\n case BlockType.UnorderedList:\n return (\n <ul className={cx(...blockStyles)} style={{ listStylePosition: 'inside' }}>\n <Descendants descendants={descendant.children} />\n </ul>\n )\n case BlockType.ListItem:\n return (\n <li className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </li>\n )\n case BlockType.ListItemChild:\n return (\n <span className={cx(...blockStyles)}>\n <Descendants descendants={descendant.children} />\n </span>\n )\n default:\n return null\n }\n}\n\nfunction Descendants({ descendants }: { descendants: Descendant[] }) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (Slate.isText(descendant)) {\n return <TextElement key={index} descendant={descendant} />\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return <InlineElement key={index} descendant={descendant} />\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.Default:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return <BlockElement key={index} descendant={descendant} />\n default:\n return null\n }\n })}\n </>\n )\n}\n\nfunction isBlock(descendant: Descendant): descendant is Slate.Block {\n if ('text' in descendant) return false\n\n switch (descendant.type) {\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.Default:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return true\n\n default:\n return false\n }\n}\n\nfunction getTextByDescendant(descendant: Descendant): string {\n if ('text' in descendant) {\n return descendant.text ?? ''\n }\n\n switch (descendant.type) {\n case InlineType.Link:\n case InlineType.Code:\n case InlineType.SubScript:\n case InlineType.SuperScript:\n return descendant.children.map(descendant => getTextByDescendant(descendant)).join('') ?? ''\n case BlockType.Heading1:\n case BlockType.Heading2:\n case BlockType.Heading3:\n case BlockType.Heading4:\n case BlockType.Heading5:\n case BlockType.Heading6:\n case BlockType.BlockQuote:\n case BlockType.Paragraph:\n case BlockType.Default:\n case BlockType.OrderedList:\n case BlockType.UnorderedList:\n case BlockType.ListItem:\n case BlockType.ListItemChild:\n return (\n descendant.children\n .map(descendant => getTextByDescendant(descendant))\n .join(descendant.children.every(isBlock) ? '\\n' : '') ?? ''\n )\n default:\n return ''\n }\n}\n\nfunction getText(descendant: Descendant[]): string {\n return descendant.map(getTextByDescendant).join('\\n')\n}\n"],"mappings":";AA4CoC,SA8KhC,UA9KgC;AA1CpC,SAAS,UAAU;AACnB,SAAuB,kBAAkB;AAGzC,SAAS,OAAsB,wBAAwB;AAEvD,SAAS,0BAA0B;AACnC,SAAS,YAAY,iBAAiB;AACtC,SAAS,gBAAgB;AACzB,OAAO,yBAAyB,8BAA8B;AAC9D,SAAS,YAAY;AASrB,MAAM,eAAe,WAAW,SAASA,cACvC,EAAE,IAAI,MAAM,OAAO,OAAO,GAC1B,KACA;AACA,QAAM,cAAc,QAAQ,OAAO,CAAC,IAAI,iBAAiB,IAAI;AAC7D,QAAM,sBAAsB,QAAQ,WAAW;AAE/C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAML,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAAA,MACA,WAAW,GAAG,OAAO,MAAM;AAAA,MAE1B,kCAAwB,KAAK,oBAAC,eAAY,IAAK,oBAAC,eAAY,aAA0B;AAAA;AAAA,EACzF;AAEJ,CAAC;AAED,IAAO,uBAAQ;AAEf,SAAS,YAAY,EAAE,OAAO,qBAAqB,GAAsB;AACvE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,SAAS;AAAA,QAClB,SAAS;AAAA,QACT,OAAO;AAAA,QACP,UAAU;AAAA,QACV,YAAY;AAAA,Q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A,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AACb,aAAO;AAAA,IAET;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,oBAAoB,YAAgC;AAC3D,MAAI,UAAU,YAAY;AACxB,WAAO,WAAW,QAAQ;AAAA,EAC5B;AAEA,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AAAA,IAChB,KAAK,WAAW;AACd,aAAO,WAAW,SAAS,IAAI,CAAAC,gBAAc,oBAAoBA,WAAU,CAAC,EAAE,KAAK,EAAE,KAAK;AAAA,IAC5F,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AAAA,IACf,KAAK,UAAU;AACb,aACE,WAAW,SACR,IAAI,CAAAA,gBAAc,oBAAoBA,WAAU,CAAC,EACjD,KAAK,WAAW,SAAS,MAAM,OAAO,IAAI,OAAO,EAAE,KAAK;AAAA,IAE/D;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,QAAQ,YAAkC;AACjD,SAAO,WAAW,IAAI,mBAAmB,EAAE,KAAK,IAAI;AACtD;","names":["ReadOnlyText","descendant"]}
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import {
|
|
19
19
|
RichText
|
|
20
20
|
} from "../../../../../controls/rich-text-v2";
|
|
21
|
-
import { useBuilderEditMode } from "
|
|
21
|
+
import { useBuilderEditMode } from "../../../hooks/use-builder-edit-mode";
|
|
22
22
|
import { useSlateReset } from "../../use-slate-reset";
|
|
23
23
|
import { BuilderEditMode } from "../../../../../state/modules/builder-edit-mode";
|
|
24
24
|
import { pollBoxModel } from "../../../poll-box-model";
|
|
@@ -28,8 +28,8 @@ import { RichTextV2Element } from "./render-element";
|
|
|
28
28
|
import { RichTextV2Leaf } from "./render-leaf";
|
|
29
29
|
import { useSyncRemoteChanges } from "./useRemoteChanges";
|
|
30
30
|
import { defaultValue, usePresetValue } from "./usePresetValue";
|
|
31
|
-
function EditableTextV2({ text,
|
|
32
|
-
const plugins = useMemo(() =>
|
|
31
|
+
function EditableTextV2({ text, config, control }) {
|
|
32
|
+
const plugins = useMemo(() => config.plugins, [config]);
|
|
33
33
|
const [editor] = useState(
|
|
34
34
|
() => plugins.reduceRight(
|
|
35
35
|
(editor2, plugin) => plugin?.withPlugin?.(editor2) ?? editor2,
|
|
@@ -53,9 +53,9 @@ function EditableTextV2({ text, definition, control }) {
|
|
|
53
53
|
isPreservingFocus.current = false;
|
|
54
54
|
ReactEditor.deselect(editor);
|
|
55
55
|
}
|
|
56
|
-
}, [editMode]);
|
|
56
|
+
}, [editMode, editor]);
|
|
57
57
|
useSyncRemoteChanges(editor, text);
|
|
58
|
-
const presetValue = usePresetValue(
|
|
58
|
+
const presetValue = usePresetValue(config);
|
|
59
59
|
const initialValue = useMemo(
|
|
60
60
|
() => (text && RichText.dataToNodes(text)) ?? presetValue,
|
|
61
61
|
[text, presetValue]
|
|
@@ -71,15 +71,15 @@ function EditableTextV2({ text, definition, control }) {
|
|
|
71
71
|
}, [control, initialValue, presetValue]);
|
|
72
72
|
const renderElement = useCallback(
|
|
73
73
|
(props) => {
|
|
74
|
-
return /* @__PURE__ */ jsx(RichTextV2Element, { ...props,
|
|
74
|
+
return /* @__PURE__ */ jsx(RichTextV2Element, { ...props, plugins });
|
|
75
75
|
},
|
|
76
|
-
[plugins
|
|
76
|
+
[plugins]
|
|
77
77
|
);
|
|
78
78
|
const renderLeaf = useCallback(
|
|
79
79
|
(props) => {
|
|
80
|
-
return /* @__PURE__ */ jsx(RichTextV2Leaf, { ...props,
|
|
80
|
+
return /* @__PURE__ */ jsx(RichTextV2Leaf, { ...props, plugins });
|
|
81
81
|
},
|
|
82
|
-
[plugins
|
|
82
|
+
[plugins]
|
|
83
83
|
);
|
|
84
84
|
const handleFocus = useCallback(() => {
|
|
85
85
|
isPreservingFocus.current = true;
|
|
@@ -110,7 +110,7 @@ function EditableTextV2({ text, definition, control }) {
|
|
|
110
110
|
e.preventDefault();
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
-
[
|
|
113
|
+
[editMode]
|
|
114
114
|
);
|
|
115
115
|
const handleClick = useCallback(
|
|
116
116
|
(e) => {
|
|
@@ -144,9 +144,7 @@ function EditableTextV2({ text, definition, control }) {
|
|
|
144
144
|
}
|
|
145
145
|
) });
|
|
146
146
|
}
|
|
147
|
-
var editable_text_v2_default = EditableTextV2;
|
|
148
147
|
export {
|
|
149
|
-
EditableTextV2
|
|
150
|
-
editable_text_v2_default as default
|
|
148
|
+
EditableTextV2
|
|
151
149
|
};
|
|
152
150
|
//# sourceMappingURL=editable-text-v2.js.map
|
package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["'use client'\n\nimport {\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.tsx"],"sourcesContent":["'use client'\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { createEditor } from 'slate'\nimport isHotkey from 'is-hotkey'\nimport {\n withReact,\n ReactEditor,\n RenderElementProps,\n RenderLeafProps,\n Slate,\n Editable,\n} from 'slate-react'\n\nimport { type ConfigType } from '@makeswift/controls'\n\nimport {\n RichTextV2Definition,\n RichText,\n RichTextV2Control,\n type RichTextDataV2,\n} from '../../../../../controls/rich-text-v2'\n\nimport { useBuilderEditMode } from '../../../hooks/use-builder-edit-mode'\nimport { useSlateReset } from '../../use-slate-reset'\nimport { BuilderEditMode } from '../../../../../state/modules/builder-edit-mode'\nimport { pollBoxModel } from '../../../poll-box-model'\nimport { withBuilder, withLocalChanges } from '../../../../../slate'\n\nimport { useSyncDOMSelection } from './useSyncDOMSelection'\nimport { RichTextV2Element } from './render-element'\nimport { RichTextV2Leaf } from './render-leaf'\nimport { useSyncRemoteChanges } from './useRemoteChanges'\nimport { defaultValue, usePresetValue } from './usePresetValue'\n\ntype Props = {\n text?: RichTextDataV2\n config: ConfigType<RichTextV2Definition>\n control: RichTextV2Control | null\n}\n\nexport function EditableTextV2({ text, config, control }: Props) {\n const plugins = useMemo(() => config.plugins, [config])\n\n const [editor] = useState(() =>\n plugins.reduceRight(\n (editor, plugin) => plugin?.withPlugin?.(editor) ?? editor,\n withLocalChanges(withBuilder(withReact(createEditor()))),\n ),\n )\n\n useEffect(() => {\n if (control == null) return\n\n const element = ReactEditor.toDOMNode(editor, editor)\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeBoxModel(boxModel),\n })\n }, [editor, control])\n\n // ------ Preserving selection ------\n\n const isPreservingFocus = useRef(false)\n useSyncDOMSelection(editor, isPreservingFocus)\n const editMode = useBuilderEditMode()\n\n useEffect(() => {\n /**\n * This is required because clicking on the overlay has `relatedTarget` null just like the sidebar, but\n * - in the case of the overlay we switch to BUILD mode\n * - in the case of the sidebar we preserve the selection\n */\n if (editMode !== BuilderEditMode.CONTENT) {\n isPreservingFocus.current = false\n ReactEditor.deselect(editor)\n }\n }, [editMode, editor])\n\n // ------ Syncing remote changes ------\n\n useSyncRemoteChanges(editor, text)\n\n // ------ Default value ------\n\n const presetValue = usePresetValue(config)\n\n const initialValue = useMemo(\n () => (text && RichText.dataToNodes(text)) ?? presetValue,\n [text, presetValue],\n )\n\n useEffect(() => {\n control?.setEditor(editor)\n control?.setDefaultValue(defaultValue)\n }, [control, editor])\n\n /**\n * When initialValue is set to the default value we need to trigger an local change so that the sidebar updates and so the data is saved\n */\n useEffect(() => {\n if (initialValue === presetValue) {\n control?.onLocalUserChange()\n }\n }, [control, initialValue, presetValue])\n\n // ------ Rendering ------\n\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return <RichTextV2Element {...props} plugins={plugins} />\n },\n [plugins],\n )\n\n const renderLeaf = useCallback(\n (props: RenderLeafProps) => {\n return <RichTextV2Leaf {...props} plugins={plugins} />\n },\n [plugins],\n )\n\n // ------ Event handlers ------\n\n const handleFocus = useCallback(() => {\n isPreservingFocus.current = true\n control?.select()\n }, [control])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n if (isHotkey('mod+shift+z', e)) return control?.redo()\n if (isHotkey('mod+z', e)) return control?.undo()\n if (isHotkey('escape')(e)) {\n isPreservingFocus.current = false\n ReactEditor.blur(editor)\n control?.switchToBuildMode()\n }\n\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n }\n\n plugins.forEach(plugin => plugin?.onKeyDown?.(e, editor))\n },\n [control, plugins, editor, editMode],\n )\n\n const handleKeyUp = useCallback(\n (e: KeyboardEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [editMode],\n )\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n if (editMode === BuilderEditMode.CONTENT) {\n e.stopPropagation()\n e.preventDefault()\n }\n },\n [editMode],\n )\n\n const handleBlur = useCallback((e: FocusEvent) => {\n // outside of iframe (overlay, sidebar, etc)\n if (e.relatedTarget == null) return\n // another text\n if (e.relatedTarget?.getAttribute('contenteditable') === 'true')\n isPreservingFocus.current = false\n }, [])\n\n const slateReset = useSlateReset()\n\n return (\n <Slate editor={editor} value={initialValue}>\n <Editable\n className={slateReset}\n renderLeaf={renderLeaf}\n renderElement={renderElement}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onClick={handleClick}\n onBlur={handleBlur}\n readOnly={editMode !== BuilderEditMode.CONTENT}\n placeholder=\"Write some text...\"\n />\n </Slate>\n )\n}\n"],"mappings":";AAuHa;AArHb;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,OAAO,cAAc;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AAIP;AAAA,EAEE;AAAA,OAGK;AAEP,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,aAAa,wBAAwB;AAE9C,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,cAAc,sBAAsB;AAQtC,SAAS,eAAe,EAAE,MAAM,QAAQ,QAAQ,GAAU;AAC/D,QAAM,UAAU,QAAQ,MAAM,OAAO,SAAS,CAAC,MAAM,CAAC;AAEtD,QAAM,CAAC,MAAM,IAAI;AAAA,IAAS,MACxB,QAAQ;AAAA,MACN,CAACA,SAAQ,WAAW,QAAQ,aAAaA,OAAM,KAAKA;AAAA,MACpD,iBAAiB,YAAY,UAAU,aAAa,CAAC,CAAC,CAAC;AAAA,IACzD;AAAA,EACF;AAEA,YAAU,MAAM;AACd,QAAI,WAAW;AAAM;AAErB,UAAM,UAAU,YAAY,UAAU,QAAQ,MAAM;AACpD,WAAO,aAAa;AAAA,MAClB;AAAA,MACA,kBAAkB,cAAY,QAAQ,eAAe,QAAQ;AAAA,IAC/D,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,OAAO,CAAC;AAIpB,QAAM,oBAAoB,OAAO,KAAK;AACtC,sBAAoB,QAAQ,iBAAiB;AAC7C,QAAM,WAAW,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;AAEA,UAAI,aAAa,gBAAgB,SAAS;AACxC,UAAE,gBAAgB;AAAA,MACpB;AAEA,cAAQ,QAAQ,YAAU,QAAQ,YAAY,GAAG,MAAM,CAAC;AAAA,IAC1D;AAAA,IACA,CAAC,SAAS,SAAS,QAAQ,QAAQ;AAAA,EACrC;AAEA,QAAM,cAAc;AAAA,IAClB,CAAC,MAAqB;AACpB,UAAI,aAAa,gBAAgB,SAAS;AACxC,UAAE,gBAAgB;AAClB,UAAE,eAAe;AAAA,MACnB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,cAAc;AAAA,IAClB,CAAC,MAAkB;AACjB,UAAI,aAAa,gBAAgB,SAAS;AACxC,UAAE,gBAAgB;AAClB,UAAE,eAAe;AAAA,MACnB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,aAAa,YAAY,CAAC,MAAkB;AAEhD,QAAI,EAAE,iBAAiB;AAAM;AAE7B,QAAI,EAAE,eAAe,aAAa,iBAAiB,MAAM;AACvD,wBAAkB,UAAU;AAAA,EAChC,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,cAAc;AAEjC,SACE,oBAAC,SAAM,QAAgB,OAAO,cAC5B;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,WAAW;AAAA,MACX,SAAS;AAAA,MACT,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,UAAU,aAAa,gBAAgB;AAAA,MACvC,aAAY;AAAA;AAAA,EACd,GACF;AAEJ;","names":["editor"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.tsx"],"sourcesContent":["export * from './editable-text-v2'\nimport EditableTextV2 from './editable-text-v2'\nexport default EditableTextV2\n"],"mappings":"AAAA,cAAc;AACd,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/index.tsx"],"sourcesContent":["export * from './editable-text-v2'\nimport { EditableTextV2 } from './editable-text-v2'\nexport default EditableTextV2\n"],"mappings":"AAAA,cAAc;AACd,SAAS,sBAAsB;AAC/B,IAAO,yBAAQ;","names":[]}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ControlValue } from "../../control";
|
|
3
|
-
function RichTextV2Element({
|
|
3
|
+
function RichTextV2Element({ plugins, ...props }) {
|
|
4
4
|
function initialRenderElement(props2) {
|
|
5
5
|
return props2.children;
|
|
6
6
|
}
|
|
7
7
|
const renderElement = plugins.reduce(
|
|
8
|
-
(renderFn, plugin) => (props2)
|
|
8
|
+
(renderFn, plugin) => function RenderElementPlugin(props2) {
|
|
9
9
|
const { control, renderElement: renderElement2 } = plugin;
|
|
10
10
|
if (renderElement2 == null)
|
|
11
11
|
return renderFn(props2);
|
|
12
12
|
if (control == null || control.getElementValue == null)
|
|
13
13
|
return renderElement2(renderFn, void 0)(props2);
|
|
14
|
-
return /* @__PURE__ */ jsx(
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
ControlValue,
|
|
16
|
+
{
|
|
17
|
+
definition: control.definition,
|
|
18
|
+
data: control.getElementValue(props2.element),
|
|
19
|
+
children: (value) => renderElement2(renderFn, value)(props2)
|
|
20
|
+
}
|
|
21
|
+
);
|
|
15
22
|
},
|
|
16
23
|
initialRenderElement
|
|
17
24
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.tsx"],"sourcesContent":["import { RenderElementProps } from 'slate-react'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-element.tsx"],"sourcesContent":["import { RenderElementProps } from 'slate-react'\n\nimport { RichTextV2Plugin } from '../../../../../controls/rich-text-v2/plugin'\n\nimport { ControlValue } from '../../control'\n\ntype RichTextV2ElementProps = RenderElementProps & {\n plugins: RichTextV2Plugin[]\n}\n\nexport function RichTextV2Element({ plugins, ...props }: RichTextV2ElementProps) {\n function initialRenderElement(props: RenderElementProps) {\n return props.children\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) =>\n function RenderElementPlugin(props: RenderElementProps) {\n const { control, renderElement } = plugin\n\n if (renderElement == null) return renderFn(props)\n\n if (control == null || control.getElementValue == null)\n return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue\n definition={control.definition}\n data={control.getElementValue(props.element)}\n >\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement(props)\n}\n"],"mappings":"AA0BU;AAtBV,SAAS,oBAAoB;AAMtB,SAAS,kBAAkB,EAAE,SAAS,GAAG,MAAM,GAA2B;AAC/E,WAAS,qBAAqBA,QAA2B;AACvD,WAAOA,OAAM;AAAA,EACf;AAEA,QAAM,gBAAgB,QAAQ;AAAA,IAC5B,CAAC,UAAU,WACT,SAAS,oBAAoBA,QAA2B;AACtD,YAAM,EAAE,SAAS,eAAAC,eAAc,IAAI;AAEnC,UAAIA,kBAAiB;AAAM,eAAO,SAASD,MAAK;AAEhD,UAAI,WAAW,QAAQ,QAAQ,mBAAmB;AAChD,eAAOC,eAAc,UAAU,MAAS,EAAED,MAAK;AAEjD,aACE;AAAA,QAAC;AAAA;AAAA,UACC,YAAY,QAAQ;AAAA,UACpB,MAAM,QAAQ,gBAAgBA,OAAM,OAAO;AAAA,UAE1C,qBAASC,eAAc,UAAU,KAAK,EAAED,MAAK;AAAA;AAAA,MAChD;AAAA,IAEJ;AAAA,IACF;AAAA,EACF;AAEA,SAAO,cAAc,KAAK;AAC5B;","names":["props","renderElement"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ControlValue } from "../../control";
|
|
3
|
-
function RichTextV2Leaf({
|
|
3
|
+
function RichTextV2Leaf({ plugins, ...props }) {
|
|
4
4
|
function initialRenderLeaf({ attributes, children, leaf }) {
|
|
5
5
|
return /* @__PURE__ */ jsx("span", { className: leaf.className, ...attributes, children });
|
|
6
6
|
}
|
|
7
7
|
const renderLeaf = plugins.reduce(
|
|
8
|
-
(renderFn, plugin) => (props2)
|
|
8
|
+
(renderFn, plugin) => function RenderLeafPlugin(props2) {
|
|
9
9
|
const { control, renderLeaf: renderLeaf2 } = plugin;
|
|
10
10
|
if (control?.definition == null || renderLeaf2 == null)
|
|
11
11
|
return renderFn(props2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.tsx"],"sourcesContent":["import { ReactNode } from 'react'\nimport { RenderLeafProps } from 'slate-react'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/render-leaf.tsx"],"sourcesContent":["import { ReactNode } from 'react'\nimport { RenderLeafProps } from 'slate-react'\nimport { RichTextV2Plugin } from '../../../../../controls/rich-text-v2/plugin'\nimport { ControlValue } from '../../control'\n\ntype RichTextV2LeafProps = RenderLeafProps & {\n plugins: RichTextV2Plugin[]\n}\n\nexport function RichTextV2Leaf({ plugins, ...props }: RichTextV2LeafProps) {\n function initialRenderLeaf({ attributes, children, leaf }: RenderLeafProps): ReactNode {\n return (\n <span className={leaf.className} {...attributes}>\n {children}\n </span>\n )\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) =>\n function RenderLeafPlugin(props: RenderLeafProps) {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf(props)\n}\n"],"mappings":"AAYM;AATN,SAAS,oBAAoB;AAMtB,SAAS,eAAe,EAAE,SAAS,GAAG,MAAM,GAAwB;AACzE,WAAS,kBAAkB,EAAE,YAAY,UAAU,KAAK,GAA+B;AACrF,WACE,oBAAC,UAAK,WAAW,KAAK,WAAY,GAAG,YAClC,UACH;AAAA,EAEJ;AAEA,QAAM,aAAa,QAAQ;AAAA,IACzB,CAAC,UAAU,WACT,SAAS,iBAAiBA,QAAwB;AAChD,YAAM,EAAE,SAAS,YAAAC,YAAW,IAAI;AAEhC,UAAI,SAAS,cAAc,QAAQA,eAAc;AAAM,eAAO,SAASD,MAAK;AAE5E,UAAI,QAAQ,gBAAgB;AAAM,eAAOC,YAAW,UAAU,MAAS,EAAED,MAAK;AAE9E,aACE,oBAAC,gBAAa,YAAY,QAAQ,YAAY,MAAM,QAAQ,aAAaA,OAAM,IAAI,GAChF,qBAASC,YAAW,UAAU,KAAK,EAAED,MAAK,GAC7C;AAAA,IAEJ;AAAA,IACF;AAAA,EACF;AAEA,SAAO,WAAW,KAAK;AACzB;","names":["props","renderLeaf"]}
|
|
@@ -3,7 +3,7 @@ import { Slate, getBaseBreakpoint } from "@makeswift/controls";
|
|
|
3
3
|
import { DefaultBreakpointID } from "../../../../../state/modules/breakpoints";
|
|
4
4
|
import { useBreakpoints } from "../../../hooks/use-breakpoints";
|
|
5
5
|
import { RichText } from "../../../../../controls";
|
|
6
|
-
function usePresetValue(
|
|
6
|
+
function usePresetValue(config) {
|
|
7
7
|
const breakpoints = useBreakpoints();
|
|
8
8
|
return useMemo(
|
|
9
9
|
() => [
|
|
@@ -11,8 +11,8 @@ function usePresetValue(definition) {
|
|
|
11
11
|
type: Slate.BlockType.Default,
|
|
12
12
|
children: [
|
|
13
13
|
{
|
|
14
|
-
text:
|
|
15
|
-
...
|
|
14
|
+
text: config.defaultValue ?? "",
|
|
15
|
+
...config.mode === RichText.Mode.Inline ? {} : {
|
|
16
16
|
typography: {
|
|
17
17
|
style: [
|
|
18
18
|
{
|
|
@@ -36,7 +36,7 @@ function usePresetValue(definition) {
|
|
|
36
36
|
]
|
|
37
37
|
}
|
|
38
38
|
],
|
|
39
|
-
[
|
|
39
|
+
[config.mode, config.defaultValue, breakpoints]
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
const defaultValue = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.tsx"],"sourcesContent":["import { useMemo } from 'react'\nimport { Descendant } from 'slate'\nimport { Slate, getBaseBreakpoint } from '@makeswift/controls'\n\nimport { DefaultBreakpointID } from '../../../../../state/modules/breakpoints'\nimport { useBreakpoints } from '../../../hooks/use-breakpoints'\nimport { RichTextV2Definition, RichText } from '../../../../../controls'\n\nexport function usePresetValue(
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text-v2/EditableTextV2/usePresetValue.tsx"],"sourcesContent":["import { useMemo } from 'react'\nimport { Descendant } from 'slate'\n\nimport { type ConfigType, Slate, getBaseBreakpoint } from '@makeswift/controls'\n\nimport { DefaultBreakpointID } from '../../../../../state/modules/breakpoints'\nimport { useBreakpoints } from '../../../hooks/use-breakpoints'\nimport { RichTextV2Definition, RichText } from '../../../../../controls'\n\nexport function usePresetValue(config: ConfigType<RichTextV2Definition>): Descendant[] {\n const breakpoints = useBreakpoints()\n return useMemo(\n () => [\n {\n type: Slate.BlockType.Default,\n children: [\n {\n text: config.defaultValue ?? '',\n ...(config.mode === RichText.Mode.Inline\n ? {}\n : {\n typography: {\n style: [\n {\n deviceId: getBaseBreakpoint(breakpoints).id,\n value: {\n fontWeight: 400,\n fontSize: { value: 18, unit: 'px' },\n lineHeight: 1.5,\n },\n },\n ...(breakpoints.some(({ id }) => id === DefaultBreakpointID.Mobile)\n ? [\n {\n deviceId: DefaultBreakpointID.Mobile,\n value: { fontSize: { value: 16, unit: 'px' } },\n },\n ]\n : []),\n ],\n },\n }),\n },\n ],\n },\n ],\n [config.mode, config.defaultValue, breakpoints],\n )\n}\n\nexport const defaultValue = [\n {\n type: Slate.BlockType.Default,\n children: [\n {\n text: '',\n },\n ],\n },\n]\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,SAA0B,OAAO,yBAAyB;AAE1D,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAA+B,gBAAgB;AAExC,SAAS,eAAe,QAAwD;AACrF,QAAM,cAAc,eAAe;AACnC,SAAO;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,QACE,MAAM,MAAM,UAAU;AAAA,QACtB,UAAU;AAAA,UACR;AAAA,YACE,MAAM,OAAO,gBAAgB;AAAA,YAC7B,GAAI,OAAO,SAAS,SAAS,KAAK,SAC9B,CAAC,IACD;AAAA,cACE,YAAY;AAAA,gBACV,OAAO;AAAA,kBACL;AAAA,oBACE,UAAU,kBAAkB,WAAW,EAAE;AAAA,oBACzC,OAAO;AAAA,sBACL,YAAY;AAAA,sBACZ,UAAU,EAAE,OAAO,IAAI,MAAM,KAAK;AAAA,sBAClC,YAAY;AAAA,oBACd;AAAA,kBACF;AAAA,kBACA,GAAI,YAAY,KAAK,CAAC,EAAE,GAAG,MAAM,OAAO,oBAAoB,MAAM,IAC9D;AAAA,oBACE;AAAA,sBACE,UAAU,oBAAoB;AAAA,sBAC9B,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,MAAM,KAAK,EAAE;AAAA,oBAC/C;AAAA,kBACF,IACA,CAAC;AAAA,gBACP;AAAA,cACF;AAAA,YACF;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,OAAO,MAAM,OAAO,cAAc,WAAW;AAAA,EAChD;AACF;AAEO,MAAM,eAAe;AAAA,EAC1B;AAAA,IACE,MAAM,MAAM,UAAU;AAAA,IACtB,UAAU;AAAA,MACR;AAAA,QACE,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
|
-
import {
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
|
+
import {
|
|
4
|
+
RichText
|
|
5
|
+
} from "../../../../controls/rich-text-v2";
|
|
4
6
|
import { useStyle } from "../../use-style";
|
|
5
7
|
import { toText } from "../../../../slate/utils";
|
|
6
8
|
import { ControlValue } from "../control";
|
|
7
|
-
const ReadOnlyTextV2 = forwardRef(function ReadOnlyText({ text,
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
);
|
|
9
|
+
const ReadOnlyTextV2 = forwardRef(function ReadOnlyText({ text, config }, ref) {
|
|
10
|
+
const descendants = useMemo(() => text?.descendants ?? [], [text?.descendants]);
|
|
11
|
+
const plugins = useMemo(() => config?.plugins ?? [], [config]);
|
|
12
|
+
const descendantsAsString = toText(descendants, config?.mode ?? RichText.Mode.Block);
|
|
12
13
|
return /* @__PURE__ */ jsx(
|
|
13
14
|
"div",
|
|
14
15
|
{
|
|
@@ -23,13 +24,7 @@ const ReadOnlyTextV2 = forwardRef(function ReadOnlyText({ text, definition }, re
|
|
|
23
24
|
whiteSpace: "pre-wrap",
|
|
24
25
|
wordWrap: "break-word"
|
|
25
26
|
},
|
|
26
|
-
children: descendantsAsString === "" ? /* @__PURE__ */ jsx(Placeholder, {}) : /* @__PURE__ */ jsx(
|
|
27
|
-
Descendants,
|
|
28
|
-
{
|
|
29
|
-
plugins: definition?.config.plugins ?? [],
|
|
30
|
-
descendants: text?.descendants ?? []
|
|
31
|
-
}
|
|
32
|
-
)
|
|
27
|
+
children: descendantsAsString === "" ? /* @__PURE__ */ jsx(Placeholder, {}) : /* @__PURE__ */ jsx(Descendants, { plugins, descendants })
|
|
33
28
|
}
|
|
34
29
|
);
|
|
35
30
|
});
|
|
@@ -55,7 +50,7 @@ function LeafComponent({ plugins, ...props }) {
|
|
|
55
50
|
return /* @__PURE__ */ jsx("span", { className: leaf.className, children: leaf.text === "" ? "\uFEFF" : leaf.text });
|
|
56
51
|
}
|
|
57
52
|
const renderLeaf = plugins.reduce(
|
|
58
|
-
(renderFn, plugin) => (props2)
|
|
53
|
+
(renderFn, plugin) => function RenderLeafPlugin(props2) {
|
|
59
54
|
const { control, renderLeaf: renderLeaf2 } = plugin;
|
|
60
55
|
if (control?.definition == null || renderLeaf2 == null)
|
|
61
56
|
return renderFn(props2);
|
|
@@ -72,13 +67,20 @@ function ElementComponent({ plugins, ...props }) {
|
|
|
72
67
|
return /* @__PURE__ */ jsx(Descendants, { descendants: props2.element.children, plugins });
|
|
73
68
|
}
|
|
74
69
|
const renderElement = plugins.reduce(
|
|
75
|
-
(renderFn, plugin) => (props2)
|
|
70
|
+
(renderFn, plugin) => function RenderElementPlugin(props2) {
|
|
76
71
|
const { control, renderElement: renderElement2 } = plugin;
|
|
77
72
|
if (control?.definition == null || renderElement2 == null)
|
|
78
73
|
return renderFn(props2);
|
|
79
74
|
if (control.getElementValue == null)
|
|
80
75
|
return renderElement2(renderFn, void 0)(props2);
|
|
81
|
-
return /* @__PURE__ */ jsx(
|
|
76
|
+
return /* @__PURE__ */ jsx(
|
|
77
|
+
ControlValue,
|
|
78
|
+
{
|
|
79
|
+
definition: control.definition,
|
|
80
|
+
data: control.getElementValue(props2.element),
|
|
81
|
+
children: (value) => renderElement2(renderFn, value)(props2)
|
|
82
|
+
}
|
|
83
|
+
);
|
|
82
84
|
},
|
|
83
85
|
initialRenderElement
|
|
84
86
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef,
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.tsx"],"sourcesContent":["import { type ReactNode, type ForwardedRef, forwardRef, useMemo } from 'react'\nimport { type Descendant, type Element, type Text } from 'slate'\nimport { type RenderElementProps, type RenderLeafProps } from 'slate-react'\n\nimport { type ConfigType } from '@makeswift/controls'\n\nimport {\n type RichTextDataV2,\n RichTextV2Definition,\n RichText,\n} from '../../../../controls/rich-text-v2'\nimport { useStyle } from '../../use-style'\nimport { toText } from '../../../../slate/utils'\nimport { RichTextV2Plugin } from '../../../../controls/rich-text-v2/plugin'\n\nimport { ControlValue } from '../control'\n\ntype Props = {\n text: RichTextDataV2 | undefined\n config: ConfigType<RichTextV2Definition> | undefined\n}\n\nconst ReadOnlyTextV2 = forwardRef(function ReadOnlyText(\n { text, config }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendants = useMemo(() => text?.descendants ?? [], [text?.descendants])\n const plugins = useMemo(() => config?.plugins ?? [], [config])\n const descendantsAsString = toText(descendants, config?.mode ?? RichText.Mode.Block)\n\n return (\n <div\n ref={ref}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n >\n {descendantsAsString === '' ? (\n <Placeholder />\n ) : (\n <Descendants plugins={plugins} descendants={descendants} />\n )}\n </div>\n )\n})\n\nexport default ReadOnlyTextV2\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\ntype LeafProps = {\n leaf: Text\n plugins: RichTextV2Plugin[]\n}\n\nexport function LeafComponent({ plugins, ...props }: LeafProps) {\n function initialRenderLeaf({ leaf }: RenderLeafProps): ReactNode {\n return <span className={leaf.className}>{leaf.text === '' ? '\\uFEFF' : leaf.text}</span>\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) =>\n function RenderLeafPlugin(props: RenderLeafProps) {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf({ attributes: {} as any, leaf: props.leaf, children: null, text: props.leaf })\n}\n\ntype ElementProps = {\n descendant: Element\n plugins: RichTextV2Plugin[]\n}\n\nfunction ElementComponent({ plugins, ...props }: ElementProps) {\n function initialRenderElement(props: RenderElementProps): ReactNode {\n return <Descendants descendants={props.element.children} plugins={plugins} />\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) =>\n function RenderElementPlugin(props: RenderElementProps) {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue\n definition={control.definition}\n data={control.getElementValue(props.element)}\n >\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement({ attributes: {} as any, children: null, element: props.descendant })\n}\n\n// reimplemented from slate source for code splitting\nfunction isText(node: Descendant): node is Text {\n if (typeof node === 'object' && 'text' in node) return true\n\n return false\n}\n\nfunction Descendants({\n descendants,\n plugins,\n}: {\n plugins: RichTextV2Plugin[]\n descendants: Descendant[]\n}) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (isText(descendant)) {\n return <LeafComponent key={index} plugins={plugins} leaf={descendant} />\n }\n\n return <ElementComponent key={index} descendant={descendant} plugins={plugins} />\n })}\n </>\n )\n}\n"],"mappings":"AA6CQ,SA2GJ,UA3GI;AA7CR,SAA4C,YAAY,eAAe;AAMvE;AAAA,EAGE;AAA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AAI,CAAC,YAAY,UAAU;AACtC,QAAI,OAAO,UAAU,GAAG;AACtB,aAAO,oBAAC,iBAA0B,SAAkB,MAAM,cAA/B,KAA2C;AAAA,IACxE;AAEA,WAAO,oBAAC,oBAA6B,YAAwB,WAA/B,KAAiD;AAAA,EACjF,CAAC,GACH;AAEJ;","names":["props","renderLeaf","renderElement"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/index.ts"],"sourcesContent":["import { type ReactNode } from 'react'\n\nimport { RichTextV2Definition } from '../../../../controls/rich-text-v2'\n\nexport type RichTextV2ControlValue = ReactNode\nexport type Descriptors = { text?: RichTextV2Definition }\n\nexport { renderRichTextV2 } from './render-rich-text-v2'\n"],"mappings":"AAOA,SAAS,wBAAwB;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { lazy } from "react";
|
|
3
|
+
import { RichTextV2Definition } from "../../../../controls/rich-text-v2";
|
|
4
|
+
import { RichTextV2Value } from "./rich-text-v2-value";
|
|
5
|
+
const ReadOnlyTextV1 = lazy(() => import("../rich-text/ReadOnlyText"));
|
|
6
|
+
function renderRichTextV2(data, config, control) {
|
|
7
|
+
return RichTextV2Definition.isV1Data(data) ? /* @__PURE__ */ jsx(ReadOnlyTextV1, { text: data }) : /* @__PURE__ */ jsx(RichTextV2Value, { data, config, control });
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
renderRichTextV2
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=render-rich-text-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/render-rich-text-v2.tsx"],"sourcesContent":["import { type ReactNode, lazy } from 'react'\n\nimport { type DataType, type ConfigType } from '@makeswift/controls'\n\nimport { RichTextV2Control, RichTextV2Definition } from '../../../../controls/rich-text-v2'\n\nimport { RichTextV2Value } from './rich-text-v2-value'\n\nconst ReadOnlyTextV1 = lazy(() => import('../rich-text/ReadOnlyText'))\n\nexport function renderRichTextV2(\n data: DataType<RichTextV2Definition> | undefined,\n config: ConfigType<RichTextV2Definition>,\n control: RichTextV2Control | null,\n): ReactNode {\n return RichTextV2Definition.isV1Data(data) ? (\n <ReadOnlyTextV1 text={data} />\n ) : (\n <RichTextV2Value data={data} config={config} control={control} />\n )\n}\n"],"mappings":"AAgBI;AAhBJ,SAAyB,YAAY;AAIrC,SAA4B,4BAA4B;AAExD,SAAS,uBAAuB;AAEhC,MAAM,iBAAiB,KAAK,MAAM,OAAO,2BAA2B,CAAC;AAE9D,SAAS,iBACd,MACA,QACA,SACW;AACX,SAAO,qBAAqB,SAAS,IAAI,IACvC,oBAAC,kBAAe,MAAM,MAAM,IAE5B,oBAAC,mBAAgB,MAAY,QAAgB,SAAkB;AAEnE;","names":[]}
|