@makeswift/runtime 0.28.8-canary.6 → 0.28.8-canary.7

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.
Files changed (30) hide show
  1. package/dist/cjs/api/graphql-api-client.js +1 -1
  2. package/dist/cjs/api/rest-api-client.js +1 -1
  3. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/client/index.js +1 -1
  5. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js +4 -2
  6. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js.map +1 -1
  7. package/dist/cjs/slate/TypographyPlugin/normalizeTypographyUp.js.map +1 -1
  8. package/dist/cjs/slate/selectors.js.map +1 -1
  9. package/dist/cjs/utils/intersection.js.map +1 -1
  10. package/dist/esm/api/graphql-api-client.js +1 -1
  11. package/dist/esm/api/rest-api-client.js +1 -1
  12. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  13. package/dist/esm/client/index.js +1 -1
  14. package/dist/esm/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js +4 -2
  15. package/dist/esm/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.js.map +1 -1
  16. package/dist/esm/slate/TypographyPlugin/normalizeTypographyUp.js.map +1 -1
  17. package/dist/esm/slate/selectors.js.map +1 -1
  18. package/dist/esm/utils/intersection.js.map +1 -1
  19. package/dist/types/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.d.ts.map +1 -1
  20. package/dist/types/slate/selectors.d.ts +2 -2
  21. package/dist/types/slate/selectors.d.ts.map +1 -1
  22. package/dist/types/utils/intersection.d.ts +2 -1
  23. package/dist/types/utils/intersection.d.ts.map +1 -1
  24. package/package.json +3 -3
  25. package/dist/cjs/utils/is.js +0 -26
  26. package/dist/cjs/utils/is.js.map +0 -1
  27. package/dist/esm/utils/is.js +0 -6
  28. package/dist/esm/utils/is.js.map +0 -1
  29. package/dist/types/utils/is.d.ts +0 -3
  30. package/dist/types/utils/is.d.ts.map +0 -1
