@soleil-se/config-svelte 1.7.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.8.0] - 2021-11-xx
9
+
10
+ ### Changed
11
+
12
+ - Improvements for passing server data to the app.
13
+ - Remove `hydrate` option since we're never using SSR in config apps.
14
+
15
+ ### Fixed
16
+
17
+ - Properly target div with id `app_root` when rendering app.
18
+
8
19
  ## [1.7.0] - 2021-09-24
9
20
 
10
21
  ### Added
@@ -1,15 +1,14 @@
1
1
  import 'focus-visible';
2
2
 
3
- export default function createConfigApp(App, { hydrate = true } = {}) {
3
+ export default function createConfigApp(App) {
4
4
  window.setValues = (values) => {
5
5
  window.CONFIG_VALUES = values;
6
6
  const app = new App({
7
- target: document.querySelector('#app_root, body'),
7
+ target: document.querySelector('#app_root') || document.querySelector('body'),
8
8
  props: {
9
- ...window.CONFIG_APP_DATA,
9
+ ...window.CONFIG_APP_PROPS,
10
10
  values,
11
11
  },
12
- hydrate,
13
12
  });
14
13
 
15
14
  return app;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/config-svelte",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "./index.js",
5
5
  "module": "./index.js",
6
6
  "svelte": "./index.js",
package/server/index.js CHANGED
@@ -1,3 +1,23 @@
1
- /* Might add more exports in the future */
2
- /* eslint-disable import/prefer-default-export */
3
- export { default as createAppData } from './createAppData';
1
+ /**
2
+ * Creates a HTML string for passing data to the app.
3
+ * @param {object} props Props to be passed to the app.
4
+ * @returns {string} HTML string to make props available to the app.
5
+ */
6
+ export function createAppProps(props) {
7
+ return `
8
+ <script>
9
+ window.CONFIG_APP_PROPS = ${JSON.stringify(props)};
10
+ </script>
11
+ <div id="app_root"></div>
12
+ `;
13
+ }
14
+
15
+ /**
16
+ * Creates a HTML string for passing data to the app.
17
+ * @param {object} data Data to be passed to the app.
18
+ * @deprecated Use `createAppProps` instead.
19
+ * @returns {string} HTML string to make data available to the config app.
20
+ */
21
+ export function createAppData(data) {
22
+ return createAppProps(data);
23
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get app props value or object that is passed to app when rendering.
3
+ * @export
4
+ * @param {string} [key] - Key for value.
5
+ * @return {*|object} - Value or object.
6
+ */
7
+ export default function getAppProps(key) {
8
+ return key ? window.CONFIG_APP_PROPS[key] : window.CONFIG_APP_PROPS;
9
+ }
package/utils/index.js CHANGED
@@ -5,3 +5,4 @@ export { default as addPrefix } from './addPrefix';
5
5
  export { default as pluckPrefix } from './pluckPrefix';
6
6
  export { default as triggerInput } from './triggerInput';
7
7
  export { default as createI18n } from './createI18n';
8
+ export { default as getAppProps } from './getAppProps';
@@ -1,8 +0,0 @@
1
- export default function createAppData(data) {
2
- return `
3
- <script>
4
- window.CONFIG_APP_DATA = ${JSON.stringify(data)};
5
- </script>
6
- <div id="app_root"></div>
7
- `;
8
- }