@movable/studio-framework 3.16.0-canary.0 → 3.16.1-canary.16

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.es.js CHANGED
@@ -146,13 +146,37 @@ class StyledElement extends React.Component {
146
146
  this.updateStyleElement();
147
147
  }
148
148
 
149
+ componentDidUpdate() {
150
+ this.updateStyleElement();
151
+ }
152
+
149
153
  render() {
150
154
  const {
151
155
  tag,
152
- children
156
+ children,
157
+ resolveProperty
153
158
  } = this.props;
154
159
  const style = styleFromAttributes(tag);
155
160
  const className = classNameFromAttributes(tag);
161
+ const href = resolveProperty && tag.dynamicHref ? resolveProperty(tag.dynamicHref) : null;
162
+
163
+ if (href) {
164
+ const analyticsId = tag.dynamicHref?.analyticsId;
165
+ return /*#__PURE__*/React.createElement("a", {
166
+ className: className,
167
+ style: {
168
+ textDecoration: 'none',
169
+ color: 'inherit',
170
+ ...style
171
+ },
172
+ href: href,
173
+ target: "_blank",
174
+ rel: "noopener noreferrer",
175
+ "data-mi-analytics-id": analyticsId || undefined,
176
+ ref: this.setStyleElementRef
177
+ }, children);
178
+ }
179
+
156
180
  return /*#__PURE__*/React.createElement("div", {
157
181
  className: className,
158
182
  style: style,
@@ -480,6 +504,29 @@ class TagComponent extends React.Component {
480
504
 
481
505
  }
482
506
 
507
+ function makeResolveProperty(propertyResolver) {
508
+ return function resolveProperty(prop) {
509
+ if (!prop) return null;
510
+
511
+ if (prop.propertyValue) {
512
+ return prop.propertyValue;
513
+ }
514
+
515
+ const {
516
+ propertyPath,
517
+ context,
518
+ propertyGroupKey = false
519
+ } = prop;
520
+ const [result] = propertyResolver.getPropertyStateTuple(propertyGroupKey, propertyPath, context);
521
+
522
+ if (result !== null && typeof result !== 'undefined' && result !== '') {
523
+ return result;
524
+ }
525
+
526
+ return prop.propertyFallback || null;
527
+ };
528
+ }
529
+
483
530
  class Tags extends React.Component {
484
531
  render() {
485
532
  const {
@@ -489,6 +536,7 @@ class Tags extends React.Component {
489
536
  tags,
490
537
  canvas
491
538
  } = this.props;
539
+ const resolveProperty = makeResolveProperty(propertyResolver);
492
540
  return tags.map((tag, index) => {
493
541
  const {
494
542
  subtags
@@ -496,7 +544,8 @@ class Tags extends React.Component {
496
544
  return /*#__PURE__*/React.createElement(StyledElement, {
497
545
  key: index,
498
546
  tag: tag,
499
- registryResolver: registryResolver
547
+ registryResolver: registryResolver,
548
+ resolveProperty: resolveProperty
500
549
  }, subtags ? /*#__PURE__*/React.createElement(Tags, {
501
550
  tags: subtags,
502
551
  canvas: canvas,
@@ -1900,11 +1949,55 @@ const getYPosition = justifyContent => {
1900
1949
  const RichTextSpan = ({
1901
1950
  attributes,
1902
1951
  insert,
1903
- fitToOneLine
1952
+ fitToOneLine,
1953
+ getPropertyWithFallback
1904
1954
  }) => {
1905
1955
  const whiteSpace = fitToOneLine ? 'nowrap' : 'pre-wrap';
1956
+
1957
+ if (attributes && attributes.dynamicLink) {
1958
+ try {
1959
+ const dynamicLinkData = typeof attributes.dynamicLink === 'string' ? JSON.parse(attributes.dynamicLink) : attributes.dynamicLink;
1960
+ let href = null;
1961
+
1962
+ if (dynamicLinkData.propertyValue) {
1963
+ href = dynamicLinkData.propertyValue;
1964
+ } else if (getPropertyWithFallback) {
1965
+ href = getPropertyWithFallback(dynamicLinkData);
1966
+ } else if (dynamicLinkData.propertyFallback) {
1967
+ href = dynamicLinkData.propertyFallback;
1968
+ }
1969
+
1970
+ if (href) {
1971
+ const {
1972
+ dynamicLink,
1973
+ ...cleanAttributes
1974
+ } = attributes;
1975
+ const styles = {
1976
+ color: 'inherit',
1977
+ textDecoration: 'inherit',
1978
+ ...normalizeRichTextStyles(cleanAttributes),
1979
+ whiteSpace
1980
+ };
1981
+ const analyticsId = dynamicLinkData.analyticsId;
1982
+ return /*#__PURE__*/React.createElement("a", {
1983
+ href: href,
1984
+ target: "_blank",
1985
+ rel: "noopener noreferrer",
1986
+ style: styles,
1987
+ "data-mi-analytics-id": analyticsId || undefined
1988
+ }, insert);
1989
+ }
1990
+ } catch (e) {// Parse error — fall through to render as span
1991
+ }
1992
+ }
1993
+
1994
+ const attrs = attributes || {};
1995
+ const {
1996
+ dynamicLink: _dl,
1997
+ ...cleanAttrs
1998
+ } = attrs;
1906
1999
  return /*#__PURE__*/React.createElement("span", {
1907
- style: { ...normalizeRichTextStyles(attributes),
2000
+ style: { ...normalizeRichTextStyles(cleanAttrs),
1908
2001
  whiteSpace
1909
2002
  }
1910
2003
  }, insert);
@@ -1916,12 +2009,13 @@ const isNewLine = ({
1916
2009
 
1917
2010
  const haveSpans = spans => spans.length;
1918
2011
 
1919
- const mapSpans = (spans, fitToOneLine) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React.createElement("br", {
2012
+ const mapSpans = (spans, fitToOneLine, getPropertyWithFallback) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React.createElement("br", {
1920
2013
  key: n
1921
2014
  }) : /*#__PURE__*/React.createElement(RichTextSpan, _extends({
1922
2015
  key: n
1923
2016
  }, span, {
1924
- fitToOneLine: fitToOneLine
2017
+ fitToOneLine: fitToOneLine,
2018
+ getPropertyWithFallback: getPropertyWithFallback
1925
2019
  })));
1926
2020
 
1927
2021
  class RichTextElement extends StudioTool {
@@ -2016,6 +2110,9 @@ class RichTextElement extends StudioTool {
2016
2110
  const {
2017
2111
  fitToOneLine = false
2018
2112
  } = this.props.tag;
2113
+ const {
2114
+ getPropertyWithFallback
2115
+ } = this.props;
2019
2116
  this.lastRichText = richTextStructure;
2020
2117
  const style = {
2021
2118
  fontSize: baseFontSize
@@ -2031,7 +2128,7 @@ class RichTextElement extends StudioTool {
2031
2128
  style: { ...attributes
2032
2129
  },
2033
2130
  key: i
2034
- }, haveSpans(spans) ? mapSpans(spans, fitToOneLine) : /*#__PURE__*/React.createElement("br", null))));
2131
+ }, haveSpans(spans) ? mapSpans(spans, fitToOneLine, getPropertyWithFallback) : /*#__PURE__*/React.createElement("br", null))));
2035
2132
  }
2036
2133
 
2037
2134
  }
package/dist/index.js CHANGED
@@ -156,13 +156,37 @@ class StyledElement extends React__default['default'].Component {
156
156
  this.updateStyleElement();
157
157
  }
158
158
 
159
+ componentDidUpdate() {
160
+ this.updateStyleElement();
161
+ }
162
+
159
163
  render() {
160
164
  const {
161
165
  tag,
162
- children
166
+ children,
167
+ resolveProperty
163
168
  } = this.props;
164
169
  const style = styleFromAttributes(tag);
165
170
  const className = classNameFromAttributes(tag);
171
+ const href = resolveProperty && tag.dynamicHref ? resolveProperty(tag.dynamicHref) : null;
172
+
173
+ if (href) {
174
+ const analyticsId = tag.dynamicHref?.analyticsId;
175
+ return /*#__PURE__*/React__default['default'].createElement("a", {
176
+ className: className,
177
+ style: {
178
+ textDecoration: 'none',
179
+ color: 'inherit',
180
+ ...style
181
+ },
182
+ href: href,
183
+ target: "_blank",
184
+ rel: "noopener noreferrer",
185
+ "data-mi-analytics-id": analyticsId || undefined,
186
+ ref: this.setStyleElementRef
187
+ }, children);
188
+ }
189
+
166
190
  return /*#__PURE__*/React__default['default'].createElement("div", {
167
191
  className: className,
168
192
  style: style,
@@ -490,6 +514,29 @@ class TagComponent extends React__default['default'].Component {
490
514
 
491
515
  }
492
516
 
517
+ function makeResolveProperty(propertyResolver) {
518
+ return function resolveProperty(prop) {
519
+ if (!prop) return null;
520
+
521
+ if (prop.propertyValue) {
522
+ return prop.propertyValue;
523
+ }
524
+
525
+ const {
526
+ propertyPath,
527
+ context,
528
+ propertyGroupKey = false
529
+ } = prop;
530
+ const [result] = propertyResolver.getPropertyStateTuple(propertyGroupKey, propertyPath, context);
531
+
532
+ if (result !== null && typeof result !== 'undefined' && result !== '') {
533
+ return result;
534
+ }
535
+
536
+ return prop.propertyFallback || null;
537
+ };
538
+ }
539
+
493
540
  class Tags extends React__default['default'].Component {
494
541
  render() {
495
542
  const {
@@ -499,6 +546,7 @@ class Tags extends React__default['default'].Component {
499
546
  tags,
500
547
  canvas
501
548
  } = this.props;
549
+ const resolveProperty = makeResolveProperty(propertyResolver);
502
550
  return tags.map((tag, index) => {
503
551
  const {
504
552
  subtags
@@ -506,7 +554,8 @@ class Tags extends React__default['default'].Component {
506
554
  return /*#__PURE__*/React__default['default'].createElement(StyledElement, {
507
555
  key: index,
508
556
  tag: tag,
509
- registryResolver: registryResolver
557
+ registryResolver: registryResolver,
558
+ resolveProperty: resolveProperty
510
559
  }, subtags ? /*#__PURE__*/React__default['default'].createElement(Tags, {
511
560
  tags: subtags,
512
561
  canvas: canvas,
@@ -1910,11 +1959,55 @@ const getYPosition = justifyContent => {
1910
1959
  const RichTextSpan = ({
1911
1960
  attributes,
1912
1961
  insert,
1913
- fitToOneLine
1962
+ fitToOneLine,
1963
+ getPropertyWithFallback
1914
1964
  }) => {
1915
1965
  const whiteSpace = fitToOneLine ? 'nowrap' : 'pre-wrap';
1966
+
1967
+ if (attributes && attributes.dynamicLink) {
1968
+ try {
1969
+ const dynamicLinkData = typeof attributes.dynamicLink === 'string' ? JSON.parse(attributes.dynamicLink) : attributes.dynamicLink;
1970
+ let href = null;
1971
+
1972
+ if (dynamicLinkData.propertyValue) {
1973
+ href = dynamicLinkData.propertyValue;
1974
+ } else if (getPropertyWithFallback) {
1975
+ href = getPropertyWithFallback(dynamicLinkData);
1976
+ } else if (dynamicLinkData.propertyFallback) {
1977
+ href = dynamicLinkData.propertyFallback;
1978
+ }
1979
+
1980
+ if (href) {
1981
+ const {
1982
+ dynamicLink,
1983
+ ...cleanAttributes
1984
+ } = attributes;
1985
+ const styles = {
1986
+ color: 'inherit',
1987
+ textDecoration: 'inherit',
1988
+ ...normalizeRichTextStyles(cleanAttributes),
1989
+ whiteSpace
1990
+ };
1991
+ const analyticsId = dynamicLinkData.analyticsId;
1992
+ return /*#__PURE__*/React__default['default'].createElement("a", {
1993
+ href: href,
1994
+ target: "_blank",
1995
+ rel: "noopener noreferrer",
1996
+ style: styles,
1997
+ "data-mi-analytics-id": analyticsId || undefined
1998
+ }, insert);
1999
+ }
2000
+ } catch (e) {// Parse error — fall through to render as span
2001
+ }
2002
+ }
2003
+
2004
+ const attrs = attributes || {};
2005
+ const {
2006
+ dynamicLink: _dl,
2007
+ ...cleanAttrs
2008
+ } = attrs;
1916
2009
  return /*#__PURE__*/React__default['default'].createElement("span", {
1917
- style: { ...normalizeRichTextStyles(attributes),
2010
+ style: { ...normalizeRichTextStyles(cleanAttrs),
1918
2011
  whiteSpace
1919
2012
  }
1920
2013
  }, insert);
@@ -1926,12 +2019,13 @@ const isNewLine = ({
1926
2019
 
1927
2020
  const haveSpans = spans => spans.length;
1928
2021
 
1929
- const mapSpans = (spans, fitToOneLine) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React__default['default'].createElement("br", {
2022
+ const mapSpans = (spans, fitToOneLine, getPropertyWithFallback) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React__default['default'].createElement("br", {
1930
2023
  key: n
1931
2024
  }) : /*#__PURE__*/React__default['default'].createElement(RichTextSpan, _extends({
1932
2025
  key: n
1933
2026
  }, span, {
1934
- fitToOneLine: fitToOneLine
2027
+ fitToOneLine: fitToOneLine,
2028
+ getPropertyWithFallback: getPropertyWithFallback
1935
2029
  })));
1936
2030
 
1937
2031
  class RichTextElement extends StudioTool {
@@ -2026,6 +2120,9 @@ class RichTextElement extends StudioTool {
2026
2120
  const {
2027
2121
  fitToOneLine = false
2028
2122
  } = this.props.tag;
2123
+ const {
2124
+ getPropertyWithFallback
2125
+ } = this.props;
2029
2126
  this.lastRichText = richTextStructure;
2030
2127
  const style = {
2031
2128
  fontSize: baseFontSize
@@ -2041,7 +2138,7 @@ class RichTextElement extends StudioTool {
2041
2138
  style: { ...attributes
2042
2139
  },
2043
2140
  key: i
2044
- }, haveSpans(spans) ? mapSpans(spans, fitToOneLine) : /*#__PURE__*/React__default['default'].createElement("br", null))));
2141
+ }, haveSpans(spans) ? mapSpans(spans, fitToOneLine, getPropertyWithFallback) : /*#__PURE__*/React__default['default'].createElement("br", null))));
2045
2142
  }
2046
2143
 
2047
2144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movable/studio-framework",
3
- "version": "3.16.0-canary.0",
3
+ "version": "3.16.1-canary.16+522db5c7",
4
4
  "description": "A Component library for reactive Studio apps.",
5
5
  "author": "Movable Ink",
6
6
  "repository": "movableink/studio-framework",
@@ -31,8 +31,8 @@
31
31
  "@babel/preset-react": "^7.14.5",
32
32
  "@babel/preset-typescript": "^7.13.0",
33
33
  "@movable/eslint-config-react": "^1.0.1",
34
- "@movable/framework-types": "^3.16.0-canary.0",
35
- "@movable/studio-framework-test-helpers": "^3.16.0-canary.0",
34
+ "@movable/framework-types": "^3.16.1-canary.16+522db5c7",
35
+ "@movable/studio-framework-test-helpers": "^3.16.1-canary.16+522db5c7",
36
36
  "@types/qunit": "^2.11.1",
37
37
  "@types/qunit-dom": "^0.7.0",
38
38
  "@types/react": "^17.0.6",
@@ -66,5 +66,5 @@
66
66
  "volta": {
67
67
  "extends": "../../package.json"
68
68
  },
69
- "gitHead": "d6f0e51a3681678cd00f243f26f42dc49b54b578"
69
+ "gitHead": "522db5c7e47fc01f7087933d9091b2396d5f7815"
70
70
  }