@@ -27,7 +27,7 @@ class MakeswiftGraphQLApiClient {
27
27
  graphqlClient;
28
28
  constructor({ endpoint }) {
29
29
  this.graphqlClient = new import_client.GraphQLClient(endpoint, {
30
- "makeswift-runtime-version": "0.28.8-canary.6"
30
+ "makeswift-runtime-version": "0.28.8-canary.7"
31
31
  });
32
32
  }
33
33
  async createTableRecord(tableId, columns) {
@@ -147,7 +147,7 @@ class MakeswiftRestAPIClient {
147
147
  const requestHeaders = new Headers({
148
148
  "x-api-key": this.apiKey,
149
149
  "makeswift-site-api-key": this.apiKey,
150
- "makeswift-runtime-version": "0.28.8-canary.6"
150
+ "makeswift-runtime-version": "0.28.8-canary.7"
151
151
  });
152
152
  if (siteVersion?.token) {
153
153
  requestUrl.searchParams.set("version", siteVersion.version);
@@ -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.8-canary.6",
31
+ version: "0.28.8-canary.7",
32
32
  interactionMode: true,
33
33
  clientSideNavigation: false,
34
34
  elementFromPoint: false,
@@ -689,7 +689,7 @@ Received "${apiKey}" instead.`
689
689
  headers: {
690
690
  "x-api-key": this.apiKey,
691
691
  "makeswift-site-api-key": this.apiKey,
692
- "makeswift-runtime-version": "0.28.8-canary.6",
692
+ "makeswift-runtime-version": "0.28.8-canary.7",
693
693
  "content-type": "application/json"
694
694
  },
695
695
  body: JSON.stringify({ token }),
@@ -32,6 +32,7 @@ __export(useSyncWithBuilder_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(useSyncWithBuilder_exports);
34
34
  var import_react = require("react");
35
+ var import_slate = require("slate");
35
36
  var import_controls = require("@makeswift/controls");
36
37
  var import_use_is_in_builder = require("../../../hooks/use-is-in-builder");
37
38
  var import_deepEqual = __toESM(require("../../../../../utils/deepEqual"));
@@ -43,13 +44,14 @@ function useSyncWithBuilder(editor, text) {
43
44
  if (shouldCommit && text && isInBuilder) {
44
45
  const nextValue = (0, import_controls.richTextDTOtoDAO)(text);
45
46
  const nextSelection = (0, import_controls.richTextDTOtoSelection)(text);
46
- if (!(0, import_deepEqual.default)(editor.children, nextValue) || !(0, import_deepEqual.default)(editor.selection, nextSelection)) {
47
+ const sameSelection = editor.selection == null || nextSelection == null ? editor.selection == nextSelection : import_slate.Range.equals(editor.selection, nextSelection);
48
+ if (!(0, import_deepEqual.default)(editor.children, nextValue) || !sameSelection) {
47
49
  editor.children = nextValue;
48
50
  editor.selection = nextSelection;
49
51
  editor.onChange();
50
52
  }
51
53
  }
52
- }, [editor, shouldCommit, text]);
54
+ }, [editor, isInBuilder, shouldCommit, text]);
53
55
  (0, import_react.useEffect)(() => {
54
56
  if (shouldCommit)
55
57
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { type RichTextDTO, richTextDTOtoDAO, richTextDTOtoSelection } from '@makeswift/controls'\n\nimport { useIsInBuilder } from '../../../hooks/use-is-in-builder'\nimport deepEqual from '../../../../../utils/deepEqual'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextDTO) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AAEjD,sBAA2E;AAE3E,+BAA+B;AAC/B,uBAAsB;AAEtB,MAAM,wBAAwB;AAMvB,SAAS,mBAAmB,QAAgB,MAAoB;AACrE,QAAM,CAAC,cAAc,eAAe,QAAI,uBAAS,IAAI;AACrD,QAAM,kBAAc,yCAAe;AAEnC,8BAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ,aAAa;AACvC,YAAM,gBAAY,kCAAiB,IAAI;AACvC,YAAM,oBAAgB,wCAAuB,IAAI;AACjD,UAAI,KAAC,iBAAAA,SAAU,OAAO,UAAU,SAAS,KAAK,KAAC,iBAAAA,SAAU,OAAO,WAAW,aAAa,GAAG;AACzF,eAAO,WAAW;AAClB,eAAO,YAAY;AACnB,eAAO,SAAS;AAAA,MAClB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,cAAc,IAAI,CAAC;AAE/B,8BAAU,MAAM;AACd,QAAI;AAAc;AAElB,UAAM,YAAY,OAAO,WAAW,MAAM;AACxC,sBAAgB,IAAI;AAAA,IACtB,GAAG,qBAAqB;AAExB,WAAO,MAAM;AACX,aAAO,aAAa,SAAS;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAEjB,aAAO,0BAAY,MAAM,gBAAgB,KAAK,GAAG,CAAC,CAAC;AACrD;","names":["deepEqual"]}
1
+ {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\nimport { Editor, Range } from 'slate'\nimport { type RichTextDTO, richTextDTOtoDAO, richTextDTOtoSelection } from '@makeswift/controls'\n\nimport { useIsInBuilder } from '../../../hooks/use-is-in-builder'\nimport deepEqual from '../../../../../utils/deepEqual'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextDTO) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n const sameSelection =\n editor.selection == null || nextSelection == null\n ? editor.selection == nextSelection\n : Range.equals(editor.selection, nextSelection)\n\n if (!deepEqual(editor.children, nextValue) || !sameSelection) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, isInBuilder, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AACjD,mBAA8B;AAC9B,sBAA2E;AAE3E,+BAA+B;AAC/B,uBAAsB;AAEtB,MAAM,wBAAwB;AAMvB,SAAS,mBAAmB,QAAgB,MAAoB;AACrE,QAAM,CAAC,cAAc,eAAe,QAAI,uBAAS,IAAI;AACrD,QAAM,kBAAc,yCAAe;AAEnC,8BAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ,aAAa;AACvC,YAAM,gBAAY,kCAAiB,IAAI;AACvC,YAAM,oBAAgB,wCAAuB,IAAI;AACjD,YAAM,gBACJ,OAAO,aAAa,QAAQ,iBAAiB,OACzC,OAAO,aAAa,gBACpB,mBAAM,OAAO,OAAO,WAAW,aAAa;AAElD,UAAI,KAAC,iBAAAA,SAAU,OAAO,UAAU,SAAS,KAAK,CAAC,eAAe;AAC5D,eAAO,WAAW;AAClB,eAAO,YAAY;AACnB,eAAO,SAAS;AAAA,MAClB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,cAAc,IAAI,CAAC;AAE5C,8BAAU,MAAM;AACd,QAAI;AAAc;AAElB,UAAM,YAAY,OAAO,WAAW,MAAM;AACxC,sBAAgB,IAAI;AAAA,IACtB,GAAG,qBAAqB;AAExB,WAAO,MAAM;AACX,aAAO,aAAa,SAAS;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAEjB,aAAO,0BAAY,MAAM,gBAAgB,KAAK,GAAG,CAAC,CAAC;AACrD;","names":["deepEqual"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/slate/TypographyPlugin/normalizeTypographyUp.ts"],"sourcesContent":["import { Editor, Element, NodeEntry, Transforms, Node, Text } from 'slate'\nimport { RichTextTypography } from '@makeswift/controls'\n\nimport { MakeswiftEditor } from '../types'\nimport keys from '../../utils/keys'\nimport deepEqual from '../../utils/deepEqual'\nimport { shallowMergeTypographies } from './normalizeTypographyDown'\n\nfunction shallowAnd<A extends Record<string, unknown>, B extends Record<string, unknown>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = keys(b)\n const aPrime = { ...a } as A & B\n const and = {} as A & B\n\n bKeys.forEach(key => {\n if (deepEqual(aPrime[key], b[key])) and[key] = aPrime[key]\n })\n\n return and\n}\n\nfunction shallowAndTypographies(...typographies: RichTextTypography[]): RichTextTypography {\n return {\n id: typographies.every(typography => typography?.id === typographies.at(0)?.id)\n ? typographies.at(0)?.id\n : undefined,\n style: [\n ...new Set(\n typographies.flatMap(typography => typography?.style.map(node => node.deviceId) ?? []),\n ),\n ].flatMap(deviceId => {\n const stylesForThisDevice = typographies\n .map(typography => typography.style.find(s => s.deviceId === deviceId)?.value)\n .filter((typography): typography is RichTextTypography['style'][number]['value'] =>\n Boolean(typography),\n )\n\n if (typographies.length !== stylesForThisDevice.length) return []\n\n const value = stylesForThisDevice.reduce(\n (acc, curr) => {\n return shallowAnd(acc, curr)\n },\n stylesForThisDevice.at(0) as RichTextTypography['style'][number]['value'],\n )\n\n if (value == null || Object.keys(value).length === 0) {\n return []\n }\n\n return [\n {\n deviceId,\n value,\n },\n ]\n }),\n }\n}\n\nfunction shallowInverseAnd<A extends Record<string, unknown>, B extends Record<string, unknown>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = Array.from(new Set([...keys(b), ...keys(a)]))\n const aPrime = { ...a } as A & B\n const bPrime = { ...b } as A & B\n const xor = {} as A & B\n\n bKeys.forEach(key => {\n if (!deepEqual(aPrime[key], bPrime[key as any])) xor[key] = aPrime[key]\n })\n\n return xor\n}\n\nfunction shallowInverseAndTypographies(\n a: RichTextTypography,\n b: RichTextTypography,\n): RichTextTypography {\n const typography = { style: [] } as RichTextTypography\n if (a?.id !== b.id) {\n typography.id = a?.id\n }\n\n if (a && a.style.length > 0) {\n const styles: RichTextTypography['style'] = []\n for (const style of a.style) {\n const bDeviceTypography = b.style.find(s => s.deviceId === style.deviceId)\n if (bDeviceTypography == null) {\n styles.push(style)\n } else {\n const uniquePropertiesOfA = shallowInverseAnd(style.value, bDeviceTypography.value)\n\n if (Object.keys(uniquePropertiesOfA).length > 0) {\n styles.push({\n deviceId: style.deviceId,\n value: uniquePropertiesOfA,\n })\n }\n }\n }\n typography.style = styles\n }\n\n return typography\n}\n\n/**\n * If a text is empty then don't include it in our comparison.\n */\nfunction isException(node: Node): boolean {\n return Text.isText(node) && node.text === ''\n}\n\nexport function normalizeTypographyUp(editor: MakeswiftEditor, entry: NodeEntry): boolean {\n const [node, path] = entry\n if (Element.isElement(node) && node.children.length) {\n const typographiesOfChildren = node.children\n .filter(child => !isException(child))\n .map(child => child.typography)\n\n const definedTypographiesOfChildren = typographiesOfChildren.filter(\n (typography): typography is RichTextTypography => Boolean(typography),\n )\n if (typographiesOfChildren.length === definedTypographiesOfChildren.length) {\n let sharedTypography: RichTextTypography = shallowAndTypographies(\n ...definedTypographiesOfChildren,\n )\n\n if (sharedTypography.style.length > 0 || sharedTypography.id != null) {\n const rootTypography: RichTextTypography = shallowMergeTypographies(\n sharedTypography,\n node.typography,\n )\n Editor.withoutNormalizing(editor, () => {\n Transforms.setNodes(editor, { typography: rootTypography }, { at: path })\n for (let i = 0; i < node.children.length; i++) {\n const typography: RichTextTypography = shallowInverseAndTypographies(\n node.children.at(i)?.typography ?? { style: [] },\n sharedTypography,\n )\n\n Transforms.setNodes(editor, { typography }, { at: [...path, i] })\n }\n })\n return true\n }\n }\n }\n return false\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmE;AAInE,kBAAiB;AACjB,uBAAsB;AACtB,qCAAyC;AAEzC,SAAS,WACP,GACA,GACO;AACP,QAAM,YAAQ,YAAAA,SAAK,CAAC;AACpB,QAAM,SAAS,EAAE,GAAG,EAAE;AACtB,QAAM,MAAM,CAAC;AAEb,QAAM,QAAQ,SAAO;AACnB,YAAI,iBAAAC,SAAU,OAAO,GAAG,GAAG,EAAE,GAAG,CAAC;AAAG,UAAI,GAAG,IAAI,OAAO,GAAG;AAAA,EAC3D,CAAC;AAED,SAAO;AACT;AAEA,SAAS,0BAA0B,cAAwD;AACzF,SAAO;AAAA,IACL,IAAI,aAAa,MAAM,gBAAc,YAAY,OAAO,aAAa,GAAG,CAAC,GAAG,EAAE,IAC1E,aAAa,GAAG,CAAC,GAAG,KACpB;AAAA,IACJ,OAAO;AAAA,MACL,GAAG,IAAI;AAAA,QACL,aAAa,QAAQ,gBAAc,YAAY,MAAM,IAAI,UAAQ,KAAK,QAAQ,KAAK,CAAC,CAAC;AAAA,MACvF;AAAA,IACF,EAAE,QAAQ,cAAY;AACpB,YAAM,sBAAsB,aACzB,IAAI,gBAAc,WAAW,MAAM,KAAK,OAAK,EAAE,aAAa,QAAQ,GA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,MAAM,CAAC,EAAE,CAAC;AAAA,UAClE;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["keys","deepEqual"]}
1
+ {"version":3,"sources":["../../../../src/slate/TypographyPlugin/normalizeTypographyUp.ts"],"sourcesContent":["import { Editor, Element, NodeEntry, Transforms, Node, Text } from 'slate'\nimport { type Data, RichTextTypography } from '@makeswift/controls'\n\nimport { MakeswiftEditor } from '../types'\nimport keys from '../../utils/keys'\nimport deepEqual from '../../utils/deepEqual'\nimport { shallowMergeTypographies } from './normalizeTypographyDown'\n\nfunction shallowAnd<A extends Record<string, Data>, B extends Record<string, Data>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = keys(b)\n const aPrime = { ...a } as A & B\n const and = {} as A & B\n\n bKeys.forEach(key => {\n if (deepEqual(aPrime[key], b[key])) and[key] = aPrime[key]\n })\n\n return and\n}\n\nfunction shallowAndTypographies(...typographies: RichTextTypography[]): RichTextTypography {\n return {\n id: typographies.every(typography => typography?.id === typographies.at(0)?.id)\n ? typographies.at(0)?.id\n : undefined,\n style: [\n ...new Set(\n typographies.flatMap(typography => typography?.style.map(node => node.deviceId) ?? []),\n ),\n ].flatMap(deviceId => {\n const stylesForThisDevice = typographies\n .map(typography => typography.style.find(s => s.deviceId === deviceId)?.value)\n .filter((typography): typography is RichTextTypography['style'][number]['value'] =>\n Boolean(typography),\n )\n\n if (typographies.length !== stylesForThisDevice.length) return []\n\n const value = stylesForThisDevice.reduce(\n (acc, curr) => {\n return shallowAnd(acc, curr)\n },\n stylesForThisDevice.at(0) as RichTextTypography['style'][number]['value'],\n )\n\n if (value == null || Object.keys(value).length === 0) {\n return []\n }\n\n return [\n {\n deviceId,\n value,\n },\n ]\n }),\n }\n}\n\nfunction shallowInverseAnd<A extends Record<string, Data>, B extends Record<string, Data>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = Array.from(new Set([...keys(b), ...keys(a)]))\n const aPrime = { ...a } as A & B\n const bPrime = { ...b } as A & B\n const xor = {} as A & B\n\n bKeys.forEach(key => {\n if (!deepEqual(aPrime[key], bPrime[key])) xor[key] = aPrime[key]\n })\n\n return xor\n}\n\nfunction shallowInverseAndTypographies(\n a: RichTextTypography,\n b: RichTextTypography,\n): RichTextTypography {\n const typography = { style: [] } as RichTextTypography\n if (a?.id !== b.id) {\n typography.id = a?.id\n }\n\n if (a && a.style.length > 0) {\n const styles: RichTextTypography['style'] = []\n for (const style of a.style) {\n const bDeviceTypography = b.style.find(s => s.deviceId === style.deviceId)\n if (bDeviceTypography == null) {\n styles.push(style)\n } else {\n const uniquePropertiesOfA = shallowInverseAnd(style.value, bDeviceTypography.value)\n\n if (Object.keys(uniquePropertiesOfA).length > 0) {\n styles.push({\n deviceId: style.deviceId,\n value: uniquePropertiesOfA,\n })\n }\n }\n }\n typography.style = styles\n }\n\n return typography\n}\n\n/**\n * If a text is empty then don't include it in our comparison.\n */\nfunction isException(node: Node): boolean {\n return Text.isText(node) && node.text === ''\n}\n\nexport function normalizeTypographyUp(editor: MakeswiftEditor, entry: NodeEntry): boolean {\n const [node, path] = entry\n if (Element.isElement(node) && node.children.length) {\n const typographiesOfChildren = node.children\n .filter(child => !isException(child))\n .map(child => child.typography)\n\n const definedTypographiesOfChildren = typographiesOfChildren.filter(\n (typography): typography is RichTextTypography => Boolean(typography),\n )\n if (typographiesOfChildren.length === definedTypographiesOfChildren.length) {\n let sharedTypography: RichTextTypography = shallowAndTypographies(\n ...definedTypographiesOfChildren,\n )\n\n if (sharedTypography.style.length > 0 || sharedTypography.id != null) {\n const rootTypography: RichTextTypography = shallowMergeTypographies(\n sharedTypography,\n node.typography,\n )\n Editor.withoutNormalizing(editor, () => {\n Transforms.setNodes(editor, { typography: rootTypography }, { at: path })\n for (let i = 0; i < node.children.length; i++) {\n const typography: RichTextTypography = shallowInverseAndTypographies(\n node.children.at(i)?.typography ?? { style: [] },\n sharedTypography,\n )\n\n Transforms.setNodes(editor, { typography }, {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AAEO,SAAS,sBAAsB,QAAyB,OAA2B;AACxF,QAAM,CAAC,MAAM,IAAI,IAAI;AACrB,MAAI,qBAAQ,UAAU,IAAI,KAAK,KAAK,SAAS,QAAQ;AACnD,UAAM,yBAAyB,KAAK,SACjC,OAAO,WAAS,CAAC,YAAY,KAAK,CAAC,EACnC,IAAI,WAAS,MAAM,UAAU;AAEhC,UAAM,gCAAgC,uBAAuB;AAAA,MAC3D,CAAC,eAAiD,QAAQ,UAAU;AAAA,IACtE;AACA,QAAI,uBAAuB,WAAW,8BAA8B,QAAQ;AAC1E,UAAI,mBAAuC;AAAA,QACzC,GAAG;AAAA,MACL;AAEA,UAAI,iBAAiB,MAAM,SAAS,KAAK,iBAAiB,MAAM,MAAM;AACpE,cAAM,qBAAqC;AAAA,UACzC;AAAA,UACA,KAAK;AAAA,QACP;AACA,4BAAO,mBAAmB,QAAQ,MAAM;AACtC,kCAAW,SAAS,QAAQ,EAAE,YAAY,eAAe,GAAG,EAAE,IAAI,KAAK,CAAC;AACxE,mBAAS,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;AAC7C,kBAAM,aAAiC;AAAA,cACrC,KAAK,SAAS,GAAG,CAAC,GAAG,cAAc,EAAE,OAAO,CAAC,EAAE;AAAA,cAC/C;AAAA,YACF;AAEA,oCAAW,SAAS,QAAQ,EAAE,WAAW,GAAG,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;AAAA,UAClE;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["keys","deepEqual"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA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;AAAA,IACL,IAAI,OAAO,IAAI,OAAK,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,MAAO,MAAM,IAAI,IAAI,MAAU,KAAK;AAAA,IAC9E,OAAO,QAAQ;AAAA,MAAI,cACjB,OACG;AAAA,QACC,OACG,SAAK,wCAAuB,aAAa,EAAE,OAAO,QAAQ,KAAM;AAAA,UAC/D;AAAA,UACA,OAAO,CAAC;AAAA,QACV;AAAA,MACJ,EACC,OAAO,CAAC,KAAK,EAAE,MAAM,MAAM;AAC1B,cAAM,IAAI,aAAa,IAAI,OAAO,KAAK;AACvC,eAAO;AAAA,UACL;AAAA,UACA,OAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,wBACd,QACA,aACkB;AAClB,QAAM,SAA6B,CAAC;AAEpC,QAAM,YAAY,oBAAO,MAAM,QAAQ;AAAA,IACrC,IAAI,aAAa,MAAM;AAAA,IACvB,OAAO,UAAQ,kBAAK,OAAO,IAAI;AAAA,EACjC,CAAC;AAED,aAAW,CAAC,IAAI,KAAK,WAAW;AAC9B,QAAI,kBAAK,OAAO,IAAI,KAAK,gBAAgB,QAAQ,KAAK,cAAc,QAAW;AAC7E,aAAO,KAAK,KAAK,UAAU;AAAA,IAC7B;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,oBAAoB,QAAQ,WAAW;AACtF;","names":["unhangRange","shallowEqual","deepEqual","keys"]}
1
+ {"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n type Data,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, Data>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: Data, b: Data) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+C;AAC/C,sBAMO;AAIP,y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AAO,MAAM,IAAI,IAAI,MAAU,KAAK;AAAA,IAC9E,OAAO,QAAQ;AAAA,MAAI,cACjB,OACG;AAAA,QACC,OACG,SAAK,wCAAuB,aAAa,EAAE,OAAO,QAAQ,KAAM;AAAA,UAC/D;AAAA,UACA,OAAO,CAAC;AAAA,QACV;AAAA,MACJ,EACC,OAAO,CAAC,KAAK,EAAE,MAAM,MAAM;AAC1B,cAAM,IAAI,aAAa,IAAI,OAAO,KAAK;AACvC,eAAO;AAAA,UACL;AAAA,UACA,OAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,wBACd,QACA,aACkB;AAClB,QAAM,SAA6B,CAAC;AAEpC,QAAM,YAAY,oBAAO,MAAM,QAAQ;AAAA,IACrC,IAAI,aAAa,MAAM;AAAA,IACvB,OAAO,UAAQ,kBAAK,OAAO,IAAI;AAAA,EACjC,CAAC;AAED,aAAW,CAAC,IAAI,KAAK,WAAW;AAC9B,QAAI,kBAAK,OAAO,IAAI,KAAK,gBAAgB,QAAQ,KAAK,cAAc,QAAW;AAC7E,aAAO,KAAK,KAAK,UAAU;AAAA,IAC7B;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,oBAAoB,QAAQ,WAAW;AACtF;","names":["unhangRange","shallowEqual","deepEqual","keys"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/intersection.ts"],"sourcesContent":["import deepEqual from './deepEqual'\nimport keys from './keys'\n\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | null } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = null\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | null },\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,kBAAiB;AAEF,SAAR,aACL,GACA,GACA,UAA+C,iBAAAA,SACd;AACjC,QAAM,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,OAAG,YAAAC,SAAK,CAAC,GAAG,OAAG,YAAAA,SAAK,CAAC,CAAC,CAAC,CAAC;AAErD,SAAO,QAAQ;AAAA,IACb,CAAC,KAAK,MAAM;AACV,UAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAAG,YAAI,CAAC,IAAI,EAAE,CAAC;AAAA;AAChC,YAAI,CAAC,IAAI;AAEd,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["deepEqual","keys"]}
1
+ {"version":3,"sources":["../../../src/utils/intersection.ts"],"sourcesContent":["import { type Data } from '@makeswift/controls'\n\nimport deepEqual from './deepEqual'\nimport keys from './keys'\n\nexport default function intersection<A extends Record<string, Data>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: Data, b: Data) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | null } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = null\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | null },\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAsB;AACtB,kBAAiB;AAEF,SAAR,aACL,GACA,GACA,UAAyC,iBAAAA,SACR;AACjC,QAAM,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,OAAG,YAAAC,SAAK,CAAC,GAAG,OAAG,YAAAA,SAAK,CAAC,CAAC,CAAC,CAAC;AAErD,SAAO,QAAQ;AAAA,IACb,CAAC,KAAK,MAAM;AACV,UAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAAG,YAAI,CAAC,IAAI,EAAE,CAAC;AAAA;AAChC,YAAI,CAAC,IAAI;AAEd,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["deepEqual","keys"]}
@@ -9,7 +9,7 @@ class MakeswiftGraphQLApiClient {
9
9
  graphqlClient;
10
10
  constructor({ endpoint }) {
11
11
  this.graphqlClient = new GraphQLClient(endpoint, {
12
- "makeswift-runtime-version": "0.28.8-canary.6"
12
+ "makeswift-runtime-version": "0.28.8-canary.7"
13
13
  });
14
14
  }
15
15
  async createTableRecord(tableId, columns) {
@@ -113,7 +113,7 @@ class MakeswiftRestAPIClient {
113
113
  const requestHeaders = new Headers({
114
114
  "x-api-key": this.apiKey,
115
115
  "makeswift-site-api-key": this.apiKey,
116
- "makeswift-runtime-version": "0.28.8-canary.6"
116
+ "makeswift-runtime-version": "0.28.8-canary.7"
117
117
  });
118
118
  if (siteVersion?.token) {
119
119
  requestUrl.searchParams.set("version", siteVersion.version);
@@ -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.8-canary.6",
11
+ version: "0.28.8-canary.7",
12
12
  interactionMode: true,
13
13
  clientSideNavigation: false,
14
14
  elementFromPoint: false,
@@ -669,7 +669,7 @@ Received "${apiKey}" instead.`
669
669
  headers: {
670
670
  "x-api-key": this.apiKey,
671
671
  "makeswift-site-api-key": this.apiKey,
672
- "makeswift-runtime-version": "0.28.8-canary.6",
672
+ "makeswift-runtime-version": "0.28.8-canary.7",
673
673
  "content-type": "application/json"
674
674
  },
675
675
  body: JSON.stringify({ token }),
@@ -1,4 +1,5 @@
1
1
  import { useState, useEffect, useCallback } from "react";
2
+ import { Range } from "slate";
2
3
  import { richTextDTOtoDAO, richTextDTOtoSelection } from "@makeswift/controls";
3
4
  import { useIsInBuilder } from "../../../hooks/use-is-in-builder";
4
5
  import deepEqual from "../../../../../utils/deepEqual";
@@ -10,13 +11,14 @@ function useSyncWithBuilder(editor, text) {
10
11
  if (shouldCommit && text && isInBuilder) {
11
12
  const nextValue = richTextDTOtoDAO(text);
12
13
  const nextSelection = richTextDTOtoSelection(text);
13
- if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {
14
+ const sameSelection = editor.selection == null || nextSelection == null ? editor.selection == nextSelection : Range.equals(editor.selection, nextSelection);
15
+ if (!deepEqual(editor.children, nextValue) || !sameSelection) {
14
16
  editor.children = nextValue;
15
17
  editor.selection = nextSelection;
16
18
  editor.onChange();
17
19
  }
18
20
  }
19
- }, [editor, shouldCommit, text]);
21
+ }, [editor, isInBuilder, shouldCommit, text]);
20
22
  useEffect(() => {
21
23
  if (shouldCommit)
22
24
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\nimport { Editor } from 'slate'\nimport { type RichTextDTO, richTextDTOtoDAO, richTextDTOtoSelection } from '@makeswift/controls'\n\nimport { useIsInBuilder } from '../../../hooks/use-is-in-builder'\nimport deepEqual from '../../../../../utils/deepEqual'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextDTO) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n if (!deepEqual(editor.children, nextValue) || !deepEqual(editor.selection, nextSelection)) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n"],"mappings":"AAAA,SAAS,UAAU,WAAW,mBAAmB;AAEjD,SAA2B,kBAAkB,8BAA8B;AAE3E,SAAS,sBAAsB;AAC/B,OAAO,eAAe;AAEtB,MAAM,wBAAwB;AAMvB,SAAS,mBAAmB,QAAgB,MAAoB;AACrE,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,IAAI;AACrD,QAAM,cAAc,eAAe;AAEnC,YAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ,aAAa;AACvC,YAAM,YAAY,iBAAiB,IAAI;AACvC,YAAM,gBAAgB,uBAAuB,IAAI;AACjD,UAAI,CAAC,UAAU,OAAO,UAAU,SAAS,KAAK,CAAC,UAAU,OAAO,WAAW,aAAa,GAAG;AACzF,eAAO,WAAW;AAClB,eAAO,YAAY;AACnB,eAAO,SAAS;AAAA,MAClB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,cAAc,IAAI,CAAC;AAE/B,YAAU,MAAM;AACd,QAAI;AAAc;AAElB,UAAM,YAAY,OAAO,WAAW,MAAM;AACxC,sBAAgB,IAAI;AAAA,IACtB,GAAG,qBAAqB;AAExB,WAAO,MAAM;AACX,aAAO,aAAa,SAAS;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAEjB,SAAO,YAAY,MAAM,gBAAgB,KAAK,GAAG,CAAC,CAAC;AACrD;","names":[]}
1
+ {"version":3,"sources":["../../../../../../../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react'\nimport { Editor, Range } from 'slate'\nimport { type RichTextDTO, richTextDTOtoDAO, richTextDTOtoSelection } from '@makeswift/controls'\n\nimport { useIsInBuilder } from '../../../hooks/use-is-in-builder'\nimport deepEqual from '../../../../../utils/deepEqual'\n\nconst COMMIT_DEBOUNCE_DELAY = 500\n\n/**\n * Compare new prop value with current editor and update editor\n * if the values are not equal.\n */\nexport function useSyncWithBuilder(editor: Editor, text?: RichTextDTO) {\n const [shouldCommit, setShouldCommit] = useState(true)\n const isInBuilder = useIsInBuilder()\n\n useEffect(() => {\n if (shouldCommit && text && isInBuilder) {\n const nextValue = richTextDTOtoDAO(text)\n const nextSelection = richTextDTOtoSelection(text)\n const sameSelection =\n editor.selection == null || nextSelection == null\n ? editor.selection == nextSelection\n : Range.equals(editor.selection, nextSelection)\n\n if (!deepEqual(editor.children, nextValue) || !sameSelection) {\n editor.children = nextValue\n editor.selection = nextSelection\n editor.onChange()\n }\n }\n }, [editor, isInBuilder, shouldCommit, text])\n\n useEffect(() => {\n if (shouldCommit) return\n\n const timeoutId = window.setTimeout(() => {\n setShouldCommit(true)\n }, COMMIT_DEBOUNCE_DELAY)\n\n return () => {\n window.clearTimeout(timeoutId)\n }\n }, [shouldCommit])\n\n return useCallback(() => setShouldCommit(false), [])\n}\n"],"mappings":"AAAA,SAAS,UAAU,WAAW,mBAAmB;AACjD,SAAiB,aAAa;AAC9B,SAA2B,kBAAkB,8BAA8B;AAE3E,SAAS,sBAAsB;AAC/B,OAAO,eAAe;AAEtB,MAAM,wBAAwB;AAMvB,SAAS,mBAAmB,QAAgB,MAAoB;AACrE,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,IAAI;AACrD,QAAM,cAAc,eAAe;AAEnC,YAAU,MAAM;AACd,QAAI,gBAAgB,QAAQ,aAAa;AACvC,YAAM,YAAY,iBAAiB,IAAI;AACvC,YAAM,gBAAgB,uBAAuB,IAAI;AACjD,YAAM,gBACJ,OAAO,aAAa,QAAQ,iBAAiB,OACzC,OAAO,aAAa,gBACpB,MAAM,OAAO,OAAO,WAAW,aAAa;AAElD,UAAI,CAAC,UAAU,OAAO,UAAU,SAAS,KAAK,CAAC,eAAe;AAC5D,eAAO,WAAW;AAClB,eAAO,YAAY;AACnB,eAAO,SAAS;AAAA,MAClB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,cAAc,IAAI,CAAC;AAE5C,YAAU,MAAM;AACd,QAAI;AAAc;AAElB,UAAM,YAAY,OAAO,WAAW,MAAM;AACxC,sBAAgB,IAAI;AAAA,IACtB,GAAG,qBAAqB;AAExB,WAAO,MAAM;AACX,aAAO,aAAa,SAAS;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAEjB,SAAO,YAAY,MAAM,gBAAgB,KAAK,GAAG,CAAC,CAAC;AACrD;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/slate/TypographyPlugin/normalizeTypographyUp.ts"],"sourcesContent":["import { Editor, Element, NodeEntry, Transforms, Node, Text } from 'slate'\nimport { RichTextTypography } from '@makeswift/controls'\n\nimport { MakeswiftEditor } from '../types'\nimport keys from '../../utils/keys'\nimport deepEqual from '../../utils/deepEqual'\nimport { shallowMergeTypographies } from './normalizeTypographyDown'\n\nfunction shallowAnd<A extends Record<string, unknown>, B extends Record<string, unknown>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = keys(b)\n const aPrime = { ...a } as A & B\n const and = {} as A & B\n\n bKeys.forEach(key => {\n if (deepEqual(aPrime[key], b[key])) and[key] = aPrime[key]\n })\n\n return and\n}\n\nfunction shallowAndTypographies(...typographies: RichTextTypography[]): RichTextTypography {\n return {\n id: typographies.every(typography => typography?.id === typographies.at(0)?.id)\n ? typographies.at(0)?.id\n : undefined,\n style: [\n ...new Set(\n typographies.flatMap(typography => typography?.style.map(node => node.deviceId) ?? []),\n ),\n ].flatMap(deviceId => {\n const stylesForThisDevice = typographies\n .map(typography => typography.style.find(s => s.deviceId === deviceId)?.value)\n .filter((typography): typography is RichTextTypography['style'][number]['value'] =>\n Boolean(typography),\n )\n\n if (typographies.length !== stylesForThisDevice.length) return []\n\n const value = stylesForThisDevice.reduce(\n (acc, curr) => {\n return shallowAnd(acc, curr)\n },\n stylesForThisDevice.at(0) as RichTextTypography['style'][number]['value'],\n )\n\n if (value == null || Object.keys(value).length === 0) {\n return []\n }\n\n return [\n {\n deviceId,\n value,\n },\n ]\n }),\n }\n}\n\nfunction shallowInverseAnd<A extends Record<string, unknown>, B extends Record<string, unknown>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = Array.from(new Set([...keys(b), ...keys(a)]))\n const aPrime = { ...a } as A & B\n const bPrime = { ...b } as A & B\n const xor = {} as A & B\n\n bKeys.forEach(key => {\n if (!deepEqual(aPrime[key], bPrime[key as any])) xor[key] = aPrime[key]\n })\n\n return xor\n}\n\nfunction shallowInverseAndTypographies(\n a: RichTextTypography,\n b: RichTextTypography,\n): RichTextTypography {\n const typography = { style: [] } as RichTextTypography\n if (a?.id !== b.id) {\n typography.id = a?.id\n }\n\n if (a && a.style.length > 0) {\n const styles: RichTextTypography['style'] = []\n for (const style of a.style) {\n const bDeviceTypography = b.style.find(s => s.deviceId === style.deviceId)\n if (bDeviceTypography == null) {\n styles.push(style)\n } else {\n const uniquePropertiesOfA = shallowInverseAnd(style.value, bDeviceTypography.value)\n\n if (Object.keys(uniquePropertiesOfA).length > 0) {\n styles.push({\n deviceId: style.deviceId,\n value: uniquePropertiesOfA,\n })\n }\n }\n }\n typography.style = styles\n }\n\n return typography\n}\n\n/**\n * If a text is empty then don't include it in our comparison.\n */\nfunction isException(node: Node): boolean {\n return Text.isText(node) && node.text === ''\n}\n\nexport function normalizeTypographyUp(editor: MakeswiftEditor, entry: NodeEntry): boolean {\n const [node, path] = entry\n if (Element.isElement(node) && node.children.length) {\n const typographiesOfChildren = node.children\n .filter(child => !isException(child))\n .map(child => child.typography)\n\n const definedTypographiesOfChildren = typographiesOfChildren.filter(\n (typography): typography is RichTextTypography => Boolean(typography),\n )\n if (typographiesOfChildren.length === definedTypographiesOfChildren.length) {\n let sharedTypography: RichTextTypography = shallowAndTypographies(\n ...definedTypographiesOfChildren,\n )\n\n if (sharedTypography.style.length > 0 || sharedTypography.id != null) {\n const rootTypography: RichTextTypography = shallowMergeTypographies(\n sharedTypography,\n node.typography,\n )\n Editor.withoutNormalizing(editor, () => {\n Transforms.setNodes(editor, { typography: rootTypography }, { at: path })\n for (let i = 0; i < node.children.length; i++) {\n const typography: RichTextTypography = shallowInverseAndTypographies(\n node.children.at(i)?.typography ?? { style: [] },\n sharedTypography,\n )\n\n Transforms.setNodes(editor, { typography }, { at: [...path, i] })\n }\n })\n return true\n }\n }\n }\n return false\n}\n"],"mappings":"AAAA,SAAS,QAAQ,SAAoB,YAAkB,YAAY;AAInE,OAAO,UAAU;AACjB,OAAO,eAAe;AACtB,SAAS,gCAAgC;AAEzC,SAAS,WACP,GACA,GACO;AACP,QAAM,QAAQ,KAAK,CAAC;AACpB,QAAM,SAAS,EAAE,GAAG,EAAE;AACtB,QAAM,MAAM,CAAC;AAEb,QAAM,QAAQ,SAAO;AACnB,QAAI,UAAU,OAAO,GAAG,GAAG,EAAE,GAAG,CAAC;AAAG,UAAI,GAAG,IAAI,OAAO,GAAG;AAAA,EAC3D,CAAC;AAED,SAAO;AACT;AAEA,SAAS,0BAA0B,cAAwD;AACzF,SAAO;AAAA,IACL,IAAI,aAAa,MAAM,gBAAc,YAAY,OAAO,aAAa,GAAG,CAAC,GAAG,EAAE,IAC1E,aAAa,GAAG,CAAC,GAAG,KACpB;AAAA,IACJ,OAAO;AAAA,MACL,GAAG,IAAI;AAAA,QACL,aAAa,QAAQ,gBAAc,YAAY,MAAM,IAAI,UAAQ,KAAK,QAAQ,KAAK,CAAC,CAAC;AAAA,MACvF;AAAA,IACF,EAAE,QAAQ,cAAY;AACpB,YAAM,sBAAsB,aACzB,IAAI,gBAAc,WAAW,MAAM,KAAK,OAAK,EAAE,aAAa,QAAQ,GAAG,KAAK,EAC5E;AAAA,QAAO,CAAC,eACP,QAAQ,UAAU;AAAA,MACpB;AAEF,UAAI,aAAa,WAAW,oBAAoB;AAAQ,eAAO,CAAC;AAEhE,YAAM,QAA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/normalizeTypographyUp.ts"],"sourcesContent":["import { Editor, Element, NodeEntry, Transforms, Node, Text } from 'slate'\nimport { type Data, RichTextTypography } from '@makeswift/controls'\n\nimport { MakeswiftEditor } from '../types'\nimport keys from '../../utils/keys'\nimport deepEqual from '../../utils/deepEqual'\nimport { shallowMergeTypographies } from './normalizeTypographyDown'\n\nfunction shallowAnd<A extends Record<string, Data>, B extends Record<string, Data>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = keys(b)\n const aPrime = { ...a } as A & B\n const and = {} as A & B\n\n bKeys.forEach(key => {\n if (deepEqual(aPrime[key], b[key])) and[key] = aPrime[key]\n })\n\n return and\n}\n\nfunction shallowAndTypographies(...typographies: RichTextTypography[]): RichTextTypography {\n return {\n id: typographies.every(typography => typography?.id === typographies.at(0)?.id)\n ? typographies.at(0)?.id\n : undefined,\n style: [\n ...new Set(\n typographies.flatMap(typography => typography?.style.map(node => node.deviceId) ?? []),\n ),\n ].flatMap(deviceId => {\n const stylesForThisDevice = typographies\n .map(typography => typography.style.find(s => s.deviceId === deviceId)?.value)\n .filter((typography): typography is RichTextTypography['style'][number]['value'] =>\n Boolean(typography),\n )\n\n if (typographies.length !== stylesForThisDevice.length) return []\n\n const value = stylesForThisDevice.reduce(\n (acc, curr) => {\n return shallowAnd(acc, curr)\n },\n stylesForThisDevice.at(0) as RichTextTypography['style'][number]['value'],\n )\n\n if (value == null || Object.keys(value).length === 0) {\n return []\n }\n\n return [\n {\n deviceId,\n value,\n },\n ]\n }),\n }\n}\n\nfunction shallowInverseAnd<A extends Record<string, Data>, B extends Record<string, Data>>(\n a: A,\n b: B,\n): A & B {\n const bKeys = Array.from(new Set([...keys(b), ...keys(a)]))\n const aPrime = { ...a } as A & B\n const bPrime = { ...b } as A & B\n const xor = {} as A & B\n\n bKeys.forEach(key => {\n if (!deepEqual(aPrime[key], bPrime[key])) xor[key] = aPrime[key]\n })\n\n return xor\n}\n\nfunction shallowInverseAndTypographies(\n a: RichTextTypography,\n b: RichTextTypography,\n): RichTextTypography {\n const typography = { style: [] } as RichTextTypography\n if (a?.id !== b.id) {\n typography.id = a?.id\n }\n\n if (a && a.style.length > 0) {\n const styles: RichTextTypography['style'] = []\n for (const style of a.style) {\n const bDeviceTypography = b.style.find(s => s.deviceId === style.deviceId)\n if (bDeviceTypography == null) {\n styles.push(style)\n } else {\n const uniquePropertiesOfA = shallowInverseAnd(style.value, bDeviceTypography.value)\n\n if (Object.keys(uniquePropertiesOfA).length > 0) {\n styles.push({\n deviceId: style.deviceId,\n value: uniquePropertiesOfA,\n })\n }\n }\n }\n typography.style = styles\n }\n\n return typography\n}\n\n/**\n * If a text is empty then don't include it in our comparison.\n */\nfunction isException(node: Node): boolean {\n return Text.isText(node) && node.text === ''\n}\n\nexport function normalizeTypographyUp(editor: MakeswiftEditor, entry: NodeEntry): boolean {\n const [node, path] = entry\n if (Element.isElement(node) && node.children.length) {\n const typographiesOfChildren = node.children\n .filter(child => !isException(child))\n .map(child => child.typography)\n\n const definedTypographiesOfChildren = typographiesOfChildren.filter(\n (typography): typography is RichTextTypography => Boolean(typography),\n )\n if (typographiesOfChildren.length === definedTypographiesOfChildren.length) {\n let sharedTypography: RichTextTypography = shallowAndTypographies(\n ...definedTypographiesOfChildren,\n )\n\n if (sharedTypography.style.length > 0 || sharedTypography.id != null) {\n const rootTypography: RichTextTypography = shallowMergeTypographies(\n sharedTypography,\n node.typography,\n )\n Editor.withoutNormalizing(editor, () => {\n Transforms.setNodes(editor, { typography: rootTypography }, { at: path })\n for (let i = 0; i < node.children.length; i++) {\n const typography: RichTextTypography = shallowInverseAndTypographies(\n node.children.at(i)?.typography ?? { style: [] },\n sharedTypography,\n )\n\n Transforms.setNodes(editor, { typography }, { at: [...path, i] })\n }\n })\n return true\n }\n }\n }\n return false\n}\n"],"mappings":"AAAA,SAAS,QAAQ,SAAoB,YAAkB,YAAY;AAInE,OAAO,UAAU;AACjB,OAAO,eAAe;AACtB,SAAS,gCAAgC;AAEzC,SAAS,WACP,GAC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AAM,gCAAgC,uBAAuB;AAAA,MAC3D,CAAC,eAAiD,QAAQ,UAAU;AAAA,IACtE;AACA,QAAI,uBAAuB,WAAW,8BAA8B,QAAQ;AAC1E,UAAI,mBAAuC;AAAA,QACzC,GAAG;AAAA,MACL;AAEA,UAAI,iBAAiB,MAAM,SAAS,KAAK,iBAAiB,MAAM,MAAM;AACpE,cAAM,iBAAqC;AAAA,UACzC;AAAA,UACA,KAAK;AAAA,QACP;AACA,eAAO,mBAAmB,QAAQ,MAAM;AACtC,qBAAW,SAAS,QAAQ,EAAE,YAAY,eAAe,GAAG,EAAE,IAAI,KAAK,CAAC;AACxE,mBAAS,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;AAC7C,kBAAM,aAAiC;AAAA,cACrC,KAAK,SAAS,GAAG,CAAC,GAAG,cAAc,EAAE,OAAO,CAAC,EAAE;AAAA,cAC/C;AAAA,YACF;AAEA,uBAAW,SAAS,QAAQ,EAAE,WAAW,GAAG,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;AAAA,UAClE;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":"AAAA,SAAS,QAA0B,YAAY;AAC/C;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAIP,OAAO,iBAAiB;AACxB,OAAO,kBAAkB;AACzB,SAAS,qBAAqB;AAE9B,OAAO,eAAe;AACtB,OAAO,UAAU;AAEV,SAAS,aAAa,QAAuB;AAClD,MAAI,OAAO;AAAW,WAAO,YAAY,QAAQ,OAAO,SAAS;AACjE,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AA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,IAAI,OAAO,KAAK;AACvC,eAAO;AAAA,UACL;AAAA,UACA,OAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,wBACd,QACA,aACkB;AAClB,QAAM,SAA6B,CAAC;AAEpC,QAAM,YAAY,OAAO,MAAM,QAAQ;AAAA,IACrC,IAAI,aAAa,MAAM;AAAA,IACvB,OAAO,UAAQ,KAAK,OAAO,IAAI;AAAA,EACjC,CAAC;AAED,aAAW,CAAC,IAAI,KAAK,WAAW;AAC9B,QAAI,KAAK,OAAO,IAAI,KAAK,gBAAgB,QAAQ,KAAK,cAAc,QAAW;AAC7E,aAAO,KAAK,KAAK,UAAU;AAAA,IAC7B;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,oBAAoB,QAAQ,WAAW;AACtF;","names":[]}
1
+ {"version":3,"sources":["../../../src/slate/selectors.ts"],"sourcesContent":["import { Editor, NodeEntry, Range, Text } from 'slate'\nimport {\n type Breakpoints,\n type BreakpointId,\n type Data,\n findBreakpointOverride,\n Slate,\n} from '@makeswift/controls'\n\nimport { EditableBlockKey } from './BlockPlugin/types'\n\nimport unhangRange from './utils/unhangRange'\nimport shallowEqual from '../utils/shallowEqual'\nimport { isNonNullable } from '../utils/isNonNullable'\n\nimport deepEqual from '../utils/deepEqual'\nimport keys from '../utils/keys'\n\nexport function getSelection(editor: Editor): Range {\n if (editor.selection) return unhangRange(editor, editor.selection)\n return {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n }\n}\n\nexport function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isRootBlock(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.RootBlock> => Slate.isRootBlock(entry[0]))\n}\n\nexport function getInlinesInSelection(editor: Editor): NodeEntry<Slate.Inline>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Slate.isInline(node),\n }),\n ).filter((entry): entry is NodeEntry<Slate.Inline> => Slate.isInline(entry[0]))\n}\n\nexport function getActiveBlockType(editor: Editor): Slate.RootBlockType | null {\n const rootBlocks = getBlocksInSelection(editor).map(([node]) => node.type)\n\n return rootBlocks.reduce<Slate.RootBlockType | null>(\n (a, b) => (a === b ? b : null),\n rootBlocks.at(0) ?? null,\n )\n}\n\nexport function getActiveBlockValue(editor: Editor, key: EditableBlockKey) {\n const blocks = getBlocksInSelection(editor)\n\n const active = blocks.map(\n ([block]) => block[key] ?? null,\n ) as (Slate.ResponsiveBlockTextAlignment | null)[]\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\nexport function getActiveBlockDeviceOverrideValue(\n editor: Editor,\n key: EditableBlockKey,\n breakpoints: Breakpoints,\n deviceId: BreakpointId,\n) {\n const active: (Slate.BlockTextAlignment | null)[] = []\n const blocks = getBlocksInSelection(editor)\n\n blocks.forEach(([block]) => {\n const deviceOverride =\n findBreakpointOverride<Slate.BlockTextAlignment>(breakpoints, block[key], deviceId) || null\n active.push(deviceOverride?.value ?? null)\n })\n\n return active.length === 0 ? null : active.reduce((a, b) => (shallowEqual(a, b) ? b : null))\n}\n\n// Typography\n\nconst concat = (a: unknown[], b: unknown[]) => a.concat(b)\n\n// TODO: This is more cruft from trying to remove null from the typography type. This optimization is not worth it.\n/**\n * This is a c/p of the intersection of the utils from the root utils folder.\n * The only change is defaulting to undefined instead of to null.\n */\nexport default function intersection<A extends Record<string, Data>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: Data, b: Data) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | undefined } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = undefined\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | undefined },\n )\n}\n\nconst fuseTypographyMarks = (\n values: Array<Slate.Typography | null | undefined>,\n breakpoints: Breakpoints,\n): Slate.Typography => {\n const devices = [\n ...new Set(\n values\n .filter(isNonNullable)\n .map(({ style }) => style.map(({ deviceId }) => deviceId))\n .reduce(concat, []),\n ),\n ] as BreakpointId[]\n\n return {\n id: values.map(v => v && v.id).reduce((a, b) => (a === b ? a : undefined)) ?? undefined,\n style: devices.map(deviceId =>\n values\n .map(\n v =>\n (v && findBreakpointOverride(breakpoints, v.style, deviceId)) || {\n deviceId,\n value: {},\n },\n )\n .reduce((acc, { value }) => {\n const a = intersection(acc.value, value)\n return {\n deviceId,\n value: a,\n }\n }),\n ),\n }\n}\n\nexport function getActiveTypographyMark(\n editor: Editor,\n breakpoints: Breakpoints,\n): Slate.Typography {\n const active: Slate.Typography[] = []\n\n const textNodes = Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => Text.isText(node),\n })\n\n for (const [node] of textNodes) {\n if (Text.isText(node) && 'typography' in node && node.typography != undefined) {\n active.push(node.typography)\n }\n }\n return active.length === 0 ? { style: [] } : fuseTypographyMarks(active, breakpoints)\n}\n"],"mappings":"AAAA,SAAS,QAA0B,YAAY;AAC/C;AAAA,EAIE;AAAA,EACA;AAAA,OACK;AAIP,OAAO,iBAAiB;AACxB,OAAO,kBAAkB;AACzB,SAAS,qBAAqB;AAE9B,OAAO,eAAe;AACtB,OAAO,UAAU;AAEV,SAAS,aAAa,QAAuB;AAClD,MAAI,OAAO;AAAW,WAAO,YAAY,QAAQ,OAAO,SAAS;AACjE,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AACF;AAEO,SAAS,qBAAqB,QAA8C;AACjF,SAAO,MAAM;AAAA,IACX,OAAO,MAAM,QAAQ;AAAA,MACnB,IAAI,aAAa,MAAM;AAAA,MACvB,OAAO,UAAQ,MAAM,YAAY,I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,IACrC,IAAI,aAAa,MAAM;AAAA,IACvB,OAAO,UAAQ,KAAK,OAAO,IAAI;AAAA,EACjC,CAAC;AAED,aAAW,CAAC,IAAI,KAAK,WAAW;AAC9B,QAAI,KAAK,OAAO,IAAI,KAAK,gBAAgB,QAAQ,KAAK,cAAc,QAAW;AAC7E,aAAO,KAAK,KAAK,UAAU;AAAA,IAC7B;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,oBAAoB,QAAQ,WAAW;AACtF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/intersection.ts"],"sourcesContent":["import deepEqual from './deepEqual'\nimport keys from './keys'\n\nexport default function intersection<A extends Record<string, unknown>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: unknown, b: unknown) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | null } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = null\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | null },\n )\n}\n"],"mappings":"AAAA,OAAO,eAAe;AACtB,OAAO,UAAU;AAEF,SAAR,aACL,GACA,GACA,UAA+C,WACd;AACjC,QAAM,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAErD,SAAO,QAAQ;AAAA,IACb,CAAC,KAAK,MAAM;AACV,UAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAAG,YAAI,CAAC,IAAI,EAAE,CAAC;AAAA;AAChC,YAAI,CAAC,IAAI;AAEd,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/utils/intersection.ts"],"sourcesContent":["import { type Data } from '@makeswift/controls'\n\nimport deepEqual from './deepEqual'\nimport keys from './keys'\n\nexport default function intersection<A extends Record<string, Data>, B extends A>(\n a: A,\n b: B,\n isEqual: (a: Data, b: Data) => boolean = deepEqual,\n): { [K in keyof A]: A[K] | null } {\n const allKeys = [...new Set([...keys(a), ...keys(b)])] as (keyof A)[]\n\n return allKeys.reduce(\n (acc, k) => {\n if (isEqual(a[k], b[k])) acc[k] = a[k]\n else acc[k] = null\n\n return acc\n },\n {} as { [K in keyof A]: A[K] | null },\n )\n}\n"],"mappings":"AAEA,OAAO,eAAe;AACtB,OAAO,UAAU;AAEF,SAAR,aACL,GACA,GACA,UAAyC,WACR;AACjC,QAAM,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAErD,SAAO,QAAQ;AAAA,IACb,CAAC,KAAK,MAAM;AACV,UAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAAG,YAAI,CAAC,IAAI,EAAE,CAAC;AAAA;AAChC,YAAI,CAAC,IAAI;AAEd,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useSyncWithBuilder.d.ts","sourceRoot":"","sources":["../../../../../../../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,KAAK,WAAW,EAA4C,MAAM,qBAAqB,CAAA;AAOhG;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,cA6BpE"}
1
+ {"version":3,"file":"useSyncWithBuilder.d.ts","sourceRoot":"","sources":["../../../../../../../src/runtimes/react/controls/rich-text/EditableText/useSyncWithBuilder.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAS,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,KAAK,WAAW,EAA4C,MAAM,qBAAqB,CAAA;AAOhG;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,cAkCpE"}
@@ -1,5 +1,5 @@
1
1
  import { Editor, NodeEntry, Range } from 'slate';
2
- import { type Breakpoints, type BreakpointId, Slate } from '@makeswift/controls';
2
+ import { type Breakpoints, type BreakpointId, type Data, Slate } from '@makeswift/controls';
3
3
  import { EditableBlockKey } from './BlockPlugin/types';
4
4
  export declare function getSelection(editor: Editor): Range;
5
5
  export declare function getBlocksInSelection(editor: Editor): NodeEntry<Slate.RootBlock>[];
@@ -11,7 +11,7 @@ export declare function getActiveBlockDeviceOverrideValue(editor: Editor, key: E
11
11
  * This is a c/p of the intersection of the utils from the root utils folder.
12
12
  * The only change is defaulting to undefined instead of to null.
13
13
  */
14
- export default function intersection<A extends Record<string, unknown>, B extends A>(a: A, b: B, isEqual?: (a: unknown, b: unknown) => boolean): {
14
+ export default function intersection<A extends Record<string, Data>, B extends A>(a: A, b: B, isEqual?: (a: Data, b: Data) => boolean): {
15
15
  [K in keyof A]: A[K] | undefined;
16
16
  };
17
17
  export declare function getActiveTypographyMark(editor: Editor, breakpoints: Breakpoints): Slate.Typography;
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../src/slate/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAQ,MAAM,OAAO,CAAA;AACtD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EAEjB,KAAK,EACN,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAStD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAMlD;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,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AAM,GAAG,KAAK,CAMlD;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAOjF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAO/E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,aAAa,GAAG,IAAI,CAO7E;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,6CAQxE;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,gBAAgB,EACrB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,YAAY,mCAYvB;AAOD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,EAC9E,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,OAAO,GAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,KAAK,OAAmB,GACjD;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,CAYtC;AAqCD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,GACvB,KAAK,CAAC,UAAU,CAclB"}
@@ -1,4 +1,5 @@
1
- export default function intersection<A extends Record<string, unknown>, B extends A>(a: A, b: B, isEqual?: (a: unknown, b: unknown) => boolean): {
1
+ import { type Data } from '@makeswift/controls';
2
+ export default function intersection<A extends Record<string, Data>, B extends A>(a: A, b: B, isEqual?: (a: Data, b: Data) => boolean): {
2
3
  [K in keyof A]: A[K] | null;
3
4
  };
4
5
  //# sourceMappingURL=intersection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../../src/utils/intersection.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,EACjF,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,OAAO,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAmB,GACvD;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;CAAE,CAYjC"}
1
+ {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../../src/utils/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAK/C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,EAC9E,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,OAAO,GAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,KAAK,OAAmB,GACjD;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;CAAE,CAYjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makeswift/runtime",
3
- "version": "0.28.8-canary.6",
3
+ "version": "0.28.8-canary.7",
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.21-canary.1",
241
+ "@makeswift/controls": "0.1.21-canary.2",
242
242
  "@makeswift/next-plugin": "0.6.1",
243
- "@makeswift/prop-controllers": "0.4.15-canary.1"
243
+ "@makeswift/prop-controllers": "0.4.15-canary.2"
244
244
  },
245
245
  "devDependencies": {
246
246
  "@emotion/jest": "^11.11.0",
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var is_exports = {};
20
- __export(is_exports, {
21
- default: () => is_default
22
- });
23
- module.exports = __toCommonJS(is_exports);
24
- var import_controls = require("@makeswift/controls");
25
- var is_default = import_controls.is;
26
- //# sourceMappingURL=is.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/is.ts"],"sourcesContent":["import { is } from '@makeswift/controls'\n\nexport default is\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAmB;AAEnB,IAAO,aAAQ;","names":[]}
@@ -1,6 +0,0 @@
1
- import { is } from "@makeswift/controls";
2
- var is_default = is;
3
- export {
4
- is_default as default
5
- };
6
- //# sourceMappingURL=is.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utils/is.ts"],"sourcesContent":["import { is } from '@makeswift/controls'\n\nexport default is\n"],"mappings":"AAAA,SAAS,UAAU;AAEnB,IAAO,aAAQ;","names":[]}
@@ -1,3 +0,0 @@
1
- import { is } from '@makeswift/controls';
2
- export default is;
3
- //# sourceMappingURL=is.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/utils/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAA;AAExC,eAAe,EAAE,CAAA"}