@11ty/client 4.0.0-alpha.11 → 4.0.0-alpha.12

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.
@@ -1,4 +1,4 @@
1
- /*! Eleventy (Build Awesome) v4.0.0-alpha.11 (@11ty/client/liquid Engine Bundle) */
1
+ /*! Eleventy (Build Awesome) v4.0.0-alpha.12 (@11ty/client/liquid Engine Bundle) */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1236,6 +1236,9 @@ var require_Merge = __commonJS({
1236
1236
  target = {};
1237
1237
  }
1238
1238
  }
1239
+ if (sourcePlainObjectShortcut && Object.isFrozen(target) && isPlainObject(target)) {
1240
+ target = Object.assign({}, target);
1241
+ }
1239
1242
  if (Array.isArray(target) && Array.isArray(source)) {
1240
1243
  return target.concat(source);
1241
1244
  }
@@ -1269,6 +1272,9 @@ var require_Merge = __commonJS({
1269
1272
  if (isPlainObject(target)) {
1270
1273
  for (let key in target) {
1271
1274
  if (key.indexOf(OVERRIDE_PREFIX) === 0) {
1275
+ if (Object.isFrozen(target)) {
1276
+ target = Object.assign({}, target);
1277
+ }
1272
1278
  let cleanedKey = key.slice(OVERRIDE_PREFIX.length);
1273
1279
  if (cleanedKey !== UNSAFE_KEY) {
1274
1280
  target[cleanedKey] = target[key];
@@ -1288,8 +1294,8 @@ var require_Merge = __commonJS({
1288
1294
  return target;
1289
1295
  }
1290
1296
  __name(Merge, "Merge");
1297
+ Merge.DeepCopy = DeepCopy;
1291
1298
  module.exports = Merge;
1292
- module.exports.DeepCopy = DeepCopy;
1293
1299
  }
1294
1300
  });
1295
1301
 
@@ -1478,7 +1484,10 @@ var require_lib_sha256 = __commonJS({
1478
1484
  buf[bp++] = L >>> 8 & 255;
1479
1485
  buf[bp++] = L & 255;
1480
1486
  process2();
1481
- let reply = new Uint8Array(32);
1487
+ let reply = (
1488
+ /** @type {Uint8Array & { hex?: () => string }} */
1489
+ new Uint8Array(32)
1490
+ );
1482
1491
  reply[0] = h0 >>> 24;
1483
1492
  reply[1] = h0 >>> 16 & 255;
1484
1493
  reply[2] = h0 >>> 8 & 255;
@@ -1644,7 +1653,10 @@ var require_HashTypes = __commonJS({
1644
1653
  __name(this, "ScriptHash");
1645
1654
  }
1646
1655
  static toHash(...content) {
1647
- let hash = sha2562();
1656
+ let hash = (
1657
+ /** @type {{ add: (data: any) => void, digest: () => Uint8Array }} */
1658
+ sha2562()
1659
+ );
1648
1660
  for (let c of content) {
1649
1661
  hash.add(c);
1650
1662
  }
@@ -7614,6 +7626,8 @@ var TemplateEngine = class {
7614
7626
 
7615
7627
  // ../../src/Engines/Util/ContextAugmenter.js
7616
7628
  var DATA_KEYS = ["page", "eleventy", "buildawesome", "collections"];
7629
+ var DATA_METHOD = "getData";
7630
+ var augmented = /* @__PURE__ */ new WeakMap();
7617
7631
  function augmentObject(targetObject, options = {}) {
7618
7632
  options = Object.assign(
7619
7633
  {
@@ -7623,11 +7637,15 @@ function augmentObject(targetObject, options = {}) {
7623
7637
  lazy: false
7624
7638
  // lazily fetch the property
7625
7639
  // getter: function() {},
7640
+ // dataGetter: function(source) {}, // defaults to `source`
7626
7641
  },
7627
7642
  options
7628
7643
  );
7644
+ if (targetObject === options.source) {
7645
+ return targetObject;
7646
+ }
7629
7647
  for (let key of DATA_KEYS) {
7630
- if (!options.overwrite && targetObject[key]) {
7648
+ if (!options.overwrite && isUserDefined(targetObject, key)) {
7631
7649
  continue;
7632
7650
  }
7633
7651
  if (options.lazy) {
@@ -7637,12 +7655,7 @@ function augmentObject(targetObject, options = {}) {
7637
7655
  } else {
7638
7656
  value = /* @__PURE__ */ __name(() => options.source?.[key], "value");
7639
7657
  }
7640
- Object.defineProperty(targetObject, key, {
7641
- writable: true,
7642
- configurable: true,
7643
- enumerable: true,
7644
- value
7645
- });
7658
+ defineGetter(targetObject, key, value);
7646
7659
  } else {
7647
7660
  let value;
7648
7661
  if (typeof options.getter == "function") {
@@ -7652,12 +7665,46 @@ function augmentObject(targetObject, options = {}) {
7652
7665
  }
7653
7666
  if (value) {
7654
7667
  targetObject[key] = value;
7668
+ markAugmented(targetObject, key);
7655
7669
  }
7656
7670
  }
7657
7671
  }
7672
+ if (options.overwrite || !isUserDefined(targetObject, DATA_METHOD)) {
7673
+ let dataGetter = options.dataGetter ?? ((source) => source);
7674
+ targetObject[DATA_METHOD] = () => dataGetter(options.source);
7675
+ markAugmented(targetObject, DATA_METHOD);
7676
+ }
7658
7677
  return targetObject;
7659
7678
  }
7660
7679
  __name(augmentObject, "augmentObject");
7680
+ function isUserDefined(targetObject, key) {
7681
+ return Boolean(targetObject[key]) && !augmented.get(targetObject)?.has(key);
7682
+ }
7683
+ __name(isUserDefined, "isUserDefined");
7684
+ function markAugmented(targetObject, key) {
7685
+ if (!augmented.has(targetObject)) {
7686
+ augmented.set(targetObject, /* @__PURE__ */ new Set());
7687
+ }
7688
+ augmented.get(targetObject).add(key);
7689
+ }
7690
+ __name(markAugmented, "markAugmented");
7691
+ function defineGetter(targetObject, key, get) {
7692
+ markAugmented(targetObject, key);
7693
+ Object.defineProperty(targetObject, key, {
7694
+ configurable: true,
7695
+ enumerable: true,
7696
+ get,
7697
+ set(value) {
7698
+ Object.defineProperty(this, key, {
7699
+ value,
7700
+ writable: true,
7701
+ configurable: true,
7702
+ enumerable: true
7703
+ });
7704
+ }
7705
+ });
7706
+ }
7707
+ __name(defineGetter, "defineGetter");
7661
7708
 
7662
7709
  // ../../src/Engines/Liquid.js
7663
7710
  var Liquid2 = class _Liquid extends TemplateEngine {
@@ -7732,6 +7779,7 @@ var Liquid2 = class _Liquid extends TemplateEngine {
7732
7779
  augmentObject(this, {
7733
7780
  source: this.context,
7734
7781
  getter: /* @__PURE__ */ __name((key, context) => context.get([key]), "getter"),
7782
+ dataGetter: /* @__PURE__ */ __name((context) => context.getAll(), "dataGetter"),
7735
7783
  lazy: this.context.strictVariables
7736
7784
  });
7737
7785
  }
@@ -7746,6 +7794,7 @@ var Liquid2 = class _Liquid extends TemplateEngine {
7746
7794
  augmentObject(obj, {
7747
7795
  source: context,
7748
7796
  getter: /* @__PURE__ */ __name((key, context2) => context2.get([key]), "getter"),
7797
+ dataGetter: /* @__PURE__ */ __name((context2) => context2.getAll(), "dataGetter"),
7749
7798
  lazy: context.strictVariables
7750
7799
  });
7751
7800
  }
@@ -1,4 +1,4 @@
1
- /*! Eleventy (Build Awesome) v4.0.0-alpha.11 (@11ty/client/md Engine Bundle) */
1
+ /*! Eleventy (Build Awesome) v4.0.0-alpha.12 (@11ty/client/md Engine Bundle) */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
  var __export = (target, all) => {
@@ -1,4 +1,4 @@
1
- /*! Eleventy (Build Awesome) v4.0.0-alpha.11 (@11ty/client/njk Engine Bundle) */
1
+ /*! Eleventy (Build Awesome) v4.0.0-alpha.12 (@11ty/client/njk Engine Bundle) */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1236,6 +1236,9 @@ var require_Merge = __commonJS({
1236
1236
  target = {};
1237
1237
  }
1238
1238
  }
1239
+ if (sourcePlainObjectShortcut && Object.isFrozen(target) && isPlainObject(target)) {
1240
+ target = Object.assign({}, target);
1241
+ }
1239
1242
  if (Array.isArray(target) && Array.isArray(source)) {
1240
1243
  return target.concat(source);
1241
1244
  }
@@ -1269,6 +1272,9 @@ var require_Merge = __commonJS({
1269
1272
  if (isPlainObject(target)) {
1270
1273
  for (let key in target) {
1271
1274
  if (key.indexOf(OVERRIDE_PREFIX) === 0) {
1275
+ if (Object.isFrozen(target)) {
1276
+ target = Object.assign({}, target);
1277
+ }
1272
1278
  let cleanedKey = key.slice(OVERRIDE_PREFIX.length);
1273
1279
  if (cleanedKey !== UNSAFE_KEY) {
1274
1280
  target[cleanedKey] = target[key];
@@ -1288,8 +1294,8 @@ var require_Merge = __commonJS({
1288
1294
  return target;
1289
1295
  }
1290
1296
  __name(Merge, "Merge");
1297
+ Merge.DeepCopy = DeepCopy;
1291
1298
  module.exports = Merge;
1292
- module.exports.DeepCopy = DeepCopy;
1293
1299
  }
1294
1300
  });
1295
1301
 
@@ -1478,7 +1484,10 @@ var require_lib_sha256 = __commonJS({
1478
1484
  buf[bp++] = L >>> 8 & 255;
1479
1485
  buf[bp++] = L & 255;
1480
1486
  process2();
1481
- let reply = new Uint8Array(32);
1487
+ let reply = (
1488
+ /** @type {Uint8Array & { hex?: () => string }} */
1489
+ new Uint8Array(32)
1490
+ );
1482
1491
  reply[0] = h0 >>> 24;
1483
1492
  reply[1] = h0 >>> 16 & 255;
1484
1493
  reply[2] = h0 >>> 8 & 255;
@@ -1644,7 +1653,10 @@ var require_HashTypes = __commonJS({
1644
1653
  __name(this, "ScriptHash");
1645
1654
  }
1646
1655
  static toHash(...content) {
1647
- let hash = sha256();
1656
+ let hash = (
1657
+ /** @type {{ add: (data: any) => void, digest: () => Uint8Array }} */
1658
+ sha256()
1659
+ );
1648
1660
  for (let c of content) {
1649
1661
  hash.add(c);
1650
1662
  }
@@ -8092,6 +8104,8 @@ var TemplateEngine = class {
8092
8104
 
8093
8105
  // ../../src/Engines/Util/ContextAugmenter.js
8094
8106
  var DATA_KEYS = ["page", "eleventy", "buildawesome", "collections"];
8107
+ var DATA_METHOD = "getData";
8108
+ var augmented = /* @__PURE__ */ new WeakMap();
8095
8109
  function augmentObject(targetObject, options = {}) {
8096
8110
  options = Object.assign(
8097
8111
  {
@@ -8101,11 +8115,15 @@ function augmentObject(targetObject, options = {}) {
8101
8115
  lazy: false
8102
8116
  // lazily fetch the property
8103
8117
  // getter: function() {},
8118
+ // dataGetter: function(source) {}, // defaults to `source`
8104
8119
  },
8105
8120
  options
8106
8121
  );
8122
+ if (targetObject === options.source) {
8123
+ return targetObject;
8124
+ }
8107
8125
  for (let key of DATA_KEYS) {
8108
- if (!options.overwrite && targetObject[key]) {
8126
+ if (!options.overwrite && isUserDefined(targetObject, key)) {
8109
8127
  continue;
8110
8128
  }
8111
8129
  if (options.lazy) {
@@ -8115,12 +8133,7 @@ function augmentObject(targetObject, options = {}) {
8115
8133
  } else {
8116
8134
  value = /* @__PURE__ */ __name(() => options.source?.[key], "value");
8117
8135
  }
8118
- Object.defineProperty(targetObject, key, {
8119
- writable: true,
8120
- configurable: true,
8121
- enumerable: true,
8122
- value
8123
- });
8136
+ defineGetter(targetObject, key, value);
8124
8137
  } else {
8125
8138
  let value;
8126
8139
  if (typeof options.getter == "function") {
@@ -8130,12 +8143,46 @@ function augmentObject(targetObject, options = {}) {
8130
8143
  }
8131
8144
  if (value) {
8132
8145
  targetObject[key] = value;
8146
+ markAugmented(targetObject, key);
8133
8147
  }
8134
8148
  }
8135
8149
  }
8150
+ if (options.overwrite || !isUserDefined(targetObject, DATA_METHOD)) {
8151
+ let dataGetter = options.dataGetter ?? ((source) => source);
8152
+ targetObject[DATA_METHOD] = () => dataGetter(options.source);
8153
+ markAugmented(targetObject, DATA_METHOD);
8154
+ }
8136
8155
  return targetObject;
8137
8156
  }
8138
8157
  __name(augmentObject, "augmentObject");
8158
+ function isUserDefined(targetObject, key) {
8159
+ return Boolean(targetObject[key]) && !augmented.get(targetObject)?.has(key);
8160
+ }
8161
+ __name(isUserDefined, "isUserDefined");
8162
+ function markAugmented(targetObject, key) {
8163
+ if (!augmented.has(targetObject)) {
8164
+ augmented.set(targetObject, /* @__PURE__ */ new Set());
8165
+ }
8166
+ augmented.get(targetObject).add(key);
8167
+ }
8168
+ __name(markAugmented, "markAugmented");
8169
+ function defineGetter(targetObject, key, get) {
8170
+ markAugmented(targetObject, key);
8171
+ Object.defineProperty(targetObject, key, {
8172
+ configurable: true,
8173
+ enumerable: true,
8174
+ get,
8175
+ set(value) {
8176
+ Object.defineProperty(this, key, {
8177
+ value,
8178
+ writable: true,
8179
+ configurable: true,
8180
+ enumerable: true
8181
+ });
8182
+ }
8183
+ });
8184
+ }
8185
+ __name(defineGetter, "defineGetter");
8139
8186
 
8140
8187
  // ../../src/Engines/Nunjucks.js
8141
8188
  var debug2 = createDebug4("Nunjucks");
@@ -8277,23 +8324,28 @@ var Nunjucks = class _Nunjucks extends TemplateEngine {
8277
8324
  }
8278
8325
  addFilters(filters, isAsync) {
8279
8326
  for (let name in filters) {
8280
- this.njkEnv.addFilter(name, _Nunjucks.wrapFilter(name, filters[name]), isAsync);
8327
+ this.njkEnv.addFilter(name, _Nunjucks.wrapFilter(name, filters[name], isAsync), isAsync);
8281
8328
  }
8282
8329
  }
8283
- static wrapFilter(name, fn) {
8330
+ static wrapFilter(name, fn, isAsync = false) {
8284
8331
  return function(...args) {
8332
+ let getError = /* @__PURE__ */ __name((e) => new BuildAwesomeNunjucksError(
8333
+ `Error in Nunjucks Filter \`${name}\`${this.page ? ` (${this.page.inputPath})` : ""}`,
8334
+ e
8335
+ ), "getError");
8285
8336
  try {
8286
8337
  augmentObject(this, {
8287
8338
  source: this.ctx,
8288
8339
  lazy: false
8289
8340
  // context.env?.opts.throwOnUndefined,
8290
8341
  });
8342
+ if (isAsync) {
8343
+ let cb = args.pop();
8344
+ args.push((error, result) => cb(error ? getError(error) : null, result));
8345
+ }
8291
8346
  return fn.call(this, ...args);
8292
8347
  } catch (e) {
8293
- throw new BuildAwesomeNunjucksError(
8294
- `Error in Nunjucks Filter \`${name}\`${this.page ? ` (${this.page.inputPath})` : ""}`,
8295
- e
8296
- );
8348
+ throw getError(e);
8297
8349
  }
8298
8350
  };
8299
8351
  }
@@ -1,4 +1,4 @@
1
- /*! Eleventy (Build Awesome) v4.0.0-alpha.11 (i18n Plugin) */
1
+ /*! Eleventy (Build Awesome) v4.0.0-alpha.12 (i18n Plugin) */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1236,6 +1236,9 @@ var require_Merge = __commonJS({
1236
1236
  target = {};
1237
1237
  }
1238
1238
  }
1239
+ if (sourcePlainObjectShortcut && Object.isFrozen(target) && isPlainObject(target)) {
1240
+ target = Object.assign({}, target);
1241
+ }
1239
1242
  if (Array.isArray(target) && Array.isArray(source)) {
1240
1243
  return target.concat(source);
1241
1244
  }
@@ -1269,6 +1272,9 @@ var require_Merge = __commonJS({
1269
1272
  if (isPlainObject(target)) {
1270
1273
  for (let key in target) {
1271
1274
  if (key.indexOf(OVERRIDE_PREFIX) === 0) {
1275
+ if (Object.isFrozen(target)) {
1276
+ target = Object.assign({}, target);
1277
+ }
1272
1278
  let cleanedKey = key.slice(OVERRIDE_PREFIX.length);
1273
1279
  if (cleanedKey !== UNSAFE_KEY) {
1274
1280
  target[cleanedKey] = target[key];
@@ -1288,8 +1294,8 @@ var require_Merge = __commonJS({
1288
1294
  return target;
1289
1295
  }
1290
1296
  __name(Merge, "Merge");
1297
+ Merge.DeepCopy = DeepCopy2;
1291
1298
  module.exports = Merge;
1292
- module.exports.DeepCopy = DeepCopy2;
1293
1299
  }
1294
1300
  });
1295
1301
 
@@ -1478,7 +1484,10 @@ var require_lib_sha256 = __commonJS({
1478
1484
  buf[bp++] = L >>> 8 & 255;
1479
1485
  buf[bp++] = L & 255;
1480
1486
  process2();
1481
- let reply = new Uint8Array(32);
1487
+ let reply = (
1488
+ /** @type {Uint8Array & { hex?: () => string }} */
1489
+ new Uint8Array(32)
1490
+ );
1482
1491
  reply[0] = h0 >>> 24;
1483
1492
  reply[1] = h0 >>> 16 & 255;
1484
1493
  reply[2] = h0 >>> 8 & 255;
@@ -1644,7 +1653,10 @@ var require_HashTypes = __commonJS({
1644
1653
  __name(this, "ScriptHash");
1645
1654
  }
1646
1655
  static toHash(...content) {
1647
- let hash = sha256();
1656
+ let hash = (
1657
+ /** @type {{ add: (data: any) => void, digest: () => Uint8Array }} */
1658
+ sha256()
1659
+ );
1648
1660
  for (let c of content) {
1649
1661
  hash.add(c);
1650
1662
  }
@@ -1978,19 +1990,26 @@ function I18nPlugin(eleventyConfig, opts = {}) {
1978
1990
  `Localized file for URL ${prependedLangCodeUrl} was not found in your project. A non-localized version does exist\u2014are you sure you meant to use the \`${options.filters.url}\` filter for this? You can bypass this error using the \`errorMode\` option in the I18N plugin (current value: "${options.errorMode}").`
1979
1991
  );
1980
1992
  }
1981
- } else if (options.errorMode === "allow-fallback") {
1993
+ } else if (options.errorMode !== "never") {
1982
1994
  throw new Error(
1983
1995
  `Localized file for URL ${prependedLangCodeUrl} was not found in your project! You will need to add it if you want to link to it using the \`${options.filters.url}\` filter. You can bypass this error using the \`errorMode\` option in the I18N plugin (current value: "${options.errorMode}").`
1984
1996
  );
1985
1997
  }
1986
1998
  return originalUrl;
1987
1999
  });
1988
- eleventyConfig.addFilter(options.filters.links, function(urlOverride) {
1989
- let url = urlOverride || this.page?.url;
1990
- return (contentMaps.localeUrlsMap[url] || []).filter((entry) => {
1991
- return entry.url !== url;
1992
- });
1993
- });
2000
+ eleventyConfig.addFilter(
2001
+ options.filters.links,
2002
+ function(urlOverride, { includeCurrent = false } = {}) {
2003
+ let url = urlOverride || this.page?.url;
2004
+ let entries = contentMaps.localeUrlsMap[url] || [];
2005
+ if (includeCurrent) {
2006
+ return entries.slice();
2007
+ }
2008
+ return entries.filter((entry) => {
2009
+ return entry.url !== url;
2010
+ });
2011
+ }
2012
+ );
1994
2013
  eleventyConfig.addFilter(
1995
2014
  "locale_page",
1996
2015
  // This is not exposed in `options` because it is an Eleventy internals filter (used in get*CollectionItem filters)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@11ty/client",
3
3
  "description": "Run Build Awesome (Eleventy) in your browser.",
4
- "version": "4.0.0-alpha.11",
4
+ "version": "4.0.0-alpha.12",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true