storybook-addon-sdc 0.1.5 → 0.1.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.
package/README.md CHANGED
@@ -185,7 +185,7 @@ The [community will have to decide](https://docs.google.com/document/d/1wCQLXrK1
185
185
 
186
186
  ## Known issues:
187
187
 
188
- - UI Patterns stories format not yet [supported](https://www.drupal.org/project/ui_patterns/issues/3480464).
188
+ - UI Patterns stories format not fully yet [supported](https://www.drupal.org/project/ui_patterns/issues/3480464).
189
189
  - Same problem will be with `$ref: json-schema-definitions://` for SDC from Experience Builder.
190
190
  - Plugin uses [Experimental indexers](https://storybook.js.org/docs/api/main-config/main-config-indexers)
191
191
 
package/dist/preset.js CHANGED
@@ -28,8 +28,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  ));
29
29
 
30
30
  // node_modules/tsup/assets/esm_shims.js
31
+ import { fileURLToPath } from "url";
32
+ import path from "path";
33
+ var getFilename, getDirname, __dirname;
31
34
  var init_esm_shims = __esm({
32
35
  "node_modules/tsup/assets/esm_shims.js"() {
36
+ getFilename = () => fileURLToPath(import.meta.url);
37
+ getDirname = () => path.dirname(getFilename());
38
+ __dirname = /* @__PURE__ */ getDirname();
33
39
  }
34
40
  });
35
41
 
@@ -2127,7 +2133,7 @@ var require_parse_cst = __commonJS({
2127
2133
  * @returns {?Node} - null if at a document boundary
2128
2134
  */
2129
2135
  };
2130
- function parse2(src) {
2136
+ function parse3(src) {
2131
2137
  const cr = [];
2132
2138
  if (src.indexOf("\r") !== -1) {
2133
2139
  src = src.replace(/\r\n?/g, (match, offset2) => {
@@ -2158,7 +2164,7 @@ var require_parse_cst = __commonJS({
2158
2164
  documents.toString = () => documents.join("...\n");
2159
2165
  return documents;
2160
2166
  }
2161
- exports.parse = parse2;
2167
+ exports.parse = parse3;
2162
2168
  }
2163
2169
  });
2164
2170
 
@@ -2207,10 +2213,10 @@ ${indent}${str}`;
2207
2213
  return String(this.value);
2208
2214
  }
2209
2215
  };
2210
- function collectionFromPath(schema, path, value) {
2216
+ function collectionFromPath(schema, path2, value) {
2211
2217
  let v = value;
2212
- for (let i = path.length - 1; i >= 0; --i) {
2213
- const k = path[i];
2218
+ for (let i = path2.length - 1; i >= 0; --i) {
2219
+ const k = path2[i];
2214
2220
  if (Number.isInteger(k) && k >= 0) {
2215
2221
  const a = [];
2216
2222
  a[k] = v;
@@ -2228,17 +2234,17 @@ ${indent}${str}`;
2228
2234
  }
2229
2235
  return schema.createNode(v, false);
2230
2236
  }
2231
- var isEmptyPath = (path) => path == null || typeof path === "object" && path[Symbol.iterator]().next().done;
2237
+ var isEmptyPath = (path2) => path2 == null || typeof path2 === "object" && path2[Symbol.iterator]().next().done;
2232
2238
  var Collection = class _Collection extends Node {
2233
2239
  constructor(schema) {
2234
2240
  super();
2235
2241
  PlainValue._defineProperty(this, "items", []);
2236
2242
  this.schema = schema;
2237
2243
  }
2238
- addIn(path, value) {
2239
- if (isEmptyPath(path)) this.add(value);
2244
+ addIn(path2, value) {
2245
+ if (isEmptyPath(path2)) this.add(value);
2240
2246
  else {
2241
- const [key, ...rest] = path;
2247
+ const [key, ...rest] = path2;
2242
2248
  const node = this.get(key, true);
2243
2249
  if (node instanceof _Collection) node.addIn(rest, value);
2244
2250
  else if (node === void 0 && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));
@@ -2791,12 +2797,12 @@ ${ctx.indent}`;
2791
2797
  for (const {
2792
2798
  format,
2793
2799
  test,
2794
- resolve: resolve3
2800
+ resolve: resolve4
2795
2801
  } of tags) {
2796
2802
  if (test) {
2797
2803
  const match = str.match(test);
2798
2804
  if (match) {
2799
- let res = resolve3.apply(null, match);
2805
+ let res = resolve4.apply(null, match);
2800
2806
  if (!(res instanceof Scalar)) res = new Scalar(res);
2801
2807
  if (format) res.format = format;
2802
2808
  return res;
@@ -4277,8 +4283,8 @@ ${pair.comment}` : item.comment;
4277
4283
  }
4278
4284
  function warnFileDeprecation(filename) {
4279
4285
  if (shouldWarn(true)) {
4280
- const path = filename.replace(/.*yaml[/\\]/i, "").replace(/\.js$/, "").replace(/\\/g, "/");
4281
- warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, "DeprecationWarning");
4286
+ const path2 = filename.replace(/.*yaml[/\\]/i, "").replace(/\.js$/, "").replace(/\\/g, "/");
4287
+ warn(`The endpoint 'yaml/${path2}' will be removed in a future release.`, "DeprecationWarning");
4282
4288
  }
4283
4289
  }
4284
4290
  var warned = {};
@@ -5191,22 +5197,22 @@ ${cbNode.commentBefore}` : cb;
5191
5197
  assertCollection(this.contents);
5192
5198
  return this.contents.add(value);
5193
5199
  }
5194
- addIn(path, value) {
5200
+ addIn(path2, value) {
5195
5201
  assertCollection(this.contents);
5196
- this.contents.addIn(path, value);
5202
+ this.contents.addIn(path2, value);
5197
5203
  }
5198
5204
  delete(key) {
5199
5205
  assertCollection(this.contents);
5200
5206
  return this.contents.delete(key);
5201
5207
  }
5202
- deleteIn(path) {
5203
- if (resolveSeq.isEmptyPath(path)) {
5208
+ deleteIn(path2) {
5209
+ if (resolveSeq.isEmptyPath(path2)) {
5204
5210
  if (this.contents == null) return false;
5205
5211
  this.contents = null;
5206
5212
  return true;
5207
5213
  }
5208
5214
  assertCollection(this.contents);
5209
- return this.contents.deleteIn(path);
5215
+ return this.contents.deleteIn(path2);
5210
5216
  }
5211
5217
  getDefaults() {
5212
5218
  return _Document.defaults[this.version] || _Document.defaults[this.options.version] || {};
@@ -5214,26 +5220,26 @@ ${cbNode.commentBefore}` : cb;
5214
5220
  get(key, keepScalar) {
5215
5221
  return this.contents instanceof resolveSeq.Collection ? this.contents.get(key, keepScalar) : void 0;
5216
5222
  }
5217
- getIn(path, keepScalar) {
5218
- if (resolveSeq.isEmptyPath(path)) return !keepScalar && this.contents instanceof resolveSeq.Scalar ? this.contents.value : this.contents;
5219
- return this.contents instanceof resolveSeq.Collection ? this.contents.getIn(path, keepScalar) : void 0;
5223
+ getIn(path2, keepScalar) {
5224
+ if (resolveSeq.isEmptyPath(path2)) return !keepScalar && this.contents instanceof resolveSeq.Scalar ? this.contents.value : this.contents;
5225
+ return this.contents instanceof resolveSeq.Collection ? this.contents.getIn(path2, keepScalar) : void 0;
5220
5226
  }
5221
5227
  has(key) {
5222
5228
  return this.contents instanceof resolveSeq.Collection ? this.contents.has(key) : false;
5223
5229
  }
5224
- hasIn(path) {
5225
- if (resolveSeq.isEmptyPath(path)) return this.contents !== void 0;
5226
- return this.contents instanceof resolveSeq.Collection ? this.contents.hasIn(path) : false;
5230
+ hasIn(path2) {
5231
+ if (resolveSeq.isEmptyPath(path2)) return this.contents !== void 0;
5232
+ return this.contents instanceof resolveSeq.Collection ? this.contents.hasIn(path2) : false;
5227
5233
  }
5228
5234
  set(key, value) {
5229
5235
  assertCollection(this.contents);
5230
5236
  this.contents.set(key, value);
5231
5237
  }
5232
- setIn(path, value) {
5233
- if (resolveSeq.isEmptyPath(path)) this.contents = value;
5238
+ setIn(path2, value) {
5239
+ if (resolveSeq.isEmptyPath(path2)) this.contents = value;
5234
5240
  else {
5235
5241
  assertCollection(this.contents);
5236
- this.contents.setIn(path, value);
5242
+ this.contents.setIn(path2, value);
5237
5243
  }
5238
5244
  }
5239
5245
  setSchema(id, customTags) {
@@ -5438,7 +5444,7 @@ var require_dist = __commonJS({
5438
5444
  }
5439
5445
  return doc;
5440
5446
  }
5441
- function parse2(src, options) {
5447
+ function parse3(src, options) {
5442
5448
  const doc = parseDocument(src, options);
5443
5449
  doc.warnings.forEach((warning) => warnings.warn(warning));
5444
5450
  if (doc.errors.length > 0) throw doc.errors[0];
@@ -5453,7 +5459,7 @@ var require_dist = __commonJS({
5453
5459
  createNode,
5454
5460
  defaultOptions: Document$1.defaultOptions,
5455
5461
  Document,
5456
- parse: parse2,
5462
+ parse: parse3,
5457
5463
  parseAllDocuments,
5458
5464
  parseCST: parseCst.parse,
5459
5465
  parseDocument,
@@ -5477,9 +5483,9 @@ init_esm_shims();
5477
5483
 
5478
5484
  // src/vite-plugin-storybook-yaml-stories.ts
5479
5485
  init_esm_shims();
5480
- var import_yaml = __toESM(require_yaml(), 1);
5481
- import { readdirSync, readFileSync, existsSync } from "fs";
5482
- import { dirname, extname, relative, resolve, join } from "path";
5486
+ var import_yaml2 = __toESM(require_yaml(), 1);
5487
+ import { readdirSync, readFileSync as readFileSync2, existsSync } from "fs";
5488
+ import { dirname, extname, relative, resolve as resolve2, join } from "path";
5483
5489
 
5484
5490
  // src/argsGenerator.ts
5485
5491
  init_esm_shims();
@@ -5564,11 +5570,51 @@ var generateComponent = (item) => {
5564
5570
  return `${kebabCaseName}.component(${JSON.stringify(componentProps)})`;
5565
5571
  };
5566
5572
 
5573
+ // src/customRefsTransform.ts
5574
+ init_esm_shims();
5575
+ var import_yaml = __toESM(require_yaml(), 1);
5576
+ import { readFileSync } from "node:fs";
5577
+ import { resolve } from "node:path";
5578
+ var customRefs = (0, import_yaml.parse)(
5579
+ readFileSync(resolve(__dirname, "uiPatternsSchema.yml"), "utf8")
5580
+ );
5581
+ var memo = /* @__PURE__ */ new Map();
5582
+ function resolveRef(ref) {
5583
+ return customRefs[ref.toString()];
5584
+ }
5585
+ function processObject(obj) {
5586
+ if (typeof obj !== "object" || obj === null) {
5587
+ return obj;
5588
+ }
5589
+ if (memo.has(obj)) {
5590
+ return memo.get(obj);
5591
+ }
5592
+ for (const key in obj) {
5593
+ const value = obj[key];
5594
+ if (key === "$ref" && typeof value === "string") {
5595
+ const resolvedRef = resolveRef(value);
5596
+ if (!resolvedRef) {
5597
+ throw new Error(`Reference "${value}" not found in custom schema`);
5598
+ }
5599
+ const processedRef = processObject(resolvedRef);
5600
+ Object.assign(obj, processedRef);
5601
+ delete obj[key];
5602
+ } else if (typeof value === "object") {
5603
+ processObject(value);
5604
+ }
5605
+ }
5606
+ memo.set(obj, { ...obj });
5607
+ return obj;
5608
+ }
5609
+ var customRefsTransform_default = (schema) => {
5610
+ return processObject(schema);
5611
+ };
5612
+
5567
5613
  // src/vite-plugin-storybook-yaml-stories.ts
5568
- var readCDC = (id) => (0, import_yaml.parse)(readFileSync(id, "utf8"));
5614
+ var readCDC = (id) => customRefsTransform_default((0, import_yaml2.parse)(readFileSync2(id, "utf8")));
5569
5615
  var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => join(baseDir, dirent.name));
5570
5616
  var resolveComponentPath = (namespace, component) => {
5571
- const baseComponentDir = resolve("./components");
5617
+ const baseComponentDir = resolve2("./components");
5572
5618
  const directories = [baseComponentDir, ...getSubdirectories(baseComponentDir)];
5573
5619
  const possiblePaths = directories.map(
5574
5620
  (dir) => join(dir, component, `${component}.component.yml`)
@@ -5688,22 +5734,22 @@ var yamlStoriesIndexer = {
5688
5734
  // src/preset.ts
5689
5735
  import twig from "vite-plugin-twig-drupal";
5690
5736
  import { mergeConfig } from "vite";
5691
- import { resolve as resolve2, join as join2 } from "path";
5737
+ import { resolve as resolve3, join as join2 } from "path";
5692
5738
  import fs from "fs";
5693
5739
  var getSubdirectories2 = (baseDir) => {
5694
5740
  return fs.readdirSync(baseDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => join2(baseDir, dirent.name));
5695
5741
  };
5696
5742
  var getComponentDirectories = () => {
5697
- const baseComponentDir = resolve2("./components");
5743
+ const baseComponentDir = resolve3("./components");
5698
5744
  const subdirectories = getSubdirectories2(baseComponentDir);
5699
5745
  return [baseComponentDir, ...subdirectories];
5700
5746
  };
5701
5747
  var resolveComponentPath2 = (namespace, component) => {
5702
5748
  const componentDirectories = getComponentDirectories();
5703
5749
  const possiblePaths = componentDirectories.map(
5704
- (dir) => resolve2(`${dir}/${component}/${component}.component.yml`)
5750
+ (dir) => resolve3(`${dir}/${component}/${component}.component.yml`)
5705
5751
  );
5706
- return possiblePaths.find((path) => fs.existsSync(path));
5752
+ return possiblePaths.find((path2) => fs.existsSync(path2));
5707
5753
  };
5708
5754
  function viteFinal(config, options) {
5709
5755
  const { namespace } = options.sdcStorybookOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",