@webstudio-is/react-sdk 0.195.0 → 0.197.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -82,7 +82,7 @@ import {
82
82
 
83
83
  // src/core-components.ts
84
84
  import {
85
- EditIcon,
85
+ ContentBlockIcon,
86
86
  ListViewIcon,
87
87
  PaintBrushIcon,
88
88
  SettingsIcon,
@@ -214,11 +214,10 @@ var blockTemplatePropsMeta = {
214
214
  initialProps: []
215
215
  };
216
216
  var blockMeta = {
217
- category: "data",
218
- order: 2,
217
+ category: "typography",
219
218
  type: "container",
220
219
  label: "Content Block",
221
- icon: EditIcon,
220
+ icon: ContentBlockIcon,
222
221
  constraints: [
223
222
  {
224
223
  relation: "ancestor",
@@ -332,17 +331,7 @@ var blockMeta = {
332
331
  {
333
332
  component: "ListItem",
334
333
  type: "instance",
335
- children: [{ type: "text", value: "list item you can edit" }]
336
- },
337
- {
338
- component: "ListItem",
339
- type: "instance",
340
- children: [{ type: "text", value: "list item you can edit" }]
341
- },
342
- {
343
- component: "ListItem",
344
- type: "instance",
345
- children: [{ type: "text", value: "list item you can edit" }]
334
+ children: []
346
335
  }
347
336
  ]
348
337
  },
@@ -361,17 +350,7 @@ var blockMeta = {
361
350
  {
362
351
  component: "ListItem",
363
352
  type: "instance",
364
- children: [{ type: "text", value: "list item you can edit" }]
365
- },
366
- {
367
- component: "ListItem",
368
- type: "instance",
369
- children: [{ type: "text", value: "list item you can edit" }]
370
- },
371
- {
372
- component: "ListItem",
373
- type: "instance",
374
- children: [{ type: "text", value: "list item you can edit" }]
353
+ children: []
375
354
  }
376
355
  ]
377
356
  },
@@ -632,7 +611,10 @@ var generateCss = ({
632
611
  }
633
612
  let descendantSuffix = "";
634
613
  const instance = instances.get(instanceId);
635
- if (instance?.component === descendantComponent) {
614
+ if (instance === void 0) {
615
+ continue;
616
+ }
617
+ if (instance.component === descendantComponent) {
636
618
  const parentId = parentIdByInstanceId.get(instanceId);
637
619
  const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
638
620
  if (parentId && descendantSelector) {
@@ -640,8 +622,9 @@ var generateCss = ({
640
622
  instanceId = parentId;
641
623
  }
642
624
  }
643
- const meta = instance ? componentMetas.get(instance.component) : void 0;
644
- const baseName = instance?.label ?? meta?.label ?? instance?.component ?? instanceId;
625
+ const meta = componentMetas.get(instance.component);
626
+ const [_namespace, shortName] = parseComponentName(instance.component);
627
+ const baseName = instance.label ?? meta?.label ?? shortName;
645
628
  const className = `w-${scope.getName(instanceId, baseName)}`;
646
629
  if (atomic === false) {
647
630
  let classList = classes.get(instanceId);
@@ -773,6 +756,8 @@ var showAttribute = "data-ws-show";
773
756
  var indexAttribute = "data-ws-index";
774
757
  var collapsedAttribute = "data-ws-collapsed";
775
758
  var textContentAttribute = "data-ws-text-content";
759
+ var editablePlaceholderVariable = "--data-ws-editable-placeholder";
760
+ var editingPlaceholderVariable = "--data-ws-editing-placeholder";
776
761
  var attributeNameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
777
762
  var attributeNameChar = attributeNameStartChar + ":\\-0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
778
763
  var validAttributeNameRegex = new RegExp(
@@ -796,262 +781,12 @@ var isAttributeNameSafe = (attributeName) => {
796
781
  return false;
797
782
  };
798
783
 
799
- // src/prop-meta.ts
800
- import { z } from "zod";
801
- var common = {
802
- label: z.string().optional(),
803
- description: z.string().optional(),
804
- required: z.boolean()
805
- };
806
- var Number = z.object({
807
- ...common,
808
- control: z.literal("number"),
809
- type: z.literal("number"),
810
- defaultValue: z.number().optional()
811
- });
812
- var Range = z.object({
813
- ...common,
814
- control: z.literal("range"),
815
- type: z.literal("number"),
816
- defaultValue: z.number().optional()
817
- });
818
- var Text = z.object({
819
- ...common,
820
- control: z.literal("text"),
821
- type: z.literal("string"),
822
- defaultValue: z.string().optional(),
823
- /**
824
- * The number of rows in <textarea>. If set to 0 an <input> will be used instead.
825
- * In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
826
- */
827
- rows: z.number().optional()
828
- });
829
- var Code = z.object({
830
- ...common,
831
- control: z.literal("code"),
832
- type: z.literal("string"),
833
- language: z.union([z.literal("html"), z.literal("markdown")]),
834
- defaultValue: z.string().optional()
835
- });
836
- var CodeText = z.object({
837
- ...common,
838
- control: z.literal("codetext"),
839
- type: z.literal("string"),
840
- defaultValue: z.string().optional()
841
- });
842
- var Color = z.object({
843
- ...common,
844
- control: z.literal("color"),
845
- type: z.literal("string"),
846
- defaultValue: z.string().optional()
847
- });
848
- var Boolean = z.object({
849
- ...common,
850
- control: z.literal("boolean"),
851
- type: z.literal("boolean"),
852
- defaultValue: z.boolean().optional()
853
- });
854
- var Radio = z.object({
855
- ...common,
856
- control: z.literal("radio"),
857
- type: z.literal("string"),
858
- defaultValue: z.string().optional(),
859
- options: z.array(z.string())
860
- });
861
- var InlineRadio = z.object({
862
- ...common,
863
- control: z.literal("inline-radio"),
864
- type: z.literal("string"),
865
- defaultValue: z.string().optional(),
866
- options: z.array(z.string())
867
- });
868
- var Select = z.object({
869
- ...common,
870
- control: z.literal("select"),
871
- type: z.literal("string"),
872
- defaultValue: z.string().optional(),
873
- options: z.array(z.string())
874
- });
875
- var Check = z.object({
876
- ...common,
877
- control: z.literal("check"),
878
- type: z.literal("string[]"),
879
- defaultValue: z.array(z.string()).optional(),
880
- options: z.array(z.string())
881
- });
882
- var InlineCheck = z.object({
883
- ...common,
884
- control: z.literal("inline-check"),
885
- type: z.literal("string[]"),
886
- defaultValue: z.array(z.string()).optional(),
887
- options: z.array(z.string())
888
- });
889
- var MultiSelect = z.object({
890
- ...common,
891
- control: z.literal("multi-select"),
892
- type: z.literal("string[]"),
893
- defaultValue: z.array(z.string()).optional(),
894
- options: z.array(z.string())
895
- });
896
- var File = z.object({
897
- ...common,
898
- control: z.literal("file"),
899
- type: z.literal("string"),
900
- defaultValue: z.string().optional(),
901
- /** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
902
- accept: z.string().optional()
903
- });
904
- var Url = z.object({
905
- ...common,
906
- control: z.literal("url"),
907
- type: z.literal("string"),
908
- defaultValue: z.string().optional()
909
- });
910
- var Json = z.object({
911
- ...common,
912
- control: z.literal("json"),
913
- type: z.literal("json"),
914
- defaultValue: z.unknown().optional()
915
- });
916
- var Date = z.object({
917
- ...common,
918
- control: z.literal("date"),
919
- // @todo not sure what type should be here
920
- // (we don't support Date yet, added for completeness)
921
- type: z.literal("string"),
922
- defaultValue: z.string().optional()
923
- });
924
- var Action = z.object({
925
- ...common,
926
- control: z.literal("action"),
927
- type: z.literal("action"),
928
- defaultValue: z.undefined().optional()
929
- });
930
- var TextContent = z.object({
931
- ...common,
932
- control: z.literal("textContent"),
933
- type: z.literal("string"),
934
- defaultValue: z.string().optional()
935
- });
936
- var PropMeta = z.union([
937
- Number,
938
- Range,
939
- Text,
940
- Code,
941
- CodeText,
942
- Color,
943
- Boolean,
944
- Radio,
945
- InlineRadio,
946
- Select,
947
- MultiSelect,
948
- Check,
949
- InlineCheck,
950
- File,
951
- Url,
952
- Json,
953
- Date,
954
- Action,
955
- TextContent
956
- ]);
957
-
958
- // src/components/component-meta.ts
959
- import { z as z3 } from "zod";
960
- import { Matchers } from "@webstudio-is/sdk";
961
-
962
784
  // src/embed-template.ts
963
- import { z as z2 } from "zod";
964
785
  import { nanoid } from "nanoid";
965
786
  import {
966
787
  encodeDataSourceVariable,
967
788
  transpileExpression
968
789
  } from "@webstudio-is/sdk";
969
- import { StyleValue } from "@webstudio-is/css-engine";
970
- var EmbedTemplateText = z2.object({
971
- type: z2.literal("text"),
972
- value: z2.string(),
973
- placeholder: z2.boolean().optional()
974
- });
975
- var EmbedTemplateExpression = z2.object({
976
- type: z2.literal("expression"),
977
- value: z2.string()
978
- });
979
- var EmbedTemplateVariable = z2.object({
980
- alias: z2.optional(z2.string()),
981
- initialValue: z2.unknown()
982
- });
983
- var EmbedTemplateProp = z2.union([
984
- z2.object({
985
- type: z2.literal("number"),
986
- name: z2.string(),
987
- value: z2.number()
988
- }),
989
- z2.object({
990
- type: z2.literal("string"),
991
- name: z2.string(),
992
- value: z2.string()
993
- }),
994
- z2.object({
995
- type: z2.literal("boolean"),
996
- name: z2.string(),
997
- value: z2.boolean()
998
- }),
999
- z2.object({
1000
- type: z2.literal("string[]"),
1001
- name: z2.string(),
1002
- value: z2.array(z2.string())
1003
- }),
1004
- z2.object({
1005
- type: z2.literal("json"),
1006
- name: z2.string(),
1007
- value: z2.unknown()
1008
- }),
1009
- z2.object({
1010
- type: z2.literal("expression"),
1011
- name: z2.string(),
1012
- code: z2.string()
1013
- }),
1014
- z2.object({
1015
- type: z2.literal("parameter"),
1016
- name: z2.string(),
1017
- variableName: z2.string(),
1018
- variableAlias: z2.optional(z2.string())
1019
- }),
1020
- z2.object({
1021
- type: z2.literal("action"),
1022
- name: z2.string(),
1023
- value: z2.array(
1024
- z2.object({
1025
- type: z2.literal("execute"),
1026
- args: z2.optional(z2.array(z2.string())),
1027
- code: z2.string()
1028
- })
1029
- )
1030
- })
1031
- ]);
1032
- var EmbedTemplateStyleDeclRaw = z2.object({
1033
- // State selector, e.g. :hover
1034
- state: z2.optional(z2.string()),
1035
- property: z2.string(),
1036
- value: StyleValue
1037
- });
1038
- var EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
1039
- var EmbedTemplateInstance = z2.lazy(
1040
- () => z2.object({
1041
- type: z2.literal("instance"),
1042
- component: z2.string(),
1043
- label: z2.optional(z2.string()),
1044
- variables: z2.optional(z2.record(z2.string(), EmbedTemplateVariable)),
1045
- props: z2.optional(z2.array(EmbedTemplateProp)),
1046
- styles: z2.optional(z2.array(EmbedTemplateStyleDecl)),
1047
- children: WsEmbedTemplate
1048
- })
1049
- );
1050
- var WsEmbedTemplate = z2.lazy(
1051
- () => z2.array(
1052
- z2.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
1053
- )
1054
- );
1055
790
  var getVariablValue = (value) => {
1056
791
  if (typeof value === "string") {
1057
792
  return { type: "string", value };
@@ -1226,13 +961,14 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
1226
961
  }
1227
962
  return parentChildren;
1228
963
  };
1229
- var generateDataFromEmbedTemplate = (treeTemplate, metas, defaultBreakpointId, generateId = nanoid) => {
964
+ var generateDataFromEmbedTemplate = (treeTemplate, metas, generateId = nanoid) => {
1230
965
  const instances = [];
1231
966
  const props = [];
1232
967
  const dataSourceByRef = /* @__PURE__ */ new Map();
1233
968
  const styleSourceSelections = [];
1234
969
  const styleSources = [];
1235
970
  const styles = [];
971
+ const baseBreakpointId = generateId();
1236
972
  const children = createInstancesFromTemplate(
1237
973
  treeTemplate,
1238
974
  instances,
@@ -1242,9 +978,16 @@ var generateDataFromEmbedTemplate = (treeTemplate, metas, defaultBreakpointId, g
1242
978
  styleSources,
1243
979
  styles,
1244
980
  metas,
1245
- defaultBreakpointId,
981
+ baseBreakpointId,
1246
982
  generateId
1247
983
  );
984
+ const breakpoints = [];
985
+ if (styles.length > 0) {
986
+ breakpoints.push({
987
+ id: baseBreakpointId,
988
+ label: ""
989
+ });
990
+ }
1248
991
  return {
1249
992
  children,
1250
993
  instances,
@@ -1253,8 +996,8 @@ var generateDataFromEmbedTemplate = (treeTemplate, metas, defaultBreakpointId, g
1253
996
  styleSourceSelections,
1254
997
  styleSources,
1255
998
  styles,
999
+ breakpoints,
1256
1000
  assets: [],
1257
- breakpoints: [],
1258
1001
  resources: []
1259
1002
  };
1260
1003
  };
@@ -1326,61 +1069,6 @@ var namespaceMeta = (meta, namespace, components) => {
1326
1069
  return newMeta;
1327
1070
  };
1328
1071
 
1329
- // src/components/component-meta.ts
1330
- var WsComponentPropsMeta = z3.object({
1331
- props: z3.record(PropMeta),
1332
- // Props that will be always visible in properties panel.
1333
- initialProps: z3.array(z3.string()).optional()
1334
- });
1335
- var componentCategories = [
1336
- "general",
1337
- "text",
1338
- "data",
1339
- "media",
1340
- "forms",
1341
- "radix",
1342
- "xml",
1343
- "hidden",
1344
- "internal"
1345
- ];
1346
- var stateCategories = ["states", "component-states"];
1347
- var ComponentState = z3.object({
1348
- category: z3.enum(stateCategories).optional(),
1349
- selector: z3.string(),
1350
- label: z3.string()
1351
- });
1352
- var defaultStates = [
1353
- { selector: ":hover", label: "Hover" },
1354
- { selector: ":active", label: "Active" },
1355
- { selector: ":focus", label: "Focus" },
1356
- { selector: ":focus-visible", label: "Focus Visible" },
1357
- { selector: ":focus-within", label: "Focus Within" }
1358
- ];
1359
- var WsComponentMeta = z3.object({
1360
- category: z3.enum(componentCategories).optional(),
1361
- // container - can accept other components with dnd or be edited as text
1362
- // control - usually form controls like inputs, without children
1363
- // embed - images, videos or other embeddable components, without children
1364
- // rich-text-child - formatted text fragment, not listed in components list
1365
- type: z3.enum(["container", "control", "embed", "rich-text-child"]),
1366
- constraints: Matchers.optional(),
1367
- // when this field is specified component receives
1368
- // prop with index of same components withiin specified ancestor
1369
- // important to automatically enumerate collections without
1370
- // naming every item manually
1371
- indexWithinAncestor: z3.optional(z3.string()),
1372
- stylable: z3.optional(z3.boolean()),
1373
- label: z3.optional(z3.string()),
1374
- description: z3.string().optional(),
1375
- icon: z3.string(),
1376
- presetStyle: z3.optional(
1377
- z3.record(z3.string(), z3.array(EmbedTemplateStyleDecl))
1378
- ),
1379
- states: z3.optional(z3.array(ComponentState)),
1380
- template: z3.optional(WsEmbedTemplate),
1381
- order: z3.number().optional()
1382
- });
1383
-
1384
1072
  // src/instance-utils.ts
1385
1073
  var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1386
1074
  const ancestors = /* @__PURE__ */ new Set();
@@ -1800,12 +1488,6 @@ var generateWebstudioComponent = ({
1800
1488
  return generatedComponent;
1801
1489
  };
1802
1490
  export {
1803
- EmbedTemplateInstance,
1804
- EmbedTemplateProp,
1805
- EmbedTemplateStyleDecl,
1806
- PropMeta,
1807
- WsComponentMeta,
1808
- WsEmbedTemplate,
1809
1491
  addGlobalRules,
1810
1492
  blockComponent,
1811
1493
  blockTemplateComponent,
@@ -1813,12 +1495,12 @@ export {
1813
1495
  collapsedAttribute,
1814
1496
  collectionComponent,
1815
1497
  componentAttribute,
1816
- componentCategories,
1817
1498
  coreMetas,
1818
1499
  corePropsMetas,
1819
1500
  createImageValueTransformer,
1820
- defaultStates,
1821
1501
  descendantComponent,
1502
+ editablePlaceholderVariable,
1503
+ editingPlaceholderVariable,
1822
1504
  generateCss,
1823
1505
  generateDataFromEmbedTemplate,
1824
1506
  generateJsxChildren,
@@ -1837,6 +1519,5 @@ export {
1837
1519
  rootComponent,
1838
1520
  selectorIdAttribute,
1839
1521
  showAttribute,
1840
- stateCategories,
1841
1522
  textContentAttribute
1842
1523
  };
package/lib/runtime.js CHANGED
@@ -48,6 +48,7 @@ var useVariableState = (initialState) => {
48
48
  };
49
49
 
50
50
  // src/runtime.ts
51
+ var xmlNodeTagSuffix = "-ws-xml-node-fb77f896-8e96-40b9-b8f8-90a4e70d724a";
51
52
  var getIndexWithinAncestorFromComponentProps = (props) => {
52
53
  return props["data-ws-index"];
53
54
  };
@@ -56,5 +57,6 @@ export {
56
57
  getClosestInstance,
57
58
  getIndexWithinAncestorFromComponentProps,
58
59
  useResource,
59
- useVariableState
60
+ useVariableState,
61
+ xmlNodeTagSuffix
60
62
  };
@@ -1,4 +1,4 @@
1
- import type { WsComponentMeta } from "./components/component-meta";
1
+ import type { WsComponentMeta } from "@webstudio-is/sdk";
2
2
  export declare const rootComponent = "ws:root";
3
3
  export declare const portalComponent = "Slot";
4
4
  export declare const collectionComponent = "ws:collection";
@@ -1,6 +1,5 @@
1
1
  import { type TransformValue } from "@webstudio-is/css-engine";
2
- import { type Assets, type Breakpoints, type Instances, type Props, type StyleSourceSelections, type Styles } from "@webstudio-is/sdk";
3
- import type { WsComponentMeta } from "../components/component-meta";
2
+ import { type Assets, type Breakpoints, type Instances, type Props, type StyleSourceSelections, type Styles, type WsComponentMeta } from "@webstudio-is/sdk";
4
3
  export type CssConfig = {
5
4
  assets: Assets;
6
5
  instances: Instances;