@newtonedev/editor 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -264,11 +264,12 @@ function useEditorState({
264
264
  const [colorMode, setColorMode] = useState(
265
265
  initialState.preview.mode
266
266
  );
267
+ const defaultCategoryId = CATEGORIES[0]?.id ?? "colors";
267
268
  const [previewView, setPreviewView] = useState(
268
- initialPreviewView ?? { kind: "overview" }
269
+ initialPreviewView ?? { kind: "category", categoryId: defaultCategoryId }
269
270
  );
270
271
  const [activeSectionId, setActiveSectionId] = useState(
271
- CATEGORIES[0]?.id ?? "colors"
272
+ (initialPreviewView?.kind === "category" ? initialPreviewView.categoryId : void 0) ?? defaultCategoryId
272
273
  );
273
274
  const [sidebarSelection, setSidebarSelection] = useState(null);
274
275
  const [propOverrides, setPropOverrides] = useState(
@@ -368,11 +369,10 @@ function useEditorState({
368
369
  (sectionId) => {
369
370
  setActiveSectionId(sectionId);
370
371
  const sectionComponents = getComponentsByCategory(sectionId);
372
+ onNavigate?.({ kind: "category", categoryId: sectionId });
371
373
  if (sectionComponents.length === 1) {
372
374
  const comp = sectionComponents[0];
373
- const view = { kind: "component", componentId: comp.id };
374
- setPreviewView(view);
375
- onNavigate?.(view);
375
+ setPreviewView({ kind: "component", componentId: comp.id });
376
376
  const firstVariantId = comp.variants[0]?.id;
377
377
  setSidebarSelection(
378
378
  firstVariantId ? { scope: "variant", componentId: comp.id, variantId: firstVariantId } : { scope: "component", componentId: comp.id }
@@ -381,7 +381,6 @@ function useEditorState({
381
381
  } else {
382
382
  const view = { kind: "category", categoryId: sectionId };
383
383
  setPreviewView(view);
384
- onNavigate?.(view);
385
384
  setSidebarSelection(null);
386
385
  setPropOverrides({});
387
386
  }
@@ -637,6 +636,94 @@ function EditorShell({
637
636
  }
638
637
  );
639
638
  }
639
+ var SIDEBAR_WIDTH2 = 360;
640
+ function Sidebar({
641
+ isDirty,
642
+ onRevert
643
+ }) {
644
+ const tokens = useTokens();
645
+ const borderColor = srgbToHex(tokens.border.srgb);
646
+ const bgColor = srgbToHex(tokens.background.srgb);
647
+ return /* @__PURE__ */ jsxs(
648
+ "div",
649
+ {
650
+ style: {
651
+ width: SIDEBAR_WIDTH2,
652
+ flexShrink: 0,
653
+ display: "flex",
654
+ flexDirection: "column",
655
+ height: "100vh",
656
+ borderLeft: `1px solid ${borderColor}`,
657
+ backgroundColor: bgColor
658
+ },
659
+ children: [
660
+ /* @__PURE__ */ jsx(
661
+ "div",
662
+ {
663
+ style: {
664
+ flexShrink: 0,
665
+ padding: "16px 20px",
666
+ borderBottom: `1px solid ${borderColor}`,
667
+ display: "flex",
668
+ alignItems: "center"
669
+ },
670
+ children: /* @__PURE__ */ jsx(
671
+ "span",
672
+ {
673
+ style: {
674
+ fontSize: 16,
675
+ fontWeight: 700,
676
+ color: srgbToHex(tokens.textPrimary.srgb)
677
+ },
678
+ children: "newtone"
679
+ }
680
+ )
681
+ }
682
+ ),
683
+ /* @__PURE__ */ jsx(
684
+ "div",
685
+ {
686
+ style: {
687
+ flex: 1,
688
+ overflowY: "auto",
689
+ overflowX: "hidden"
690
+ }
691
+ }
692
+ ),
693
+ /* @__PURE__ */ jsx(
694
+ "div",
695
+ {
696
+ style: {
697
+ flexShrink: 0,
698
+ padding: "12px 20px",
699
+ borderTop: `1px solid ${borderColor}`
700
+ },
701
+ children: /* @__PURE__ */ jsx(
702
+ "button",
703
+ {
704
+ disabled: !isDirty,
705
+ onClick: onRevert,
706
+ "aria-label": "Revert all changes to the last saved version",
707
+ style: {
708
+ width: "100%",
709
+ padding: "8px 16px",
710
+ borderRadius: 6,
711
+ border: `1px solid ${borderColor}`,
712
+ backgroundColor: "transparent",
713
+ color: isDirty ? srgbToHex(tokens.textPrimary.srgb) : srgbToHex(tokens.textSecondary.srgb),
714
+ fontSize: 13,
715
+ cursor: isDirty ? "pointer" : "not-allowed",
716
+ opacity: isDirty ? 1 : 0.5
717
+ },
718
+ children: "Revert Changes"
719
+ }
720
+ )
721
+ }
722
+ )
723
+ ]
724
+ }
725
+ );
726
+ }
640
727
  function PresetSelector({
641
728
  presets,
642
729
  activePresetId,
@@ -1040,118 +1127,6 @@ function PresetSelector({
1040
1127
  )
1041
1128
  ] });
1042
1129
  }
1043
- var SIDEBAR_WIDTH2 = 360;
1044
- function Sidebar({
1045
- isDirty,
1046
- onRevert,
1047
- presets,
1048
- activePresetId,
1049
- publishedPresetId,
1050
- onSwitchPreset,
1051
- onCreatePreset,
1052
- onRenamePreset,
1053
- onDeletePreset,
1054
- onDuplicatePreset
1055
- }) {
1056
- const tokens = useTokens();
1057
- const borderColor = srgbToHex(tokens.border.srgb);
1058
- const bgColor = srgbToHex(tokens.background.srgb);
1059
- return /* @__PURE__ */ jsxs(
1060
- "div",
1061
- {
1062
- style: {
1063
- width: SIDEBAR_WIDTH2,
1064
- flexShrink: 0,
1065
- display: "flex",
1066
- flexDirection: "column",
1067
- height: "100vh",
1068
- borderLeft: `1px solid ${borderColor}`,
1069
- backgroundColor: bgColor
1070
- },
1071
- children: [
1072
- /* @__PURE__ */ jsxs(
1073
- "div",
1074
- {
1075
- style: {
1076
- flexShrink: 0,
1077
- padding: "16px 20px",
1078
- borderBottom: `1px solid ${borderColor}`,
1079
- display: "flex",
1080
- alignItems: "center",
1081
- justifyContent: "space-between"
1082
- },
1083
- children: [
1084
- /* @__PURE__ */ jsx(
1085
- "span",
1086
- {
1087
- style: {
1088
- fontSize: 16,
1089
- fontWeight: 700,
1090
- color: srgbToHex(tokens.textPrimary.srgb)
1091
- },
1092
- children: "newtone"
1093
- }
1094
- ),
1095
- /* @__PURE__ */ jsx(
1096
- PresetSelector,
1097
- {
1098
- presets,
1099
- activePresetId,
1100
- publishedPresetId,
1101
- onSwitchPreset,
1102
- onCreatePreset,
1103
- onRenamePreset,
1104
- onDeletePreset,
1105
- onDuplicatePreset
1106
- }
1107
- )
1108
- ]
1109
- }
1110
- ),
1111
- /* @__PURE__ */ jsx(
1112
- "div",
1113
- {
1114
- style: {
1115
- flex: 1,
1116
- overflowY: "auto",
1117
- overflowX: "hidden"
1118
- }
1119
- }
1120
- ),
1121
- /* @__PURE__ */ jsx(
1122
- "div",
1123
- {
1124
- style: {
1125
- flexShrink: 0,
1126
- padding: "12px 20px",
1127
- borderTop: `1px solid ${borderColor}`
1128
- },
1129
- children: /* @__PURE__ */ jsx(
1130
- "button",
1131
- {
1132
- disabled: !isDirty,
1133
- onClick: onRevert,
1134
- "aria-label": "Revert all changes to the last saved version",
1135
- style: {
1136
- width: "100%",
1137
- padding: "8px 16px",
1138
- borderRadius: 6,
1139
- border: `1px solid ${borderColor}`,
1140
- backgroundColor: "transparent",
1141
- color: isDirty ? srgbToHex(tokens.textPrimary.srgb) : srgbToHex(tokens.textSecondary.srgb),
1142
- fontSize: 13,
1143
- cursor: isDirty ? "pointer" : "not-allowed",
1144
- opacity: isDirty ? 1 : 0.5
1145
- },
1146
- children: "Revert Changes"
1147
- }
1148
- )
1149
- }
1150
- )
1151
- ]
1152
- }
1153
- );
1154
- }
1155
1130
  var STATUS_LABEL = {
1156
1131
  saved: "Saved",
1157
1132
  saving: "Saving...",
@@ -1164,7 +1139,15 @@ function EditorHeader({
1164
1139
  publishing,
1165
1140
  onPublish,
1166
1141
  onRetry,
1167
- headerSlots
1142
+ headerSlots,
1143
+ presets,
1144
+ activePresetId,
1145
+ publishedPresetId,
1146
+ onSwitchPreset,
1147
+ onCreatePreset,
1148
+ onRenamePreset,
1149
+ onDeletePreset,
1150
+ onDuplicatePreset
1168
1151
  }) {
1169
1152
  const tokens = useTokens();
1170
1153
  const borderColor = srgbToHex(tokens.border.srgb);
@@ -1187,7 +1170,22 @@ function EditorHeader({
1187
1170
  flexShrink: 0
1188
1171
  },
1189
1172
  children: [
1190
- /* @__PURE__ */ jsx("div", { style: { display: "flex", alignItems: "center", gap: 16 }, children: headerSlots?.left }),
1173
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: 16 }, children: [
1174
+ headerSlots?.left,
1175
+ /* @__PURE__ */ jsx(
1176
+ PresetSelector,
1177
+ {
1178
+ presets,
1179
+ activePresetId,
1180
+ publishedPresetId,
1181
+ onSwitchPreset,
1182
+ onCreatePreset,
1183
+ onRenamePreset,
1184
+ onDeletePreset,
1185
+ onDuplicatePreset
1186
+ }
1187
+ )
1188
+ ] }),
1191
1189
  /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: 12 }, children: [
1192
1190
  /* @__PURE__ */ jsx(
1193
1191
  "span",
@@ -1219,7 +1217,7 @@ function EditorHeader({
1219
1217
  );
1220
1218
  }
1221
1219
  var NAV_WIDTH = 60;
1222
- function PrimaryNav({ activeSectionId, onSelectSection }) {
1220
+ function PrimaryNav({ activeSectionId, onSelectSection, footer }) {
1223
1221
  const tokens = useTokens();
1224
1222
  const [hoveredId, setHoveredId] = useState(null);
1225
1223
  const bg = srgbToHex(tokens.background.srgb);
@@ -1227,7 +1225,7 @@ function PrimaryNav({ activeSectionId, onSelectSection }) {
1227
1225
  const activeBg = srgbToHex(tokens.backgroundInteractive.srgb);
1228
1226
  const iconColor = srgbToHex(tokens.textSecondary.srgb);
1229
1227
  const activeIconColor = srgbToHex(tokens.textPrimary.srgb);
1230
- return /* @__PURE__ */ jsx(
1228
+ return /* @__PURE__ */ jsxs(
1231
1229
  "nav",
1232
1230
  {
1233
1231
  "aria-label": "Section navigation",
@@ -1242,41 +1240,44 @@ function PrimaryNav({ activeSectionId, onSelectSection }) {
1242
1240
  backgroundColor: bg,
1243
1241
  borderRight: `1px solid ${borderColor}`
1244
1242
  },
1245
- children: CATEGORIES.map((category) => {
1246
- const isActive = activeSectionId === category.id;
1247
- const isHovered = hoveredId === category.id;
1248
- return /* @__PURE__ */ jsx(
1249
- "button",
1250
- {
1251
- onClick: () => onSelectSection(category.id),
1252
- onMouseEnter: () => setHoveredId(category.id),
1253
- onMouseLeave: () => setHoveredId(null),
1254
- title: category.name,
1255
- "aria-current": isActive ? "page" : void 0,
1256
- style: {
1257
- display: "flex",
1258
- alignItems: "center",
1259
- justifyContent: "center",
1260
- width: 44,
1261
- height: 44,
1262
- borderRadius: 12,
1263
- border: "none",
1264
- backgroundColor: isActive ? activeBg : isHovered ? `${borderColor}20` : "transparent",
1265
- cursor: "pointer",
1266
- transition: "background-color 150ms"
1243
+ children: [
1244
+ CATEGORIES.map((category) => {
1245
+ const isActive = activeSectionId === category.id;
1246
+ const isHovered = hoveredId === category.id;
1247
+ return /* @__PURE__ */ jsx(
1248
+ "button",
1249
+ {
1250
+ onClick: () => onSelectSection(category.id),
1251
+ onMouseEnter: () => setHoveredId(category.id),
1252
+ onMouseLeave: () => setHoveredId(null),
1253
+ title: category.name,
1254
+ "aria-current": isActive ? "page" : void 0,
1255
+ style: {
1256
+ display: "flex",
1257
+ alignItems: "center",
1258
+ justifyContent: "center",
1259
+ width: 44,
1260
+ height: 44,
1261
+ borderRadius: 12,
1262
+ border: "none",
1263
+ backgroundColor: isActive ? activeBg : isHovered ? `${borderColor}20` : "transparent",
1264
+ cursor: "pointer",
1265
+ transition: "background-color 150ms"
1266
+ },
1267
+ children: /* @__PURE__ */ jsx(
1268
+ Icon,
1269
+ {
1270
+ name: category.icon ?? "circle",
1271
+ size: 24,
1272
+ color: isActive ? activeIconColor : iconColor
1273
+ }
1274
+ )
1267
1275
  },
1268
- children: /* @__PURE__ */ jsx(
1269
- Icon,
1270
- {
1271
- name: category.icon ?? "circle",
1272
- size: 24,
1273
- color: isActive ? activeIconColor : iconColor
1274
- }
1275
- )
1276
- },
1277
- category.id
1278
- );
1279
- })
1276
+ category.id
1277
+ );
1278
+ }),
1279
+ footer && /* @__PURE__ */ jsx("div", { style: { marginTop: "auto", paddingBottom: 12 }, children: footer })
1280
+ ]
1280
1281
  }
1281
1282
  );
1282
1283
  }
@@ -2586,7 +2587,7 @@ function OthersSection({ state, dispatch }) {
2586
2587
  ] })
2587
2588
  ] });
2588
2589
  }
2589
- var PANEL_WIDTH = 280;
2590
+ var PANEL_WIDTH = 360;
2590
2591
  function ConfiguratorPanel({
2591
2592
  activeSectionId,
2592
2593
  state,
@@ -2633,7 +2634,7 @@ function ConfiguratorPanel({
2633
2634
  }
2634
2635
  );
2635
2636
  }
2636
- var TOC_WIDTH = 220;
2637
+ var TOC_WIDTH = 360;
2637
2638
  function TableOfContents({
2638
2639
  activeSectionId,
2639
2640
  activeView,
@@ -3568,7 +3569,7 @@ function ComponentDetailView({
3568
3569
  scopeFontMap
3569
3570
  }) {
3570
3571
  const tokens = useTokens();
3571
- const { config } = useNewtoneTheme();
3572
+ const { config, mode } = useNewtoneTheme();
3572
3573
  const component = getComponent(componentId);
3573
3574
  const [hoveredId, setHoveredId] = useState(null);
3574
3575
  const [previewBreakpoint, setPreviewBreakpoint] = useState("lg");
@@ -3711,7 +3712,7 @@ function ComponentDetailView({
3711
3712
  );
3712
3713
  }) })
3713
3714
  ] }),
3714
- component.previewLayout === "list" ? /* @__PURE__ */ jsx(NewtoneProvider, { config: scaledConfig, children: /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: component.variants.map((variant) => {
3715
+ component.previewLayout === "list" ? /* @__PURE__ */ jsx(NewtoneProvider, { config: scaledConfig, initialMode: mode, children: /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: component.variants.map((variant) => {
3715
3716
  const isSelected = selectedVariantId === variant.id;
3716
3717
  const isHovered = hoveredId === variant.id;
3717
3718
  const borderColor = isSelected ? interactiveColor : isHovered ? `${interactiveColor}66` : srgbToHex(tokens.border.srgb);
@@ -3804,7 +3805,7 @@ function ComponentDetailView({
3804
3805
  },
3805
3806
  variant.id
3806
3807
  );
3807
- }) }) }) : /* @__PURE__ */ jsx(
3808
+ }) }) }, mode) : /* @__PURE__ */ jsx(
3808
3809
  "div",
3809
3810
  {
3810
3811
  style: {
@@ -4444,6 +4445,7 @@ function Editor({
4444
4445
  chromeThemeConfig,
4445
4446
  persistence,
4446
4447
  headerSlots,
4448
+ navFooter,
4447
4449
  onNavigate,
4448
4450
  initialPreviewView,
4449
4451
  manifestUrl,
@@ -4489,15 +4491,7 @@ function Editor({
4489
4491
  Sidebar,
4490
4492
  {
4491
4493
  isDirty: editor.isDirty,
4492
- onRevert: editor.handleRevert,
4493
- presets: editor.presets,
4494
- activePresetId: editor.activePresetId,
4495
- publishedPresetId: editor.publishedPresetId,
4496
- onSwitchPreset: editor.switchPreset,
4497
- onCreatePreset: editor.createPreset,
4498
- onRenamePreset: editor.renamePreset,
4499
- onDeletePreset: editor.deletePreset,
4500
- onDuplicatePreset: editor.duplicatePreset
4494
+ onRevert: editor.handleRevert
4501
4495
  }
4502
4496
  ),
4503
4497
  navbar: /* @__PURE__ */ jsx(
@@ -4508,7 +4502,15 @@ function Editor({
4508
4502
  publishing: editor.publishing,
4509
4503
  onPublish: editor.handlePublish,
4510
4504
  onRetry: () => editor.saveDraft(editor.latestStateRef.current),
4511
- headerSlots
4505
+ headerSlots,
4506
+ presets: editor.presets,
4507
+ activePresetId: editor.activePresetId,
4508
+ publishedPresetId: editor.publishedPresetId,
4509
+ onSwitchPreset: editor.switchPreset,
4510
+ onCreatePreset: editor.createPreset,
4511
+ onRenamePreset: editor.renamePreset,
4512
+ onDeletePreset: editor.deletePreset,
4513
+ onDuplicatePreset: editor.duplicatePreset
4512
4514
  }
4513
4515
  ),
4514
4516
  content: /* @__PURE__ */ jsxs(
@@ -4525,7 +4527,8 @@ function Editor({
4525
4527
  PrimaryNav,
4526
4528
  {
4527
4529
  activeSectionId: editor.activeSectionId,
4528
- onSelectSection: editor.handleSectionChange
4530
+ onSelectSection: editor.handleSectionChange,
4531
+ footer: navFooter
4529
4532
  }
4530
4533
  ),
4531
4534
  editor.activeSectionId === "components" ? /* @__PURE__ */ jsx(