@makeswift/runtime 0.28.3-canary.0 → 0.28.3-canary.1
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-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +3 -3
- package/dist/cjs/controls/slot.js +7 -4
- package/dist/cjs/controls/slot.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +4 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/runtimes/react/controls/slot.js +49 -21
- package/dist/cjs/runtimes/react/controls/slot.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +3 -3
- package/dist/esm/controls/slot.js +7 -4
- package/dist/esm/controls/slot.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +4 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/runtimes/react/controls/slot.js +50 -22
- package/dist/esm/runtimes/react/controls/slot.js.map +1 -1
- package/dist/types/controls/slot.d.ts +11 -2
- package/dist/types/controls/slot.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +2 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
- package/dist/types/runtimes/react/controls/slot.d.ts +4 -1
- package/dist/types/runtimes/react/controls/slot.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -28,7 +28,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
28
28
|
return import_request_response.ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
29
29
|
}
|
|
30
30
|
return import_request_response.ApiResponse.json({
|
|
31
|
-
version: "0.28.3-canary.
|
|
31
|
+
version: "0.28.3-canary.1",
|
|
32
32
|
interactionMode: true,
|
|
33
33
|
clientSideNavigation: false,
|
|
34
34
|
elementFromPoint: false,
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -211,7 +211,7 @@ Received "${apiKey}" instead.`
|
|
|
211
211
|
}
|
|
212
212
|
this.apiKey = apiKey;
|
|
213
213
|
this.graphqlClient = new import_client.GraphQLClient(new URL("graphql", runtime.apiOrigin).href, {
|
|
214
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
214
|
+
"makeswift-runtime-version": "0.28.3-canary.1"
|
|
215
215
|
});
|
|
216
216
|
this.runtime = runtime;
|
|
217
217
|
}
|
|
@@ -223,7 +223,7 @@ Received "${apiKey}" instead.`
|
|
|
223
223
|
const requestHeaders = new Headers({
|
|
224
224
|
"x-api-key": this.apiKey,
|
|
225
225
|
"makeswift-site-api-key": this.apiKey,
|
|
226
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
226
|
+
"makeswift-runtime-version": "0.28.3-canary.1"
|
|
227
227
|
});
|
|
228
228
|
if (siteVersion?.token) {
|
|
229
229
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -681,7 +681,7 @@ Received "${apiKey}" instead.`
|
|
|
681
681
|
headers: {
|
|
682
682
|
"x-api-key": this.apiKey,
|
|
683
683
|
"makeswift-site-api-key": this.apiKey,
|
|
684
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
684
|
+
"makeswift-runtime-version": "0.28.3-canary.1",
|
|
685
685
|
"content-type": "application/json"
|
|
686
686
|
},
|
|
687
687
|
body: JSON.stringify({ token }),
|
|
@@ -32,12 +32,15 @@ class SlotDefinition extends BaseDefinition {
|
|
|
32
32
|
if (data.type !== SlotDefinition.type) {
|
|
33
33
|
throw new Error(`Slot: expected type ${SlotDefinition.type}, got ${data.type}`);
|
|
34
34
|
}
|
|
35
|
-
return Slot();
|
|
35
|
+
return Slot(data.config ?? {});
|
|
36
|
+
}
|
|
37
|
+
constructor(config = {}) {
|
|
38
|
+
super(config);
|
|
36
39
|
}
|
|
37
40
|
resolveValue(data, _resolver, _stylesheet, control) {
|
|
38
41
|
const stableValue = (0, import_controls.StableValue)({
|
|
39
42
|
name: SlotDefinition.type,
|
|
40
|
-
read: () => (0, import_slot.renderSlot)({ data, control: control ?? null })
|
|
43
|
+
read: () => (0, import_slot.renderSlot)({ data, control: control ?? null, config: this.config })
|
|
41
44
|
});
|
|
42
45
|
return {
|
|
43
46
|
...stableValue,
|
|
@@ -46,8 +49,8 @@ class SlotDefinition extends BaseDefinition {
|
|
|
46
49
|
};
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
function Slot() {
|
|
50
|
-
return new SlotDefinition();
|
|
52
|
+
function Slot(config = {}) {
|
|
53
|
+
return new SlotDefinition(config);
|
|
51
54
|
}
|
|
52
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
56
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/controls/slot.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport {\n SlotDefinition as BaseSlotDefinition,\n SlotControl,\n StableValue,\n type DeserializedRecord,\n type ResourceResolver,\n type Stylesheet,\n type Resolvable,\n type DataType,\n} from '@makeswift/controls'\n\nimport { renderSlot } from '../runtimes/react/controls/slot'\n\nabstract class BaseDefinition extends BaseSlotDefinition<ReactNode> {}\n\nexport class SlotDefinition extends BaseDefinition {\n static deserialize(data: DeserializedRecord): SlotDefinition {\n if (data.type !== SlotDefinition.type) {\n throw new Error(`Slot: expected type ${SlotDefinition.type}, got ${data.type}`)\n }\n\n return Slot()\n }\n\n resolveValue(\n data: DataType<BaseDefinition> | undefined,\n _resolver: ResourceResolver,\n _stylesheet: Stylesheet,\n control?: SlotControl,\n ): Resolvable<ReactNode | undefined> {\n const stableValue = StableValue({\n name: SlotDefinition.type,\n read: () => renderSlot({ data, control: control ?? null }),\n })\n\n return {\n ...stableValue,\n triggerResolve: async () => {},\n }\n }\n}\n\nexport function Slot(): SlotDefinition {\n return new SlotDefinition()\n}\n\nexport { SlotControl }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBASO;AAEP,kBAA2B;
|
|
1
|
+
{"version":3,"sources":["../../../src/controls/slot.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport {\n SlotDefinition as BaseSlotDefinition,\n SlotControl,\n StableValue,\n type DeserializedRecord,\n type ResourceResolver,\n type Stylesheet,\n type Resolvable,\n type DataType,\n} from '@makeswift/controls'\n\nimport { renderSlot } from '../runtimes/react/controls/slot'\n\nexport type SlotPlaceholderConfig = {\n builderOnly?: boolean\n height?: number\n text?: string\n}\n\n// TODO: We need to make a decision on how we want to allow users to configure\n// the Slot placeholder. Some considerations (not exhaustive):\n// - Inline vs block slot placeholders\n// - Slots that shouldn't occupy space when they are empty\n// - Slots that are only shown when you engage drop & drop in the builder\n// - Which of these behaviors should be configurable vs. hardcoded\n// - Addressing the builtin box\n//\n// For now, this initial config allows us to experiment with some initial\n// customization. This is subject to change.\nexport type SlotConfig = {\n unstable_placeholder?: SlotPlaceholderConfig\n}\n\nabstract class BaseDefinition extends BaseSlotDefinition<ReactNode, SlotConfig> {}\n\nexport class SlotDefinition extends BaseDefinition {\n static deserialize(data: DeserializedRecord): SlotDefinition {\n if (data.type !== SlotDefinition.type) {\n throw new Error(`Slot: expected type ${SlotDefinition.type}, got ${data.type}`)\n }\n\n return Slot(data.config ?? {})\n }\n\n constructor(config: SlotConfig = {}) {\n super(config)\n }\n\n resolveValue(\n data: DataType<BaseDefinition> | undefined,\n _resolver: ResourceResolver,\n _stylesheet: Stylesheet,\n control?: SlotControl,\n ): Resolvable<ReactNode | undefined> {\n const stableValue = StableValue({\n name: SlotDefinition.type,\n read: () => renderSlot({ data, control: control ?? null, config: this.config }),\n })\n\n return {\n ...stableValue,\n triggerResolve: async () => {},\n }\n }\n}\n\nexport function Slot(config: SlotConfig = {}): SlotDefinition {\n return new SlotDefinition(config)\n}\n\nexport { SlotControl }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBASO;AAEP,kBAA2B;AAsB3B,MAAe,uBAAuB,gBAAAA,eAA0C;AAAC;AAE1E,MAAM,uBAAuB,eAAe;AAAA,EACjD,OAAO,YAAY,MAA0C;AAC3D,QAAI,KAAK,SAAS,eAAe,MAAM;AACrC,YAAM,IAAI,MAAM,uBAAuB,eAAe,IAAI,SAAS,KAAK,IAAI,EAAE;AAAA,IAChF;AAEA,WAAO,KAAK,KAAK,UAAU,CAAC,CAAC;AAAA,EAC/B;AAAA,EAEA,YAAY,SAAqB,CAAC,GAAG;AACnC,UAAM,MAAM;AAAA,EACd;AAAA,EAEA,aACE,MACA,WACA,aACA,SACmC;AACnC,UAAM,kBAAc,6BAAY;AAAA,MAC9B,MAAM,eAAe;AAAA,MACrB,MAAM,UAAM,wBAAW,EAAE,MAAM,SAAS,WAAW,MAAM,QAAQ,KAAK,OAAO,CAAC;AAAA,IAChF,CAAC;AAED,WAAO;AAAA,MACL,GAAG;AAAA,MACH,gBAAgB,YAAY;AAAA,MAAC;AAAA,IAC/B;AAAA,EACF;AACF;AAEO,SAAS,KAAK,SAAqB,CAAC,GAAmB;AAC5D,SAAO,IAAI,eAAe,MAAM;AAClC;","names":["BaseSlotDefinition"]}
|
|
@@ -38,6 +38,7 @@ var import_jsdom = require("jsdom");
|
|
|
38
38
|
var import_react2 = require("@testing-library/react");
|
|
39
39
|
var import_jest_dom = require("@testing-library/jest-dom");
|
|
40
40
|
var import_navigation = require("next/navigation");
|
|
41
|
+
var import_read_only_actions = require("../../../../state/actions/internal/read-only-actions");
|
|
41
42
|
var import_MakeswiftComponent = require("../../../../runtimes/react/components/MakeswiftComponent");
|
|
42
43
|
var import_page = require("../../page");
|
|
43
44
|
var import_is_server = require("../../../../utils/is-server");
|
|
@@ -84,7 +85,8 @@ async function testPageControlPropRendering(controlDefinition, {
|
|
|
84
85
|
expectedRenders,
|
|
85
86
|
registerComponents,
|
|
86
87
|
action,
|
|
87
|
-
rootElements = []
|
|
88
|
+
rootElements = [],
|
|
89
|
+
isInBuilder = false
|
|
88
90
|
}) {
|
|
89
91
|
const controlData = value !== void 0 ? toData ? toData(value) : controlDefinition.toData(value) : void 0;
|
|
90
92
|
const testComponentMeta = {
|
|
@@ -101,6 +103,7 @@ async function testPageControlPropRendering(controlDefinition, {
|
|
|
101
103
|
}
|
|
102
104
|
};
|
|
103
105
|
const runtime = Testing.createReactRuntime();
|
|
106
|
+
runtime.store.dispatch((0, import_read_only_actions.setIsInBuilder)(isInBuilder));
|
|
104
107
|
registerComponents?.(runtime);
|
|
105
108
|
runtime.registerComponent(
|
|
106
109
|
(0, import_react.forwardRef)(({ propKey }, ref) => {
|
|
@@ -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/client'\nimport { ElementData } from '../../../../state/read-only-state'\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\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 }: {\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 },\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 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 <Testing.ReactProvider runtime={runtime}>{component}</Testing.ReactProvider>\n )\n\n if (!isServer()) {\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 } 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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/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\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 }: {\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 },\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.store.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 <Testing.ReactProvider runtime={runtime}>{component}</Testing.ReactProvider>\n )\n\n if (!isServer()) {\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 } 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsDI;AAtDJ,mBAAkF;AAClF,oBAAuC;AACvC,mBAAsB;AACtB,IAAAA,gBAA+B;AAC/B,sBAAO;AACP,wBAA0C;AAM1C,+BAA+B;AAE/B,gCAAmC;AACnC,kBAAqB;AACrB,uBAAyB;AACzB,cAAyB;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEn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CAAC;AAAA,IACH;AAEA,WAAO,QAAQ,EAAE,gBAAgB,UAAU;AAC3C,WAAO,aAAa,qBAAO,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AAEhF,QAAI,mBAAmB,MAAM;AAC3B,aAAO,OAAO,qBAAO,YAAY,iBAAiB,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IACxF;AAAA,EACF,OAAO;AAEL,YAAQ,OAAO,UAAU,IAAI;AAC7B,YAAQ,OAAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,4CAAC,gDAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,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":["import_react"]}
|
|
@@ -27,6 +27,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_css = require("@emotion/css");
|
|
29
29
|
var import_Element = require("../components/Element");
|
|
30
|
+
var import_use_is_in_builder = require("../hooks/use-is-in-builder");
|
|
30
31
|
var import_columns = require("../../../components/utils/columns");
|
|
31
32
|
var import_responsive_style = require("../../../components/utils/responsive-style");
|
|
32
33
|
var import_use_style = require("../use-style");
|
|
@@ -37,10 +38,11 @@ function renderSlot(props) {
|
|
|
37
38
|
const SlotValue = (0, import_react.memo)(
|
|
38
39
|
({
|
|
39
40
|
data,
|
|
40
|
-
control
|
|
41
|
+
control,
|
|
42
|
+
config
|
|
41
43
|
}) => {
|
|
42
44
|
if (data == null || data.elements.length === 0) {
|
|
43
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot.Placeholder, { control });
|
|
45
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot.Placeholder, { control, placeholder: config.unstable_placeholder });
|
|
44
46
|
}
|
|
45
47
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot, { control, children: data.elements.map((element, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Slot.Item, { control, grid: data.columns, index: i, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Element.Element, { element }) }, element.key)) });
|
|
46
48
|
}
|
|
@@ -101,8 +103,15 @@ function SlotItem({
|
|
|
101
103
|
}, [element, control, index]);
|
|
102
104
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(As, { ...restOfProps, ref: setElement, className: (0, import_css.cx)(baseClassName, className), children });
|
|
103
105
|
}
|
|
104
|
-
|
|
106
|
+
const DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY = false;
|
|
107
|
+
const DEFAULT_PLACEHOLDER_HEIGHT_PX = 80;
|
|
108
|
+
function SlotPlaceholder({ control, placeholder }) {
|
|
109
|
+
const isInBuilder = (0, import_use_is_in_builder.useIsInBuilder)();
|
|
105
110
|
const [element, setElement] = (0, import_react.useState)(null);
|
|
111
|
+
const showInBuilderOnly = placeholder?.builderOnly ?? DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY;
|
|
112
|
+
const placeholderHeight = placeholder?.height ?? DEFAULT_PLACEHOLDER_HEIGHT_PX;
|
|
113
|
+
const text = placeholder?.text;
|
|
114
|
+
const hidePlaceholder = showInBuilderOnly && !isInBuilder;
|
|
106
115
|
(0, import_react.useEffect)(() => {
|
|
107
116
|
if (element == null || control == null)
|
|
108
117
|
return;
|
|
@@ -117,31 +126,50 @@ function SlotPlaceholder({ control }) {
|
|
|
117
126
|
ref: setElement,
|
|
118
127
|
className: (0, import_use_style.useStyle)({
|
|
119
128
|
width: "100%",
|
|
120
|
-
background: "rgba(161, 168, 194, 0.18)"
|
|
121
|
-
height: "80px"
|
|
129
|
+
background: "rgba(161, 168, 194, 0.18)"
|
|
122
130
|
}),
|
|
123
|
-
|
|
131
|
+
style: {
|
|
132
|
+
height: hidePlaceholder ? 0 : placeholderHeight,
|
|
133
|
+
visibility: hidePlaceholder ? "hidden" : void 0
|
|
134
|
+
},
|
|
135
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
124
136
|
"svg",
|
|
125
137
|
{
|
|
126
138
|
xmlns: "http://www.w3.org/2000/svg",
|
|
127
139
|
width: "100%",
|
|
128
140
|
height: "100%",
|
|
129
141
|
className: (0, import_use_style.useStyle)({ overflow: "visible", padding: 8 }),
|
|
130
|
-
children:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
144
|
+
"rect",
|
|
145
|
+
{
|
|
146
|
+
x: 0,
|
|
147
|
+
y: 0,
|
|
148
|
+
width: "100%",
|
|
149
|
+
height: "100%",
|
|
150
|
+
strokeWidth: 2,
|
|
151
|
+
strokeDasharray: "4 2",
|
|
152
|
+
fill: "none",
|
|
153
|
+
stroke: "rgba(161, 168, 194, 0.40)",
|
|
154
|
+
rx: "4",
|
|
155
|
+
ry: "4"
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
text != null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
159
|
+
"text",
|
|
160
|
+
{
|
|
161
|
+
x: "50%",
|
|
162
|
+
y: "50%",
|
|
163
|
+
dominantBaseline: "central",
|
|
164
|
+
textAnchor: "middle",
|
|
165
|
+
fill: "rgba(161, 168, 194, 0.80)",
|
|
166
|
+
fontSize: "14px",
|
|
167
|
+
fontFamily: "sans-serif",
|
|
168
|
+
style: { userSelect: "none" },
|
|
169
|
+
children: text
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
]
|
|
145
173
|
}
|
|
146
174
|
)
|
|
147
175
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"sourcesContent":["'use client'\n\nimport { ComponentPropsWithoutRef, ElementType, ReactNode, useEffect, useState, memo } from 'react'\nimport { cx } from '@emotion/css'\n\nimport { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls'\n\nimport { Element } from '../components/Element'\nimport { getIndexes } from '../../../components/utils/columns'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { useStyle } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport function renderSlot(props: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n}): ReactNode {\n return <SlotValue {...props} />\n}\n\nconst SlotValue = memo(\n ({\n data,\n control,\n }: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n }): ReactNode => {\n // TODO(miguel): While the UI shouldn't allow the state, we should probably check that at least\n // one element is visible.\n if (data == null || data.elements.length === 0) {\n return <Slot.Placeholder control={control} />\n }\n\n return (\n <Slot control={control}>\n {data.elements.map((element, i) => (\n <Slot.Item key={element.key} control={control} grid={data.columns} index={i}>\n <Element element={element} />\n </Slot.Item>\n ))}\n </Slot>\n )\n },\n)\n\ntype SlotProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n children?: ReactNode\n className?: string\n}\n\nexport function Slot<T extends ElementType = 'div'>({\n as,\n control,\n children,\n className,\n ...restOfProps\n}: SlotProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotProps<T>>) {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n flexWrap: 'wrap',\n width: '100%',\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\nSlot.Placeholder = SlotPlaceholder\n\nSlot.Item = SlotItem\n\ntype SlotItemProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n // @arvin: review for correctness\n grid: DataType<SlotDefinition<ReactNode>> extends undefined\n ? undefined\n : NonNullable<DataType<SlotDefinition<ReactNode>>>['columns']\n index: number\n children?: ReactNode\n className?: string\n}\n\nfunction SlotItem<T extends ElementType = 'div'>({\n as,\n control,\n grid,\n index,\n children,\n className,\n ...restOfProps\n}: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): ReactNode {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n ...useResponsiveStyle([grid], ([{ count = 12, spans = [[12]] } = {}]) => {\n const [rowIndex, columnIndex] = getIndexes(spans, index)\n const span = spans[rowIndex][columnIndex]\n const flexBasis = `calc(100% * ${(span / count).toFixed(5)})`\n\n return span === 0 ? { display: 'none' } : { flexBasis, minWidth: flexBasis }\n }),\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeItemBoxModel(index, boxModel),\n })\n }, [element, control, index])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\ntype SlotPlaceholderProps = {\n control: SlotControl | null\n}\n\nfunction SlotPlaceholder({ control }: SlotPlaceholderProps): ReactNode {\n const [element, setElement] = useState<Element | null>(null)\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <div\n ref={setElement}\n className={useStyle({\n width: '100%',\n background: 'rgba(161, 168, 194, 0.18)',\n height: '
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"sourcesContent":["'use client'\n\nimport { ComponentPropsWithoutRef, ElementType, ReactNode, useEffect, useState, memo } from 'react'\nimport { cx } from '@emotion/css'\n\nimport { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls'\n\nimport { type SlotConfig, type SlotPlaceholderConfig } from '../../../controls/slot'\nimport { Element } from '../components/Element'\nimport { useIsInBuilder } from '../hooks/use-is-in-builder'\nimport { getIndexes } from '../../../components/utils/columns'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { useStyle } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport function renderSlot(props: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n config: SlotConfig\n}): ReactNode {\n return <SlotValue {...props} />\n}\n\nconst SlotValue = memo(\n ({\n data,\n control,\n config,\n }: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n config: SlotConfig\n }): ReactNode => {\n // TODO(miguel): While the UI shouldn't allow the state, we should probably check that at least\n // one element is visible.\n if (data == null || data.elements.length === 0) {\n return <Slot.Placeholder control={control} placeholder={config.unstable_placeholder} />\n }\n\n return (\n <Slot control={control}>\n {data.elements.map((element, i) => (\n <Slot.Item key={element.key} control={control} grid={data.columns} index={i}>\n <Element element={element} />\n </Slot.Item>\n ))}\n </Slot>\n )\n },\n)\n\ntype SlotProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n children?: ReactNode\n className?: string\n}\n\nexport function Slot<T extends ElementType = 'div'>({\n as,\n control,\n children,\n className,\n ...restOfProps\n}: SlotProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotProps<T>>) {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n flexWrap: 'wrap',\n width: '100%',\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\nSlot.Placeholder = SlotPlaceholder\n\nSlot.Item = SlotItem\n\ntype SlotItemProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n // @arvin: review for correctness\n grid: DataType<SlotDefinition<ReactNode>> extends undefined\n ? undefined\n : NonNullable<DataType<SlotDefinition<ReactNode>>>['columns']\n index: number\n children?: ReactNode\n className?: string\n}\n\nfunction SlotItem<T extends ElementType = 'div'>({\n as,\n control,\n grid,\n index,\n children,\n className,\n ...restOfProps\n}: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): ReactNode {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n ...useResponsiveStyle([grid], ([{ count = 12, spans = [[12]] } = {}]) => {\n const [rowIndex, columnIndex] = getIndexes(spans, index)\n const span = spans[rowIndex][columnIndex]\n const flexBasis = `calc(100% * ${(span / count).toFixed(5)})`\n\n return span === 0 ? { display: 'none' } : { flexBasis, minWidth: flexBasis }\n }),\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeItemBoxModel(index, boxModel),\n })\n }, [element, control, index])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\ntype SlotPlaceholderProps = {\n control: SlotControl | null\n placeholder?: SlotPlaceholderConfig\n}\n\nconst DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY = false\nconst DEFAULT_PLACEHOLDER_HEIGHT_PX = 80\n\nfunction SlotPlaceholder({ control, placeholder }: SlotPlaceholderProps): ReactNode {\n const isInBuilder = useIsInBuilder()\n const [element, setElement] = useState<Element | null>(null)\n\n // TODO: When ready, we can default to only showing the slot placeholder in\n // the builder\n const showInBuilderOnly = placeholder?.builderOnly ?? DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY\n const placeholderHeight = placeholder?.height ?? DEFAULT_PLACEHOLDER_HEIGHT_PX\n const text = placeholder?.text\n\n const hidePlaceholder = showInBuilderOnly && !isInBuilder\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <div\n ref={setElement}\n className={useStyle({\n width: '100%',\n background: 'rgba(161, 168, 194, 0.18)',\n })}\n style={{\n height: hidePlaceholder ? 0 : placeholderHeight,\n visibility: hidePlaceholder ? 'hidden' : undefined,\n }}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"100%\"\n height=\"100%\"\n className={useStyle({ overflow: 'visible', padding: 8 })}\n >\n <rect\n x={0}\n y={0}\n width=\"100%\"\n height=\"100%\"\n strokeWidth={2}\n strokeDasharray=\"4 2\"\n fill=\"none\"\n stroke=\"rgba(161, 168, 194, 0.40)\"\n rx=\"4\"\n ry=\"4\"\n />\n {text != null && (\n <text\n x=\"50%\"\n y=\"50%\"\n dominantBaseline=\"central\"\n textAnchor=\"middle\"\n fill=\"rgba(161, 168, 194, 0.80)\"\n fontSize=\"14px\"\n fontFamily=\"sans-serif\"\n style={{ userSelect: 'none' }}\n >\n {text}\n </text>\n )}\n </svg>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBS;AAlBT,mBAA4F;AAC5F,iBAAmB;AAKnB,qBAAwB;AACxB,+BAA+B;AAC/B,qBAA2B;AAC3B,8BAAmC;AACnC,uBAA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xE,CAAC;AAAA,EACH,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,eAAW,2BAAS;AAAA,QAClB,OAAO;AAAA,QACP,YAAY;AAAA,MACd,CAAC;AAAA,MACD,OAAO;AAAA,QACL,QAAQ,kBAAkB,IAAI;AAAA,QAC9B,YAAY,kBAAkB,WAAW;AAAA,MAC3C;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,OAAM;AAAA,UACN,OAAM;AAAA,UACN,QAAO;AAAA,UACP,eAAW,2BAAS,EAAE,UAAU,WAAW,SAAS,EAAE,CAAC;AAAA,UAEvD;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,GAAG;AAAA,gBACH,GAAG;AAAA,gBACH,OAAM;AAAA,gBACN,QAAO;AAAA,gBACP,aAAa;AAAA,gBACb,iBAAgB;AAAA,gBAChB,MAAK;AAAA,gBACL,QAAO;AAAA,gBACP,IAAG;AAAA,gBACH,IAAG;AAAA;AAAA,YACL;AAAA,YACC,QAAQ,QACP;AAAA,cAAC;AAAA;AAAA,gBACC,GAAE;AAAA,gBACF,GAAE;AAAA,gBACF,kBAAiB;AAAA,gBACjB,YAAW;AAAA,gBACX,MAAK;AAAA,gBACL,UAAS;AAAA,gBACT,YAAW;AAAA,gBACX,OAAO,EAAE,YAAY,OAAO;AAAA,gBAE3B;AAAA;AAAA,YACH;AAAA;AAAA;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
8
8
|
return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
9
9
|
}
|
|
10
10
|
return ApiResponse.json({
|
|
11
|
-
version: "0.28.3-canary.
|
|
11
|
+
version: "0.28.3-canary.1",
|
|
12
12
|
interactionMode: true,
|
|
13
13
|
clientSideNavigation: false,
|
|
14
14
|
elementFromPoint: false,
|
package/dist/esm/client/index.js
CHANGED
|
@@ -195,7 +195,7 @@ Received "${apiKey}" instead.`
|
|
|
195
195
|
}
|
|
196
196
|
this.apiKey = apiKey;
|
|
197
197
|
this.graphqlClient = new GraphQLClient(new URL("graphql", runtime.apiOrigin).href, {
|
|
198
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
198
|
+
"makeswift-runtime-version": "0.28.3-canary.1"
|
|
199
199
|
});
|
|
200
200
|
this.runtime = runtime;
|
|
201
201
|
}
|
|
@@ -207,7 +207,7 @@ Received "${apiKey}" instead.`
|
|
|
207
207
|
const requestHeaders = new Headers({
|
|
208
208
|
"x-api-key": this.apiKey,
|
|
209
209
|
"makeswift-site-api-key": this.apiKey,
|
|
210
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
210
|
+
"makeswift-runtime-version": "0.28.3-canary.1"
|
|
211
211
|
});
|
|
212
212
|
if (siteVersion?.token) {
|
|
213
213
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -665,7 +665,7 @@ Received "${apiKey}" instead.`
|
|
|
665
665
|
headers: {
|
|
666
666
|
"x-api-key": this.apiKey,
|
|
667
667
|
"makeswift-site-api-key": this.apiKey,
|
|
668
|
-
"makeswift-runtime-version": "0.28.3-canary.
|
|
668
|
+
"makeswift-runtime-version": "0.28.3-canary.1",
|
|
669
669
|
"content-type": "application/json"
|
|
670
670
|
},
|
|
671
671
|
body: JSON.stringify({ token }),
|
|
@@ -11,12 +11,15 @@ class SlotDefinition extends BaseDefinition {
|
|
|
11
11
|
if (data.type !== SlotDefinition.type) {
|
|
12
12
|
throw new Error(`Slot: expected type ${SlotDefinition.type}, got ${data.type}`);
|
|
13
13
|
}
|
|
14
|
-
return Slot();
|
|
14
|
+
return Slot(data.config ?? {});
|
|
15
|
+
}
|
|
16
|
+
constructor(config = {}) {
|
|
17
|
+
super(config);
|
|
15
18
|
}
|
|
16
19
|
resolveValue(data, _resolver, _stylesheet, control) {
|
|
17
20
|
const stableValue = StableValue({
|
|
18
21
|
name: SlotDefinition.type,
|
|
19
|
-
read: () => renderSlot({ data, control: control ?? null })
|
|
22
|
+
read: () => renderSlot({ data, control: control ?? null, config: this.config })
|
|
20
23
|
});
|
|
21
24
|
return {
|
|
22
25
|
...stableValue,
|
|
@@ -25,8 +28,8 @@ class SlotDefinition extends BaseDefinition {
|
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
|
-
function Slot() {
|
|
29
|
-
return new SlotDefinition();
|
|
31
|
+
function Slot(config = {}) {
|
|
32
|
+
return new SlotDefinition(config);
|
|
30
33
|
}
|
|
31
34
|
export {
|
|
32
35
|
Slot,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/controls/slot.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport {\n SlotDefinition as BaseSlotDefinition,\n SlotControl,\n StableValue,\n type DeserializedRecord,\n type ResourceResolver,\n type Stylesheet,\n type Resolvable,\n type DataType,\n} from '@makeswift/controls'\n\nimport { renderSlot } from '../runtimes/react/controls/slot'\n\nabstract class BaseDefinition extends BaseSlotDefinition<ReactNode> {}\n\nexport class SlotDefinition extends BaseDefinition {\n static deserialize(data: DeserializedRecord): SlotDefinition {\n if (data.type !== SlotDefinition.type) {\n throw new Error(`Slot: expected type ${SlotDefinition.type}, got ${data.type}`)\n }\n\n return Slot()\n }\n\n resolveValue(\n data: DataType<BaseDefinition> | undefined,\n _resolver: ResourceResolver,\n _stylesheet: Stylesheet,\n control?: SlotControl,\n ): Resolvable<ReactNode | undefined> {\n const stableValue = StableValue({\n name: SlotDefinition.type,\n read: () => renderSlot({ data, control: control ?? null }),\n })\n\n return {\n ...stableValue,\n triggerResolve: async () => {},\n }\n }\n}\n\nexport function Slot(): SlotDefinition {\n return new SlotDefinition()\n}\n\nexport { SlotControl }\n"],"mappings":"AACA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,OAMK;AAEP,SAAS,kBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../../src/controls/slot.ts"],"sourcesContent":["import { ReactNode } from 'react'\nimport {\n SlotDefinition as BaseSlotDefinition,\n SlotControl,\n StableValue,\n type DeserializedRecord,\n type ResourceResolver,\n type Stylesheet,\n type Resolvable,\n type DataType,\n} from '@makeswift/controls'\n\nimport { renderSlot } from '../runtimes/react/controls/slot'\n\nexport type SlotPlaceholderConfig = {\n builderOnly?: boolean\n height?: number\n text?: string\n}\n\n// TODO: We need to make a decision on how we want to allow users to configure\n// the Slot placeholder. Some considerations (not exhaustive):\n// - Inline vs block slot placeholders\n// - Slots that shouldn't occupy space when they are empty\n// - Slots that are only shown when you engage drop & drop in the builder\n// - Which of these behaviors should be configurable vs. hardcoded\n// - Addressing the builtin box\n//\n// For now, this initial config allows us to experiment with some initial\n// customization. This is subject to change.\nexport type SlotConfig = {\n unstable_placeholder?: SlotPlaceholderConfig\n}\n\nabstract class BaseDefinition extends BaseSlotDefinition<ReactNode, SlotConfig> {}\n\nexport class SlotDefinition extends BaseDefinition {\n static deserialize(data: DeserializedRecord): SlotDefinition {\n if (data.type !== SlotDefinition.type) {\n throw new Error(`Slot: expected type ${SlotDefinition.type}, got ${data.type}`)\n }\n\n return Slot(data.config ?? {})\n }\n\n constructor(config: SlotConfig = {}) {\n super(config)\n }\n\n resolveValue(\n data: DataType<BaseDefinition> | undefined,\n _resolver: ResourceResolver,\n _stylesheet: Stylesheet,\n control?: SlotControl,\n ): Resolvable<ReactNode | undefined> {\n const stableValue = StableValue({\n name: SlotDefinition.type,\n read: () => renderSlot({ data, control: control ?? null, config: this.config }),\n })\n\n return {\n ...stableValue,\n triggerResolve: async () => {},\n }\n }\n}\n\nexport function Slot(config: SlotConfig = {}): SlotDefinition {\n return new SlotDefinition(config)\n}\n\nexport { SlotControl }\n"],"mappings":"AACA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,OAMK;AAEP,SAAS,kBAAkB;AAsB3B,MAAe,uBAAuB,mBAA0C;AAAC;AAE1E,MAAM,uBAAuB,eAAe;AAAA,EACjD,OAAO,YAAY,MAA0C;AAC3D,QAAI,KAAK,SAAS,eAAe,MAAM;AACrC,YAAM,IAAI,MAAM,uBAAuB,eAAe,IAAI,SAAS,KAAK,IAAI,EAAE;AAAA,IAChF;AAEA,WAAO,KAAK,KAAK,UAAU,CAAC,CAAC;AAAA,EAC/B;AAAA,EAEA,YAAY,SAAqB,CAAC,GAAG;AACnC,UAAM,MAAM;AAAA,EACd;AAAA,EAEA,aACE,MACA,WACA,aACA,SACmC;AACnC,UAAM,cAAc,YAAY;AAAA,MAC9B,MAAM,eAAe;AAAA,MACrB,MAAM,MAAM,WAAW,EAAE,MAAM,SAAS,WAAW,MAAM,QAAQ,KAAK,OAAO,CAAC;AAAA,IAChF,CAAC;AAED,WAAO;AAAA,MACL,GAAG;AAAA,MACH,gBAAgB,YAAY;AAAA,MAAC;AAAA,IAC/B;AAAA,EACF;AACF;AAEO,SAAS,KAAK,SAAqB,CAAC,GAAmB;AAC5D,SAAO,IAAI,eAAe,MAAM;AAClC;","names":[]}
|
|
@@ -5,6 +5,7 @@ import { JSDOM } from "jsdom";
|
|
|
5
5
|
import { render, screen } from "@testing-library/react";
|
|
6
6
|
import "@testing-library/jest-dom";
|
|
7
7
|
import { ServerInsertedHTMLContext } from "next/navigation";
|
|
8
|
+
import { setIsInBuilder } from "../../../../state/actions/internal/read-only-actions";
|
|
8
9
|
import { MakeswiftComponent } from "../../../../runtimes/react/components/MakeswiftComponent";
|
|
9
10
|
import { Page } from "../../page";
|
|
10
11
|
import { isServer } from "../../../../utils/is-server";
|
|
@@ -51,7 +52,8 @@ async function testPageControlPropRendering(controlDefinition, {
|
|
|
51
52
|
expectedRenders,
|
|
52
53
|
registerComponents,
|
|
53
54
|
action,
|
|
54
|
-
rootElements = []
|
|
55
|
+
rootElements = [],
|
|
56
|
+
isInBuilder = false
|
|
55
57
|
}) {
|
|
56
58
|
const controlData = value !== void 0 ? toData ? toData(value) : controlDefinition.toData(value) : void 0;
|
|
57
59
|
const testComponentMeta = {
|
|
@@ -68,6 +70,7 @@ async function testPageControlPropRendering(controlDefinition, {
|
|
|
68
70
|
}
|
|
69
71
|
};
|
|
70
72
|
const runtime = Testing.createReactRuntime();
|
|
73
|
+
runtime.store.dispatch(setIsInBuilder(isInBuilder));
|
|
71
74
|
registerComponents?.(runtime);
|
|
72
75
|
runtime.registerComponent(
|
|
73
76
|
forwardRef(({ propKey }, ref) => {
|
|
@@ -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/client'\nimport { ElementData } from '../../../../state/read-only-state'\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\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 }: {\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 },\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 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 <Testing.ReactProvider runtime={runtime}>{component}</Testing.ReactProvider>\n )\n\n if (!isServer()) {\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 } 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":"
|
|
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/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\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 }: {\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 },\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.store.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 <Testing.ReactProvider runtime={runtime}>{component}</Testing.ReactProvider>\n )\n\n if (!isServer()) {\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 } 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,cA6EI,YA7EJ;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,oBAAoB,KAAK,aAAa,qBAAqB,MAAM,eAAe,EAAE;AA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B,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IACxF;AAAA,EACF,OAAO;AAEL,YAAQ,OAAO,UAAU,IAAI;AAC7B,YAAQ,OAAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,oBAAC,sBAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,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,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useState, memo } from "react";
|
|
4
4
|
import { cx } from "@emotion/css";
|
|
5
5
|
import { Element } from "../components/Element";
|
|
6
|
+
import { useIsInBuilder } from "../hooks/use-is-in-builder";
|
|
6
7
|
import { getIndexes } from "../../../components/utils/columns";
|
|
7
8
|
import { useResponsiveStyle } from "../../../components/utils/responsive-style";
|
|
8
9
|
import { useStyle } from "../use-style";
|
|
@@ -13,10 +14,11 @@ function renderSlot(props) {
|
|
|
13
14
|
const SlotValue = memo(
|
|
14
15
|
({
|
|
15
16
|
data,
|
|
16
|
-
control
|
|
17
|
+
control,
|
|
18
|
+
config
|
|
17
19
|
}) => {
|
|
18
20
|
if (data == null || data.elements.length === 0) {
|
|
19
|
-
return /* @__PURE__ */ jsx(Slot.Placeholder, { control });
|
|
21
|
+
return /* @__PURE__ */ jsx(Slot.Placeholder, { control, placeholder: config.unstable_placeholder });
|
|
20
22
|
}
|
|
21
23
|
return /* @__PURE__ */ jsx(Slot, { control, children: data.elements.map((element, i) => /* @__PURE__ */ jsx(Slot.Item, { control, grid: data.columns, index: i, children: /* @__PURE__ */ jsx(Element, { element }) }, element.key)) });
|
|
22
24
|
}
|
|
@@ -77,8 +79,15 @@ function SlotItem({
|
|
|
77
79
|
}, [element, control, index]);
|
|
78
80
|
return /* @__PURE__ */ jsx(As, { ...restOfProps, ref: setElement, className: cx(baseClassName, className), children });
|
|
79
81
|
}
|
|
80
|
-
|
|
82
|
+
const DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY = false;
|
|
83
|
+
const DEFAULT_PLACEHOLDER_HEIGHT_PX = 80;
|
|
84
|
+
function SlotPlaceholder({ control, placeholder }) {
|
|
85
|
+
const isInBuilder = useIsInBuilder();
|
|
81
86
|
const [element, setElement] = useState(null);
|
|
87
|
+
const showInBuilderOnly = placeholder?.builderOnly ?? DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY;
|
|
88
|
+
const placeholderHeight = placeholder?.height ?? DEFAULT_PLACEHOLDER_HEIGHT_PX;
|
|
89
|
+
const text = placeholder?.text;
|
|
90
|
+
const hidePlaceholder = showInBuilderOnly && !isInBuilder;
|
|
82
91
|
useEffect(() => {
|
|
83
92
|
if (element == null || control == null)
|
|
84
93
|
return;
|
|
@@ -93,31 +102,50 @@ function SlotPlaceholder({ control }) {
|
|
|
93
102
|
ref: setElement,
|
|
94
103
|
className: useStyle({
|
|
95
104
|
width: "100%",
|
|
96
|
-
background: "rgba(161, 168, 194, 0.18)"
|
|
97
|
-
height: "80px"
|
|
105
|
+
background: "rgba(161, 168, 194, 0.18)"
|
|
98
106
|
}),
|
|
99
|
-
|
|
107
|
+
style: {
|
|
108
|
+
height: hidePlaceholder ? 0 : placeholderHeight,
|
|
109
|
+
visibility: hidePlaceholder ? "hidden" : void 0
|
|
110
|
+
},
|
|
111
|
+
children: /* @__PURE__ */ jsxs(
|
|
100
112
|
"svg",
|
|
101
113
|
{
|
|
102
114
|
xmlns: "http://www.w3.org/2000/svg",
|
|
103
115
|
width: "100%",
|
|
104
116
|
height: "100%",
|
|
105
117
|
className: useStyle({ overflow: "visible", padding: 8 }),
|
|
106
|
-
children:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
children: [
|
|
119
|
+
/* @__PURE__ */ jsx(
|
|
120
|
+
"rect",
|
|
121
|
+
{
|
|
122
|
+
x: 0,
|
|
123
|
+
y: 0,
|
|
124
|
+
width: "100%",
|
|
125
|
+
height: "100%",
|
|
126
|
+
strokeWidth: 2,
|
|
127
|
+
strokeDasharray: "4 2",
|
|
128
|
+
fill: "none",
|
|
129
|
+
stroke: "rgba(161, 168, 194, 0.40)",
|
|
130
|
+
rx: "4",
|
|
131
|
+
ry: "4"
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
text != null && /* @__PURE__ */ jsx(
|
|
135
|
+
"text",
|
|
136
|
+
{
|
|
137
|
+
x: "50%",
|
|
138
|
+
y: "50%",
|
|
139
|
+
dominantBaseline: "central",
|
|
140
|
+
textAnchor: "middle",
|
|
141
|
+
fill: "rgba(161, 168, 194, 0.80)",
|
|
142
|
+
fontSize: "14px",
|
|
143
|
+
fontFamily: "sans-serif",
|
|
144
|
+
style: { userSelect: "none" },
|
|
145
|
+
children: text
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
]
|
|
121
149
|
}
|
|
122
150
|
)
|
|
123
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"sourcesContent":["'use client'\n\nimport { ComponentPropsWithoutRef, ElementType, ReactNode, useEffect, useState, memo } from 'react'\nimport { cx } from '@emotion/css'\n\nimport { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls'\n\nimport { Element } from '../components/Element'\nimport { getIndexes } from '../../../components/utils/columns'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { useStyle } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport function renderSlot(props: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n}): ReactNode {\n return <SlotValue {...props} />\n}\n\nconst SlotValue = memo(\n ({\n data,\n control,\n }: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n }): ReactNode => {\n // TODO(miguel): While the UI shouldn't allow the state, we should probably check that at least\n // one element is visible.\n if (data == null || data.elements.length === 0) {\n return <Slot.Placeholder control={control} />\n }\n\n return (\n <Slot control={control}>\n {data.elements.map((element, i) => (\n <Slot.Item key={element.key} control={control} grid={data.columns} index={i}>\n <Element element={element} />\n </Slot.Item>\n ))}\n </Slot>\n )\n },\n)\n\ntype SlotProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n children?: ReactNode\n className?: string\n}\n\nexport function Slot<T extends ElementType = 'div'>({\n as,\n control,\n children,\n className,\n ...restOfProps\n}: SlotProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotProps<T>>) {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n flexWrap: 'wrap',\n width: '100%',\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\nSlot.Placeholder = SlotPlaceholder\n\nSlot.Item = SlotItem\n\ntype SlotItemProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n // @arvin: review for correctness\n grid: DataType<SlotDefinition<ReactNode>> extends undefined\n ? undefined\n : NonNullable<DataType<SlotDefinition<ReactNode>>>['columns']\n index: number\n children?: ReactNode\n className?: string\n}\n\nfunction SlotItem<T extends ElementType = 'div'>({\n as,\n control,\n grid,\n index,\n children,\n className,\n ...restOfProps\n}: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): ReactNode {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n ...useResponsiveStyle([grid], ([{ count = 12, spans = [[12]] } = {}]) => {\n const [rowIndex, columnIndex] = getIndexes(spans, index)\n const span = spans[rowIndex][columnIndex]\n const flexBasis = `calc(100% * ${(span / count).toFixed(5)})`\n\n return span === 0 ? { display: 'none' } : { flexBasis, minWidth: flexBasis }\n }),\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeItemBoxModel(index, boxModel),\n })\n }, [element, control, index])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\ntype SlotPlaceholderProps = {\n control: SlotControl | null\n}\n\nfunction SlotPlaceholder({ control }: SlotPlaceholderProps): ReactNode {\n const [element, setElement] = useState<Element | null>(null)\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <div\n ref={setElement}\n className={useStyle({\n width: '100%',\n background: 'rgba(161, 168, 194, 0.18)',\n height: '
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"sourcesContent":["'use client'\n\nimport { ComponentPropsWithoutRef, ElementType, ReactNode, useEffect, useState, memo } from 'react'\nimport { cx } from '@emotion/css'\n\nimport { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls'\n\nimport { type SlotConfig, type SlotPlaceholderConfig } from '../../../controls/slot'\nimport { Element } from '../components/Element'\nimport { useIsInBuilder } from '../hooks/use-is-in-builder'\nimport { getIndexes } from '../../../components/utils/columns'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { useStyle } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport function renderSlot(props: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n config: SlotConfig\n}): ReactNode {\n return <SlotValue {...props} />\n}\n\nconst SlotValue = memo(\n ({\n data,\n control,\n config,\n }: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n config: SlotConfig\n }): ReactNode => {\n // TODO(miguel): While the UI shouldn't allow the state, we should probably check that at least\n // one element is visible.\n if (data == null || data.elements.length === 0) {\n return <Slot.Placeholder control={control} placeholder={config.unstable_placeholder} />\n }\n\n return (\n <Slot control={control}>\n {data.elements.map((element, i) => (\n <Slot.Item key={element.key} control={control} grid={data.columns} index={i}>\n <Element element={element} />\n </Slot.Item>\n ))}\n </Slot>\n )\n },\n)\n\ntype SlotProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n children?: ReactNode\n className?: string\n}\n\nexport function Slot<T extends ElementType = 'div'>({\n as,\n control,\n children,\n className,\n ...restOfProps\n}: SlotProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotProps<T>>) {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n flexWrap: 'wrap',\n width: '100%',\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\nSlot.Placeholder = SlotPlaceholder\n\nSlot.Item = SlotItem\n\ntype SlotItemProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n // @arvin: review for correctness\n grid: DataType<SlotDefinition<ReactNode>> extends undefined\n ? undefined\n : NonNullable<DataType<SlotDefinition<ReactNode>>>['columns']\n index: number\n children?: ReactNode\n className?: string\n}\n\nfunction SlotItem<T extends ElementType = 'div'>({\n as,\n control,\n grid,\n index,\n children,\n className,\n ...restOfProps\n}: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): ReactNode {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n ...useResponsiveStyle([grid], ([{ count = 12, spans = [[12]] } = {}]) => {\n const [rowIndex, columnIndex] = getIndexes(spans, index)\n const span = spans[rowIndex][columnIndex]\n const flexBasis = `calc(100% * ${(span / count).toFixed(5)})`\n\n return span === 0 ? { display: 'none' } : { flexBasis, minWidth: flexBasis }\n }),\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeItemBoxModel(index, boxModel),\n })\n }, [element, control, index])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\ntype SlotPlaceholderProps = {\n control: SlotControl | null\n placeholder?: SlotPlaceholderConfig\n}\n\nconst DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY = false\nconst DEFAULT_PLACEHOLDER_HEIGHT_PX = 80\n\nfunction SlotPlaceholder({ control, placeholder }: SlotPlaceholderProps): ReactNode {\n const isInBuilder = useIsInBuilder()\n const [element, setElement] = useState<Element | null>(null)\n\n // TODO: When ready, we can default to only showing the slot placeholder in\n // the builder\n const showInBuilderOnly = placeholder?.builderOnly ?? DEFAULT_SHOW_PLACEHOLDER_IN_BUILDER_ONLY\n const placeholderHeight = placeholder?.height ?? DEFAULT_PLACEHOLDER_HEIGHT_PX\n const text = placeholder?.text\n\n const hidePlaceholder = showInBuilderOnly && !isInBuilder\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <div\n ref={setElement}\n className={useStyle({\n width: '100%',\n background: 'rgba(161, 168, 194, 0.18)',\n })}\n style={{\n height: hidePlaceholder ? 0 : placeholderHeight,\n visibility: hidePlaceholder ? 'hidden' : undefined,\n }}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"100%\"\n height=\"100%\"\n className={useStyle({ overflow: 'visible', padding: 8 })}\n >\n <rect\n x={0}\n y={0}\n width=\"100%\"\n height=\"100%\"\n strokeWidth={2}\n strokeDasharray=\"4 2\"\n fill=\"none\"\n stroke=\"rgba(161, 168, 194, 0.40)\"\n rx=\"4\"\n ry=\"4\"\n />\n {text != null && (\n <text\n x=\"50%\"\n y=\"50%\"\n dominantBaseline=\"central\"\n textAnchor=\"middle\"\n fill=\"rgba(161, 168, 194, 0.80)\"\n fontSize=\"14px\"\n fontFamily=\"sans-serif\"\n style={{ userSelect: 'none' }}\n >\n {text}\n </text>\n )}\n </svg>\n </div>\n )\n}\n"],"mappings":";AAoBS,cAoKH,YApKG;AAlBT,SAA2D,WAAW,UAAU,YAAY;AAC5F,SAAS,UAAU;AAKnB,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAEtB,SAAS,WAAW,OAIb;AACZ,SAAO,oBAAC,aAAW,GAAG,OAAO;AAC/B;AAEA,MAAM,YAAY;AAAA,EAChB,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAIiB;AAGf,QAAI,QAAQ,QAAQ,KAAK,SAAS,WAAW,GAAG;AAC9C,aAAO,oBAAC,KAAK,aAAL,EAAiB,SAAkB,aAAa,OAAO,sBAAsB;AAAA,IACvF;AAEA,WACE,oBAAC,QAAK,SACH,eAAK,SAAS,IAA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S,EAAE,UAAU,WAAW,SAAS,EAAE,CAAC;AAAA,UAEvD;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,GAAG;AAAA,gBACH,GAAG;AAAA,gBACH,OAAM;AAAA,gBACN,QAAO;AAAA,gBACP,aAAa;AAAA,gBACb,iBAAgB;AAAA,gBAChB,MAAK;AAAA,gBACL,QAAO;AAAA,gBACP,IAAG;AAAA,gBACH,IAAG;AAAA;AAAA,YACL;AAAA,YACC,QAAQ,QACP;AAAA,cAAC;AAAA;AAAA,gBACC,GAAE;AAAA,gBACF,GAAE;AAAA,gBACF,kBAAiB;AAAA,gBACjB,YAAW;AAAA,gBACX,MAAK;AAAA,gBACL,UAAS;AAAA,gBACT,YAAW;AAAA,gBACX,OAAO,EAAE,YAAY,OAAO;AAAA,gBAE3B;AAAA;AAAA,YACH;AAAA;AAAA;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { SlotDefinition as BaseSlotDefinition, SlotControl, type DeserializedRecord, type ResourceResolver, type Stylesheet, type Resolvable, type DataType } from '@makeswift/controls';
|
|
3
|
-
|
|
3
|
+
export type SlotPlaceholderConfig = {
|
|
4
|
+
builderOnly?: boolean;
|
|
5
|
+
height?: number;
|
|
6
|
+
text?: string;
|
|
7
|
+
};
|
|
8
|
+
export type SlotConfig = {
|
|
9
|
+
unstable_placeholder?: SlotPlaceholderConfig;
|
|
10
|
+
};
|
|
11
|
+
declare abstract class BaseDefinition extends BaseSlotDefinition<ReactNode, SlotConfig> {
|
|
4
12
|
}
|
|
5
13
|
export declare class SlotDefinition extends BaseDefinition {
|
|
6
14
|
static deserialize(data: DeserializedRecord): SlotDefinition;
|
|
15
|
+
constructor(config?: SlotConfig);
|
|
7
16
|
resolveValue(data: DataType<BaseDefinition> | undefined, _resolver: ResourceResolver, _stylesheet: Stylesheet, control?: SlotControl): Resolvable<ReactNode | undefined>;
|
|
8
17
|
}
|
|
9
|
-
export declare function Slot(): SlotDefinition;
|
|
18
|
+
export declare function Slot(config?: SlotConfig): SlotDefinition;
|
|
10
19
|
export { SlotControl };
|
|
11
20
|
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../src/controls/slot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,WAAW,EAEX,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAA;AAI5B,uBAAe,cAAe,SAAQ,kBAAkB,CAAC,SAAS,CAAC;CAAG;
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../src/controls/slot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,WAAW,EAEX,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAA;AAI5B,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAYD,MAAM,MAAM,UAAU,GAAG;IACvB,oBAAoB,CAAC,EAAE,qBAAqB,CAAA;CAC7C,CAAA;AAED,uBAAe,cAAe,SAAQ,kBAAkB,CAAC,SAAS,EAAE,UAAU,CAAC;CAAG;AAElF,qBAAa,cAAe,SAAQ,cAAc;IAChD,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,cAAc;gBAQhD,MAAM,GAAE,UAAe;IAInC,YAAY,CACV,IAAI,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,SAAS,EAC1C,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,UAAU,EACvB,OAAO,CAAC,EAAE,WAAW,GACpB,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC;CAWrC;AAED,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,cAAc,CAE5D;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { type ValueType, type DataType, ControlDefinition } from '@makeswift/con
|
|
|
3
3
|
import { type CacheData } from '../../../../api/client';
|
|
4
4
|
import { ElementData } from '../../../../state/read-only-state';
|
|
5
5
|
import { ReactRuntime } from '../../../../runtimes/react/react-runtime';
|
|
6
|
-
export declare function testPageControlPropRendering<D extends ControlDefinition>(controlDefinition: D, { toData, value, locale, cacheData, expectedRenders, registerComponents, action, rootElements, }: {
|
|
6
|
+
export declare function testPageControlPropRendering<D extends ControlDefinition>(controlDefinition: D, { toData, value, locale, cacheData, expectedRenders, registerComponents, action, rootElements, isInBuilder, }: {
|
|
7
7
|
toData?: (value: ValueType<D>) => DataType<D>;
|
|
8
8
|
value: ValueType<D> | undefined;
|
|
9
9
|
locale?: string | null;
|
|
@@ -12,5 +12,6 @@ export declare function testPageControlPropRendering<D extends ControlDefinition
|
|
|
12
12
|
registerComponents?: (runtime: ReactRuntime) => void;
|
|
13
13
|
action?: (element: HTMLElement) => Promise<void>;
|
|
14
14
|
rootElements?: ElementData[];
|
|
15
|
+
isInBuilder?: boolean;
|
|
15
16
|
}): Promise<void>;
|
|
16
17
|
//# sourceMappingURL=page-control-prop-rendering.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-control-prop-rendering.d.ts","sourceRoot":"","sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"names":[],"mappings":"AAIA,OAAO,2BAA2B,CAAA;AAGlC,OAAO,EAAa,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEjG,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"page-control-prop-rendering.d.ts","sourceRoot":"","sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"names":[],"mappings":"AAIA,OAAO,2BAA2B,CAAA;AAGlC,OAAO,EAAa,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEjG,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAA;AAiEvE,wBAAsB,4BAA4B,CAAC,CAAC,SAAS,iBAAiB,EAC5E,iBAAiB,EAAE,CAAC,EACpB,EACE,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,MAAM,EACN,YAAiB,EACjB,WAAmB,GACpB,EAAE;IACD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC7C,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;IACpD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAChD,YAAY,CAAC,EAAE,WAAW,EAAE,CAAA;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,iBA6FF"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, ElementType, ReactNode } from 'react';
|
|
2
2
|
import { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls';
|
|
3
|
+
import { type SlotConfig, type SlotPlaceholderConfig } from '../../../controls/slot';
|
|
3
4
|
export declare function renderSlot(props: {
|
|
4
5
|
data: DataType<SlotDefinition<ReactNode>> | undefined;
|
|
5
6
|
control: SlotControl | null;
|
|
7
|
+
config: SlotConfig;
|
|
6
8
|
}): ReactNode;
|
|
7
9
|
type SlotProps<T extends ElementType> = {
|
|
8
10
|
as?: T;
|
|
@@ -26,7 +28,8 @@ type SlotItemProps<T extends ElementType> = {
|
|
|
26
28
|
declare function SlotItem<T extends ElementType = 'div'>({ as, control, grid, index, children, className, ...restOfProps }: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): ReactNode;
|
|
27
29
|
type SlotPlaceholderProps = {
|
|
28
30
|
control: SlotControl | null;
|
|
31
|
+
placeholder?: SlotPlaceholderConfig;
|
|
29
32
|
};
|
|
30
|
-
declare function SlotPlaceholder({ control }: SlotPlaceholderProps): ReactNode;
|
|
33
|
+
declare function SlotPlaceholder({ control, placeholder }: SlotPlaceholderProps): ReactNode;
|
|
31
34
|
export {};
|
|
32
35
|
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAA;AAGnG,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB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,SAAS,SAAS,GACvD,SAAS,GACT,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAC/D,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,iBAAS,QAAQ,CAAC,CAAC,SAAS,WAAW,GAAG,KAAK,EAAE,EAC/C,EAAE,EACF,OAAO,EACP,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,GAAG,WAAW,EACf,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CA4B1F;AAED,KAAK,oBAAoB,GAAG;IAC1B,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,qBAAqB,CAAA;CACpC,CAAA;AAKD,iBAAS,eAAe,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,oBAAoB,GAAG,SAAS,CAoElF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makeswift/runtime",
|
|
3
|
-
"version": "0.28.3-canary.
|
|
3
|
+
"version": "0.28.3-canary.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "makeswift/makeswift",
|
|
@@ -238,9 +238,9 @@
|
|
|
238
238
|
"use-sync-external-store": "^1.5.0",
|
|
239
239
|
"uuid": "^9.0.0",
|
|
240
240
|
"zod": "^3.21.4",
|
|
241
|
-
"@makeswift/controls": "0.1.
|
|
241
|
+
"@makeswift/controls": "0.1.17-canary.0",
|
|
242
242
|
"@makeswift/next-plugin": "0.6.1",
|
|
243
|
-
"@makeswift/prop-controllers": "0.4.
|
|
243
|
+
"@makeswift/prop-controllers": "0.4.11-canary.0"
|
|
244
244
|
},
|
|
245
245
|
"devDependencies": {
|
|
246
246
|
"@emotion/jest": "^11.11.0",
|